mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Improve caching of decomposed transformation values.
This commit is contained in:
parent
9ca92165ee
commit
758c9b6146
1 changed files with 38 additions and 19 deletions
|
@ -212,6 +212,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// Clear cached bounds and position whenever geometry changes
|
||||
delete this._bounds;
|
||||
delete this._position;
|
||||
delete this._decomposed;
|
||||
}
|
||||
if (parent && (flags
|
||||
& (/*#=*/ ChangeFlag.GEOMETRY | /*#=*/ ChangeFlag.STROKE))) {
|
||||
|
@ -962,22 +963,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* @ignore
|
||||
*/
|
||||
}), /** @lends Item# */{
|
||||
/**
|
||||
* The current scaling of the item, as described by its {@link #matrix}.
|
||||
*
|
||||
* @type Point
|
||||
* @bean
|
||||
*/
|
||||
getScaling: function() {
|
||||
return this._matrix.getScaling();
|
||||
},
|
||||
|
||||
setScaling: function(/* scale */) {
|
||||
var scaling = this.getScaling();
|
||||
if (scaling != null) {
|
||||
var scale = Point.read(arguments);
|
||||
this.scale(scale.x / scaling.x, scale.y / scaling.y);
|
||||
}
|
||||
_decompose: function() {
|
||||
return this._decomposed = this._matrix.decompose();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -987,12 +974,44 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* @bean
|
||||
*/
|
||||
getRotation: function() {
|
||||
return this._matrix.getRotation();
|
||||
var decomposed = this._decomposed || this._decompose();
|
||||
return decomposed && decomposed.rotation;
|
||||
},
|
||||
|
||||
setRotation: function(rotation) {
|
||||
if (rotation != null)
|
||||
this.rotate(rotation - this.getRotation());
|
||||
var current = this.getRotation();
|
||||
if (current != null && rotation != null) {
|
||||
// Preseve the cached _decomposed values over rotation, and only
|
||||
// update the rotation property on it.
|
||||
var decomposed = this._decomposed;
|
||||
this.rotate(rotation - current);
|
||||
decomposed.rotation = rotation;
|
||||
this._decomposed = decomposed;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The current scaling of the item, as described by its {@link #matrix}.
|
||||
*
|
||||
* @type Point
|
||||
* @bean
|
||||
*/
|
||||
getScaling: function() {
|
||||
var decomposed = this._decomposed || this._decompose();
|
||||
return decomposed && decomposed.scaling;
|
||||
},
|
||||
|
||||
setScaling: function(/* scaling */) {
|
||||
var current = this.getScaling();
|
||||
if (current != null) {
|
||||
// Clone existing points since we're caching internally.
|
||||
var scaling = Point.read(arguments, 0, 0, { clone: true }),
|
||||
// See #setRotation() for preservation of _decomposed.
|
||||
decomposed = this._decomposed;
|
||||
this.scale(scaling.x / current.x, scaling.y / current.y);
|
||||
decomposed.scaling = scaling;
|
||||
this._decomposed = decomposed;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue