mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Use getBounds.call(item) to use this instead of item, since we're accessing it a lot.
This commit is contained in:
parent
1fd9242fd8
commit
8729e9919f
1 changed files with 17 additions and 18 deletions
|
@ -1254,39 +1254,38 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
}
|
}
|
||||||
}, new function() {
|
}, new function() {
|
||||||
/**
|
/**
|
||||||
* Private method that deals with the calling of _getBounds and handles all
|
* Private method that deals with the calling of _getBounds, recursive
|
||||||
* the complicated caching mechanisms.
|
* matrix concatenation and handles all the complicated caching mechanisms.
|
||||||
|
* Note: Needs to be called on an item using getBounds.call(item, ...).
|
||||||
*/
|
*/
|
||||||
// TODO: See if calling getBounds.call(item, type, matrix) and using this
|
function getBounds(type, matrix) {
|
||||||
// instead of item speeds things up.
|
|
||||||
function getBounds(item, type, matrix) {
|
|
||||||
// If the result of concatinating the passed matrix with our internal
|
// If the result of concatinating the passed matrix with our internal
|
||||||
// one is an identity transformation, set it to null for faster
|
// one is an identity transformation, set it to null for faster
|
||||||
// processing
|
// processing
|
||||||
var identity = item._matrix.isIdentity();
|
var identity = this._matrix.isIdentity();
|
||||||
matrix = !matrix || matrix.isIdentity()
|
matrix = !matrix || matrix.isIdentity()
|
||||||
? identity ? null : item._matrix
|
? identity ? null : this._matrix
|
||||||
: identity ? matrix : matrix.clone().concatenate(item._matrix);
|
: identity ? matrix : matrix.clone().concatenate(this._matrix);
|
||||||
// See if we can cache these bounds. We only cache non-transformed
|
// See if we can cache these bounds. We only cache non-transformed
|
||||||
// bounds on items without children, as we do not receive hierarchy
|
// bounds on items without children, as we do not receive hierarchy
|
||||||
// change notifiers from children, and walking up the parents and
|
// change notifiers from children, and walking up the parents and
|
||||||
// merging cache bounds is not expensive.
|
// merging cache bounds is not expensive.
|
||||||
var cache = !item._children && !matrix && type;
|
var cache = !this._children && !matrix && type;
|
||||||
if (cache && item._bounds && item._bounds[cache])
|
if (cache && this._bounds && this._bounds[cache])
|
||||||
return item._bounds[cache];
|
return this._bounds[cache];
|
||||||
var bounds = item._getBounds(type, matrix);
|
var bounds = this._getBounds(type, matrix);
|
||||||
// If we're returning 'bounds', create a LinkedRectangle that uses
|
// If we're returning 'bounds', create a LinkedRectangle that uses
|
||||||
// the setBounds() setter to update the Item whenever the bounds are
|
// the setBounds() setter to update the Item whenever the bounds are
|
||||||
// changed:
|
// changed:
|
||||||
if (name == 'bounds')
|
if (name == 'bounds')
|
||||||
bounds = LinkedRectangle.create(item, 'setBounds',
|
bounds = LinkedRectangle.create(this, 'setBounds',
|
||||||
bounds.x, bounds.y, bounds.width, bounds.height);
|
bounds.x, bounds.y, bounds.width, bounds.height);
|
||||||
// If we can cache the result, update the _bounds cache structure
|
// If we can cache the result, update the _bounds cache structure
|
||||||
// before returning
|
// before returning
|
||||||
if (cache) {
|
if (cache) {
|
||||||
if (!item._bounds)
|
if (!this._bounds)
|
||||||
item._bounds = {};
|
this._bounds = {};
|
||||||
item._bounds[cache] = bounds;
|
this._bounds[cache] = bounds;
|
||||||
}
|
}
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
@ -1298,7 +1297,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
// overridden by subclasses, see below.
|
// overridden by subclasses, see below.
|
||||||
this['get' + Base.capitalize(name)] = function(/* matrix */) {
|
this['get' + Base.capitalize(name)] = function(/* matrix */) {
|
||||||
var type = this._boundsType;
|
var type = this._boundsType;
|
||||||
return getBounds(this,
|
return getBounds.call(this,
|
||||||
// Allow subclasses to override _boundsType if they use the
|
// Allow subclasses to override _boundsType if they use the
|
||||||
// same calculations for multiple types.
|
// same calculations for multiple types.
|
||||||
// The default is name:
|
// The default is name:
|
||||||
|
@ -1331,7 +1330,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
for (var i = 0, l = children.length; i < l; i++) {
|
for (var i = 0, l = children.length; i < l; i++) {
|
||||||
var child = children[i];
|
var child = children[i];
|
||||||
if (child._visible) {
|
if (child._visible) {
|
||||||
var rect = getBounds(child, type, matrix);
|
var rect = getBounds.call(child, type, matrix);
|
||||||
x1 = Math.min(rect.x, x1);
|
x1 = Math.min(rect.x, x1);
|
||||||
y1 = Math.min(rect.y, y1);
|
y1 = Math.min(rect.y, y1);
|
||||||
x2 = Math.max(rect.x + rect.width, x2);
|
x2 = Math.max(rect.x + rect.width, x2);
|
||||||
|
|
Loading…
Reference in a new issue