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

This commit is contained in:
Karl Wright 2018-03-15 12:29:30 -04:00
parent 0dfe19880c
commit b896fe68a7
2 changed files with 38 additions and 4 deletions

View File

@ -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.

View File

@ -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);
@ -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));
}
@Test
public void testInterpolation() {
// [X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],