Add check of value range in solveCubic

Performance of `Curve.solveCubic()` can be improved by first checking if the specified value is within the curve's value range. If it is outside the range, the expensive call to `Numerical.solveCubic()` is not necessary.
This commit is contained in:
Jan 2016-06-16 13:13:16 +02:00 committed by GitHub
parent eb752a43cd
commit 7009fc3ea0

View file

@ -628,8 +628,13 @@ statics: /** @lends Curve */{
var p1 = v[coord],
c1 = v[coord + 2],
c2 = v[coord + 4],
p2 = v[coord + 6],
c = 3 * (c1 - p1),
p2 = v[coord + 6];
if (p1 < val && p2 < val && c1 < val && c2 < val
|| p1 > val && p2 > val && c1 > val && c2 > val) {
// If val is outside the curve values, no solution is possible.
return 0;
}
var c = 3 * (c1 - p1),
b = 3 * (c2 - c1) - c,
a = p2 - p1 - c - b;
return Numerical.solveCubic(a, b, c, p1 - val, roots, min, max);