Merge pull request #1083 from iconexperience/solve-cubic

Add check of value range in Curve.solveCubic to improve performance
This commit is contained in:
Jürg Lehni 2016-06-16 14:02:48 +02:00 committed by GitHub
commit fa0a474ec7

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);