/*
- * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
*/
-
package eu.svjatoslav.sixth.e3d.geometry;
+import static java.lang.Math.sqrt;
+
public class Point2D implements Cloneable {
public double x, y;
return this;
}
+ public boolean isZero() {
+ return (x == 0) && (y == 0);
+ }
+
@Override
public Point2D clone() {
return new Point2D(this);
y = source.y;
}
- public Point2D computeMiddlePoint(final Point2D p1, final Point2D p2) {
+ public Point2D getMiddle(final Point2D p1, final Point2D p2) {
x = (p1.x + p2.x) / 2d;
y = (p1.y + p2.y) / 2d;
return this;
return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
}
+ /**
+ * Compute distance to another point.
+ */
public double getDistanceTo(final Point2D anotherPoint) {
final double xDiff = x - anotherPoint.x;
final double yDiff = y - anotherPoint.y;
- return Math.sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
+ return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
+ }
+
+ public double getVectorLength() {
+ return sqrt(((x * x) + (y * y)));
}
public Point2D invert() {
y = (int) y;
}
- public Point2D subtract(final Point2D direction) {
- x -= direction.x;
- y -= direction.y;
+ public Point2D subtract(final Point2D point) {
+ x -= point.x;
+ y -= point.y;
return this;
}
return this;
}
+ @Override
+ public String toString() {
+ return "Point2D{" +
+ "x=" + x +
+ ", y=" + y +
+ '}';
+ }
}