diff --git a/src/item/Item.js b/src/item/Item.js index 9e315a3b..d4fc614f 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -43,6 +43,7 @@ var Item = this.Item = Base.extend({ */ _changed: function(flags) { if (flags & ChangeFlags.GEOMETRY) { + delete this._bounds; delete this._position; } }, @@ -1040,9 +1041,9 @@ var Item = this.Item = Base.extend({ } } return includeStroke - ? Rectangle.create(x1, y1, x2 - x1, y2 - y1) - : LinkedRectangle.create(this, 'setBounds', - x1, y1, x2 - x1, y2 - y1); + ? Rectangle.create(x1, y1, x2 - x1, y2 - y1) + : LinkedRectangle.create(this, 'setBounds', + x1, y1, x2 - x1, y2 - y1); }, setBounds: function(rect) { @@ -1401,8 +1402,13 @@ var Item = this.Item = Base.extend({ // TODO: Handle flags, add TransformFlag class and convert to bit mask // for quicker checking. // TODO: Call transform on chidren only if 'children' flag is provided. - if (this._transform) + if (this._transform) { + // TODO: Detect matrices that contain only translations and scaling + // and transform the cached _bounds and _position without + // recalculating each time. this._transform(matrix, flags); + this._changed(ChangeFlags.GEOMETRY); + } // Transform position as well. Do not modify _position directly, // since it's a LinkedPoint and would cause recursion! if (this._position) diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 92121d72..bf392288 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -90,9 +90,12 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({ }, getBounds: function() { - var bounds = this.symbol._definition.getStrokeBounds(this.matrix); - return LinkedRectangle.create(this, 'setBounds', - bounds.x, bounds.y, bounds.width, bounds.height); + if (!this._bounds) { + var bounds = this.symbol._definition.getStrokeBounds(this.matrix); + this._bounds = LinkedRectangle.create(this, 'setBounds', + bounds.x, bounds.y, bounds.width, bounds.height); + } + return this._bounds; }, getStrokeBounds: function() { diff --git a/src/path/Path.js b/src/path/Path.js index aaffaa11..d2944dc3 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -61,10 +61,10 @@ var Path = this.Path = PathItem.extend({ _changed: function(flags) { if (flags & ChangeFlags.GEOMETRY) { - delete this._length; delete this._bounds; delete this._position; delete this._strokeBounds; + delete this._length; // Clockwise state becomes undefined as soon as geometry changes. delete this._clockwise; } else if (flags & ChangeFlags.STROKE) { @@ -217,7 +217,6 @@ var Path = this.Path = PathItem.extend({ if (strokeColor && strokeColor.transform) strokeColor.transform(matrix); } - this._changed(ChangeFlags.GEOMETRY); }, /**