]> git.basschouten.com Git - openhab-addons.git/blob
9f029d51a42b92cee81e745bd554a0a6e74f713c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.DrawingSettings;
20 import org.openhab.binding.nanoleaf.internal.layout.ImagePoint2D;
21 import org.openhab.binding.nanoleaf.internal.layout.PanelState;
22 import org.openhab.binding.nanoleaf.internal.layout.Point2D;
23 import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
24
25 /**
26  * Panel is a physical piece of plastic you place on the wall and connect to other panels.
27  *
28  * @author Jørgen Austvik - Initial contribution
29  */
30 @NonNullByDefault
31 public abstract class Panel {
32     private final ShapeType shapeType;
33
34     public Panel(ShapeType shapeType) {
35         this.shapeType = shapeType;
36     }
37
38     public ShapeType getShapeType() {
39         return shapeType;
40     }
41
42     /**
43      * Calculates the minimal bounding rectangle around an outline.
44      *
45      * @param outline The outline to find the minimal bounding rectangle around
46      * @return The opposite points of the minimum bounding rectangle around this shape.
47      */
48     public Point2D[] findBounds(List<ImagePoint2D> outline) {
49         int minX = Integer.MAX_VALUE;
50         int minY = Integer.MAX_VALUE;
51         int maxX = Integer.MIN_VALUE;
52         int maxY = Integer.MIN_VALUE;
53
54         for (ImagePoint2D point : outline) {
55             maxX = Math.max(point.getX(), maxX);
56             maxY = Math.max(point.getY(), maxY);
57             minX = Math.min(point.getX(), minX);
58             minY = Math.min(point.getY(), minY);
59         }
60
61         return new Point2D[] { new Point2D(minX, minY), new Point2D(maxX, maxY) };
62     }
63
64     /**
65      * Generate the outline of the shape.
66      *
67      * @return The points that make up this shape.
68      */
69     public abstract List<Point2D> generateOutline();
70
71     /**
72      * Draws the shape on the the supplied graphics.
73      *
74      * @param graphics The picture to draw on
75      * @param settings Information on how to draw
76      * @param state The state of the panels to draw
77      */
78     public abstract void draw(Graphics2D graphics, DrawingSettings settings, PanelState state);
79 }