You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2020/06/16 07:02:15 UTC

[lucene-solr] branch branch_8x updated: LUCENE-9400: Tessellator might fail when several holes share the same vertex (#1562)

This is an automated email from the ASF dual-hosted git repository.

ivera pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new d78f430  LUCENE-9400: Tessellator might fail when several holes share the same vertex (#1562)
d78f430 is described below

commit d78f430eca3588ac35d4994de6670637016a90b2
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Tue Jun 16 09:00:36 2020 +0200

    LUCENE-9400: Tessellator might fail when several holes share the same vertex (#1562)
---
 lucene/CHANGES.txt                                              | 2 ++
 lucene/core/src/java/org/apache/lucene/geo/Tessellator.java     | 7 ++++++-
 lucene/core/src/test/org/apache/lucene/geo/TestTessellator.java | 8 ++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 83f7fad..0bbf6c8 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -132,6 +132,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.java
index c61fba9..1600955 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.java
index 0d1f270..2410ba1 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);