diff --git a/src/basic/Line.js b/src/basic/Line.js index 5faebe30..9070bd6a 100644 --- a/src/basic/Line.js +++ b/src/basic/Line.js @@ -119,5 +119,26 @@ var Line = this.Line = Base.extend(/** @lends Line# */{ return this.infinite ? dist : Math.min(dist, point.getDistance(this.point), point.getDistance(this.point.add(this.vector))); + }, + + statics: { + intersect: function(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, infinite) { + var adx = ax2 - ax1, + ady = ay2 - ay1, + bdx = bx2 - bx1, + bdy = by2 - by1, + dx = ax1 - bx1, + dy = ay1 - by1, + cross = bdy * adx - bdx * ady; + if (!Numerical.isZero(cross)) { + var ta = (bdx * dy - bdy * dx) / cross, + tb = (adx * dy - ady * dx) / cross; + if ((infinite || 0 <= ta && ta <= 1) + && (infinite || 0 <= tb && tb <= 1)) + return Point.create( + ax1 + ta * adx, + ay1 + ta * ady); + } + } } }); diff --git a/src/path/Curve.js b/src/path/Curve.js index 1d8eaebe..dff14f4d 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -753,8 +753,13 @@ statics: { }); /*#*/ } // See if the parametric equations of the lines interesct. - var point = new Line(v1[0], v1[1], v1[6], v1[7], false) - .intersect(new Line(v2[0], v2[1], v2[6], v2[7], false)); + // var point = new Line(v1[0], v1[1], v1[6], v1[7], false) + // .intersect(new Line(v2[0], v2[1], v2[6], v2[7], false)); + // Use static version without creation of Line objects, but it + // doesn't seem to yield measurable speed improvements! + var point = Line.intersect( + v1[0], v1[1], v1[6], v1[7], + v2[0], v2[1], v2[6], v2[7], false); if (point) { // Avoid duplicates when hitting segments (closed paths too) var first = locations[0],