X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FPolygon.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FPolygon.java;h=d5f558ea5e34c3edd4b878e8e37d9891d76a175d;hp=5475badee9224bbd4170d1f26622379b4ae3d2c8;hb=7e383c71392e298dde478015129bc739f3eb4e4a;hpb=f3da0bbe2c31d899156d410f8e75dabb0255efdf 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 5475bad..d5f558e 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Polygon.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Polygon.java @@ -20,7 +20,7 @@ public class Polygon { private static boolean intersectsLine(final Point2D point, Point2D lineP1, Point2D lineP2) { - // Sort line points by y coordinate. + // Sort line points by y coordinate. if (lineP1.y > lineP2.y) { final Point2D tmp = lineP1; lineP1 = lineP2; @@ -28,21 +28,16 @@ public class Polygon { } // Check if point is within line y range. - if (point.y < lineP1.y) - return false; - if (point.y > lineP2.y) + if (point.y < lineP1.y || point.y > lineP2.y) return false; // 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 - lineP1.y; - - final double crossX = lineP1.x + ((xp * yp2) / yp); + final double crossX = lineP1.x + ((xp * (point.y - lineP1.y)) / yp); return point.x >= crossX; - } public static boolean pointWithinPolygon(final Point2D point,