Permalink
Browse files

Fix extraction of scale when translations are involved

  • Loading branch information...
1 parent 9ab2f5e commit feadeabafc7111f5f2168ed666a5b9b00fdd9d6b @davidaurelio davidaurelio committed Dec 3, 2012
Showing with 13 additions and 3 deletions.
  1. +10 −1 src/runner/display_object.js
  2. +3 −2 test/display_object-spec.js
View
11 src/runner/display_object.js
@@ -106,7 +106,16 @@ define([
m.d = matrix.d;
m.tx = matrix.tx;
m.ty = matrix.ty;
- m.scale( 1/scaleX || 1, 1/scaleY || 1); // avoid scaling by NaN
+
+ if (scaleX !== 1 || scaleY !== 1) {
+ // Make sure we rotate around the chosen origin
+ var origin = m.transformPoint(this._origin);
+ m.tx -= origin.x;
+ m.ty -= origin.y;
+ m.scale( 1/scaleX || 1, 1/scaleY || 1); // avoid scaling by NaN
+ m.tx += origin.x;
+ m.ty += origin.y;
+ }
}
function getX() {
View
5 test/display_object-spec.js
@@ -160,14 +160,15 @@ define([
it('should return the an equivalent matrix when setting the matrix attribute', function() {
var scaleX = 2;
var scaleY = 3;
- var d = new DisplayObject(), m = new Matrix(scaleX, 0, 0, scaleY);
+ var tx = 123, ty = 654;
+ var d = new DisplayObject(), m = new Matrix(scaleX, 0, 0, scaleY, tx, ty);
// scale up, then set the matrix
d.attr('scaleX', 1.5);
d.attr('scaleY', 2);
d.attr('matrix', m);
- expect(d.attr('matrix')).toEqual(new Matrix(scaleX, 0, 0, scaleY));
+ expect(d.attr('matrix')).toEqual(new Matrix(scaleX, 0, 0, scaleY, tx, ty));
});
});

0 comments on commit feadeab

Please sign in to comment.