lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject lucene-solr:branch_6x: LUCENE-8208: Use a tighter definition of identical when it comes to vectors.
Date Thu, 15 Mar 2018 16:31:26 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 40297e05c -> 793614bd1


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/793614bd
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/793614bd
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/793614bd

Branch: refs/heads/branch_6x
Commit: 793614bd14821e5a3d965e77869d8ba658b18a9e
Parents: 40297e0
Author: Karl Wright <DaddyWri@gmail.com>
Authored: Thu Mar 15 12:29:30 2018 -0400
Committer: Karl Wright <DaddyWri@gmail.com>
Committed: Thu Mar 15 12:31:14 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/793614bd/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/793614bd/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],


Mime
View raw message