From 6a11532322f098ccaf99662c58c44bbcb164f6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 28 Sep 2014 11:49:46 +0200 Subject: [PATCH] Clean up and simplify code a bit further. --- src/path/Curve.js | 9 ++++----- src/util/Numerical.js | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index f14f15c1..cfcc9ff0 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -1036,11 +1036,10 @@ new function() { // Scope for methods that require numerical integration start = t; return length - offset; } - return Numerical.findRoot(f, ds, - // Start with out initial guess for x. - // NOTE: guess is a negative value when not looking forward. - forward ? a + guess : b + guess, - a, b, 16, /*#=*/Numerical.TOLERANCE); + // Start with out initial guess for x. + // NOTE: guess is a negative value when not looking forward. + return Numerical.findRoot(f, ds, start + guess, a, b, 16, + /*#=*/Numerical.TOLERANCE); } }; }, new function() { // Scope for intersection using bezier fat-line clipping diff --git a/src/util/Numerical.js b/src/util/Numerical.js index c14895f4..433e185f 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -101,7 +101,7 @@ var Numerical = new function() { integrate: function(f, a, b, n) { var x = abscissas[n - 2], w = weights[n - 2], - A = 0.5 * (b - a), + A = (b - a) * 0.5, B = A + a, i = 0, m = (n + 1) >> 1, @@ -134,10 +134,10 @@ var Numerical = new function() { // intercept is larger than lower / smaller than upper. if (fx > 0) { b = x; - x = nx <= a ? 0.5 * (a + b) : nx; + x = nx <= a ? (a + b) * 0.5 : nx; } else { 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