mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-13 16:33:28 -04:00
Give Numerical methods more meaningful names.
This commit is contained in:
parent
f5c79bf709
commit
2ac9a13e2a
2 changed files with 6 additions and 6 deletions
|
@ -321,7 +321,7 @@ var Curve = this.Curve = Base.extend({
|
|||
}
|
||||
var ds = getLengthIntegrand(
|
||||
p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
|
||||
return Numerical.gauss(ds, a, b, 8);
|
||||
return Numerical.integrate(ds, a, b, 8);
|
||||
},
|
||||
|
||||
getParameter: function(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y,
|
||||
|
@ -339,18 +339,18 @@ var Curve = this.Curve = Base.extend({
|
|||
p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
|
||||
// Use integrand both to calculate total length and part lengths
|
||||
// in f(t) below.
|
||||
var bezierLength = Numerical.gauss(ds, 0, 1, 8);
|
||||
var bezierLength = Numerical.integrate(ds, 0, 1, 8);
|
||||
if (length >= bezierLength)
|
||||
return 1;
|
||||
// Let's use the Van Wijngaarden–Dekker–Brent Method to find
|
||||
// solutions more reliably than with False Position Method.
|
||||
function f(t) {
|
||||
// The precision of 5 iterations seems enough for this
|
||||
return length - Numerical.gauss(ds, 0, t, 5);
|
||||
return length - Numerical.integrate(ds, 0, t, 5);
|
||||
}
|
||||
// Use length / bezierLength for an initial guess for b, to
|
||||
// bring us closer:
|
||||
return Numerical.brent(f, 0, length / bezierLength,
|
||||
return Numerical.findRoot(f, 0, length / bezierLength,
|
||||
Numerical.TOLERANCE);
|
||||
},
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ var Numerical = new function() {
|
|||
* Copyright (c) 2006-2007, Jim Armstrong (www.algorithmist.net)
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
gauss: function(f, a, b, n) {
|
||||
integrate: function(f, a, b, n) {
|
||||
n = Math.min(Math.max(n, 2), 8);
|
||||
|
||||
var l = n == 2 ? 0 : n * (n - 1) / 2 - 1,
|
||||
|
@ -59,7 +59,7 @@ var Numerical = new function() {
|
|||
* Van Wijngaarden–Dekker–Brent method for root finding, implementation
|
||||
* based on Numerical Recipes in C
|
||||
*/
|
||||
brent: function(f, a, b, tol) {
|
||||
findRoot: function(f, a, b, tol) {
|
||||
var c = b, d = 0, e = 0,
|
||||
fa = f(a),
|
||||
fb = f(b),
|
||||
|
|
Loading…
Reference in a new issue