Add `DisplayObject#globalToLocal` and `DisplayObject#localToGlobal` #193

merged 1 commit into from Feb 4, 2013


None yet
4 participants

davidaurelio commented Feb 4, 2013

No description provided.

@klipstein klipstein pushed a commit that referenced this pull request Feb 4, 2013

klipstein Merge pull request #193 from uxebu/points-globallocal
Add `DisplayObject#globalToLocal` and `DisplayObject#localToGlobal`

@klipstein klipstein merged commit 443cb04 into master Feb 4, 2013

klipstein deleted the points-globallocal branch Feb 4, 2013

@basecode basecode commented on the diff Feb 5, 2013

+ var absoluteMatrix = matrix.concat(parentMatrix).concat(rootMatrix);
+ expect(displayObject.globalToLocal(point))
+ .toEqual(absoluteMatrix.transformPoint(point));
+ });
+ });
+ describe('localToGlobal', function() {
+ it('should apply the inversed transform of an display object to a point', function() {
+ var point = new Point(-102, 23.75);
+ var matrix = new Matrix(1.0625, 0.3125, -1.25, -1.09375, 26.5, -34);
+ var displayObject = new DisplayObject().attr('matrix', matrix);
+ expect(displayObject.localToGlobal(point))
+ .toEqual(matrix.invert().transformPoint(point));

basecode Feb 5, 2013


It would make the test more readable, if you would write down the expected value explicitly.


davidaurelio Feb 13, 2013


I will add some tests that test “target values” and make them very explicit.

But I think for the existing tests here it makes more sense to get the idea how to get to the desired values, rather than just writing downs six floating point values. It would not be clear how they relate to the input values.


basecode Feb 13, 2013


I don't really agree. We don't care about implementation details in tests. But we care about the expected value and I'm not able to "see" the value right now. I need to copy the test in orbit to see the result.


iamdustan Feb 13, 2013


I think there is value in both approaches. I oftentimes read through tests to see how a project works and how to use it in code. Docs are great for API details and arguments, but seeing how things can actually be used together is much more valuable.

What if the test had something along the lines of:

var localToGlobalPoint = new Point(x, y); // displayObject.localToGlobal(point)
var expected = { x: expectedX, y: expectedY } // matrix.invert().transformPoint(point);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment