Clean up and simplify code a bit further.

This commit is contained in:
Jürg Lehni 2014-09-28 11:49:46 +02:00
parent 7462fe0b70
commit 6a11532322
2 changed files with 7 additions and 8 deletions

View file

@ -1036,11 +1036,10 @@ new function() { // Scope for methods that require numerical integration
start = t; start = t;
return length - offset; return length - offset;
} }
return Numerical.findRoot(f, ds, // Start with out initial guess for x.
// Start with out initial guess for x. // NOTE: guess is a negative value when not looking forward.
// NOTE: guess is a negative value when not looking forward. return Numerical.findRoot(f, ds, start + guess, a, b, 16,
forward ? a + guess : b + guess, /*#=*/Numerical.TOLERANCE);
a, b, 16, /*#=*/Numerical.TOLERANCE);
} }
}; };
}, new function() { // Scope for intersection using bezier fat-line clipping }, new function() { // Scope for intersection using bezier fat-line clipping

View file

@ -101,7 +101,7 @@ var Numerical = new function() {
integrate: function(f, a, b, n) { integrate: function(f, a, b, n) {
var x = abscissas[n - 2], var x = abscissas[n - 2],
w = weights[n - 2], w = weights[n - 2],
A = 0.5 * (b - a), A = (b - a) * 0.5,
B = A + a, B = A + a,
i = 0, i = 0,
m = (n + 1) >> 1, m = (n + 1) >> 1,
@ -134,10 +134,10 @@ var Numerical = new function() {
// intercept is larger than lower / smaller than upper. // intercept is larger than lower / smaller than upper.
if (fx > 0) { if (fx > 0) {
b = x; b = x;
x = nx <= a ? 0.5 * (a + b) : nx; x = nx <= a ? (a + b) * 0.5 : nx;
} else { } else {
a = x; a = x;
x = nx >= b ? 0.5 * (a + b) : nx; x = nx >= b ? (a + b) * 0.5 : nx;
} }
} }
// Return the best result even though we haven't gotten close // Return the best result even though we haven't gotten close