Skip to content

Apache Lucene open-source search software

LUCENE-10508: Fix error for rectangles with an extent close to 180 degrees (#824)

Ignacio Vera2b20b3f2ca03
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java
index 3d73fb1fd84..6aa9a80da03 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoBBoxFactory.java
@@ -98,7 +98,7 @@ public class GeoBBoxFactory {
return new GeoDegenerateVerticalLine(planetModel, topLat, bottomLat, leftLon);
}
// System.err.println(" not vertical line");
- if (extent >= Math.PI) {
+ if (extent >= GeoWideRectangle.MIN_WIDE_EXTENT) {
if (latitudesEquals(topLat, bottomLat)) {
if (isNorthPole(topLat)) {
return new GeoDegeneratePoint(planetModel, topLat, 0.0);
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java
index 227a9d0bb14..e6f9a0d93fe 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoWideRectangle.java
@@ -26,6 +26,10 @@ import java.io.OutputStream;
* @lucene.internal
*/
class GeoWideRectangle extends GeoBaseBBox {
+
+ /** Minimum extent for a rectangle of this type */
+ public static final double MIN_WIDE_EXTENT = Math.PI - Vector.MINIMUM_ANGULAR_RESOLUTION;
+
/** The top latitude */
protected final double topLat;
/** The bottom latitude */
@@ -111,7 +115,7 @@ class GeoWideRectangle extends GeoBaseBBox {
if (extent < 0.0) {
extent += 2.0 * Math.PI;
}
- if (extent < Math.PI) {
+ if (extent < MIN_WIDE_EXTENT) {
throw new IllegalArgumentException("Width of rectangle too small");
}