From bfa774f717485be15887bac4c0c3cec1690f48fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 4 Jul 2011 19:53:29 +0200 Subject: [PATCH] Move private bounds methods above the actual beans definitions. --- src/item/Item.js | 78 ++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 32c92326..8cb4d8d5 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1035,6 +1035,45 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ return false; }, + /** + * Loops through all children, gets their bounds and finds the bounds around + * all of them. + */ + _getBounds: function(getter, cacheName, args) { + // Note: We cannot cache these results here, since we do not get + // _changed() notifications here for changing geometry in children. + // But cacheName is used in sub-classes such as PlacedItem. + var children = this._children; + // TODO: What to return if nothing is defined, e.g. empty Groups? + // Scriptographer behaves weirdly then too. + if (!children || children.length == 0) + return new Rectangle(); + var x1 = Infinity, + x2 = -x1, + y1 = x1, + y2 = x2; + for (var i = 0, l = children.length; i < l; i++) { + var child = children[i]; + if (child._visible) { + var rect = child[getter](args[0]); + 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); + } + } + var bounds = Rectangle.create(x1, y1, x2 - x1, y2 - y1); + return getter == 'getBounds' ? this._createBounds(bounds) : bounds; + }, + + /** + * Creates a LinkedRectangle that when modified calls #setBounds(). + */ + _createBounds: function(rect) { + return LinkedRectangle.create(this, 'setBounds', + rect.x, rect.y, rect.width, rect.height); + }, + /** * {@grouptitle Bounding Rectangles} * @@ -1099,45 +1138,6 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ return this._getBounds('getRoughBounds', '_roughBounds', arguments); }, - /** - * Loops through all children, gets their bounds and finds the bounds around - * all of them. - */ - _getBounds: function(getter, cacheName, args) { - // Note: We cannot cache these results here, since we do not get - // _changed() notifications here for changing geometry in children. - // But cacheName is used in sub-classes such as PlacedItem. - var children = this._children; - // TODO: What to return if nothing is defined, e.g. empty Groups? - // Scriptographer behaves weirdly then too. - if (!children || children.length == 0) - return new Rectangle(); - var x1 = Infinity, - x2 = -x1, - y1 = x1, - y2 = x2; - for (var i = 0, l = children.length; i < l; i++) { - var child = children[i]; - if (child._visible) { - var rect = child[getter](args[0]); - 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); - } - } - var bounds = Rectangle.create(x1, y1, x2 - x1, y2 - y1); - return getter == 'getBounds' ? this._createBounds(bounds) : bounds; - }, - - /** - * Creates a LinkedRectangle that when modified calls #setBounds(). - */ - _createBounds: function(rect) { - return LinkedRectangle.create(this, 'setBounds', - rect.x, rect.y, rect.width, rect.height); - }, - /** * {@grouptitle Stroke Style} *