Updated copyright
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / geometry / Point2D.java
index a74baee..834ffb1 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Sixth 3D engine. Copyright ©2012-2019, 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
@@ -9,6 +9,8 @@
 
 package eu.svjatoslav.sixth.e3d.geometry;
 
+import static java.lang.Math.sqrt;
+
 public class Point2D implements Cloneable {
 
     public double x, y;
@@ -32,6 +34,10 @@ public class Point2D implements Cloneable {
         return this;
     }
 
+    public boolean isZero() {
+        return (x == 0) && (y == 0);
+    }
+
     @Override
     public Point2D clone() {
         return new Point2D(this);
@@ -42,7 +48,7 @@ public class Point2D implements Cloneable {
         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;
@@ -52,11 +58,18 @@ public class Point2D implements Cloneable {
         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() {
@@ -70,9 +83,9 @@ public class Point2D implements Cloneable {
         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;
     }
 
@@ -86,4 +99,11 @@ public class Point2D implements Cloneable {
         return this;
     }
 
+    @Override
+    public String toString() {
+        return "Point2D{" +
+                "x=" + x +
+                ", y=" + y +
+                '}';
+    }
 }