diff --git a/src/basic/Line.js b/src/basic/Line.js index b8fae4ec..2aeb7aa3 100644 --- a/src/basic/Line.js +++ b/src/basic/Line.js @@ -133,14 +133,25 @@ var Line = Base.extend(/** @lends Line# */{ if (!Numerical.isZero(cross)) { var dx = p1x - p2x, dy = p1y - p2y, - t1 = (v2x * dy - v2y * dx) / cross, - t2 = (v1x * dy - v1y * dx) / cross; + u1 = (v2x * dy - v2y * dx) / cross, + u2 = (v1x * dy - v1y * dx) / cross, + // Compare the u values with EPSILON tolerance over the + // [0, 1] bounds. + uMin = -/*#=*/Numerical.EPSILON, + uMax = 1 + uMin; // Check the ranges of t parameters if the line is not allowed // to extend beyond the definition points. - if (isInfinite || 0 <= t1 && t1 <= 1 && 0 <= t2 && t2 <= 1) + if (isInfinite + || uMin < u1 && u1 < uMax && uMin < u2 && u2 < uMax) { + if (!isInfinite) { + // Address the tolerance at the bounds by clipping to + // the actual range. + u1 = u1 < 0 ? 0 : u1 > 1 ? 1 : u1; + } return new Point( - p1x + t1 * v1x, - p1y + t1 * v1y); + p1x + u1 * v1x, + p1y + u1 * v1y); + } } }, diff --git a/src/path/Curve.js b/src/path/Curve.js index f4bc01cb..f33926c0 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1379,11 +1379,11 @@ new function() { // Scope for intersection using bezier fat-line clipping // which connects back to the beginning, but only if it's not part of // a found overlap. The normal intersection will already be found at // the beginning, and would be added twice otherwise. - if (t1 >= (startConnected ? tMin : 0) && + if (t1 !== null && t1 >= (startConnected ? tMin : 0) && t1 <= (endConnected ? tMax : 1)) { if (t2 == null) t2 = Curve.getParameterOf(v2, p2.x, p2.y); - if (t2 >= (endConnected ? tMin : 0) && + if (t2 !== null && t2 >= (endConnected ? tMin : 0) && t2 <= (startConnected ? tMax : 1)) { // TODO: Don't we need to check the range of t2 as well? Does it // also need startConnected / endConnected values? diff --git a/src/util/Numerical.js b/src/util/Numerical.js index d1853cd5..1afbe575 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -112,7 +112,7 @@ var Numerical = new function() { KAPPA: 4 * (sqrt(2) - 1) / 3, /** - * Check if the value is 0, within a tolerance defined by + * Checks if the value is 0, within a tolerance defined by * Numerical.EPSILON. */ isZero: function(val) {