Move support for _bounds caching to Item and start using it in PlacedSymbol.

This commit is contained in:
Jürg Lehni 2011-06-19 18:07:53 +01:00
parent c0fa5b3711
commit bbcec27031
3 changed files with 17 additions and 9 deletions

View file

@ -43,6 +43,7 @@ var Item = this.Item = Base.extend({
*/
_changed: function(flags) {
if (flags & ChangeFlags.GEOMETRY) {
delete this._bounds;
delete this._position;
}
},
@ -1040,9 +1041,9 @@ var Item = this.Item = Base.extend({
}
}
return includeStroke
? Rectangle.create(x1, y1, x2 - x1, y2 - y1)
: LinkedRectangle.create(this, 'setBounds',
x1, y1, x2 - x1, y2 - y1);
? Rectangle.create(x1, y1, x2 - x1, y2 - y1)
: LinkedRectangle.create(this, 'setBounds',
x1, y1, x2 - x1, y2 - y1);
},
setBounds: function(rect) {
@ -1401,8 +1402,13 @@ var Item = this.Item = Base.extend({
// TODO: Handle flags, add TransformFlag class and convert to bit mask
// for quicker checking.
// TODO: Call transform on chidren only if 'children' flag is provided.
if (this._transform)
if (this._transform) {
// TODO: Detect matrices that contain only translations and scaling
// and transform the cached _bounds and _position without
// recalculating each time.
this._transform(matrix, flags);
this._changed(ChangeFlags.GEOMETRY);
}
// Transform position as well. Do not modify _position directly,
// since it's a LinkedPoint and would cause recursion!
if (this._position)

View file

@ -90,9 +90,12 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({
},
getBounds: function() {
var bounds = this.symbol._definition.getStrokeBounds(this.matrix);
return LinkedRectangle.create(this, 'setBounds',
bounds.x, bounds.y, bounds.width, bounds.height);
if (!this._bounds) {
var bounds = this.symbol._definition.getStrokeBounds(this.matrix);
this._bounds = LinkedRectangle.create(this, 'setBounds',
bounds.x, bounds.y, bounds.width, bounds.height);
}
return this._bounds;
},
getStrokeBounds: function() {

View file

@ -61,10 +61,10 @@ var Path = this.Path = PathItem.extend({
_changed: function(flags) {
if (flags & ChangeFlags.GEOMETRY) {
delete this._length;
delete this._bounds;
delete this._position;
delete this._strokeBounds;
delete this._length;
// Clockwise state becomes undefined as soon as geometry changes.
delete this._clockwise;
} else if (flags & ChangeFlags.STROKE) {
@ -217,7 +217,6 @@ var Path = this.Path = PathItem.extend({
if (strokeColor && strokeColor.transform)
strokeColor.transform(matrix);
}
this._changed(ChangeFlags.GEOMETRY);
},
/**