mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Move populating of segments list to Path#setSegments() and rely on it in constructor.
This commit is contained in:
parent
848befe103
commit
e35fb1efb6
1 changed files with 8 additions and 10 deletions
|
@ -20,18 +20,12 @@ var Path = this.Path = PathItem.extend({
|
||||||
initialize: function(/* segments */) {
|
initialize: function(/* segments */) {
|
||||||
this.base();
|
this.base();
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
this._segments = [];
|
|
||||||
// Support both passing of segments as array or arguments
|
// Support both passing of segments as array or arguments
|
||||||
// If it is an array, it can also be a description of a point, so
|
// If it is an array, it can also be a description of a point, so
|
||||||
// check its first entry for object as well
|
// check its first entry for object as well
|
||||||
var segments = arguments[0];
|
var segments = arguments[0];
|
||||||
if (!segments || !Array.isArray(segments)
|
this.setSegments(!segments || !Array.isArray(segments)
|
||||||
|| typeof segments[0] != 'object')
|
|| typeof segments[0] != 'object' ? arguments : segments);
|
||||||
segments = arguments;
|
|
||||||
for (var i = 0, l = segments.length; i < l; i++) {
|
|
||||||
var seg = Segment.read(segments, i, 1);
|
|
||||||
this._add(seg);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,9 +37,13 @@ var Path = this.Path = PathItem.extend({
|
||||||
|
|
||||||
setSegments: function(segments) {
|
setSegments: function(segments) {
|
||||||
var length = segments.length;
|
var length = segments.length;
|
||||||
this._segments.length = length;
|
if (!this._segments) {
|
||||||
|
this._segments = new Array(length);
|
||||||
|
} else {
|
||||||
|
this._segments.length = length;
|
||||||
|
}
|
||||||
for(var i = 0; i < length; i++) {
|
for(var i = 0; i < length; i++) {
|
||||||
this._segments[i] = Segment.read(segments, i, 1);
|
this._add(Segment.read(segments, i, 1));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue