From 662736ebf23fb0e367f96f980828eb6df4937c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 24 May 2013 17:27:56 -0700 Subject: [PATCH] Move getIntersections2 to PathItem.prototype. --- fatline/Intersect.js | 14 +++++++------- fatline/intersectTests.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fatline/Intersect.js b/fatline/Intersect.js index d35fc675..fbe59369 100644 --- a/fatline/Intersect.js +++ b/fatline/Intersect.js @@ -7,14 +7,14 @@ var MAX_ITERATE = 20; /** * This method is analogous to paperjs#PathItem.getIntersections */ -function getIntersections2(path1, path2) { + paper.PathItem.prototype.getIntersections2 = function(path) { // First check the bounds of the two paths. If they don't intersect, // we don't need to iterate through their curves. - if (!path1.getBounds().touches(path2.getBounds())) + if (!this.getBounds().touches(path.getBounds())) return []; var locations = [], - curves1 = path1.getCurves(), - curves2 = path2.getCurves(), + curves1 = this.getCurves(), + curves2 = path.getCurves(), length2 = curves2.length, values2 = [], i; for (var i = 0; i < length2; i++) @@ -36,7 +36,7 @@ function getIntersections2(path1, path2) { } } return locations; -} +}; /** * This method is analogous to paperjs#Curve.getIntersections @@ -132,7 +132,7 @@ paper.Curve.getIntersections2 = function(v1, v2, curve1, curve2, locations, _v1t v2Converged = (Math.abs(v2t.t2 - v2t.t1) < EPSILON); if (v1Converged || v2Converged) { var first = locations[0], - last = locations[locations.length - 1]; + last = locations[locations.length - 1]; if ((!first || !point.equals(first._point)) && (!last || !point.equals(last._point))) { var point = (v1Converged)? curve1.getPointAt(v1t.t1, true) : curve2.getPointAt(v2t.t1, true); @@ -397,7 +397,7 @@ var _getCurveLineIntersection = function(v1, v2, curve1, curve2, locations, _oth point = Curve.evaluate(vc, root, true, 0); if (other) root = null; var first = locations[0], - last = locations[locations.length - 1]; + last = locations[locations.length - 1]; if ((!first || !point.equals(first._point)) && (!last || !point.equals(last._point))) locations.push(new CurveLocation(curve1, root, point, curve2)); diff --git a/fatline/intersectTests.js b/fatline/intersectTests.js index f525f07f..97fda453 100644 --- a/fatline/intersectTests.js +++ b/fatline/intersectTests.js @@ -426,7 +426,7 @@ function testIntersections( path1, path2, caption, testname, testdata, nomark) { if( !nomark ) console.time('fatline x ' + maxCount); st = getTimestamp(); while(count--){ - ixsFatline = getIntersections2( path1, path2 ); + ixsFatline = path1.getIntersections2( path2 ); } t2 = (getTimestamp() - st) / maxCount; if( !nomark ) console.timeEnd('fatline x ' + maxCount); @@ -498,7 +498,7 @@ function doRandomTests( testdata ){ ixspaper = p1.getIntersections( p2 ); t1 = (getTimestamp() - st); st = getTimestamp(); - ixsfat = getIntersections2( p1, p2 ); + ixsfat = p1.getIntersections2( p2 ); t2 = (getTimestamp() - st); // Check against paperjs output // tol - tolerence for computed points with in 1/10 th of a pixel