You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2018/03/15 16:30:42 UTC

lucene-solr:branch_7x: LUCENE-8208: Use a tighter definition of identical when it comes to vectors.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x c3a18f477 -> 6c61b1557


LUCENE-8208: Use a tighter definition of identical when it comes to vectors.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6c61b155
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6c61b155
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6c61b155

Branch: refs/heads/branch_7x
Commit: 6c61b155799ed3829e7e63a5ef4be8d9d51cd298
Parents: c3a18f4
Author: Karl Wright <Da...@gmail.com>
Authored: Thu Mar 15 12:29:30 2018 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Thu Mar 15 12:30:32 2018 -0400

----------------------------------------------------------------------
 .../apache/lucene/spatial3d/geom/Vector.java    | 32 ++++++++++++++++++--
 .../apache/lucene/spatial3d/geom/PlaneTest.java | 10 +++++-
 2 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6c61b155/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/Vector.java
----------------------------------------------------------------------
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.java
index 1e6e27f..c91d6eb 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.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6c61b155/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/PlaneTest.java
----------------------------------------------------------------------
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.java
index 5f64bdf..293da3f 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 {
 
-
   @Test
   public void testIdenticalPlanes() {
     final GeoPoint p = new GeoPoint(PlanetModel.SPHERE, 0.123, -0.456);
@@ -45,6 +44,15 @@ public class PlaneTest {
   }
 
   @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));
+  }
+
+  @Test
   public void testInterpolation() {
     // [X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],
     // [X=0.5003343189532654, Y=0.522128543226148, Z=0.6906861469771293],