mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Remove _boundsCache and replace it with easier _simpleBounds flag.
This commit is contained in:
parent
067e0a954b
commit
310fbb260b
4 changed files with 12 additions and 10 deletions
|
@ -1260,8 +1260,10 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// bounds on items without children, as we do not receive hierarchy
|
||||
// change notifiers from children, and walking up the parents and
|
||||
// merging cache bounds is not expensive.
|
||||
// Allow subclasses to define _simpleBounds if they want to share the
|
||||
// cache across all different bound types.
|
||||
var cache = !this._children && !matrix
|
||||
&& (this._boundsName[name] || name);
|
||||
&& (this._simpleBounds && 'bounds' || name);
|
||||
if (cache && this._bounds && this._bounds[cache])
|
||||
return this._bounds[cache];
|
||||
var bounds = this._getBounds(name, matrix);
|
||||
|
@ -1281,12 +1283,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
return bounds;
|
||||
};
|
||||
}, /** @lends Item# */{
|
||||
/**
|
||||
* Used internally to override caching names, so bound types can share their
|
||||
* cache, in case they return the same results.
|
||||
*/
|
||||
_boundsName: {},
|
||||
|
||||
/**
|
||||
* Internal method used in all the bounds getters. It loops through all the
|
||||
* children, gets their bounds and finds the bounds around all of them.
|
||||
|
|
|
@ -95,7 +95,7 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
|||
},
|
||||
|
||||
_calculateBounds: function(type, matrix) {
|
||||
// Ask the symbol definition to calculate the bounds for us
|
||||
// Redirect the call to the symbol definition to calculate the bounds
|
||||
return this.symbol._definition._getBounds(type, matrix);
|
||||
},
|
||||
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
* @extends PlacedItem
|
||||
*/
|
||||
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||
// Raster doesn't make the distinction between the different bounds,
|
||||
// so use the same cache for all of them
|
||||
_simpleBounds: true,
|
||||
|
||||
// TODO: Implement url / type, width, height.
|
||||
// TODO: Have PlacedSymbol & Raster inherit from a shared class?
|
||||
// DOCS: Document Raster constructor.
|
||||
|
@ -381,8 +385,6 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
|||
},
|
||||
|
||||
_calculateBounds: function(type, matrix) {
|
||||
// Note: Raster doesn't make the distinction between the different
|
||||
// bounds
|
||||
return matrix._transformBounds(
|
||||
new Rectangle(this._size).setCenter(0, 0));
|
||||
},
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
* @extends Item
|
||||
*/
|
||||
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
||||
// TextItem doesn't make the distinction between the different bounds,
|
||||
// so use the same cache for all of them
|
||||
_simpleBounds: true,
|
||||
|
||||
initialize: function() {
|
||||
this.base();
|
||||
this._content = '';
|
||||
|
|
Loading…
Reference in a new issue