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.awt.geom.Rectangle2D;
17 import java.util.Arrays;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.nanoleaf.internal.layout.ImagePoint2D;
22 import org.openhab.binding.nanoleaf.internal.layout.Point2D;
23 import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
28 * @author Jørgen Austvik - Initial contribution
31 public class Hexagon extends Shape {
33 public Hexagon(ShapeType shapeType, int panelId, Point2D position, int orientation) {
34 super(shapeType, panelId, position, orientation);
38 public List<Point2D> generateOutline() {
39 Point2D v1 = new Point2D((int) getShapeType().getSideLength(), 0);
40 Point2D v2 = v1.rotate((1.0 / 3.0) * Math.PI);
41 Point2D v3 = v1.rotate((2.0 / 3.0) * Math.PI);
42 Point2D v4 = v1.rotate((3.0 / 3.0) * Math.PI);
43 Point2D v5 = v1.rotate((4.0 / 3.0) * Math.PI);
44 Point2D v6 = v1.rotate((5.0 / 3.0) * Math.PI);
45 return Arrays.asList(v1.move(getPosition()), v2.move(getPosition()), v3.move(getPosition()),
46 v4.move(getPosition()), v5.move(getPosition()), v6.move(getPosition()));
50 protected ImagePoint2D labelPosition(Graphics2D graphics, List<ImagePoint2D> outline) {
51 Point2D[] bounds = findBounds(outline);
52 int midX = bounds[0].getX() + (bounds[1].getX() - bounds[0].getX()) / 2;
53 int midY = bounds[0].getY() + (bounds[1].getY() - bounds[0].getY()) / 2;
55 Rectangle2D rect = graphics.getFontMetrics().getStringBounds(Integer.toString(getPanelId()), graphics);
56 return new ImagePoint2D(midX - (int) (rect.getWidth() / 2), midY + (int) (rect.getHeight() / 2));