mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Apply #position optimisation through caching to all items, not just PlacedSymbol.
This commit is contained in:
parent
1413094be2
commit
53cc1cd908
3 changed files with 11 additions and 10 deletions
|
@ -542,14 +542,16 @@ var Item = this.Item = Base.extend({
|
|||
* </code>
|
||||
*/
|
||||
getPosition: function() {
|
||||
return this.getBounds().getCenter();
|
||||
// Cache position value
|
||||
if (!this._position)
|
||||
this._position = this.getBounds().getCenter();
|
||||
return this._position.clone();
|
||||
},
|
||||
|
||||
setPosition: function(point) {
|
||||
point = Point.read(arguments);
|
||||
if (point) {
|
||||
if (point)
|
||||
this.translate(point.subtract(this.getPosition()));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -563,6 +565,9 @@ var Item = this.Item = Base.extend({
|
|||
// TODO: Call transform on chidren only if 'children' flag is provided
|
||||
if (this._transform)
|
||||
this._transform(matrix, flags);
|
||||
// Transform position as well
|
||||
if (this._position)
|
||||
this._position = matrix._transformPoint(this._position);
|
||||
if (this.children) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
var child = this.children[i];
|
||||
|
|
|
@ -32,12 +32,6 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({
|
|||
// raster, simply preconcatenate the internal matrix with the provided
|
||||
// one.
|
||||
this.matrix.preConcatenate(matrix);
|
||||
// Transform position as well
|
||||
this._position = matrix._transformPoint(this._position);
|
||||
},
|
||||
|
||||
getPosition: function() {
|
||||
return this._position.clone();
|
||||
},
|
||||
|
||||
getBounds: function() {
|
||||
|
|
|
@ -29,10 +29,12 @@ var Path = this.Path = PathItem.extend({
|
|||
},
|
||||
|
||||
_changed: function() {
|
||||
// Clear cached values.
|
||||
// TODO: Implement ChangeFlags, e.g. STROKE, COLOR, FILL, GEOMETRY,
|
||||
// and only clear caches if affected by change.
|
||||
delete this._length;
|
||||
delete this._bounds;
|
||||
delete this._strokeBounds;
|
||||
delete this._position;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue