mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-07 19:49:09 -04:00
Move getIntersections2 to PathItem.prototype.
This commit is contained in:
parent
e359dd038c
commit
662736ebf2
2 changed files with 9 additions and 9 deletions
|
@ -7,14 +7,14 @@ var MAX_ITERATE = 20;
|
||||||
/**
|
/**
|
||||||
* This method is analogous to paperjs#PathItem.getIntersections
|
* 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,
|
// First check the bounds of the two paths. If they don't intersect,
|
||||||
// we don't need to iterate through their curves.
|
// we don't need to iterate through their curves.
|
||||||
if (!path1.getBounds().touches(path2.getBounds()))
|
if (!this.getBounds().touches(path.getBounds()))
|
||||||
return [];
|
return [];
|
||||||
var locations = [],
|
var locations = [],
|
||||||
curves1 = path1.getCurves(),
|
curves1 = this.getCurves(),
|
||||||
curves2 = path2.getCurves(),
|
curves2 = path.getCurves(),
|
||||||
length2 = curves2.length,
|
length2 = curves2.length,
|
||||||
values2 = [], i;
|
values2 = [], i;
|
||||||
for (var i = 0; i < length2; i++)
|
for (var i = 0; i < length2; i++)
|
||||||
|
@ -36,7 +36,7 @@ function getIntersections2(path1, path2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return locations;
|
return locations;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is analogous to paperjs#Curve.getIntersections
|
* 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);
|
v2Converged = (Math.abs(v2t.t2 - v2t.t1) < EPSILON);
|
||||||
if (v1Converged || v2Converged) {
|
if (v1Converged || v2Converged) {
|
||||||
var first = locations[0],
|
var first = locations[0],
|
||||||
last = locations[locations.length - 1];
|
last = locations[locations.length - 1];
|
||||||
if ((!first || !point.equals(first._point))
|
if ((!first || !point.equals(first._point))
|
||||||
&& (!last || !point.equals(last._point))) {
|
&& (!last || !point.equals(last._point))) {
|
||||||
var point = (v1Converged)? curve1.getPointAt(v1t.t1, true) : curve2.getPointAt(v2t.t1, true);
|
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);
|
point = Curve.evaluate(vc, root, true, 0);
|
||||||
if (other) root = null;
|
if (other) root = null;
|
||||||
var first = locations[0],
|
var first = locations[0],
|
||||||
last = locations[locations.length - 1];
|
last = locations[locations.length - 1];
|
||||||
if ((!first || !point.equals(first._point))
|
if ((!first || !point.equals(first._point))
|
||||||
&& (!last || !point.equals(last._point)))
|
&& (!last || !point.equals(last._point)))
|
||||||
locations.push(new CurveLocation(curve1, root, point, curve2));
|
locations.push(new CurveLocation(curve1, root, point, curve2));
|
||||||
|
|
|
@ -426,7 +426,7 @@ function testIntersections( path1, path2, caption, testname, testdata, nomark) {
|
||||||
if( !nomark ) console.time('fatline x ' + maxCount);
|
if( !nomark ) console.time('fatline x ' + maxCount);
|
||||||
st = getTimestamp();
|
st = getTimestamp();
|
||||||
while(count--){
|
while(count--){
|
||||||
ixsFatline = getIntersections2( path1, path2 );
|
ixsFatline = path1.getIntersections2( path2 );
|
||||||
}
|
}
|
||||||
t2 = (getTimestamp() - st) / maxCount;
|
t2 = (getTimestamp() - st) / maxCount;
|
||||||
if( !nomark ) console.timeEnd('fatline x ' + maxCount);
|
if( !nomark ) console.timeEnd('fatline x ' + maxCount);
|
||||||
|
@ -498,7 +498,7 @@ function doRandomTests( testdata ){
|
||||||
ixspaper = p1.getIntersections( p2 );
|
ixspaper = p1.getIntersections( p2 );
|
||||||
t1 = (getTimestamp() - st);
|
t1 = (getTimestamp() - st);
|
||||||
st = getTimestamp();
|
st = getTimestamp();
|
||||||
ixsfat = getIntersections2( p1, p2 );
|
ixsfat = p1.getIntersections2( p2 );
|
||||||
t2 = (getTimestamp() - st);
|
t2 = (getTimestamp() - st);
|
||||||
// Check against paperjs output
|
// Check against paperjs output
|
||||||
// tol - tolerence for computed points with in 1/10 th of a pixel
|
// tol - tolerence for computed points with in 1/10 th of a pixel
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue