mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Check curve bounds before recursively clipping.
The speeds are back to "normal"!
This commit is contained in:
parent
3449f7e69b
commit
f6e474da50
1 changed files with 18 additions and 14 deletions
|
@ -229,24 +229,28 @@ function _clipBezierFatLine( v1, v2, v2t ){
|
||||||
}
|
}
|
||||||
// Return the parameter values for v2 for which we can be sure that the
|
// Return the parameter values for v2 for which we can be sure that the
|
||||||
// intersection with v1 lies within.
|
// intersection with v1 lies within.
|
||||||
if(tmin === Infinity || tmax === -Infinity){
|
if(tmin !== Infinity && tmax !== -Infinity){
|
||||||
return -1;
|
if( tmaxdmin > tmax ){ tmax = 1; }
|
||||||
}
|
|
||||||
if( tmaxdmin > tmax ){ tmax = 1; }
|
|
||||||
// Debug: Plot the non-parametric graph and hull
|
// Debug: Plot the non-parametric graph and hull
|
||||||
// plotD_vs_t( 500, 110, Dt, [dq0, dq1, dq2, dq3], v1, dmin, dmax, tmin, tmax, 1.0 / ( tmax - tmin + 0.3 ) )
|
// plotD_vs_t( 500, 110, Dt, [dq0, dq1, dq2, dq3], v1, dmin, dmax, tmin, tmax, 1.0 / ( tmax - tmin + 0.3 ) )
|
||||||
// tmin and tmax are within the range (0, 1). We need to project it to the original
|
// tmin and tmax are within the range (0, 1). We need to project it to the original
|
||||||
// parameter range for v2.
|
// parameter range for v2.
|
||||||
var v2tmin = v2t.t1;
|
var v2tmin = v2t.t1;
|
||||||
var tdiff = ( v2t.t2 - v2tmin );
|
var tdiff = ( v2t.t2 - v2tmin );
|
||||||
v2t.t1 = v2tmin + tmin * tdiff;
|
v2t.t1 = v2tmin + tmin * tdiff;
|
||||||
v2t.t2 = v2tmin + tmax * tdiff;
|
v2t.t2 = v2tmin + tmax * tdiff;
|
||||||
// If the new parameter range fails to converge by atleast 20% of the original range,
|
// If the new parameter range fails to converge by atleast 20% of the original range,
|
||||||
// possibly we have multiple intersections. We need to subdivide one of the curves.
|
// possibly we have multiple intersections. We need to subdivide one of the curves.
|
||||||
if( (tdiff - ( v2t.t2 - v2t.t1 ))/tdiff < 0.2 ){
|
if( (tdiff - ( v2t.t2 - v2t.t1 ))/tdiff >= 0.2 ){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Try checking with a perpendicular fatline to see if the curves overlap
|
||||||
|
// if it is any faster than this
|
||||||
|
if( Curve.getBounds( v1 ).touches( Curve.getBounds( v2 ) ) ){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue