Apache Lucene open-source search software
LUCENE-8056: Use perpendicular bounding planes for segments of exact circles.
Karl Wrightd0d8a7571761
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex d7fd0c37c05..b6618fdb2e9 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -77,6 +77,9 @@ New FeaturesBug Fixes+* LUCENE-8056: Exact circle segment bounding suffered from precision errors.+ (Karl Wright)+* LUCENE-8054: Fix the exact circle case where relationships fail when theplanet model has c <= ab, because the planes are constructed incorrectly.(Ignacio Vera)diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoExactCircle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoExactCircle.javaindex cedcab55aec..bbd1ff03248 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoExactCircle.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoExactCircle.java@@ -145,7 +145,9 @@ class GeoExactCircle extends GeoBaseCircle {// If it turns out that there's only one circle plane, this array will be populated but unusedfinal List<GeoPoint[]> notableEdgePoints = new ArrayList<>(activeSlices.size());// Back planes- final List<Membership> backPlanes = new ArrayList<>(activeSlices.size());+ final Map<Membership, Membership> backPlanes = new HashMap<>(activeSlices.size());+ // Bounds+ final Map<Membership, Membership> bounds = new HashMap<>(activeSlices.size());// Compute bounding planes and actual circle planesfor (int i = 0; i < activeSlices.size(); i++) {@@ -198,13 +200,15 @@ class GeoExactCircle extends GeoBaseCircle {}circlePlanes.add(pd.plane);- backPlanes.add(backPlane);+ if (backPlane != null) {+ backPlanes.put(pd.plane, backPlane);+ }notableEdgePoints.add(new GeoPoint[]{pd.endPoint1, pd.endPoint2});+ bounds.put(pd.plane, new EitherBound(new SidedPlane(pd.onSidePoint, pd.endPoint1, center), new SidedPlane(pd.onSidePoint, pd.endPoint2, center)));}//System.out.println("Number of planes needed: "+circlePlanes.size());- this.edgePoints = new GeoPoint[]{edgePoint};this.circlePlanes = circlePlanes;// Compute boundsif (circlePlanes.size() == 1) {@@ -213,19 +217,11 @@ class GeoExactCircle extends GeoBaseCircle {this.notableEdgePoints = null;} else {this.notableEdgePoints = notableEdgePoints;- this.backBounds = new HashMap<>(circlePlanes.size());- this.eitherBounds = new HashMap<>(circlePlanes.size());- for (int i = 0; i < circlePlanes.size(); i++) {- final SidedPlane thisPlane = circlePlanes.get(i);- final SidedPlane previousPlane = (i == 0)?circlePlanes.get(circlePlanes.size()-1):circlePlanes.get(i-1);- final SidedPlane nextPlane = (i == circlePlanes.size()-1)?circlePlanes.get(0):circlePlanes.get(i+1);- if (backPlanes.get(i) != null) {- backBounds.put(thisPlane, backPlanes.get(i));- }- eitherBounds.put(thisPlane, new EitherBound(previousPlane, nextPlane));- }+ this.eitherBounds = bounds;+ this.backBounds = backPlanes;}+ this.edgePoints = new GeoPoint[]{edgePoint};//System.out.println("Is edgepoint within? "+isWithin(edgePoint));}diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.javaindex 9206e4f70e8..d203b095f29 100755--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java@@ -520,5 +520,18 @@ public class GeoCircleTest extends LuceneTestCase {int rel = circle1.getRelationship(circle2);assertTrue(rel != GeoArea.DISJOINT);}-++ @Test+ public void testLUCENE8056(){+ GeoCircle circle = GeoCircleFactory.makeExactGeoCircle(PlanetModel.WGS84, 0.647941905154693, 0.8542472362428436, 0.8917883700569315, 1.2173787103955335E-8);+ GeoBBox bBox = GeoBBoxFactory.makeGeoBBox(PlanetModel.WGS84, 0.5890486225480862, 0.4908738521234052, 1.9634954084936207, 2.159844949342983);+ //Center iis out of the shape+ assertFalse(circle.isWithin(bBox.getCenter()));+ //Edge point is in the shape+ assertTrue(circle.isWithin(bBox.getEdgePoints()[0]));+ //Shape should intersect!!!+ assertTrue(bBox.getRelationship(circle) == GeoArea.OVERLAPS);+ }++}