mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Expose rotation and scaling transformations through Item#rotation and Item#scaling properties, by moving the setters from Matrix to Item.
This commit is contained in:
parent
3ea5c2d728
commit
9ca92165ee
2 changed files with 37 additions and 28 deletions
|
@ -522,9 +522,8 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
|
||||
/**
|
||||
* Attempts to decompose the affine transformation described by this matrix
|
||||
* into {@code translation}, {@code scaling}, {@code rotation} and
|
||||
* {@code shearing}, and returns an object with these properties if it
|
||||
* succeeded, {@code null} otherwise.
|
||||
* into {@code scaling}, {@code rotation} and {@code shearing}, and returns
|
||||
* an object with these properties if it succeeded, {@code null} otherwise.
|
||||
*
|
||||
* @return {Object} the decomposed matrix, or {@code null} if decomposition
|
||||
* is not possible.
|
||||
|
@ -562,7 +561,6 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
}
|
||||
|
||||
return {
|
||||
translation: this.getTranslation(),
|
||||
scaling: new Point(scaleX, scaleY),
|
||||
rotation: -Math.atan2(b, a) * 180 / Math.PI,
|
||||
shearing: shear
|
||||
|
@ -635,17 +633,10 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
* @bean
|
||||
*/
|
||||
getTranslation: function() {
|
||||
// No decomposition is required to extract translation, so treat this
|
||||
// No decomposition is required to extract translation.
|
||||
return new Point(this._tx, this._ty);
|
||||
},
|
||||
|
||||
setTranslation: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this._tx = point.x;
|
||||
this._ty = point.y;
|
||||
this._changed();
|
||||
},
|
||||
|
||||
/**
|
||||
* The scaling values of the matrix, if it can be decomposed.
|
||||
*
|
||||
|
@ -657,15 +648,6 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return (this.decompose() || {}).scaling;
|
||||
},
|
||||
|
||||
setScaling: function(/* scale */) {
|
||||
var scaling = this.getScaling();
|
||||
if (scaling != null) {
|
||||
var scale = Point.read(arguments);
|
||||
(this._owner || this).scale(
|
||||
scale.x / scaling.x, scale.y / scaling.y);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The rotation angle of the matrix, if it can be decomposed.
|
||||
*
|
||||
|
@ -677,12 +659,6 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
return (this.decompose() || {}).rotation;
|
||||
},
|
||||
|
||||
setRotation: function(angle) {
|
||||
var rotation = this.getRotation();
|
||||
if (rotation != null)
|
||||
(this._owner || this).rotate(angle - rotation);
|
||||
},
|
||||
|
||||
/**
|
||||
* Inverts the transformation of the matrix. If the matrix is not invertible
|
||||
* (in which case {@link #isSingular()} returns true), {@code null } is
|
||||
|
|
|
@ -962,6 +962,39 @@ 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);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The current rotation of the item, as described by its {@link #matrix}.
|
||||
*
|
||||
* @type Number
|
||||
* @bean
|
||||
*/
|
||||
getRotation: function() {
|
||||
return this._matrix.getRotation();
|
||||
},
|
||||
|
||||
setRotation: function(rotation) {
|
||||
if (rotation != null)
|
||||
this.rotate(rotation - this.getRotation());
|
||||
},
|
||||
|
||||
/**
|
||||
* The item's transformation matrix, defining position and dimensions in
|
||||
* relation to its parent item in which it is contained.
|
||||
|
@ -997,7 +1030,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
|
||||
/**
|
||||
* Specifies whether the group applies transformations directly to its
|
||||
* children, or whether they are to be stored in its {@link Item#matrix}
|
||||
* children, or whether they are to be stored in its {@link #matrix}
|
||||
*
|
||||
* @type Boolean
|
||||
* @default true
|
||||
|
|
Loading…
Reference in a new issue