mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 10:48:38 -05:00
Fix newly introduced issue in CompoundPath#moveTo() / #lineTo()
This commit is contained in:
parent
763fd5b6a3
commit
b08cc68ffe
3 changed files with 12 additions and 9 deletions
|
@ -277,10 +277,11 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
||||||
* Helper method that returns the current path and checks if a moveTo()
|
* Helper method that returns the current path and checks if a moveTo()
|
||||||
* command is required first.
|
* command is required first.
|
||||||
*/
|
*/
|
||||||
function getCurrentPath(that) {
|
function getCurrentPath(that, check) {
|
||||||
if (!that._children.length)
|
var children = that._children;
|
||||||
|
if (check && children.length === 0)
|
||||||
throw new Error('Use a moveTo() command first');
|
throw new Error('Use a moveTo() command first');
|
||||||
return that._children[that._children.length - 1];
|
return children[children.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var fields = {
|
var fields = {
|
||||||
|
@ -297,12 +298,14 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
moveBy: function(/* point */) {
|
moveBy: function(/* point */) {
|
||||||
this.moveTo(getCurrentPath(this).getLastSegment()._point.add(
|
var current = getCurrentPath(this, true),
|
||||||
Point.read(arguments)));
|
last = current && current.getLastSegment(),
|
||||||
|
point = Point.read(arguments);
|
||||||
|
this.moveTo(last ? point.add(last._point) : point);
|
||||||
},
|
},
|
||||||
|
|
||||||
closePath: function() {
|
closePath: function() {
|
||||||
getCurrentPath(this).closePath();
|
getCurrentPath(this, true).closePath();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -311,7 +314,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
||||||
'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'],
|
'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'],
|
||||||
function(key) {
|
function(key) {
|
||||||
fields[key] = function() {
|
fields[key] = function() {
|
||||||
var path = getCurrentPath(this);
|
var path = getCurrentPath(this, true);
|
||||||
path[key].apply(path, arguments);
|
path[key].apply(path, arguments);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2221,7 +2221,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
*/
|
*/
|
||||||
function getCurrentSegment(that) {
|
function getCurrentSegment(that) {
|
||||||
var segments = that._segments;
|
var segments = that._segments;
|
||||||
if (segments.length == 0)
|
if (segments.length === 0)
|
||||||
throw new Error('Use a moveTo() command first');
|
throw new Error('Use a moveTo() command first');
|
||||||
return segments[segments.length - 1];
|
return segments[segments.length - 1];
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ test('moveTo / lineTo', function() {
|
||||||
for (var i = 0; i < lists.length; i++) {
|
for (var i = 0; i < lists.length; i++) {
|
||||||
var list = lists[i];
|
var list = lists[i];
|
||||||
for (var j = 0; j < list.length; j++) {
|
for (var j = 0; j < list.length; j++) {
|
||||||
path[j == 0 ? 'moveTo' : 'lineTo'](list[j]);
|
path[j === 0 ? 'moveTo' : 'lineTo'](list[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue