Add dest and dontNotifty arguments to Matrix#_transformBounds() and use them where appropriate.

This commit is contained in:
Jürg Lehni 2011-11-24 11:29:35 +01:00
parent 3f5e68aa76
commit 1d6cfeeb9b
3 changed files with 13 additions and 6 deletions

View file

@ -414,7 +414,7 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* point and finding the new bounding box to these points. This is not
* really the transformed reactangle!
*/
_transformBounds: function(bounds) {
_transformBounds: function(bounds, dest, dontNotify) {
var coords = this._transformCorners(bounds),
min = coords.slice(0, 2),
max = coords.slice(0);
@ -426,8 +426,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
else if (val > max[j])
max[j] = val;
}
return Rectangle.create(min[0], min[1],
max[0] - min[0], max[1] - min[1]);
if (!dest)
dest = new Rectangle(Rectangle.dont);
return dest.set(min[0], min[1], max[0] - min[0], max[1] - min[1],
dontNotify);
},
/**

View file

@ -1699,8 +1699,13 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
// and transform the cached _bounds and _position without having to
// fully recalculate each time.
if (bounds && matrix.getRotation() % 90 === 0) {
this._bounds = this._createBounds(
matrix._transformBounds(bounds));
// Transform the old _bounds without notifying it of changes
this._bounds = matrix._transformBounds(bounds, bounds, true);
// Update _position again, by linking it to _bounds
// TODO: If LinkedPoint would not just sync writes, but reads too,
// we could do this: this._position = position;
// This is a bug currently in Paper.js, that should be fixed, but
// can only really be handled properly using versioning...
this._position = this._bounds.getCenter();
} else if (position) {
// Transform position as well. Do not notify _position of

View file

@ -129,7 +129,7 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
// rough guess
var bounds = Rectangle.create(x, leading / 4 + (count - 1) * leading,
width, -count * leading);
bounds = this._matrix._transformBounds(bounds);
this._matrix._transformBounds(bounds, bounds);
// TODO: Only cache if no matrix is provided
this[cacheName] = bounds;
return getter == 'getBounds' ? this._createBounds(bounds) : bounds;