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 2018/11/02 06:52:16 UTC
lucene-solr:master: LUCENE-8549: Polygon tessellator throws an error
if some parts of the shape could not be processed
Repository: lucene-solr
Updated Branches:
refs/heads/master 6ae9aa2a3 -> f7720aad8
LUCENE-8549: Polygon tessellator throws an error if some parts of the shape could not be processed
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/f7720aad
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/f7720aad
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/f7720aad
Branch: refs/heads/master
Commit: f7720aad82c6340558728c4fdc4dd716104f05f1
Parents: 6ae9aa2
Author: iverase <iv...@apache.org>
Authored: Fri Nov 2 07:50:41 2018 +0100
Committer: iverase <iv...@apache.org>
Committed: Fri Nov 2 07:50:41 2018 +0100
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +++
.../src/java/org/apache/lucene/geo/Tessellator.java | 12 ++++++++----
.../src/test/org/apache/lucene/geo/TestTessellator.java | 6 ++++++
3 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7720aad/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 64c2c6d..22b4089 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -238,6 +238,9 @@ Improvements:
Bug Fixes:
+* LUCENE-8549: Polygon tessellator throws an error if some parts of the shape
+ could not be processed. (Ignacio Vera)
+
* LUCENE-8540: Better handling of min/max values for Geo3d encoding. (Ignacio Vera)
* LUCENE-8534: Fix incorrect computation for triangles intersecting polygon edges in
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7720aad/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
----------------------------------------------------------------------
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 9f72b22..048125a 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
@@ -321,7 +321,10 @@ final public class Tessellator {
continue earcut;
case SPLIT:
// as a last resort, try splitting the remaining polygon into two
- splitEarcut(currEar, tessellation, mortonOptimized);
+ if (splitEarcut(currEar, tessellation, mortonOptimized) == false) {
+ //we could not process all points. Tessellation failed
+ tessellation.clear();
+ }
break;
}
break;
@@ -439,8 +442,8 @@ final public class Tessellator {
return node;
}
- /** Attempt to split a polygon and independently triangulate each side **/
- private static final void splitEarcut(final Node start, final List<Triangle> tessellation, final boolean mortonIndexed) {
+ /** Attempt to split a polygon and independently triangulate each side. Return true if the polygon was splitted **/
+ private static final boolean splitEarcut(final Node start, final List<Triangle> tessellation, final boolean mortonIndexed) {
// Search for a valid diagonal that divides the polygon into two.
Node searchNode = start;
Node nextNode;
@@ -462,12 +465,13 @@ final public class Tessellator {
earcutLinkedList(searchNode, tessellation, State.INIT, mortonIndexed);
earcutLinkedList(splitNode, tessellation, State.INIT, mortonIndexed);
// Finish the iterative search
- return;
+ return true;
}
diagonal = diagonal.next;
}
searchNode = searchNode.next;
} while (searchNode != start);
+ return false;
}
/** Links two polygon vertices using a bridge. **/
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7720aad/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java
----------------------------------------------------------------------
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 a2e9a8a..5cc9da1 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/geo/TestTessellator.java
@@ -84,4 +84,10 @@ public class TestTessellator extends LuceneTestCase {
List<Tessellator.Triangle> result = Tessellator.tessellate(polygons[0]);
assertEquals(113, result.size());
}
+
+ public void testInvalidPolygon() throws Exception {
+ String wkt = "POLYGON((0 0, 1 1, 0 1, 1 0, 0 0))";
+ Polygon polygon = (Polygon)SimpleWKTShapeParser.parse(wkt);
+ expectThrows( IllegalArgumentException.class, () -> {Tessellator.tessellate(polygon); });
+ }
}
\ No newline at end of file