2 * Copyright (c) 2010-2023 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.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;
26 * Panel is a physical piece of plastic you place on the wall and connect to other panels.
28 * @author Jørgen Austvik - Initial contribution
31 public abstract class Panel {
32 private final ShapeType shapeType;
34 public Panel(ShapeType shapeType) {
35 this.shapeType = shapeType;
38 public ShapeType getShapeType() {
43 * Calculates the minimal bounding rectangle around an outline.
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.
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;
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);
61 return new Point2D[] { new Point2D(minX, minY), new Point2D(maxX, maxY) };
65 * Generate the outline of the shape.
67 * @return The points that make up this shape.
69 public abstract List<Point2D> generateOutline();
72 * Draws the shape on the the supplied graphics.
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
78 public abstract void draw(Graphics2D graphics, DrawingSettings settings, PanelState state);