Introduce new TRIGONOMETRIC_EPSILON with higher precision than GEOMETRIC_EPSILON.

This commit is contained in:
Jürg Lehni 2015-10-01 20:44:27 -05:00
parent f5012a78e9
commit 9b883e5fb6
3 changed files with 10 additions and 4 deletions

View file

@ -708,7 +708,7 @@ var Point = Base.extend(/** @lends Point# */{
// TODO: Optimize by creating a static Point.isCollinear() to be used // TODO: Optimize by creating a static Point.isCollinear() to be used
// in Line.isCollinear() as well. // in Line.isCollinear() as well.
return Math.abs(this.normalize().cross(point.normalize())) return Math.abs(this.normalize().cross(point.normalize()))
< /*#=*/Numerical.GEOMETRIC_EPSILON; < /*#=*/Numerical.TRIGONOMETRIC_EPSILON;
}, },
// TODO: Remove version with typo after a while (deprecated June 2015) // TODO: Remove version with typo after a while (deprecated June 2015)
@ -727,7 +727,7 @@ var Point = Base.extend(/** @lends Point# */{
// length. // length.
// TODO: Optimize // TODO: Optimize
return Math.abs(this.normalize().dot(point.normalize())) return Math.abs(this.normalize().dot(point.normalize()))
< /*#=*/Numerical.GEOMETRIC_EPSILON; < /*#=*/Numerical.TRIGONOMETRIC_EPSILON;
}, },
/** /**

View file

@ -916,7 +916,7 @@ statics: {
*/ */
isHorizontal: function() { isHorizontal: function() {
return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).y) return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).y)
< /*#=*/Numerical.GEOMETRIC_EPSILON; < /*#=*/Numerical.TRIGONOMETRIC_EPSILON;
}, },
/** /**
@ -926,7 +926,7 @@ statics: {
*/ */
isVertical: function() { isVertical: function() {
return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).x) return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).x)
< /*#=*/Numerical.GEOMETRIC_EPSILON; < /*#=*/Numerical.TRIGONOMETRIC_EPSILON;
} }
}), /** @lends Curve# */{ }), /** @lends Curve# */{
// Explicitly deactivate the creation of beans, as we have functions here // Explicitly deactivate the creation of beans, as we have functions here

View file

@ -94,6 +94,12 @@ var Numerical = new function() {
* trial and error. * trial and error.
*/ */
GEOMETRIC_EPSILON: 1e-7, GEOMETRIC_EPSILON: 1e-7,
/**
* The epsilon to be used when performing "trigonometric" checks, such
* as examining cross products to check for collinearity. This value is
* somewhat arbitrary and was chosen by trial and error.
*/
TRIGONOMETRIC_EPSILON: 1e-8,
/** /**
* MACHINE_EPSILON for a double precision (Javascript Number) is * MACHINE_EPSILON for a double precision (Javascript Number) is
* 2.220446049250313e-16. (try this in the js console) * 2.220446049250313e-16. (try this in the js console)