Skip to content

Apache Lucene open-source search software

LUCENE-6196: committing Karl's latest patch https://reviews.apache.org/r/33811/ (diff #3)

David Wayne Smiley8e73fa7c4d16
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java
index 5f40130e414..34f2a12f9c2 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java
@@ -91,6 +91,8 @@ public class Geo3dShape implements Shape {
return SpatialRelation.DISJOINT;
}
+ protected final double ROUNDOFF_ADJUSTMENT = 0.01;
+
@Override
public Rectangle getBoundingBox() {
if (boundingBox == null) {
@@ -116,7 +118,7 @@ public class Geo3dShape implements Shape {
} else {
maxLat = bounds.getMaxLatitude().doubleValue() * DEGREES_PER_RADIAN;
}
- boundingBox = new RectangleImpl(leftLon, rightLon, minLat, maxLat, ctx);
+ boundingBox = new RectangleImpl(leftLon, rightLon, minLat, maxLat, ctx).getBuffered(ROUNDOFF_ADJUSTMENT, ctx);
}
return boundingBox;
}
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
index c8de3167482..8e2b8df9276 100755
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
@@ -45,17 +45,17 @@ public class GeoBBoxFactory {
leftLon = -Math.PI;
if (rightLon > Math.PI)
rightLon = Math.PI;
- if (leftLon == -Math.PI && rightLon == Math.PI) {
- if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5)
+ if (Math.abs(leftLon + Math.PI) < Vector.MINIMUM_RESOLUTION && Math.abs(rightLon - Math.PI) < Vector.MINIMUM_RESOLUTION) {
+ if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION && Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
return new GeoWorld();
- if (topLat == bottomLat) {
- if (topLat == Math.PI * 0.5 || topLat == -Math.PI * 0.5)
+ if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) {
+ if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
return new GeoDegeneratePoint(topLat, 0.0);
return new GeoDegenerateLatitudeZone(topLat);
}
- if (topLat == Math.PI * 0.5)
+ if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
return new GeoNorthLatitudeZone(bottomLat);
- else if (bottomLat == -Math.PI * 0.5)
+ else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
return new GeoSouthLatitudeZone(topLat);
return new GeoLatitudeZone(topLat, bottomLat);
}
@@ -64,7 +64,7 @@ public class GeoBBoxFactory {
if (extent < 0.0)
extent += Math.PI * 2.0;
if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5) {
- if (leftLon == rightLon)
+ if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_RESOLUTION)
return new GeoDegenerateLongitudeSlice(leftLon);
if (extent >= Math.PI)
@@ -73,32 +73,35 @@ public class GeoBBoxFactory {
return new GeoLongitudeSlice(leftLon, rightLon);
}
//System.err.println(" not longitude slice");
- if (leftLon == rightLon) {
- if (topLat == bottomLat)
+ if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_RESOLUTION) {
+ if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION)
return new GeoDegeneratePoint(topLat, leftLon);
return new GeoDegenerateVerticalLine(topLat, bottomLat, leftLon);
}
//System.err.println(" not vertical line");
if (extent >= Math.PI) {
- if (topLat == bottomLat) {
+ if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) {
//System.err.println(" wide degenerate line");
return new GeoWideDegenerateHorizontalLine(topLat, leftLon, rightLon);
}
- if (topLat == Math.PI * 0.5) {
+ if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
return new GeoWideNorthRectangle(bottomLat, leftLon, rightLon);
- } else if (bottomLat == -Math.PI * 0.5) {
+ } else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
return new GeoWideSouthRectangle(topLat, leftLon, rightLon);
}
//System.err.println(" wide rect");
return new GeoWideRectangle(topLat, bottomLat, leftLon, rightLon);
}
- if (topLat == bottomLat) {
+ if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) {
+ if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
+ return new GeoDegeneratePoint(topLat, 0.0);
+ }
//System.err.println(" horizontal line");
return new GeoDegenerateHorizontalLine(topLat, leftLon, rightLon);
}
- if (topLat == Math.PI * 0.5) {
+ if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
return new GeoNorthRectangle(bottomLat, leftLon, rightLon);
- } else if (bottomLat == -Math.PI * 0.5) {
+ } else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
return new GeoSouthRectangle(topLat, leftLon, rightLon);
}
//System.err.println(" rectangle");
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java
index f7c0775a8ec..2f76ea835a4 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java
@@ -72,7 +72,8 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox {
*/
@Override
public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds) {
- if (plane.evaluate(this) == 0.0)
+ // If not on the plane, no intersection
+ if (!plane.evaluateIsZero(this))
return false;
for (Membership m : bounds) {
@@ -183,9 +184,12 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox {
*/
@Override
public int getRelationship(final GeoShape shape) {
- if (shape.isWithin(this))
+ if (shape.isWithin(this)) {
+ //System.err.println("Degenerate point "+this+" is WITHIN shape "+shape);
return CONTAINS;
+ }
+ //System.err.println("Degenerate point "+this+" is NOT within shape "+shape);
return DISJOINT;
}