Skip to content

Apache Lucene open-source search software

LUCENE-7849: GeoWideLongitudeSlice can fail to construct

Karl Wrightfed7343d2ea8
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java
index f208266bd01..705d961eaee 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideLongitudeSlice.java
@@ -75,7 +75,13 @@ class GeoWideLongitudeSlice extends GeoBaseBBox {
while (leftLon > rightLon) {
rightLon += Math.PI * 2.0;
}
- final double middleLon = (leftLon + rightLon) * 0.5;
+ double middleLon = (leftLon + rightLon) * 0.5;
+ while (middleLon > Math.PI) {
+ middleLon -= Math.PI * 2.0;
+ }
+ while (middleLon < -Math.PI) {
+ middleLon += Math.PI * 2.0;
+ }
this.centerPoint = new GeoPoint(planetModel, 0.0, middleLon);
this.leftPlane = new SidedPlane(centerPoint, cosLeftLon, sinLeftLon);