Simplify getGlobalMatrix().

This commit is contained in:
Jürg Lehni 2012-12-18 00:22:39 +01:00
parent 87393d130d
commit 9022bb232b

View file

@ -285,22 +285,16 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
// cached, only used for parents of items that this is called for. // cached, only used for parents of items that this is called for.
function getGlobalMatrix(item, mx, cached) { function getGlobalMatrix(item, mx, cached) {
var cache = cached && matrices[item._id]; var cache = cached && matrices[item._id];
if (cache) { // Found a cached version? Return a clone of it.
// Found a cached version, copy over the values and return if (cache)
mx.concatenate(cache); return cache.clone();
return mx; // Get concatenated matrix from all the parents, using
} // local caching (passing true for cached):
if (item._parent) { if (item._parent)
// Get concatenated matrix from all the parents, using mx = getGlobalMatrix(item._parent, mx, true);
// local caching (passing true for cached): // No need to concatenate if it's the identity matrix
getGlobalMatrix(item._parent, mx, true); if (!item._matrix.isIdentity())
// No need to concatenate if it's the identity matrix mx.concatenate(item._matrix);
if (!item._matrix.isIdentity())
mx.concatenate(item._matrix);
} else {
// Simply copy over the item's matrix, since it's the root
mx.initialize(item._matrix);
}
// If the result needs to be cached, create a copy since matrix // If the result needs to be cached, create a copy since matrix
// might be further modified through recursive calls // might be further modified through recursive calls
if (cached) if (cached)
@ -309,8 +303,7 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
} }
for (var id in this._selectedItems) { for (var id in this._selectedItems) {
var item = this._selectedItems[id]; var item = this._selectedItems[id];
item.drawSelected(ctx, item.drawSelected(ctx, getGlobalMatrix(item, matrix.clone()));
getGlobalMatrix(item, new Matrix()).preConcatenate(matrix));
} }
ctx.restore(); ctx.restore();
} }