mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Use cubic equation solution for faster calculation
This commit is contained in:
parent
294904eac7
commit
89a45a6682
1 changed files with 5 additions and 7 deletions
|
@ -650,13 +650,11 @@ statics: {
|
|||
p2x = v[6], p2y = v[7],
|
||||
v12x = p2x - p1x, v12y = p2y - p1x,
|
||||
t = ((point.x - p1x) * v12x + (point.y - p1y) * v12y) /
|
||||
(v12x * v12x + v12y * v12y);
|
||||
if (t <= 0) return 0;
|
||||
if (t >= 1) return 1;
|
||||
if (!t) return 0.5;
|
||||
var roots = [];
|
||||
if (Numerical.solveCubic(2, -3, 0, t, roots, 0, 1) === 1)
|
||||
return roots[0];
|
||||
(v12x * v12x + v12y * v12y),
|
||||
epsilon = /*#=*/Numerical.EPSILON;
|
||||
if (t < epsilon) return 0;
|
||||
if (t + epsilon > 1) return 1;
|
||||
return 0.5 - Math.cos(Math.acos(2 * t - 1) / 3 + Math.PI * 4 / 3) || 0.5;
|
||||
}
|
||||
|
||||
var count = 100,
|
||||
|
|
Loading…
Reference in a new issue