mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Make Path#_add() handle both addition and insertion, and use it consequently so segment.path always gets correctly set.
This commit is contained in:
parent
9a2462d147
commit
e089e080c2
1 changed files with 15 additions and 9 deletions
|
@ -13,7 +13,7 @@ Path = PathItem.extend({
|
||||||
|| typeof segments[0] != 'object')
|
|| typeof segments[0] != 'object')
|
||||||
segments = arguments;
|
segments = arguments;
|
||||||
for (var i = 0, l = segments.length; i < l; i++)
|
for (var i = 0, l = segments.length; i < l; i++)
|
||||||
this._add(new Segment(segments[i]));
|
this._add(Segment.read(segments[i]));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,22 +117,28 @@ Path = PathItem.extend({
|
||||||
* Private method that adds a segment to the segment list. It assumes that
|
* Private method that adds a segment to the segment list. It assumes that
|
||||||
* the passed object is a segment already and does not perform any checks.
|
* the passed object is a segment already and does not perform any checks.
|
||||||
*/
|
*/
|
||||||
_add: function(segment) {
|
_add: function(segment, index) {
|
||||||
|
// If this segment belongs to another path already, clone it before
|
||||||
|
// adding.
|
||||||
|
if (segment.path)
|
||||||
|
segment = new Segment(segment);
|
||||||
segment.path = this;
|
segment.path = this;
|
||||||
this._segments.push(segment);
|
if (index == undefined) {
|
||||||
|
this._segments.push(segment);
|
||||||
|
} else {
|
||||||
|
this._segments.splice(index, 0, segment);
|
||||||
|
}
|
||||||
|
return segment;
|
||||||
},
|
},
|
||||||
|
|
||||||
add: function() {
|
add: function() {
|
||||||
var segment = Segment.read(arguments);
|
var segment = Segment.read(arguments);
|
||||||
if (segment)
|
return segment ? this._add(segment) : null;
|
||||||
this._add(segment);
|
|
||||||
return segment;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: make sure that if the segment belongs to another path, it clones
|
|
||||||
// the segment. Otherwise it returns the same segment.
|
|
||||||
insert: function(index, segment) {
|
insert: function(index, segment) {
|
||||||
this._segments.splice(index, 0, new Segment(segment));
|
var segment = Segment.read(arguments, 1);
|
||||||
|
return segment ? this._add(segment, index) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue