]> git.basschouten.com Git - openhab-addons.git/blob
99412ba2ea63e4594c02d3b7c40c1ac534639265
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nanoleaf.internal.layout.shape;
14
15 import java.awt.Graphics2D;
16 import java.util.List;
17
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;
21
22 /**
23  * Shape that can be drawn.
24  *
25  * @author Jørgen Austvik - Initial contribution
26  */
27 @NonNullByDefault
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;
33
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;
39     }
40
41     public int getPanelId() {
42         return panelId;
43     };
44
45     public Point2D getPosition() {
46         return position;
47     }
48
49     public int getOrientation() {
50         return orientation;
51     };
52
53     public ShapeType getShapeType() {
54         return shapeType;
55     }
56
57     /**
58      * @return The opposite points of the minimum bounding rectangle around this shape.
59      */
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;
65
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);
71         }
72
73         return new Point2D[] { new Point2D(minX, minY), new Point2D(maxX, maxY) };
74     }
75
76     /**
77      * @return The points that make up this shape.
78      */
79     public abstract List<Point2D> generateOutline();
80
81     /**
82      * @return The position where the label of the shape should be placed
83      */
84     public abstract Point2D labelPosition(Graphics2D graphics, List<Point2D> outline);
85 }