mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Allow rectangles to be created from arrays too.
This commit is contained in:
parent
af66bccb64
commit
86609103fc
1 changed files with 15 additions and 8 deletions
|
@ -101,14 +101,21 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
}
|
||||
if (this._read)
|
||||
this._read = arguments._index;
|
||||
} else if (arg0) {
|
||||
// new Rectangle(rect)
|
||||
// Use 0 as defaults, in case we're not reading from a Rectangle,
|
||||
// but a Point or Size instead
|
||||
this.x = arg0.x || 0;
|
||||
this.y = arg0.y || 0;
|
||||
this.width = arg0.width || 0;
|
||||
this.height = arg0.height || 0;
|
||||
} else {
|
||||
if (Array.isArray(arg0)) {
|
||||
this.x = arg0[0];
|
||||
this.y = arg0[1];
|
||||
this.width = arg0[2];
|
||||
this.height = arg0[3];
|
||||
} else {
|
||||
// new Rectangle(rect)
|
||||
// Use 0 as defaults, in case we're not reading from a Rectangle,
|
||||
// but a Point or Size instead
|
||||
this.x = arg0.x || 0;
|
||||
this.y = arg0.y || 0;
|
||||
this.width = arg0.width || 0;
|
||||
this.height = arg0.height || 0;
|
||||
}
|
||||
if (this._read)
|
||||
this._read = 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue