Improve _bounds handling by introducing Item#_createBounds() that always uses LinkedRectangle class.

This commit is contained in:
Jürg Lehni 2011-06-20 17:34:43 +01:00
parent 8b66c4fa83
commit 37f5a64dce
4 changed files with 22 additions and 19 deletions

View file

@ -1079,10 +1079,16 @@ var Item = this.Item = Base.extend({
y2 = Math.max(rect.y + rect.height, y2); y2 = Math.max(rect.y + rect.height, y2);
} }
} }
return includeStroke var bounds = Rectangle.create(x1, y1, x2 - x1, y2 - y1);
? Rectangle.create(x1, y1, x2 - x1, y2 - y1) return includeStroke ? bounds : this._createBounds(bounds);
: LinkedRectangle.create(this, 'setBounds', },
x1, y1, x2 - x1, y2 - y1);
/**
* Creates a LinkedRectangle that when modified calls #setBounds().
*/
_createBounds: function(rect) {
return LinkedRectangle.create(this, 'setBounds',
rect.x, rect.y, rect.width, rect.height)
}, },
setBounds: function(rect) { setBounds: function(rect) {

View file

@ -90,11 +90,9 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({
}, },
getBounds: function() { getBounds: function() {
if (!this._bounds) { if (!this._bounds)
var bounds = this.symbol._definition.getStrokeBounds(this.matrix); this._bounds = this._createBounds(
this._bounds = LinkedRectangle.create(this, 'setBounds', this.symbol._definition.getStrokeBounds(this.matrix))
bounds.x, bounds.y, bounds.width, bounds.height);
}
return this._bounds; return this._bounds;
}, },

View file

@ -148,6 +148,7 @@ var Raster = this.Raster = Item.extend({
this._size = new Size(canvas.width, canvas.height); this._size = new Size(canvas.width, canvas.height);
this._image = null; this._image = null;
this._context = null; this._context = null;
// TODO: _changed()
this._bounds = null; this._bounds = null;
}, },
@ -170,6 +171,7 @@ var Raster = this.Raster = Item.extend({
this._size = new Size(image.naturalWidth, image.naturalHeight); this._size = new Size(image.naturalWidth, image.naturalHeight);
this._canvas = null; this._canvas = null;
this._context = null; this._context = null;
// TODO: _changed()
this._bounds = null; this._bounds = null;
}, },
@ -368,14 +370,12 @@ var Raster = this.Raster = Item.extend({
// raster, simply preconcatenate the internal matrix with the provided // raster, simply preconcatenate the internal matrix with the provided
// one. // one.
this.matrix.preConcatenate(matrix); this.matrix.preConcatenate(matrix);
this._bounds = null;
}, },
getBounds: function() { getBounds: function() {
if (!this._bounds) { if (!this._bounds)
this._bounds = this.matrix._transformBounds( this._bounds = tis._createBounds(this.matrix._transformBounds(
new Rectangle(this._size).setCenter(0, 0)); new Rectangle(this._size).setCenter(0, 0)));
}
return this._bounds; return this._bounds;
}, },

View file

@ -1766,11 +1766,10 @@ var Path = this.Path = PathItem.extend({
// Pass the matrix hidden from Bootstrap, so it still inject // Pass the matrix hidden from Bootstrap, so it still inject
// getBounds as bean too. // getBounds as bean too.
if (!useCache || !this._bounds) { if (!useCache || !this._bounds) {
var bounds = getBounds(this, arguments[0]); var bounds = this._createBounds(getBounds(this, arguments[0]));
if (!useCache) if (useCache)
return bounds; this._bounds = bounds;
this._bounds = LinkedRectangle.create(this, 'setBounds', return bounds;
bounds.x, bounds.y, bounds.width, bounds.height);
} }
return this._bounds; return this._bounds;
}, },