Skip to content

Apache Lucene open-source search software

LUCENE-7185: make an empty grid the simple way

Robert Muirb59ace99e459
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java
index 5d594c68723..9b4e981ac81 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonGrid.java
@@ -74,11 +74,17 @@ final class LatLonGrid {
}
long latitudeRange = maxLat - (long) minLat;
long longitudeRange = maxLon - (long) minLon;
- // we spill over the edge of the bounding box in each direction a bit,
- // but it prevents edge case bugs.
- latPerCell = latitudeRange / (GRID_SIZE - 1);
- lonPerCell = longitudeRange / (GRID_SIZE - 1);
- fill(polygons, 0, GRID_SIZE, 0, GRID_SIZE);
+
+ if (latitudeRange < GRID_SIZE || longitudeRange < GRID_SIZE) {
+ // don't complicate fill right now if you pass e.g. emptyish stuff: make an "empty grid"
+ latPerCell = lonPerCell = Long.MAX_VALUE;
+ } else {
+ // we spill over the edge of the bounding box in each direction a bit,
+ // but it prevents edge case bugs.
+ latPerCell = latitudeRange / (GRID_SIZE - 1);
+ lonPerCell = longitudeRange / (GRID_SIZE - 1);
+ fill(polygons, 0, GRID_SIZE, 0, GRID_SIZE);
+ }
}
/** fills a 2D range of grid cells [minLatIndex .. maxLatIndex) X [minLonIndex .. maxLonIndex) */