mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Clean up and shorten code.
This commit is contained in:
parent
12e770c032
commit
27c7248a2d
1 changed files with 13 additions and 22 deletions
|
@ -97,37 +97,28 @@ var PathFitter = Base.extend({
|
||||||
pt1 = this.points[first],
|
pt1 = this.points[first],
|
||||||
pt2 = this.points[last];
|
pt2 = this.points[last];
|
||||||
|
|
||||||
var A = [];
|
|
||||||
// Compute the A's
|
|
||||||
for (var i = 0; i < nPts; i++) {
|
|
||||||
var u = uPrime[i],
|
|
||||||
t = 1 - u,
|
|
||||||
b = 3 * u * t;
|
|
||||||
A[i] = [
|
|
||||||
tHat1.normalize(b * t), // b1
|
|
||||||
tHat2.normalize(b * u) // b2
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the C and X matrices
|
// Create the C and X matrices
|
||||||
var C = [[0, 0], [0, 0]],
|
var C = [[0, 0], [0, 0]],
|
||||||
X = [0, 0];
|
X = [0, 0];
|
||||||
|
|
||||||
for (var i = 0; i < nPts; i++) {
|
for (var i = 0; i < nPts; i++) {
|
||||||
C[0][0] += A[i][0].dot(A[i][0]);
|
|
||||||
C[0][1] += A[i][0].dot(A[i][1]);
|
|
||||||
// C[1][0] += A[i][0].dot(A[i][1]);
|
|
||||||
C[1][0] = C[0][1];
|
|
||||||
C[1][1] += A[i][1].dot(A[i][1]);
|
|
||||||
|
|
||||||
var u = uPrime[i],
|
var u = uPrime[i],
|
||||||
t = 1 - u,
|
t = 1 - u,
|
||||||
b = 3 * u * t,
|
b = 3 * u * t,
|
||||||
|
b0 = t * t * t,
|
||||||
|
b1 = b * t,
|
||||||
|
b2 = b * u,
|
||||||
|
b3 = u * u * u,
|
||||||
|
a1 = tHat1.normalize(b1),
|
||||||
|
a2 = tHat2.normalize(b2),
|
||||||
tmp = this.points[first + i]
|
tmp = this.points[first + i]
|
||||||
.subtract(pt1.multiply(t * t * t) // b0
|
.subtract(pt1.multiply(b0 + b1))
|
||||||
.add(pt1.multiply(b * t)) // b1
|
.subtract(pt2.multiply(b2 + b3));
|
||||||
.add(pt2.multiply(b * u)) // b2
|
C[0][0] += a1.dot(a1);
|
||||||
.add(pt2.multiply(u * u * u))); // b3
|
C[0][1] += a1.dot(a2);
|
||||||
|
// C[1][0] += a1.dot(a2);
|
||||||
|
C[1][0] = C[0][1];
|
||||||
|
C[1][1] += a2.dot(a2);
|
||||||
X[0] += A[i][0].dot(tmp);
|
X[0] += A[i][0].dot(tmp);
|
||||||
X[1] += A[i][1].dot(tmp);
|
X[1] += A[i][1].dot(tmp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue