Apache Lucene open-source search software
LUCENE-8451: Interpret IllegalArgumentException result from convex polygon constructor as meaning a tiling failure.
Karl Wrightf2c0005e9d74
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.javaindex af5d8ef2aec..301d1ccb1af 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java@@ -1443,23 +1443,30 @@ public class GeoPolygonFactory {}// Now, construct the polygon- if (testPoint != null && holes != null && holes.size() > 0) {- // No holes, for test- final GeoPolygon testPolygon = new GeoConvexPolygon(planetModel, points, null, internalEdges, returnIsInternal);- if (testPolygon.isWithin(testPoint)) {- return null;+ // Failures in construction mean we have a polygon that is too large (>180 degrees)+ try {+ if (testPoint != null && holes != null && holes.size() > 0) {+ // No holes, for test+ final GeoPolygon testPolygon = new GeoConvexPolygon(planetModel, points, null, internalEdges, returnIsInternal);+ if (testPolygon.isWithin(testPoint)) {+ return null;+ }}- }-- final GeoPolygon realPolygon = new GeoConvexPolygon(planetModel, points, holes, internalEdges, returnIsInternal);- if (testPoint != null && (holes == null || holes.size() == 0)) {- if (realPolygon.isWithin(testPoint)) {- return null;++ final GeoPolygon realPolygon = new GeoConvexPolygon(planetModel, points, holes, internalEdges, returnIsInternal);+ if (testPoint != null && (holes == null || holes.size() == 0)) {+ if (realPolygon.isWithin(testPoint)) {+ return null;+ }}++ rval.addShape(realPolygon);+ return true;++ } catch (IllegalArgumentException e) {+ throw new TileException(e.getMessage());}- rval.addShape(realPolygon);- return true;}/** Check if a point is within a set of edges.diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.javaindex d68db13475f..dbdfa5e579e 100755--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java@@ -1890,7 +1890,7 @@ shape:}@Test- @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/LUCENE-8451")+ //@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/LUCENE-8451")public void testLUCENE8451() {//POLYGON((-2.5185339401969213 -24.093993739745027,0.0 8.828539494442529E-27,5.495998489568957E-11 -8.321407453133E-11,2.7174659198424288E-11 1.0260761462208114E-10,88.32137548549387 16.934529875343244,-87.97237709688223 39.919704493657484,-88.0876897472551 34.91204903885665,-2.5185339401969213 -24.093993739745027))final List<GeoPoint> points = new ArrayList<>();