From 53cc1cd908816f4a4b93a09f9fe64a522bfbec63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 7 May 2011 13:13:19 +0100 Subject: [PATCH] Apply #position optimisation through caching to all items, not just PlacedSymbol. --- src/item/Item.js | 11 ++++++++--- src/item/PlacedSymbol.js | 6 ------ src/path/Path.js | 4 +++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 8fe9dfbb..b9fc62c8 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -542,14 +542,16 @@ var Item = this.Item = Base.extend({ * */ getPosition: function() { - return this.getBounds().getCenter(); + // Cache position value + if (!this._position) + this._position = this.getBounds().getCenter(); + return this._position.clone(); }, setPosition: function(point) { point = Point.read(arguments); - if (point) { + if (point) this.translate(point.subtract(this.getPosition())); - } }, /** @@ -563,6 +565,9 @@ var Item = this.Item = Base.extend({ // TODO: Call transform on chidren only if 'children' flag is provided if (this._transform) this._transform(matrix, flags); + // Transform position as well + if (this._position) + this._position = matrix._transformPoint(this._position); if (this.children) { for (var i = 0, l = this.children.length; i < l; i++) { var child = this.children[i]; diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index e65cc5b2..e293128c 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -32,12 +32,6 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({ // raster, simply preconcatenate the internal matrix with the provided // one. this.matrix.preConcatenate(matrix); - // Transform position as well - this._position = matrix._transformPoint(this._position); - }, - - getPosition: function() { - return this._position.clone(); }, getBounds: function() { diff --git a/src/path/Path.js b/src/path/Path.js index 554d9913..57d59e8b 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -29,10 +29,12 @@ var Path = this.Path = PathItem.extend({ }, _changed: function() { - // Clear cached values. + // TODO: Implement ChangeFlags, e.g. STROKE, COLOR, FILL, GEOMETRY, + // and only clear caches if affected by change. delete this._length; delete this._bounds; delete this._strokeBounds; + delete this._position; }, /**