Skip to content

Apache Lucene open-source search software

LUCENE-8057: getBounds() for exact circle did not include segment endpoints.

Karl Wright9776e1f4a0a6
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.java
index bbd1ff03248..8bba244c0af 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
@@ -356,8 +356,13 @@ class GeoExactCircle extends GeoBaseCircle {
return;
}
// Add bounds for all circle planes
- for (final SidedPlane plane : circlePlanes) {
+ for (int edgeIndex = 0; edgeIndex < circlePlanes.size(); edgeIndex++) {
+ final SidedPlane plane = circlePlanes.get(edgeIndex);
bounds.addPlane(planetModel, plane, eitherBounds.get(plane));
+ final GeoPoint[] points = notableEdgePoints.get(edgeIndex);
+ for (final GeoPoint point : points) {
+ bounds.addPoint(point);
+ }
// We don't bother to compute the intersection bounds since, unless the planet model is pathological, we expect planes to be intersecting at shallow
// angles.
}
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.java
index d203b095f29..3f35ef305cf 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
@@ -533,5 +533,22 @@ public class GeoCircleTest extends LuceneTestCase {
assertTrue(bBox.getRelationship(circle) == GeoArea.OVERLAPS);
}
-
+ @Test
+ public void testExactCircleBounds() {
+
+ GeoPoint center = new GeoPoint(PlanetModel.WGS84, 0, 0);
+ // Construct four cardinal points, and then we'll build the first two planes
+ final GeoPoint northPoint = PlanetModel.WGS84.surfacePointOnBearing(center, 1, 0.0);
+ final GeoPoint southPoint = PlanetModel.WGS84.surfacePointOnBearing(center, 1, Math.PI);
+ final GeoPoint eastPoint = PlanetModel.WGS84.surfacePointOnBearing(center, 1, Math.PI * 0.5);
+ final GeoPoint westPoint = PlanetModel.WGS84.surfacePointOnBearing(center, 1, Math.PI * 1.5);
+
+ GeoCircle circle = GeoCircleFactory.makeExactGeoCircle(PlanetModel.WGS84, 0, 0, 1, 1e-6);
+ LatLonBounds bounds = new LatLonBounds();
+ circle.getBounds(bounds);
+ assertEquals(northPoint.getLatitude(), bounds.getMaxLatitude(), 1e-2);
+ assertEquals(southPoint.getLatitude(), bounds.getMinLatitude(), 1e-2);
+ assertEquals(westPoint.getLongitude(), bounds.getLeftLongitude(), 1e-2);
+ assertEquals(eastPoint.getLongitude(), bounds.getRightLongitude(), 1e-2);
+ }
}