Apache Lucene open-source search software
LUCENE-9400: Tessellator might fail when several holes share the same vertex (#1562)
Ignacio Vera75491ab3814c
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 9524a02dfce..da609cec0fd 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -269,6 +269,8 @@ Bug Fixes* LUCENE-9405: IndexWriter incorrectly calls closeMergeReaders twice when the merged segment is 100% deleted.(Michael Froh, Simon Willnauer, Mike Mccandless, Mike Sokolov)+* LUCENE-9400: Tessellator might build illegal polygons when several holes share the shame vertex. (Ignacio Vera)+Other---------------------diff --git a/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java b/lucene/core/src/java/org/apache/lucene/geo/Tessellator.javaindex c61fba938c3..1600955b172 100644--- a/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java+++ b/lucene/core/src/java/org/apache/lucene/geo/Tessellator.java@@ -376,7 +376,12 @@ final public class Tessellator {Node next = polygon;do {if (isVertexEquals(next, vertex)) {- return next;+ // make sure we are not crossing the polygon. This might happen when several holes share the same polygon vertex.+ boolean crosses = GeoUtils.lineCrossesLine(next.previous.getX(), next.previous.getY(), vertex.next.getX(), vertex.next.getY(),+ next.next.getX(), next.next.getY(), vertex.previous.getX(), vertex.previous.getY());+ if (crosses == false) {+ return next;+ }}next = next.next;} while(next != polygon);diff --git a/lucene/core/src/test/org/apache/lucene/geo/TestTessellator.java b/lucene/core/src/test/org/apache/lucene/geo/TestTessellator.javaindex 0d1f270776e..2410ba13a5d 100644--- a/lucene/core/src/test/org/apache/lucene/geo/TestTessellator.java+++ b/lucene/core/src/test/org/apache/lucene/geo/TestTessellator.java@@ -573,6 +573,14 @@ public class TestTessellator extends LuceneTestCase {}}+ public void testComplexPolygon41() throws Exception {+ String wkt = "POLYGON((-1.569137181294115 54.4855283059375, -1.5692505240440333 54.48535373128068, -1.5684753656387294 54.48534438253056, -1.568606793880459 54.485674703738624, -1.5694141387939453 54.48611720532629, -1.569137181294115 54.4855283059375)," ++ "(-1.569137181294115 54.4855283059375, -1.5690783030431206 54.48545352137167, -1.5689449291711688 54.48547663706703, -1.569137181294115 54.4855283059375)," ++ "(-1.5689449291711688 54.48547663706703, -1.5689437289004642 54.48535482680399, -1.5687730514221028 54.48538045082698, -1.5689449291711688 54.48547663706703)," ++ "(-1.5689449291711688 54.48547663706703, -1.5689879483854345 54.485580118416785, -1.5687756358893499 54.485612860811244, -1.568765285875931 54.485496217554285, -1.5689449291711688 54.48547663706703))";+ checkPolygon(wkt);+ }+private void checkPolygon(String wkt) throws Exception {Polygon polygon = (Polygon) SimpleWKTShapeParser.parse(wkt);List<Tessellator.Triangle> tessellation = Tessellator.tessellate(polygon);