mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Move support for _bounds caching to Item and start using it in PlacedSymbol.
This commit is contained in:
parent
c0fa5b3711
commit
bbcec27031
3 changed files with 17 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue