mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Improve _bounds handling by introducing Item#_createBounds() that always uses LinkedRectangle class.
This commit is contained in:
parent
8b66c4fa83
commit
37f5a64dce
4 changed files with 22 additions and 19 deletions
|
@ -1079,10 +1079,16 @@ var Item = this.Item = Base.extend({
|
|||
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);
|
||||
var bounds = Rectangle.create(x1, y1, x2 - x1, y2 - y1);
|
||||
return includeStroke ? bounds : this._createBounds(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)
|
||||
},
|
||||
|
||||
setBounds: function(rect) {
|
||||
|
|
|
@ -90,11 +90,9 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({
|
|||
},
|
||||
|
||||
getBounds: function() {
|
||||
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);
|
||||
}
|
||||
if (!this._bounds)
|
||||
this._bounds = this._createBounds(
|
||||
this.symbol._definition.getStrokeBounds(this.matrix))
|
||||
return this._bounds;
|
||||
},
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ var Raster = this.Raster = Item.extend({
|
|||
this._size = new Size(canvas.width, canvas.height);
|
||||
this._image = null;
|
||||
this._context = null;
|
||||
// TODO: _changed()
|
||||
this._bounds = null;
|
||||
},
|
||||
|
||||
|
@ -170,6 +171,7 @@ var Raster = this.Raster = Item.extend({
|
|||
this._size = new Size(image.naturalWidth, image.naturalHeight);
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
// TODO: _changed()
|
||||
this._bounds = null;
|
||||
},
|
||||
|
||||
|
@ -368,14 +370,12 @@ var Raster = this.Raster = Item.extend({
|
|||
// raster, simply preconcatenate the internal matrix with the provided
|
||||
// one.
|
||||
this.matrix.preConcatenate(matrix);
|
||||
this._bounds = null;
|
||||
},
|
||||
|
||||
getBounds: function() {
|
||||
if (!this._bounds) {
|
||||
this._bounds = this.matrix._transformBounds(
|
||||
new Rectangle(this._size).setCenter(0, 0));
|
||||
}
|
||||
if (!this._bounds)
|
||||
this._bounds = tis._createBounds(this.matrix._transformBounds(
|
||||
new Rectangle(this._size).setCenter(0, 0)));
|
||||
return this._bounds;
|
||||
},
|
||||
|
||||
|
|
|
@ -1766,11 +1766,10 @@ var Path = this.Path = PathItem.extend({
|
|||
// Pass the matrix hidden from Bootstrap, so it still inject
|
||||
// getBounds as bean too.
|
||||
if (!useCache || !this._bounds) {
|
||||
var bounds = getBounds(this, arguments[0]);
|
||||
if (!useCache)
|
||||
return bounds;
|
||||
this._bounds = LinkedRectangle.create(this, 'setBounds',
|
||||
bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
var bounds = this._createBounds(getBounds(this, arguments[0]));
|
||||
if (useCache)
|
||||
this._bounds = bounds;
|
||||
return bounds;
|
||||
}
|
||||
return this._bounds;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue