diff --git a/src/basic/Line.js b/src/basic/Line.js index 54415dd4..6f113d9d 100644 --- a/src/basic/Line.js +++ b/src/basic/Line.js @@ -69,7 +69,7 @@ var Line = this.Line = Base.extend(/** @lends Line# */{ * @param {Line} line * @return {Point} the intersection point of the lines */ - intersect: function(line) { + intersect: function(line, excludeStart, excludeEnd) { var cross = this.vector.cross(line.vector); // Avoid divisions by 0, and errors when getting too close to 0 if (Numerical.isZero(cross)) @@ -79,8 +79,10 @@ var Line = this.Line = Base.extend(/** @lends Line# */{ t2 = v.cross(this.vector) / cross; // Check the ranges of t parameters if the line is not allowed to // extend beyond the definition points. - return (this.infinite || 0 <= t1 && t1 <= 1) - && (line.infinite || 0 <= t2 && t2 <= 1) + return (this.infinite || (excludeStart ? 0 < t1 : 0 <= t1) + && (excludeEnd ? t1 < 1 : t1 <= 1)) + && (line.infinite || (excludeStart ? 0 < t2 : 0 <= t2) + && (excludeEnd ? t2 < 1 : t2 <= 1)) ? this.point.add(this.vector.multiply(t1)) : null; }, diff --git a/src/path/Curve.js b/src/path/Curve.js index d5684640..dd85dd2a 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -667,11 +667,10 @@ statics: { // See if the parametric equations of the lines interesct. var line1 = new Line(v1[0], v1[1], v1[6], v1[7], false), line2 = new Line(v2[0], v2[1], v2[6], v2[7], false), - point = line1.intersect(line2); - // Filter out beginnings of the curves, to avoid duplicate - // solutions where curves join. - if (point && !point.equals(line1.point) - && !point.equals(line2.point)) + // Filter out beginnings of the curves, to avoid duplicate + // solutions where curves join. + point = line1.intersect(line2, true, false); + if (point) // Passing null for parameter leads to lazy determination of // parameter values in CurveLocation#getParameter() only // once they are requested.