From f6e474da5086a0e15acae9dbd5b189c86cf378e6 Mon Sep 17 00:00:00 2001 From: hkrish Date: Wed, 15 May 2013 21:53:05 +0200 Subject: [PATCH] Check curve bounds before recursively clipping. The speeds are back to "normal"! --- fatline/Intersect.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/fatline/Intersect.js b/fatline/Intersect.js index 5678f14e..9ab9d9b1 100644 --- a/fatline/Intersect.js +++ b/fatline/Intersect.js @@ -229,24 +229,28 @@ function _clipBezierFatLine( v1, v2, v2t ){ } // Return the parameter values for v2 for which we can be sure that the // intersection with v1 lies within. - if(tmin === Infinity || tmax === -Infinity){ - return -1; - } - if( tmaxdmin > tmax ){ tmax = 1; } + if(tmin !== Infinity && tmax !== -Infinity){ + if( tmaxdmin > tmax ){ tmax = 1; } // 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 ) ) - // 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; - var tdiff = ( v2t.t2 - v2tmin ); - v2t.t1 = v2tmin + tmin * tdiff; - v2t.t2 = v2tmin + tmax * tdiff; - // 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. - if( (tdiff - ( v2t.t2 - v2t.t1 ))/tdiff < 0.2 ){ + // 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; + var tdiff = ( v2t.t2 - v2tmin ); + v2t.t1 = v2tmin + tmin * tdiff; + v2t.t2 = v2tmin + tmax * tdiff; + // 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. + 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 0; } /**