mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Further shorten #_getBounds() code.
This commit is contained in:
parent
82ef06212b
commit
7ca9bcf38a
1 changed files with 21 additions and 22 deletions
|
@ -1020,30 +1020,29 @@ var Item = this.Item = Base.extend({
|
|||
|
||||
_getBounds: function(includeStroke) {
|
||||
var children = this._children;
|
||||
if (children && children.length) {
|
||||
var x1 = Infinity,
|
||||
x2 = -Infinity,
|
||||
y1 = x1,
|
||||
y2 = x2,
|
||||
getBounds = includeStroke ? 'getStrokeBounds' : 'getBounds';
|
||||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
var child = children[i];
|
||||
if (child._visible) {
|
||||
var rect = child[getBounds]();
|
||||
x1 = Math.min(rect.x, x1);
|
||||
y1 = Math.min(rect.y, y1);
|
||||
x2 = Math.max(rect.x + rect.width, x2);
|
||||
y2 = Math.max(rect.y + rect.height, y2);
|
||||
}
|
||||
}
|
||||
return includeStroke
|
||||
? Rectangle.create(x1, y1, x2 - x1, y2 - y1)
|
||||
: LinkedRectangle.create(this, 'setBounds',
|
||||
x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
// TODO: What to return if nothing is defined, e.g. empty Groups?
|
||||
// Scriptographer behaves weirdly then too.
|
||||
return new Rectangle();
|
||||
if (!children || children.length == 0)
|
||||
return new Rectangle();
|
||||
var x1 = Infinity,
|
||||
x2 = -Infinity,
|
||||
y1 = x1,
|
||||
y2 = x2,
|
||||
getBounds = includeStroke ? 'getStrokeBounds' : 'getBounds';
|
||||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
var child = children[i];
|
||||
if (child._visible) {
|
||||
var rect = child[getBounds]();
|
||||
x1 = Math.min(rect.x, x1);
|
||||
y1 = Math.min(rect.y, y1);
|
||||
x2 = Math.max(rect.x + rect.width, x2);
|
||||
y2 = Math.max(rect.y + rect.height, y2);
|
||||
}
|
||||
}
|
||||
return includeStroke
|
||||
? Rectangle.create(x1, y1, x2 - x1, y2 - y1)
|
||||
: LinkedRectangle.create(this, 'setBounds',
|
||||
x1, y1, x2 - x1, y2 - y1);
|
||||
},
|
||||
|
||||
setBounds: function(rect) {
|
||||
|
|
Loading…
Reference in a new issue