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) { _changed: function(flags) {
if (flags & ChangeFlags.GEOMETRY) { if (flags & ChangeFlags.GEOMETRY) {
delete this._bounds;
delete this._position; delete this._position;
} }
}, },
@ -1401,8 +1402,13 @@ var Item = this.Item = Base.extend({
// TODO: Handle flags, add TransformFlag class and convert to bit mask // TODO: Handle flags, add TransformFlag class and convert to bit mask
// for quicker checking. // for quicker checking.
// TODO: Call transform on chidren only if 'children' flag is provided. // 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._transform(matrix, flags);
this._changed(ChangeFlags.GEOMETRY);
}
// Transform position as well. Do not modify _position directly, // Transform position as well. Do not modify _position directly,
// since it's a LinkedPoint and would cause recursion! // since it's a LinkedPoint and would cause recursion!
if (this._position) if (this._position)

View file

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

View file

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