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

This commit is contained in:
Karl Wright 2017-11-22 11:07:52 -05:00
parent d0d8a75717
commit 9776e1f4a0
2 changed files with 23 additions and 1 deletions

View File

@ -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.
}

View File

@ -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);
}
}