Allow passing of Paths to CompoundPath constructor as arguments, without an array object.

This commit is contained in:
Jürg Lehni 2011-05-15 19:14:09 +01:00
parent e9e93abb44
commit 7ba2fcad2a

View file

@ -18,18 +18,20 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
initialize: function(paths) { initialize: function(paths) {
this.base(); this.base();
this._children = []; this._children = [];
if (paths) { // Do not reassign to paths, since arguments would get modified, which
for (var i = 0, l = paths.length; i < l; i++) { // we potentially use as array, depending on what is passed.
var path = paths[i]; var items = !paths || !Array.isArray(paths)
// All paths except for the top one (last one in list) are || typeof paths[0] !== 'object' ? arguments : paths;
// set to clockwise orientation when creating a compound path, for (var i = 0, l = items.length; i < l; i++) {
// so that they appear as holes, but only if their orientation var path = items[i];
// was not already specified before (= _clockwise is defined). // All paths except for the top one (last one in list) are set to
// clockwise orientation when creating a compound path, so that they
// appear as holes, but only if their orientation was not already
// specified before (= _clockwise is defined).
if (path._clockwise === undefined) if (path._clockwise === undefined)
path.setClockwise(i < l - 1); path.setClockwise(i < l - 1);
this.appendTop(path); this.appendTop(path);
} }
}
}, },
/** /**