Use Matrix#getRotation() to decide if we can transform cached _bounds and _position for perforamce improvements.

This commit is contained in:
Jürg Lehni 2011-06-20 18:25:49 +01:00
parent c6135c6dc7
commit 5b85d78faa

View file

@ -1449,16 +1449,25 @@ var Item = this.Item = Base.extend({
// for quicker checking.
// TODO: Call transform on chidren only if 'children' flag is provided.
if (this._transform) {
// TODO: Detect matrices that contain only translations and scaling
// and transform the cached _bounds and _position without
// recalculating each time.
// Detect matrices that contain only translations and scaling
// and transform the cached _bounds and _position without having to
// fully recalculate each time.
var bounds = this._bounds,
position = this._position;
this._transform(matrix, flags);
// Calling _changed will clear _bounds and _position, but depending
// on matrix we can calculate and set them again.
this._changed(Change.GEOMETRY);
if (bounds && matrix.getRotation() === 0) {
this._bounds = this._createBounds(
matrix._transformBounds(bounds));
this._position = this._bounds.getCenter();
} else if (position) {
// Transform position as well. Do not modify _position directly,
// since it's a LinkedPoint and would cause recursion!
this._position = matrix._transformPoint(position, position, true);
}
}
// Transform position as well. Do not modify _position directly,
// since it's a LinkedPoint and would cause recursion!
if (this._position)
matrix._transformPoint(this._position, this._position, true);
if (this._children) {
for (var i = 0, l = this._children.length; i < l; i++) {
var child = this._children[i];