mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Implement Matrix#inverseTransform().
This commit is contained in:
parent
4600fe1e21
commit
34b5d043b3
1 changed files with 24 additions and 0 deletions
|
@ -430,6 +430,15 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
max[0] - min[0], max[1] - min[1]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Inverse transforms a point and returns the result.
|
||||
*
|
||||
* @param {Point} point The point to be transformed
|
||||
*/
|
||||
inverseTransform: function(point) {
|
||||
return this._inverseTransform(Point.read(arguments));
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the determinant of this transform, but only if the matrix is
|
||||
* reversible, null otherwise.
|
||||
|
@ -441,6 +450,21 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
? det : null;
|
||||
},
|
||||
|
||||
_inverseTransform: function(point, dest, dontNotify) {
|
||||
var det = this._getDeterminant();
|
||||
if (!det)
|
||||
return null;
|
||||
var x = point.x - this._tx,
|
||||
y = point.y - this._ty;
|
||||
if (!dest)
|
||||
dest = new Point(Point.dont);
|
||||
return dest.set(
|
||||
(x * this._d - y * this._b) / det,
|
||||
(y * this._a - x * this._c) / det,
|
||||
dontNotify
|
||||
);
|
||||
},
|
||||
|
||||
getTranslation: function() {
|
||||
return new Point(this._tx, this._ty);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue