LUCENE-8173: Tighten the envelope so Gram-Schmidt gets a tighter answer. Less likely to blow up later.

This commit is contained in:
Karl Wright 2018-02-13 17:00:18 -05:00
parent dd08400a3d
commit 34354e90fe
2 changed files with 12 additions and 5 deletions

View File

@ -48,6 +48,12 @@ public class Vector {
/** The z value */
public final double z;
/**
* Gram-Schmidt convergence envelope is a bit smaller than we really need because we don't want the math to fail afterwards in
* other places.
*/
private static final double MINIMUM_GRAM_SCHMIDT_ENVELOPE = MINIMUM_RESOLUTION * 0.5;
/**
* Construct from (U.S.) x,y,z coordinates.
*@param x is the x value.
@ -122,7 +128,7 @@ public class Vector {
while (true) {
final double currentDotProdA = AX * normalizeX + AY * normalizeY + AZ * normalizeZ;
final double currentDotProdB = BX * normalizeX + BY * normalizeY + BZ * normalizeZ;
if (Math.abs(currentDotProdA) < MINIMUM_RESOLUTION && Math.abs(currentDotProdB) < MINIMUM_RESOLUTION) {
if (Math.abs(currentDotProdA) < MINIMUM_GRAM_SCHMIDT_ENVELOPE && Math.abs(currentDotProdB) < MINIMUM_GRAM_SCHMIDT_ENVELOPE) {
break;
}
// Converge on the one that has largest dot product
@ -231,7 +237,7 @@ public class Vector {
while (true) {
final double currentDotProdA = A.x * normalizeX + A.y * normalizeY + A.z * normalizeZ;
final double currentDotProdB = B.x * normalizeX + B.y * normalizeY + B.z * normalizeZ;
if (Math.abs(currentDotProdA) < MINIMUM_RESOLUTION && Math.abs(currentDotProdB) < MINIMUM_RESOLUTION) {
if (Math.abs(currentDotProdA) < MINIMUM_GRAM_SCHMIDT_ENVELOPE && Math.abs(currentDotProdB) < MINIMUM_GRAM_SCHMIDT_ENVELOPE) {
break;
}
// Converge on the one that has largest dot product

View File

@ -70,10 +70,11 @@ public class RandomPlaneTest extends RandomGeo3dShapeGenerator {
if (plane == null) {
fail(msg);
}
assertTrue(plane.evaluate(check) + " " + msg, plane.isWithin(check));
assertTrue(plane.evaluate(point1) + " " +msg, plane.isWithin(point3));
// This is not expected
//assertTrue(plane.evaluate(check) + " " + msg, plane.isWithin(check));
assertTrue(plane.evaluate(point1) + " " +msg, plane.isWithin(point1));
assertTrue(plane.evaluate(point2) + " " +msg, plane.isWithin(point2));
assertTrue(plane.evaluate(point3) + " " +msg, plane.isWithin(point1));
assertTrue(plane.evaluate(point3) + " " +msg, plane.isWithin(point3));
}
}