From: Svjatoslav Agejenko Date: Wed, 29 Mar 2023 20:14:54 +0000 (+0300) Subject: Updated readability of the code. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=f3da0bbe2c31d899156d410f8e75dabb0255efdf;p=sixth-3d.git Updated readability of the code. --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Circle.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Circle.java index 6201765..2ac177d 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Circle.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Circle.java @@ -9,7 +9,14 @@ package eu.svjatoslav.sixth.e3d.geometry; */ public class Circle { - Point2D center; + /** + * The center of the circle. + */ + Point2D location; + + /** + * The radius of the circle. + */ double radius; } 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 f2d2603..a6bb6a1 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point2D.java @@ -8,6 +8,8 @@ import static java.lang.Math.sqrt; /** * Used to represent point in a 2D space or vector. + * + * @see Point3D */ public class Point2D implements Cloneable { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java index 3b8ad22..440023f 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -10,6 +10,8 @@ import static java.lang.Math.*; /** * Used to represent point in a 3D space or vector. + * + * @see Point2D */ public class Point3D implements Cloneable { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Polygon.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Polygon.java index b630ca3..5475bad 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Polygon.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Polygon.java @@ -9,26 +9,37 @@ package eu.svjatoslav.sixth.e3d.geometry; */ public class Polygon { - private static boolean intersectsLine(final Point2D point, Point2D p1, - Point2D p2) { - if (p1.y > p2.y) { - final Point2D tmp = p1; - p1 = p2; - p2 = tmp; + /** + * Checks if point is on the right side of the line. + * @param point point to check + * @param lineP1 line start point + * @param lineP2 line end point + * @return true if point is on the right side of the line + */ + private static boolean intersectsLine(final Point2D point, Point2D lineP1, + Point2D lineP2) { + + // Sort line points by y coordinate. + if (lineP1.y > lineP2.y) { + final Point2D tmp = lineP1; + lineP1 = lineP2; + lineP2 = tmp; } - if (point.y < p1.y) + // Check if point is within line y range. + if (point.y < lineP1.y) return false; - if (point.y > p2.y) + if (point.y > lineP2.y) return false; - final double xp = p2.x - p1.x; - final double yp = p2.y - p1.y; + // Check if point is on the line. + final double xp = lineP2.x - lineP1.x; + final double yp = lineP2.y - lineP1.y; - final double yp2 = point.y - p1.y; + final double yp2 = point.y - lineP1.y; - final double crossX = p1.x + ((xp * yp2) / yp); + final double crossX = lineP1.x + ((xp * yp2) / yp); return point.x >= crossX;