Apache Lucene open-source search software
LUCENE-6632: Geo3D: Compute circle planes more accurately.
David Wayne Smiley96a0dc55d56e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 6332e57ba02..9bc2715f85f 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -113,6 +113,9 @@ New Featuresinner distance and to an outside edge. Multiple distance algorithms areavailable. (Karl Wright, David Smiley)+* LUCENE-6632: Geo3D: Compute circle planes more accurately.+ (Karl Wright via David Smiley)+API Changes* LUCENE-6508: Simplify Lock api, there is now justdiff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.javaindex ee1bb6ed368..64ff34fb37a 100755--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java@@ -67,7 +67,7 @@ public class GeoCircle extends GeoBaseDistanceShape implements GeoSizeable {this.edgePoints = new GeoPoint[0];} else {// Construct normal plane- final Plane normalPlane = new Plane(upperPoint, center);+ final Plane normalPlane = Plane.constructNormalizedVerticalPlane(upperPoint, lowerPoint, center);// Construct a sided plane that goes through the two points and whose normal is in the normalPlane.this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(center, normalPlane, upperPoint, lowerPoint);if (circlePlane == null)diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPath.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPath.javaindex 4c851fc20f1..7a002785a42 100755--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPath.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPath.java@@ -329,7 +329,7 @@ public class GeoPath extends GeoBaseDistanceShape {public SegmentEndpoint(final GeoPoint point, final GeoPoint upperPoint, final GeoPoint lowerPoint) {this.point = point;// Construct normal plane- final Plane normalPlane = new Plane(upperPoint, point);+ final Plane normalPlane = Plane.constructNormalizedVerticalPlane(upperPoint, lowerPoint, point);// Construct a sided plane that goes through the two points and whose normal is in the normalPlane.this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(point, normalPlane, upperPoint, lowerPoint);this.cutoffPlanes = new Membership[0];diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.javaindex 86934897a63..27c4c9283c7 100755--- a/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java@@ -82,6 +82,23 @@ public class Plane extends Vector {this.D = D;}+ /** Construct the most accurate normalized, vertical plane given a set of points. If none of the points can determine+ * the plane, return null.+ */+ public static Plane constructNormalizedVerticalPlane(final Vector... planePoints) {+ // Pick the best one (with the greatest x-y distance)+ double bestDistance = 0.0;+ Vector bestPoint = null;+ for (final Vector point : planePoints) {+ final double pointDist = point.x * point.x + point.y * point.y;+ if (pointDist > bestDistance) {+ bestDistance = pointDist;+ bestPoint = point;+ }+ }+ return constructNormalizedVerticalPlane(bestPoint.x, bestPoint.y);+ }+/** Construct a normalized, vertical plane through an x-y point. If the x-y point is at (0,0), return null.*/public static Plane constructNormalizedVerticalPlane(final double x, final double y) {