mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Correct execution sequence in getBounds so that the parent's _boundsCache is kept up to date even when the child is returning a cached result.
This commit is contained in:
parent
e82deff4b9
commit
d3c83be3bb
1 changed files with 12 additions and 10 deletions
|
@ -1284,17 +1284,17 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
matrix = !matrix || matrix.isIdentity()
|
matrix = !matrix || matrix.isIdentity()
|
||||||
? identity ? null : this._matrix
|
? identity ? null : this._matrix
|
||||||
: identity ? matrix : matrix.clone().concatenate(this._matrix);
|
: identity ? matrix : matrix.clone().concatenate(this._matrix);
|
||||||
if (cache && this._bounds && this._bounds[cache])
|
// Set up a boundsCache structure that keeps track of items that keep
|
||||||
return this._bounds[cache];
|
// cached bounds that depend on this item. We store this in our parent,
|
||||||
|
// for multiple reasons:
|
||||||
|
// The parent receives HIERARCHY change notifications for when its
|
||||||
|
// children are added or removed and can thus clear the cache, and we
|
||||||
|
// save a lot of memory, e.g. when grouping 100 items and asking the
|
||||||
|
// group for its bounds. If stored on the children, we would have 100
|
||||||
|
// times the same structure.
|
||||||
|
// Note: This needs to happen before returning cached values, since even
|
||||||
|
// then, _boundsCache needs to be kept up-to-date.
|
||||||
if (cacheItem) {
|
if (cacheItem) {
|
||||||
// Set up a boundsCache structure that keeps track of items that
|
|
||||||
// keep cached bounds that depend on this item. We store this in our
|
|
||||||
// parent, for multiple reasons:
|
|
||||||
// The parent receives HIERARCHY change notifications for when its
|
|
||||||
// children are added or removed and can thus clear the cache, and
|
|
||||||
// we save a lot of memory, e.g. when grouping 100 items and asking
|
|
||||||
// the group for its bounds. If stored on the children, we would
|
|
||||||
// have 100 times the same structure.
|
|
||||||
if (this._parent) {
|
if (this._parent) {
|
||||||
// Set-up the parent's boundsCache structure if it does not
|
// Set-up the parent's boundsCache structure if it does not
|
||||||
// exist yet and add the cacheItem to it.
|
// exist yet and add the cacheItem to it.
|
||||||
|
@ -1313,6 +1313,8 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cache && this._bounds && this._bounds[cache])
|
||||||
|
return this._bounds[cache];
|
||||||
// If we're caching bounds on this item, pass it on as cacheItem, so the
|
// If we're caching bounds on this item, pass it on as cacheItem, so the
|
||||||
// children can setup the _boundsCache structures for it.
|
// children can setup the _boundsCache structures for it.
|
||||||
var bounds = this._getBounds(type, matrix, cache ? this : cacheItem);
|
var bounds = this._getBounds(type, matrix, cache ? this : cacheItem);
|
||||||
|
|
Loading…
Reference in a new issue