Apache Lucene open-source search software
LUCENE-8208: Use a tighter definition of identical when it comes to vectors.
Karl Wrightb896fe68a720
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.javaindex 1e6e27fbf36..c91d6eb3352 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java@@ -509,6 +509,32 @@ public class Vector {* @return true if they are numerically identical.*/public boolean isNumericallyIdentical(final double otherX, final double otherY, final double otherZ) {+ final double deltaX = x - otherX;+ final double deltaY = y - otherY;+ final double deltaZ = z - otherZ;+ return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ < MINIMUM_RESOLUTION_SQUARED;+ }++ /**+ * Compute whether two vectors are numerically identical.+ * @param other is the other vector.+ * @return true if they are numerically identical.+ */+ public boolean isNumericallyIdentical(final Vector other) {+ final double deltaX = x - other.x;+ final double deltaY = y - other.y;+ final double deltaZ = z - other.z;+ return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ < MINIMUM_RESOLUTION_SQUARED;+ }++ /**+ * Compute whether two vectors are parallel.+ * @param otherX is the other vector X.+ * @param otherY is the other vector Y.+ * @param otherZ is the other vector Z.+ * @return true if they are parallel.+ */+ public boolean isParallel(final double otherX, final double otherY, final double otherZ) {final double thisX = y * otherZ - z * otherY;final double thisY = z * otherX - x * otherZ;final double thisZ = x * otherY - y * otherX;@@ -518,15 +544,15 @@ public class Vector {/*** Compute whether two vectors are numerically identical.* @param other is the other vector.- * @return true if they are numerically identical.+ * @return true if they are parallel.*/- public boolean isNumericallyIdentical(final Vector other) {+ public boolean isParallel(final Vector other) {final double thisX = y * other.z - z * other.y;final double thisY = z * other.x - x * other.z;final double thisZ = x * other.y - y * other.x;return thisX * thisX + thisY * thisY + thisZ * thisZ < MINIMUM_RESOLUTION_SQUARED;}-+/** Compute the desired magnitude of a unit vector projected to a given* planet model.* @param planetModel is the planet model.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 5f64bdfa828..293da3fe3c9 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@@ -27,7 +27,6 @@ import static org.junit.Assert.assertEquals;*/public class PlaneTest {-@Testpublic void testIdenticalPlanes() {final GeoPoint p = new GeoPoint(PlanetModel.SPHERE, 0.123, -0.456);@@ -44,6 +43,15 @@ public class PlaneTest {assertTrue(p1.isNumericallyIdentical(p2));}+ @Test+ public void testIdenticalVector() {+ final Vector v1 = new Vector(1, 0 , 0);+ final Vector v2 = new Vector(1, 0 , 0);+ final Vector v3 = new Vector(-1, 0 , 0);+ assertTrue(v1.isNumericallyIdentical(v2));+ assertFalse(v1.isNumericallyIdentical(v3));+ }+@Testpublic void testInterpolation() {// [X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],