diff --git a/src/basic/Line.js b/src/basic/Line.js index 59481a66..3f74d033 100644 --- a/src/basic/Line.js +++ b/src/basic/Line.js @@ -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, diff --git a/src/path/PathFitter.js b/src/path/PathFitter.js index 6d012509..a9470220 100644 --- a/src/path/PathFitter.js +++ b/src/path/PathFitter.js @@ -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 diff --git a/src/util/Numerical.js b/src/util/Numerical.js index 64e97861..043e4ac7 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -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