diff --git a/src/main/java/com/github/davidmoten/rtree/geometry/Line.java b/src/main/java/com/github/davidmoten/rtree/geometry/Line.java index c86f5a5a..340215e8 100644 --- a/src/main/java/com/github/davidmoten/rtree/geometry/Line.java +++ b/src/main/java/com/github/davidmoten/rtree/geometry/Line.java @@ -3,7 +3,7 @@ import com.github.davidmoten.guavamini.Objects; import com.github.davidmoten.guavamini.Optional; import com.github.davidmoten.rtree.internal.Line2D; -import com.github.davidmoten.rtree.internal.Rectangle2D; +import com.github.davidmoten.rtree.internal.RectangleUtil; import com.github.davidmoten.rtree.internal.util.ObjectsHelper; /** @@ -72,7 +72,7 @@ public Rectangle mbr() { @Override public boolean intersects(Rectangle r) { - return Rectangle2D.rectangleIntersectsLine(r.x1(), r.y1(), r.x2() - r.x1(), r.y2() - r.y1(), + return RectangleUtil.rectangleIntersectsLine(r.x1(), r.y1(), r.x2() - r.x1(), r.y2() - r.y1(), x1, y1, x2, y2); } diff --git a/src/main/java/com/github/davidmoten/rtree/internal/Rectangle2D.java b/src/main/java/com/github/davidmoten/rtree/internal/RectangleUtil.java similarity index 93% rename from src/main/java/com/github/davidmoten/rtree/internal/Rectangle2D.java rename to src/main/java/com/github/davidmoten/rtree/internal/RectangleUtil.java index ea83de9c..beeb450c 100644 --- a/src/main/java/com/github/davidmoten/rtree/internal/Rectangle2D.java +++ b/src/main/java/com/github/davidmoten/rtree/internal/RectangleUtil.java @@ -1,6 +1,10 @@ package com.github.davidmoten.rtree.internal; -public class Rectangle2D { +public final class RectangleUtil { + + private RectangleUtil() { + // prevent instantiation + } /** * The bitmask that indicates that a point lies to the left of this @@ -89,9 +93,10 @@ private static boolean pointOnSegment(double x, double y, double x1, double y1, double y2) { if (x < x1 || x > x2 || y < y1 || y > y2) { return false; + } else { + double v = (y2 - y1) * (x - x1) - (x2 - x1) * (y - y1); + return Math.abs(v) < PRECISION; } - double v = (y2 - y1) * (x - x1) - (x2 - x1) * (y - y1); - return Math.abs(v) < PRECISION; } private static int outcode(double rectX, double rectY, double rectWidth, double rectHeight, diff --git a/src/test/java/com/github/davidmoten/rtree/internal/RectangleUtilTest.java b/src/test/java/com/github/davidmoten/rtree/internal/RectangleUtilTest.java new file mode 100644 index 00000000..a3574217 --- /dev/null +++ b/src/test/java/com/github/davidmoten/rtree/internal/RectangleUtilTest.java @@ -0,0 +1,14 @@ +package com.github.davidmoten.rtree.internal; + +import org.junit.Test; + +import com.github.davidmoten.junit.Asserts; + +public class RectangleUtilTest { + + @Test + public void isUtilityClass() { + Asserts.assertIsUtilityClass(RectangleUtil.class); + } + +}