Start implementing Item#globalToLocal() and #localToGlobal()

This commit is contained in:
Jürg Lehni 2013-09-22 18:04:27 -07:00
parent 5a45260740
commit 5f8c00fe8d

View file

@ -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