Move getIntersections2 to PathItem.prototype.

This commit is contained in:
Jürg Lehni 2013-05-24 17:27:56 -07:00
parent e359dd038c
commit 662736ebf2
2 changed files with 9 additions and 9 deletions

View file

@ -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));

View file

@ -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