mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -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()
|
||||
* command is required first.
|
||||
*/
|
||||
function getCurrentPath(that) {
|
||||
if (!that._children.length)
|
||||
function getCurrentPath(that, check) {
|
||||
var children = that._children;
|
||||
if (check && children.length === 0)
|
||||
throw new Error('Use a moveTo() command first');
|
||||
return that._children[that._children.length - 1];
|
||||
return children[children.length - 1];
|
||||
}
|
||||
|
||||
var fields = {
|
||||
|
@ -297,12 +298,14 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
},
|
||||
|
||||
moveBy: function(/* point */) {
|
||||
this.moveTo(getCurrentPath(this).getLastSegment()._point.add(
|
||||
Point.read(arguments)));
|
||||
var current = getCurrentPath(this, true),
|
||||
last = current && current.getLastSegment(),
|
||||
point = Point.read(arguments);
|
||||
this.moveTo(last ? point.add(last._point) : point);
|
||||
},
|
||||
|
||||
closePath: function() {
|
||||
getCurrentPath(this).closePath();
|
||||
getCurrentPath(this, true).closePath();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -311,7 +314,7 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'],
|
||||
function(key) {
|
||||
fields[key] = function() {
|
||||
var path = getCurrentPath(this);
|
||||
var path = getCurrentPath(this, true);
|
||||
path[key].apply(path, arguments);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2221,7 +2221,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
*/
|
||||
function getCurrentSegment(that) {
|
||||
var segments = that._segments;
|
||||
if (segments.length == 0)
|
||||
if (segments.length === 0)
|
||||
throw new Error('Use a moveTo() command first');
|
||||
return segments[segments.length - 1];
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ test('moveTo / lineTo', function() {
|
|||
for (var i = 0; i < lists.length; i++) {
|
||||
var list = lists[i];
|
||||
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