diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index 647957e..9f8198b 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -84,13 +84,20 @@ * * @method apply * @param pos {Point} The origin + * @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input) * @return {Point} The new point, transformed trough this matrix */ -PIXI.Matrix.prototype.apply = function(pos) +PIXI.Matrix.prototype.apply = function(pos, newPos) { - return new PIXI.Point( - this.a * pos.x + this.b * pos.y + this.tx, - this.c * pos.x + this.d * pos.y + this.ty); + var x = this.a * pos.x + this.b * pos.y + this.tx; + var y = this.c * pos.x + this.d * pos.y + this.ty; + if (newPos === undefined) + { + return new PIXI.Point(x, y); + } + newPos.x = x; + newPos.y = y; + return newPos; }; /** @@ -99,14 +106,21 @@ * * @method apply * @param pos {Point} The origin + * @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input) * @return {Point} The new point, inverse-transformed trough this matrix */ -PIXI.Matrix.prototype.applyInverse = function(pos) +PIXI.Matrix.prototype.applyInverse = function(pos, newPos) { var id = 1 / (this.a * this.d + this.b * -this.c); - return new PIXI.Point( - this.d * id * pos.x + -this.b * id * pos.y + (this.ty * this.b - this.tx * this.d) * id, - this.a * id * pos.y + -this.c * id * pos.x + (-this.ty * this.a + this.tx * this.c) * id); + var x = this.d * id * pos.x - this.b * id * pos.y + (this.ty * this.b - this.tx * this.d) * id; + var y = this.a * id * pos.y - this.c * id * pos.x + (this.tx * this.c - this.ty * this.a) * id; + if (newPos === undefined) + { + return new PIXI.Point(x, y); + } + newPos.x = x; + newPos.y = y; + return newPos; }; PIXI.identityMatrix = new PIXI.Matrix();