Increase stability of the implementation

This commit is contained in:
hkrish 2013-05-14 22:15:11 +02:00
parent 5bdf3bce91
commit ebbe2d7569

View file

@ -83,20 +83,20 @@ paper.Curve.getIntersections2 = function( v1, v2, curve1, curve2, locations, _v1
// ...and reuse some objects.
v2t.t1 = tmpt.t1; v2t.t2 = tmpt.t2;
_v2 = Curve.getPart( v2, v2t.t1, v2t.t2 );
}
// markCurve( _v2, '#0ff', false );
// Next we clip v1 with nuv2's fat-line
tmpt.t1 = v1t.t1; tmpt.t2 = v1t.t2;
var intersects2 = _clipBezierFatLine( _v2, _v1, tmpt );
// Stop if there are no possible intersections
if( intersects2 === 0 ){
return;
}else if( intersects1 > 0 ){
// Get the clipped parts from the original v2, to avoid cumulative errors
v1t.t1 = tmpt.t1; v1t.t2 = tmpt.t2;
_v1 = Curve.getPart( v1, v1t.t1, v1t.t2 );
}
// Next we clip v1 with nuv2's fat-line
tmpt.t1 = v1t.t1; tmpt.t2 = v1t.t2;
var intersects2 = _clipBezierFatLine( _v2, _v1, tmpt );
// Stop if there are no possible intersections
if( intersects2 === 0 ){
return;
}else if( intersects1 > 0 ){
// Get the clipped parts from the original v2, to avoid cumulative errors
v1t.t1 = tmpt.t1; v1t.t2 = tmpt.t2;
_v1 = Curve.getPart( v1, v1t.t1, v1t.t2 );
}
// markCurve( _v1, '#f0f', true );
}
// Get the clipped parts from the original v1
// Check if there could be multiple intersections
if( intersects1 < 0 || intersects2 < 0 ){
@ -227,12 +227,16 @@ function _clipBezierFatLine( v1, v2, v2t ){
// Return the parameter values for v2 for which we can be sure that the
// intersection with v1 lies within.
var tmin, tmax;
if(tmindmin === Infinity || tmaxdmin === -Infinity || tmindmax === Infinity || tmaxdmax === -Infinity){
return -1;
}
if( dq3 > dq0 ){
// if dmin or dmax doesnot intersect with the convexhull, reset the parameter limits
if( tmindmin === Infinity ) tmindmin = 0;
if( tmaxdmin === -Infinity ) tmaxdmin = 0;
if( tmindmax === Infinity ) tmindmax = 1;
if( tmaxdmax === -Infinity ) tmaxdmax =1;
// if( tmindmin === Infinity ) tmindmin = 0;
// if( tmaxdmin === -Infinity ) tmaxdmin = 0;
// if( tmindmax === Infinity ) tmindmax = 1;
// if( tmaxdmax === -Infinity ) tmaxdmax =1;
tmin = Math.min( tmindmin, tmaxdmin );
tmax = Math.max( tmindmax, tmaxdmax );
if( Math.min( tmindmax, tmaxdmax ) < tmin )
@ -241,10 +245,10 @@ function _clipBezierFatLine( v1, v2, v2t ){
tmax = 1;
}else{
// if dmin or dmax doesnot intersect with the convexhull, reset the parameter limits
if( tmindmin === Infinity ) tmindmin =1;
if( tmaxdmin === -Infinity ) tmaxdmin =1;
if( tmindmax === Infinity ) tmindmax = 0;
if( tmaxdmax === -Infinity ) tmaxdmax = 0;
// if( tmindmin === Infinity ) tmindmin =1;
// if( tmaxdmin === -Infinity ) tmaxdmin =1;
// if( tmindmax === Infinity ) tmindmax = 0;
// if( tmaxdmax === -Infinity ) tmaxdmax = 0;
tmax = Math.max( tmindmin, tmaxdmin );
tmin = Math.min( tmindmax, tmaxdmax );
if( Math.min( tmindmin, tmaxdmin ) < tmin )
@ -254,9 +258,6 @@ function _clipBezierFatLine( v1, v2, v2t ){
}
// 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 ) )
// if( tmin === 0.0 && tmax === 1.0 ){
// return 0;
// }
// tmin and tmax are within the range (0, 1). We need to project it to the original
// parameter range for v2.
var v2tmin = v2t.t1;