Apache Solr open-source search software
LUCENE-7955: Adjust degenerate path logic to not consider endpoints unless needed.
Karl Wright80ae2699cf2e
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePath.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePath.javaindex 175ca33eabb..eaceb26b4b3 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePath.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoDegeneratePath.java@@ -259,10 +259,11 @@ class GeoDegeneratePath extends GeoBasePath {// Well, sort of. We can detect intersections also due to overlap of segments with each other.// But that's an edge case and we won't be optimizing for it.//System.err.println(" Looking for intersection of plane "+plane+" with path "+this);- for (final SegmentEndpoint pathPoint : endPoints) {- if (pathPoint.intersects(planetModel, plane, notablePoints, bounds)) {- return true;- }++ // Since the endpoints are included in the path segments, we only need to do this if there are+ // no path segments+ if (endPoints.size() == 1) {+ return endPoints.get(0).intersects(planetModel, plane, notablePoints, bounds);}for (final PathSegment pathSegment : segments) {@@ -276,10 +277,10 @@ class GeoDegeneratePath extends GeoBasePath {@Overridepublic boolean intersects(GeoShape geoShape) {- for (final SegmentEndpoint pathPoint : endPoints) {- if (pathPoint.intersects(geoShape)) {- return true;- }+ // Since the endpoints are included in the path segments, we only need to do this if there are+ // no path segments+ if (endPoints.size() == 1) {+ return endPoints.get(0).intersects(geoShape);}for (final PathSegment pathSegment : segments) {@@ -300,8 +301,8 @@ class GeoDegeneratePath extends GeoBasePath {for (PathSegment pathSegment : segments) {pathSegment.getBounds(planetModel, bounds);}- for (SegmentEndpoint pathPoint : endPoints) {- pathPoint.getBounds(planetModel, bounds);+ if (endPoints.size() == 1) {+ endPoints.get(0).getBounds(planetModel, bounds);}}diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.javaindex 06aa8b9241e..2589a19b661 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/SimpleGeoPolygonRelationshipsTest.java@@ -736,6 +736,21 @@ public class SimpleGeoPolygonRelationshipsTest {assertEquals(GeoArea.CONTAINS, rel);}+ @Test+ public void testDegeneratePathShape(){+ GeoPoint point1 = new GeoPoint(PlanetModel.SPHERE, 0, 0);+ GeoPoint point2 = new GeoPoint(PlanetModel.SPHERE, 0, 1);+ GeoPoint[] pointPath1 = new GeoPoint[] {point1, point2};+ GeoPath path1 = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 0, pointPath1);+ GeoPath path2 = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 1, pointPath1);+ int rel = path1.getRelationship(path2);+ //if an end point is inside the shape it will always return intersects+ assertEquals(GeoArea.CONTAINS, rel); //should be contains?+ rel = path2.getRelationship(path1);+ assertEquals(GeoArea.WITHIN, rel);+ }++private GeoPolygon buildConvexGeoPolygon(double lon1, double lat1,double lon2, double lat2,double lon3, double lat3,