2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nanoleaf.internal.layout.shape;
15 import java.awt.Graphics2D;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.nanoleaf.internal.layout.Point2D;
20 import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
23 * Shape that can be drawn.
25 * @author Jørgen Austvik - Initial contribution
28 public abstract class Shape {
29 private final ShapeType shapeType;
30 private final int panelId;
31 private final Point2D position;
32 private final int orientation;
34 public Shape(ShapeType shapeType, int panelId, Point2D position, int orientation) {
35 this.shapeType = shapeType;
36 this.panelId = panelId;
37 this.position = position;
38 this.orientation = orientation;
41 public int getPanelId() {
45 public Point2D getPosition() {
49 public int getOrientation() {
53 public ShapeType getShapeType() {
58 * @return The opposite points of the minimum bounding rectangle around this shape.
60 public Point2D[] findBounds(List<Point2D> outline) {
61 int minX = Integer.MAX_VALUE;
62 int minY = Integer.MAX_VALUE;
63 int maxX = Integer.MIN_VALUE;
64 int maxY = Integer.MIN_VALUE;
66 for (Point2D point : outline) {
67 maxX = Math.max(point.getX(), maxX);
68 maxY = Math.max(point.getY(), maxY);
69 minX = Math.min(point.getX(), minX);
70 minY = Math.min(point.getY(), minY);
73 return new Point2D[] { new Point2D(minX, minY), new Point2D(maxX, maxY) };
77 * @return The points that make up this shape.
79 public abstract List<Point2D> generateOutline();
82 * @return The position where the label of the shape should be placed
84 public abstract Point2D labelPosition(Graphics2D graphics, List<Point2D> outline);