mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Remove tolerance parameter from solveCubic() / solveQuadratic() since we should always use EPSILON.
This commit is contained in:
parent
14aa8e5dea
commit
c45ad26b67
2 changed files with 15 additions and 14 deletions
|
@ -533,8 +533,7 @@ statics: {
|
|||
c = 3 * (c1 - p1),
|
||||
b = 3 * (c2 - c1) - c,
|
||||
a = p2 - p1 - c - b;
|
||||
return Numerical.solveCubic(a, b, c, p1 - val, roots,
|
||||
/*#=*/ Numerical.EPSILON);
|
||||
return Numerical.solveCubic(a, b, c, p1 - val, roots);
|
||||
},
|
||||
|
||||
getParameterOf: function(v, x, y) {
|
||||
|
@ -636,8 +635,7 @@ statics: {
|
|||
var a = 3 * (v1 - v2) - v0 + v3,
|
||||
b = 2 * (v0 + v2) - 4 * v1,
|
||||
c = v1 - v0,
|
||||
count = Numerical.solveQuadratic(a, b, c, roots,
|
||||
/*#=*/ Numerical.TOLERANCE),
|
||||
count = Numerical.solveQuadratic(a, b, c, roots),
|
||||
// Add some tolerance for good roots, as t = 0 / 1 are added
|
||||
// seperately anyhow, and we don't want joins to be added with
|
||||
// radiuses in getStrokeBounds()
|
||||
|
|
|
@ -132,16 +132,17 @@ var Numerical = this.Numerical = new function() {
|
|||
*
|
||||
* a*x^2 + b*x + c = 0
|
||||
*/
|
||||
solveQuadratic: function(a, b, c, roots, tolerance) {
|
||||
solveQuadratic: function(a, b, c, roots) {
|
||||
// Code ported over and adapted from Uintah library (MIT license).
|
||||
// If problem is actually linear, return 0 or 1 easy roots
|
||||
if (abs(a) < tolerance) {
|
||||
if (abs(b) >= tolerance) {
|
||||
var epsilon = this.EPSILON;
|
||||
// If a is 0, equation is actually linear, return 0 or 1 easy roots.
|
||||
if (abs(a) < epsilon) {
|
||||
if (abs(b) >= epsilon) {
|
||||
roots[0] = -c / b;
|
||||
return 1;
|
||||
}
|
||||
// If all the coefficients are 0, we have infinite solutions!
|
||||
return abs(c) < tolerance ? -1 : 0; // Infinite or 0 solutions
|
||||
return abs(c) < epsilon ? -1 : 0; // Infinite or 0 solutions
|
||||
}
|
||||
var q = b * b - 4 * a * c;
|
||||
if (q < 0)
|
||||
|
@ -161,10 +162,12 @@ var Numerical = this.Numerical = new function() {
|
|||
*
|
||||
* a*x^3 + b*x^2 + c*x + d = 0
|
||||
*/
|
||||
solveCubic: function(a, b, c, d, roots, tolerance) {
|
||||
solveCubic: function(a, b, c, d, roots) {
|
||||
// Code ported over and adapted from Uintah library (MIT license).
|
||||
if (abs(a) < tolerance)
|
||||
return Numerical.solveQuadratic(b, c, d, roots, tolerance);
|
||||
var epsilon = this.EPSILON;
|
||||
// If a is 0, equation is actually quadratic.
|
||||
if (abs(a) < epsilon)
|
||||
return Numerical.solveQuadratic(b, c, d, roots);
|
||||
// Normalize to form: x^3 + b x^2 + c x + d = 0:
|
||||
b /= a;
|
||||
c /= a;
|
||||
|
@ -178,8 +181,8 @@ var Numerical = this.Numerical = new function() {
|
|||
D = q * q - ppp;
|
||||
// Substitute x = y - b/3 to eliminate quadric term: x^3 +px + q = 0
|
||||
b /= 3;
|
||||
if (abs(D) < tolerance) {
|
||||
if (abs(q) < tolerance) { // One triple solution.
|
||||
if (abs(D) < epsilon) {
|
||||
if (abs(q) < epsilon) { // One triple solution.
|
||||
roots[0] = - b;
|
||||
return 1;
|
||||
} else { // One single and one double solution.
|
||||
|
|
Loading…
Reference in a new issue