X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FPoint2D.java;h=1cfd39c246e6319c7d8a0d0fe1af9b223e452195;hp=f8fbef9ff43a7700f5ec015b9c0095c826bc2e7f;hb=baab2e2c2ad89695293f3136311c585c9a5afed1;hpb=2e7e46514dd35006e9dde07b1959540078292691 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java index f8fbef9..1cfd39c 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java @@ -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; }