Implement Matrix#inverseTransform().

This commit is contained in:
Jürg Lehni 2011-09-23 11:19:03 +02:00
parent 4600fe1e21
commit 34b5d043b3

View file

@ -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);
},