From 5f8c00fe8d46dece4bd4fbc17b15e0317d2b97ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 22 Sep 2013 18:04:27 -0700 Subject: [PATCH] Start implementing Item#globalToLocal() and #localToGlobal() --- src/item/Item.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/item/Item.js b/src/item/Item.js index ff4cc614..aaa92445 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -765,6 +765,45 @@ var Item = Base.extend(Callback, /** @lends Item# */{ this._changed(/*#=*/ Change.GEOMETRY); }, + /** + * The item's global transformation matrix in relation to the global project + * coordinate space. + * + * @type Matrix + * @bean + */ + getGlobalMatrix: function() { + // TODO: This only works correctly if Item#draw() is in use. For other + // possible future backends and items that aren't drawn, we need have to + // implement another approach. + return this._drawCount === this._project._drawCount + && this._globalMatrix || null; + }, + + /** + * Converts the specified point from global project coordinates to local + * coordinates in relation to the the item's own coordinate space. + * + * @param {Point} point the point to be transformed + * @return {Point} the transformed point as a new instance + */ + globalToLocal: function(/* point */) { + var matrix = this.getGlobalMatrix(); + return matrix && matrix._transformPoint(Point.read(arguments)); + }, + + /** + * Converts the specified point from local coordinates to global coordinates + * in relation to the the project coordinate space. + * + * @param {Point} point the point to be transformed + * @return {Point} the transformed point as a new instance + */ + localToGlobal: function(/* point */) { + var matrix = this.getGlobalMatrix(); + return matrix && matrix._inverseTransform(Point.read(arguments)); + }, + /** * Specifies whether the item has any content or not. The meaning of what * content is differs from type to type. For example, a {@link Group} with