Improve precision of Line#intersect() and other parts that check for a divisor to not be 0, by comparing against the new Numerical.EPSILON rather than Numerical.TOLERANCE.

This commit is contained in:
Jürg Lehni 2011-07-28 11:03:59 +01:00
parent 1519a1d220
commit 3a7c5286b5
3 changed files with 6 additions and 2 deletions

View file

@ -74,7 +74,8 @@ var Line = this.Line = Base.extend(/** @lends Line# */{
*/
intersect: function(line) {
var cross = this.vector.cross(line.vector);
if (Math.abs(cross) <= Numerical.TOLERANCE)
// Avoid divisions by 0, and errors when getting too close to 0
if (Math.abs(cross) <= Numerical.EPSILON)
return null;
var v = line.point.subtract(this.point),
t1 = v.cross(line.vector) / cross,

View file

@ -93,7 +93,7 @@ var PathFitter = Base.extend({
// Use least-squares method to find Bezier control points for region.
generateBezier: function(first, last, uPrime, tan1, tan2) {
var epsilon = Numerical.TOLERANCE,
var epsilon = Numerical.EPSILON,
pt1 = this.points[first],
pt2 = this.points[last],
// Create the C and X matrices

View file

@ -63,6 +63,9 @@ var Numerical = new function() {
return {
TOLERANCE: 10e-6,
// Precision when comparing against 0
// TODO: Find a good value
EPSILON: 10e-12,
/**
* Gauss-Legendre Numerical Integration