LUCENE-9400: Tessellator might fail when several holes share the same vertex (#1562)

This commit is contained in:
Ignacio Vera 2020-06-16 09:00:36 +02:00 committed by GitHub
parent 2da71c2a40
commit 75491ab381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -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
---------------------

View File

@ -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);

View File

@ -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);