mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Cleanup solveCubic() further.
This commit is contained in:
parent
2fc4ff10ee
commit
dc9a9c42d2
2 changed files with 12 additions and 11 deletions
|
@ -301,7 +301,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
|
|||
if (t >= -tolerance && t < 1 - tolerance) {
|
||||
var pt = Curve.evaluate(vals, t, true, 0);
|
||||
/*#*/ if (options.debug) {
|
||||
console.log(t, point.y, pt.y);
|
||||
console.log(t, point + '', pt + '');
|
||||
new Path.Circle({
|
||||
center: Curve.evaluate(vals, t, true, 0),
|
||||
radius: 2,
|
||||
|
|
|
@ -180,18 +180,19 @@ var Numerical = this.Numerical = new function() {
|
|||
if (abs(q) < epsilon) { // One triple solution.
|
||||
roots[0] = - b;
|
||||
return 1;
|
||||
} else { // One single and one double solution.
|
||||
var sqp = sqrt(p),
|
||||
snq = q > 0 ? 1 : -1;
|
||||
roots[0] = -snq * 2 * sqp - b;
|
||||
roots[1] = snq * sqp - b;
|
||||
return 2;
|
||||
}
|
||||
} else if (D < 0) { // Casus irreducibilis: three real solutions
|
||||
}
|
||||
// One single and one double solution.
|
||||
var sqp = sqrt(p),
|
||||
snq = q > 0 ? 1 : -1;
|
||||
roots[0] = -snq * 2 * sqp - b;
|
||||
roots[1] = snq * sqp - b;
|
||||
return 2;
|
||||
}
|
||||
if (D < 0) { // Casus irreducibilis: three real solutions
|
||||
var sqp = sqrt(p),
|
||||
phi = Math.acos(q / (sqp * sqp * sqp)) / 3,
|
||||
o = 2 * PI / 3,
|
||||
t = -2 * sqp;
|
||||
t = -2 * sqp,
|
||||
o = 2 * PI / 3;
|
||||
roots[0] = t * cos(phi) - b;
|
||||
roots[1] = t * cos(phi + o) - b;
|
||||
roots[2] = t * cos(phi - o) - b;
|
||||
|
|
Loading…
Reference in a new issue