diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 75ed244..afbb360 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -422,9 +422,10 @@ * * @param position {PIXI.Point} The world origin to calculate from * @param [from] {PIXI.DisplayObject} The DisplayObject to calculate the global position from + * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new Point) * @return {PIXI.Point} A point object representing the position of this object */ -DisplayObject.prototype.toLocal = function (position, from) +DisplayObject.prototype.toLocal = function (position, from, point) { if (from) { @@ -446,7 +447,7 @@ } // simply apply the matrix.. - return this.worldTransform.applyInverse(position); + return this.worldTransform.applyInverse(position, point); }; /** @@ -530,7 +531,7 @@ this.position.y = y || 0; this.scale.x = !scaleX ? 1 : scaleX; this.scale.y = !scaleY ? 1 : scaleY; - this.rotation = rotation || 0; + this.rotation = rotation || 0; this.skew.x = skewX || 0; this.skew.y = skewY || 0; this.pivot.x = pivotX || 0; @@ -549,7 +550,7 @@ this.scale = null; this.pivot = null; this.skew = null; - + this.parent = null; this._bounds = null; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 75ed244..afbb360 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -422,9 +422,10 @@ * * @param position {PIXI.Point} The world origin to calculate from * @param [from] {PIXI.DisplayObject} The DisplayObject to calculate the global position from + * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new Point) * @return {PIXI.Point} A point object representing the position of this object */ -DisplayObject.prototype.toLocal = function (position, from) +DisplayObject.prototype.toLocal = function (position, from, point) { if (from) { @@ -446,7 +447,7 @@ } // simply apply the matrix.. - return this.worldTransform.applyInverse(position); + return this.worldTransform.applyInverse(position, point); }; /** @@ -530,7 +531,7 @@ this.position.y = y || 0; this.scale.x = !scaleX ? 1 : scaleX; this.scale.y = !scaleY ? 1 : scaleY; - this.rotation = rotation || 0; + this.rotation = rotation || 0; this.skew.x = skewX || 0; this.skew.y = skewY || 0; this.pivot.x = pivotX || 0; @@ -549,7 +550,7 @@ this.scale = null; this.pivot = null; this.skew = null; - + this.parent = null; this._bounds = null; diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index d0131ff..b29d188 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -38,10 +38,10 @@ * * @param displayObject {PIXI.DisplayObject} The DisplayObject that you would like the local coords off * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new point) - * param [globalPos] {PIXI.Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) + * @param [globalPos] {PIXI.Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) * @return {PIXI.Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject */ InteractionData.prototype.getLocalPosition = function (displayObject, point, globalPos) { - return displayObject.toLocal(globalPos ? globalPos : this.global, point); + return displayObject.toLocal(globalPos || this.global, null, point); }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 75ed244..afbb360 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -422,9 +422,10 @@ * * @param position {PIXI.Point} The world origin to calculate from * @param [from] {PIXI.DisplayObject} The DisplayObject to calculate the global position from + * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new Point) * @return {PIXI.Point} A point object representing the position of this object */ -DisplayObject.prototype.toLocal = function (position, from) +DisplayObject.prototype.toLocal = function (position, from, point) { if (from) { @@ -446,7 +447,7 @@ } // simply apply the matrix.. - return this.worldTransform.applyInverse(position); + return this.worldTransform.applyInverse(position, point); }; /** @@ -530,7 +531,7 @@ this.position.y = y || 0; this.scale.x = !scaleX ? 1 : scaleX; this.scale.y = !scaleY ? 1 : scaleY; - this.rotation = rotation || 0; + this.rotation = rotation || 0; this.skew.x = skewX || 0; this.skew.y = skewY || 0; this.pivot.x = pivotX || 0; @@ -549,7 +550,7 @@ this.scale = null; this.pivot = null; this.skew = null; - + this.parent = null; this._bounds = null; diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index d0131ff..b29d188 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -38,10 +38,10 @@ * * @param displayObject {PIXI.DisplayObject} The DisplayObject that you would like the local coords off * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new point) - * param [globalPos] {PIXI.Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) + * @param [globalPos] {PIXI.Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) * @return {PIXI.Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject */ InteractionData.prototype.getLocalPosition = function (displayObject, point, globalPos) { - return displayObject.toLocal(globalPos ? globalPos : this.global, point); + return displayObject.toLocal(globalPos || this.global, null, point); }; diff --git a/test/unit/interaction/InteractionData.test.js b/test/unit/interaction/InteractionData.test.js new file mode 100644 index 0000000..70660fc --- /dev/null +++ b/test/unit/interaction/InteractionData.test.js @@ -0,0 +1,17 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + + data.getLocalPosition(displayObject, point); + + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +});