Apache Lucene open-source search software
For 11965, add structural changes that would allow intersection calls to also be O(log(n)). Disabled though because test failures are the result of enabling it - work ongoing.
Karl David Wright5e4623af1fdf
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.javaindex 4dd375873ac..9b46e3a63b0 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java@@ -359,7 +359,20 @@ class GeoStandardPath extends GeoBasePath {if (rootComponent == null) {return false;}- return rootComponent.intersects(plane, notablePoints, bounds);+ // Optimization: compute plane bounds and use that in the b-tree to check if we need to do+ // an actual intersection check. This is disabled for the moment because there are randomized+ // test failures that need research to figure out.+ final XYZBounds planeBounds = null;+ /*+ final XYZBounds planeBounds = new XYZBounds();+ if (notablePoints != null) {+ for (final GeoPoint notablePoint : notablePoints) {+ planeBounds.addPoint(notablePoint);+ }+ }+ planeBounds.addPlane(planetModel, plane, bounds);+ */+ return rootComponent.intersects(plane, planeBounds, notablePoints, bounds);}@Override@@ -569,11 +582,16 @@ class GeoStandardPath extends GeoBasePath {* Determine if this endpoint intersects a specified plane.** @param p is the plane.+ * @param planeBounds are the XYZBounds of the plane we're looking for an intersection with.* @param notablePoints are the points associated with the plane.* @param bounds are any bounds which the intersection must lie within.* @return true if there is a matching intersection.*/- boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds);+ boolean intersects(+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds);/*** Determine if this endpoint intersects a GeoShape.@@ -663,8 +681,6 @@ class GeoStandardPath extends GeoBasePath {}final double child1Distance = child1.distance(distanceStyle, x, y, z);final double child2Distance = child2.distance(distanceStyle, x, y, z);- // System.out.println("In PathNode.distance(), returning child1 distance = "+child1Distance+"- // and child2 distance = "+child2Distance);return Math.min(child1Distance, child2Distance);}@@ -761,9 +777,16 @@ class GeoStandardPath extends GeoBasePath {@Overridepublic boolean intersects(- final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {- return child1.intersects(p, notablePoints, bounds)- || child2.intersects(p, notablePoints, bounds);+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds) {+ // If this node bounding box does not overlap the plane's bounding box, exit early+ if (planeBounds != null && !planeBounds.overlaps(this.bounds)) {+ return false;+ }+ return child1.intersects(p, planeBounds, notablePoints, bounds)+ || child2.intersects(p, planeBounds, notablePoints, bounds);}@Override@@ -921,7 +944,10 @@ class GeoStandardPath extends GeoBasePath {@Overridepublic boolean intersects(- final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds) {return false;}@@ -1025,7 +1051,10 @@ class GeoStandardPath extends GeoBasePath {@Overridepublic boolean intersects(- final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds) {return circlePlane.intersects(planetModel, p, notablePoints, circlePoints, bounds);}@@ -1104,7 +1133,10 @@ class GeoStandardPath extends GeoBasePath {@Overridepublic boolean intersects(- final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds) {return circlePlane.intersects(planetModel, p, notablePoints, this.notablePoints, bounds, this.cutoffPlanes);}@@ -1267,7 +1299,10 @@ class GeoStandardPath extends GeoBasePath {@Overridepublic boolean intersects(- final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds) {return circlePlane1.intersects(planetModel, p, notablePoints, this.notablePoints1, bounds, this.cutoffPlanes)|| circlePlane2.intersects(@@ -1786,7 +1821,10 @@ class GeoStandardPath extends GeoBasePath {@Overridepublic boolean intersects(- final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {+ final Plane p,+ final XYZBounds planeBounds,+ final GeoPoint[] notablePoints,+ final Membership[] bounds) {return upperConnectingPlane.intersects(planetModel,p,diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZBounds.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZBounds.javaindex 107c3e7becc..d277014a664 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZBounds.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/XYZBounds.java@@ -178,6 +178,55 @@ public class XYZBounds implements Bounds {// Modification methods+ /**+ * Check if another XYZBounds object overlaps this one.+ *+ * @param bounds is the other bounds object.+ * @return true if there is overlap.+ */+ public boolean overlaps(final XYZBounds bounds) {+ // Overlap occurs when any one corner is inside the other bounds+ // object, and visa versa+ return isCornerInside(this, bounds) || isCornerInside(bounds, this);+ }++ private static boolean isCornerInside(final XYZBounds one, final XYZBounds other) {+ if (one.minX == null+ || one.maxX == null+ || one.minY == null+ || one.maxY == null+ || one.minZ == null+ || one.maxZ == null) {+ return false;+ }+ if (other.minX == null+ || other.maxX == null+ || other.minY == null+ || other.maxY == null+ || other.minZ == null+ || other.maxZ == null) {+ return false;+ }+ return isPointInside(other, one.minX, one.minY, one.minZ)+ || isPointInside(other, one.maxX, one.minY, one.minZ)+ || isPointInside(other, one.minX, one.maxY, one.minZ)+ || isPointInside(other, one.maxX, one.maxY, one.minZ)+ || isPointInside(other, one.minX, one.minY, one.maxZ)+ || isPointInside(other, one.maxX, one.minY, one.maxZ)+ || isPointInside(other, one.minX, one.maxY, one.maxZ)+ || isPointInside(other, one.maxX, one.maxY, one.maxZ);+ }++ private static boolean isPointInside(+ final XYZBounds other, final double x, final double y, final double z) {+ return other.minX <= x+ && other.maxX >= x+ && other.minY <= y+ && other.maxY >= y+ && other.minZ <= z+ && other.maxZ >= z;+ }+/*** Add a fully-formed XYZBounds to the current one.*