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
14 package org.openhab.binding.nanoleaf.internal.layout;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
19 * Coordinate in 2D space.
21 * @author Jørgen Austvik - Initial contribution
24 public class Point2D {
28 public Point2D(int x, int y) {
42 * Rotates the point a given amount of radians.
44 * @param radians The amount to rotate the point
45 * @return A new point which is rotated
47 public Point2D rotate(double radians) {
48 double sinAngle = Math.sin(radians);
49 double cosAngle = Math.cos(radians);
51 int newX = (int) (cosAngle * x - sinAngle * y);
52 int newY = (int) (sinAngle * x + cosAngle * y);
53 return new Point2D(newX, newY);
57 * Move the point in x and y direction.
59 * @param moveX Amount to move in x direction
60 * @param moveY Amount to move in y direction
63 public Point2D move(int moveX, int moveY) {
64 return new Point2D(getX() + moveX, getY() + moveY);
68 * Move the point in x and y direction,.
70 * @param offset Offset to move
73 public Point2D move(Point2D offset) {
74 return move(offset.getX(), offset.getY());
78 public String toString() {
79 return String.format("x:%d, y:%d", x, y);