mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-15 17:29:52 -04: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);
|
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) {
|
||||||
|
|
|
@ -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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue