Apache Lucene open-source search software
LUCENE-8363: Interpolate should yield points on the ellipsoid.
Karl Wrightdcfbaf31dbe3
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.javaindex 64f8f878b9d..580338dd178 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoComplexPolygon.java@@ -706,7 +706,7 @@ class GeoComplexPolygon extends GeoBasePolygon {this.plane = new Plane(startPoint, endPoint);this.startPlane = new SidedPlane(endPoint, plane, startPoint);this.endPlane = new SidedPlane(startPoint, plane, endPoint);- final GeoPoint interpolationPoint = plane.interpolate(startPoint, endPoint, halfProportions)[0];+ final GeoPoint interpolationPoint = plane.interpolate(pm, startPoint, endPoint, halfProportions)[0];this.backingPlane = new SidedPlane(interpolationPoint, interpolationPoint, 0.0);this.planeBounds = new XYZBounds();this.planeBounds.addPoint(startPoint);diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Plane.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Plane.javaindex d03e6249f52..1f9339c73fa 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Plane.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Plane.java@@ -465,12 +465,13 @@ public class Plane extends Vector {* Find points on the boundary of the intersection of a plane and the unit sphere,* given a starting point, and ending point, and a list of proportions of the arc (e.g. 0.25, 0.5, 0.75).* The angle between the starting point and ending point is assumed to be less than pi.+ * @param planetModel is the planet model.* @param start is the start point.* @param end is the end point.* @param proportions is an array of fractional proportions measured between start and end.* @return an array of points corresponding to the proportions passed in.*/- public GeoPoint[] interpolate(final GeoPoint start, final GeoPoint end, final double[] proportions) {+ public GeoPoint[] interpolate(final PlanetModel planetModel, final GeoPoint start, final GeoPoint end, final double[] proportions) {// Steps:// (1) Translate (x0,y0,z0) of endpoints into origin-centered place:// x1 = x0 + D*A@@ -595,7 +596,7 @@ public class Plane extends Vector {final double sinNewAngle = Math.sin(newAngle);final double cosNewAngle = Math.cos(newAngle);final Vector newVector = new Vector(cosNewAngle * startMagnitude, sinNewAngle * startMagnitude, 0.0);- returnValues[i] = reverseModify(newVector, transX, transY, transZ, sinRA, cosRA, sinHA, cosHA);+ returnValues[i] = reverseModify(planetModel, newVector, transX, transY, transZ, sinRA, cosRA, sinHA, cosHA);}return returnValues;@@ -620,6 +621,7 @@ public class Plane extends Vector {/*** Reverse modify a point to produce a GeoPoint in normal space.+ * @param planetModel is the planet model.* @param point is the translated point.* @param transX is the translation x value.* @param transY is the translation y value.@@ -630,10 +632,11 @@ public class Plane extends Vector {* @param cosHA is the cosine of the height angle.* @return the original point.*/- protected static GeoPoint reverseModify(final Vector point, final double transX, final double transY, final double transZ,- final double sinRA, final double cosRA, final double sinHA, final double cosHA) {+ protected static GeoPoint reverseModify(final PlanetModel planetModel,+ final Vector point, final double transX, final double transY, final double transZ,+ final double sinRA, final double cosRA, final double sinHA, final double cosHA) {final Vector result = point.rotateXZ(-sinHA, cosHA).rotateXY(-sinRA, cosRA).translate(-transX, -transY, -transZ);- return new GeoPoint(result.x, result.y, result.z);+ return planetModel.createSurfacePoint(result.x, result.y, result.z);}/**diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/PlaneTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/PlaneTest.javaindex 293da3fe3c9..766e0677a4f 100644--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/PlaneTest.java+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/PlaneTest.java@@ -63,7 +63,7 @@ public class PlaneTest {// [A=-0.6135342247741855, B=0.21504338363863665, C=0.28188192383666794, D=0.0, side=-1.0] internal? false;final Plane p = new Plane(-0.6135342247741855, 0.21504338363863665, 0.28188192383666794, 0.0);- final GeoPoint[] points = p.interpolate(start, end, new double[]{0.25, 0.50, 0.75});+ final GeoPoint[] points = p.interpolate(PlanetModel.SPHERE, start, end, new double[]{0.25, 0.50, 0.75});for (GeoPoint point : points) {assertTrue(p.evaluateIsZero(point));