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=71ad56419ffa6e502497ae66b99d835b4b3e1aae;hp=7ada97fbb621c09f583e1a5cca6a87df3f260905;hb=0590faa0f0434ebb29955a711299f8ad5ac226d6;hpb=b1e8d7bd8c9d0905e9fe3c46fc84a11779b95982 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 7ada97f..71ad564 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java @@ -1,5 +1,5 @@ /* - * Sixth 3D engine. Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Sixth 3D engine. Copyright ©2012-2018, 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 + + '}'; + } }