mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-12 22:18:54 -04:00
Implement Matrix#rotate() without relying on Matrix#getRotateInstance().
This commit is contained in:
parent
53474aa5c0
commit
3930a40c7e
1 changed files with 20 additions and 2 deletions
|
@ -195,8 +195,26 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
* @return {Matrix} This affine transform
|
||||
*/
|
||||
rotate: function(angle, center) {
|
||||
return this.concatenate(
|
||||
Matrix.getRotateInstance.apply(Matrix, arguments));
|
||||
center = Point.read(arguments, 1);
|
||||
angle = angle * Math.PI / 180;
|
||||
// Concatenate rotation matrix into this one
|
||||
var x = center.x,
|
||||
y = center.y,
|
||||
cos = Math.cos(angle),
|
||||
sin = Math.sin(angle),
|
||||
tx = x - x * cos + y * sin,
|
||||
ty = y - x * sin - y * cos,
|
||||
a = this._a,
|
||||
b = this._b,
|
||||
c = this._c,
|
||||
d = this._d;
|
||||
this._a = cos * a + sin * b;
|
||||
this._b = -sin * a + cos * b;
|
||||
this._c = cos * c + sin * d;
|
||||
this._d = -sin * c + cos * d;
|
||||
this._tx += tx * a + ty * b;
|
||||
this._ty += tx * c + ty * d;
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue