Skip to content

Apache Lucene open-source search software

LUCENE-8559: Fix bug where polygon edges were skipped when checking for intersections

iverase9952af099ae6
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 313d7bf3188..dadc53d89fd 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -226,6 +226,9 @@ Bug fixes:
* LUCENE-8534: Fix incorrect computation for triangles intersecting polygon edges in
shape tessellation. (Ignacio Vera)
+* LUCENE-8559: Fix bug where polygon edges were skipped when checking for intersections.
+ (Ignacio Vera)
+
New Features
* LUCENE-8496: Selective indexing - modify BKDReader/BKDWriter to allow users
diff --git a/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java b/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
index 345a73b9381..8fa685ce7e3 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
@@ -540,9 +540,7 @@ final public class Tessellator {
Node nextNode;
do {
nextNode = node.next;
- if(node.getX() != x0 && node.getY() != y0 && nextNode.getX() != x0
- && nextNode.getY() != y0 && node.getX() != x1 && node.getY() != y1
- && nextNode.getX() != x1 && nextNode.getY() != y1) {
+ if(isVertexEquals(node, x0, y0) == false && isVertexEquals(node, x1, y1) == false) {
if (linesIntersect(node.getX(), node.getY(), nextNode.getX(), nextNode.getY(), x0, y0, x1, y1)) {
return true;
}
@@ -709,7 +707,12 @@ final public class Tessellator {
/** Determines if two point vertices are equal. **/
private static final boolean isVertexEquals(final Node a, final Node b) {
- return a.getX() == b.getX() && a.getY() == b.getY();
+ return isVertexEquals(a, b.getX(), b.getY());
+ }
+
+ /** Determines if two point vertices are equal. **/
+ private static final boolean isVertexEquals(final Node a, final double x, final double y) {
+ return a.getX() == x && a.getY() == y;
}
/** Compute signed area of triangle */
diff --git a/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java b/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java
index 82ba5b41698..7904725d9a3 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java
@@ -96,4 +96,11 @@ public class TestTessellator extends LuceneTestCase {
Polygon polygon = (Polygon)SimpleWKTShapeParser.parse(wkt);
assertTrue(Tessellator.tessellate(polygon).size() == 8);
}
+
+ public void testLUCENE8559() throws Exception {
+ String wkt = "POLYGON((-0.1348674 51.7458255,-0.1345884 51.7455067,-0.1329898 51.745314,-0.1326358 51.745314,-0.1324105 51.744404,-0.131981 51.7444423,-0.1312196 51.7445102,-0.1310908 51.7456794,-0.1319706 51.7460713,-0.1343095 51.7465828,-0.1348674 51.7458255)," +
+ "(-0.1322388 51.7447959,-0.1322388 51.7454336,-0.1318633 51.7457126,-0.1313912 51.7456262,-0.1318985 51.7448032,-0.1322388 51.7447959))";
+ Polygon polygon = (Polygon)SimpleWKTShapeParser.parse(wkt);
+ assertTrue(Tessellator.tessellate(polygon).size() > 0);
+ }
}
\ No newline at end of file