Clean-up code and comments.

This commit is contained in:
Jürg Lehni 2011-03-07 02:28:49 +00:00
parent add0bcf1fd
commit 172212c222

View file

@ -330,12 +330,11 @@ var Curve = this.Curve = Base.extend({
return 0;
if (p1x == c1x && p1y == c1y && p2x == c2x && p2y == c2y) {
// Straight line, calculate directly
// t = length / lineLength:
var dx = p2x - p1x,
dy = p2y - p1y;
return Math.min(length / Math.sqrt(dx * dx + dy * dy), 1);
}
// Let's use the Van WijngaardenDekkerBrent Method to find
// solutions more reliably than with False Position Method.
var ds = getLengthIntegrand(
p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
// Use integrand both to calculate total length and part lengths
@ -347,6 +346,8 @@ var Curve = this.Curve = Base.extend({
// The precision of 5 iterations seems enough for this
return length - Numerical.gauss(ds, 0, t, 5);
}
// Let's use the Van WijngaardenDekkerBrent Method to find
// solutions more reliably than with False Position Method.
// Use length / bezierLength for an initial guess for b, to
// bring us closer:
return Numerical.brent(f, 0, length / bezierLength,