mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Facilitate code minification in PathIterator.
This commit is contained in:
parent
becac4c921
commit
23f3097f84
2 changed files with 12 additions and 11 deletions
|
@ -107,25 +107,28 @@ var PathIterator = Base.extend({
|
||||||
_get: function(offset) {
|
_get: function(offset) {
|
||||||
// Make sure we're not beyond the requested offset already. Search the
|
// Make sure we're not beyond the requested offset already. Search the
|
||||||
// start position backwards from where to then process the loop below.
|
// start position backwards from where to then process the loop below.
|
||||||
var i, j = this.index;
|
var parts = this.parts,
|
||||||
|
length = parts.length,
|
||||||
|
start,
|
||||||
|
i, j = this.index;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
i = j;
|
i = j;
|
||||||
if (!j || this.parts[--j].offset < offset)
|
if (!j || parts[--j].offset < offset)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Find the part that succeeds the given offset, then interpolate
|
// Find the part that succeeds the given offset, then interpolate
|
||||||
// with the previous part
|
// with the previous part
|
||||||
for (var l = this.parts.length; i < l; i++) {
|
for (; i < length; i++) {
|
||||||
var part = this.parts[i];
|
var part = parts[i];
|
||||||
if (part.offset >= offset) {
|
if (part.offset >= offset) {
|
||||||
// Found the right part, remember current position
|
// Found the right part, remember current position
|
||||||
this.index = i;
|
this.index = i;
|
||||||
// Now get the previous part so we can linearly interpolate
|
// Now get the previous part so we can linearly interpolate
|
||||||
// the curve parameter
|
// the curve parameter
|
||||||
var prev = this.parts[i - 1];
|
var prev = parts[i - 1],
|
||||||
// Make sure we only use the previous parameter value if its
|
// Make sure we only use the previous parameter value if its
|
||||||
// for the same curve, by checking index. Use 0 otherwise.
|
// for the same curve, by checking index. Use 0 otherwise.
|
||||||
var prevTime = prev && prev.index === part.index ? prev.time : 0,
|
prevTime = prev && prev.index === part.index ? prev.time : 0,
|
||||||
prevOffset = prev ? prev.offset : 0;
|
prevOffset = prev ? prev.offset : 0;
|
||||||
return {
|
return {
|
||||||
index: part.index,
|
index: part.index,
|
||||||
|
@ -136,9 +139,8 @@ var PathIterator = Base.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we're still here, return last one
|
// If we're still here, return last one
|
||||||
var part = this.parts[this.parts.length - 1];
|
|
||||||
return {
|
return {
|
||||||
index: part.index,
|
index: parts[length - 1].index,
|
||||||
time: 1
|
time: 1
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -402,7 +402,6 @@ test('path.curves on closed paths', function() {
|
||||||
equals(path.curves.toString(), "{ point1: { x: 100, y: 0 }, handle1: { x: 55.22847, y: 0 }, handle2: { x: 0, y: -55.22847 }, point2: { x: 200, y: 100 } },{ point1: { x: 200, y: 100 }, handle1: { x: 0, y: 55.22847 }, handle2: { x: 55.22847, y: 0 }, point2: { x: 100, y: 200 } },{ point1: { x: 100, y: 200 }, handle1: { x: -55.22847, y: 0 }, handle2: { x: -55.22847, y: 0 }, point2: { x: 100, y: 0 } }");
|
equals(path.curves.toString(), "{ point1: { x: 100, y: 0 }, handle1: { x: 55.22847, y: 0 }, handle2: { x: 0, y: -55.22847 }, point2: { x: 200, y: 100 } },{ point1: { x: 200, y: 100 }, handle1: { x: 0, y: 55.22847 }, handle2: { x: 55.22847, y: 0 }, point2: { x: 100, y: 200 } },{ point1: { x: 100, y: 200 }, handle1: { x: -55.22847, y: 0 }, handle2: { x: -55.22847, y: 0 }, point2: { x: 100, y: 0 } }");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('path.flatten(maxDistance)', function() {
|
test('path.flatten(maxDistance)', function() {
|
||||||
var path = new Path.Circle(new Size(80, 50), 35);
|
var path = new Path.Circle(new Size(80, 50), 35);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue