Apache Lucene open-source search software
LUCENE-8239: Handle degenerate vector case on linear edge evaluation.
Karl Wright74c2b798eb5b
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.javaindex d11fb79d07c..f64755c0199 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java@@ -195,7 +195,7 @@ class GeoComplexPolygon extends GeoBasePolygon {}// If we're right on top of any of the test planes, we navigate solely on that plane.- if (testPointFixedYPlane.evaluateIsZero(x, y, z)) {+ if (testPointFixedYAbovePlane != null && testPointFixedYBelowPlane != null && testPointFixedYPlane.evaluateIsZero(x, y, z)) {// Use the XZ plane exclusively.final CountingEdgeIterator crossingEdgeIterator = createLinearCrossingEdgeIterator(testPointFixedYPlane, testPointFixedYAbovePlane, testPointFixedYBelowPlane, x, y, z);// Traverse our way from the test point to the check point. Use the y tree because that's fixed.@@ -204,7 +204,7 @@ class GeoComplexPolygon extends GeoBasePolygon {return true;}return ((crossingEdgeIterator.getCrossingCount() & 1) == 0)?testPointInSet:!testPointInSet;- } else if (testPointFixedXPlane.evaluateIsZero(x, y, z)) {+ } else if (testPointFixedXAbovePlane != null && testPointFixedXBelowPlane != null && testPointFixedXPlane.evaluateIsZero(x, y, z)) {// Use the YZ plane exclusively.final CountingEdgeIterator crossingEdgeIterator = createLinearCrossingEdgeIterator(testPointFixedXPlane, testPointFixedXAbovePlane, testPointFixedXBelowPlane, x, y, z);// Traverse our way from the test point to the check point. Use the x tree because that's fixed.@@ -213,7 +213,7 @@ class GeoComplexPolygon extends GeoBasePolygon {return true;}return ((crossingEdgeIterator.getCrossingCount() & 1) == 0)?testPointInSet:!testPointInSet;- } else if (testPointFixedZPlane.evaluateIsZero(x, y, z)) {+ } else if (testPointFixedZAbovePlane != null && testPointFixedZBelowPlane != null && testPointFixedZPlane.evaluateIsZero(x, y, z)) {final CountingEdgeIterator crossingEdgeIterator = createLinearCrossingEdgeIterator(testPointFixedZPlane, testPointFixedZAbovePlane, testPointFixedZBelowPlane, x, y, z);// Traverse our way from the test point to the check point. Use the z tree because that's fixed.if (!zTree.traverse(crossingEdgeIterator, testPoint.z)) {@@ -221,6 +221,8 @@ class GeoComplexPolygon extends GeoBasePolygon {return true;}return ((crossingEdgeIterator.getCrossingCount() & 1) == 0)?testPointInSet:!testPointInSet;+ } else if (testPointFixedYPlane.evaluateIsZero(x, y, z) || testPointFixedXPlane.evaluateIsZero(x, y, z) || testPointFixedZPlane.evaluateIsZero(x, y, z)) {+ throw new IllegalArgumentException("Can't compute isWithin for specified point");} else {// This is the expensive part!!@@ -903,6 +905,9 @@ class GeoComplexPolygon extends GeoBasePolygon {this.plane = plane;this.abovePlane = abovePlane;this.belowPlane = belowPlane;+ if (plane.isNumericallyIdentical(testPoint)) {+ throw new IllegalArgumentException("Plane vector identical to testpoint vector");+ }// It doesn't matter which 1/2 of the world we choose, but we must choose only one.this.bound = new SidedPlane(plane, testPoint);this.thePointX = thePointX;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 b5c18cf1f93..ee15ec48382 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@@ -1450,7 +1450,6 @@ shape:assertTrue(polygon.isWithin(point1) == largePolygon.isWithin(point1));}- @Ignore@Testpublic void testComplexPolygonDegeneratedVector() {List<GeoPoint> points = new ArrayList<>();