Skip to content
This repository
Browse code

Fix extraction of scale when translations are involved

  • Loading branch information...
commit feadeabafc7111f5f2168ed666a5b9b00fdd9d6b 1 parent 9ab2f5e
David Aurelio authored
11  src/runner/display_object.js
@@ -106,7 +106,16 @@ define([
106 106
     m.d = matrix.d;
107 107
     m.tx = matrix.tx;
108 108
     m.ty = matrix.ty;
109  
-    m.scale( 1/scaleX || 1, 1/scaleY || 1); // avoid scaling by NaN
  109
+
  110
+    if (scaleX !== 1 || scaleY !== 1) {
  111
+      // Make sure we rotate around the chosen origin
  112
+      var origin = m.transformPoint(this._origin);
  113
+      m.tx -= origin.x;
  114
+      m.ty -= origin.y;
  115
+      m.scale( 1/scaleX || 1, 1/scaleY || 1); // avoid scaling by NaN
  116
+      m.tx += origin.x;
  117
+      m.ty += origin.y;
  118
+    }
110 119
   }
111 120
 
112 121
   function getX() {
5  test/display_object-spec.js
@@ -160,14 +160,15 @@ define([
160 160
         it('should return the an equivalent matrix when setting the matrix attribute', function() {
161 161
           var scaleX = 2;
162 162
           var scaleY = 3;
163  
-          var d = new DisplayObject(), m = new Matrix(scaleX, 0, 0, scaleY);
  163
+          var tx = 123, ty = 654;
  164
+          var d = new DisplayObject(), m = new Matrix(scaleX, 0, 0, scaleY, tx, ty);
164 165
 
165 166
           // scale up, then set the matrix
166 167
           d.attr('scaleX', 1.5);
167 168
           d.attr('scaleY', 2);
168 169
           d.attr('matrix', m);
169 170
 
170  
-          expect(d.attr('matrix')).toEqual(new Matrix(scaleX, 0, 0, scaleY));
  171
+          expect(d.attr('matrix')).toEqual(new Matrix(scaleX, 0, 0, scaleY, tx, ty));
171 172
         });
172 173
       });
173 174
 

0 notes on commit feadeab

Please sign in to comment.
Something went wrong with that request. Please try again.