3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.draw.Matrix
19 Ext.define('Ext.draw.Matrix', {
21 /* Begin Definitions */
23 requires: ['Ext.draw.Draw'],
27 constructor: function(a, b, c, d, e, f) {
29 this.matrix = [[a, c, e], [b, d, f], [0, 0, 1]];
32 this.matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
36 add: function(a, b, c, d, e, f) {
39 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
45 for (x = 0; x < 3; x++) {
46 for (y = 0; y < 3; y++) {
48 for (z = 0; z < 3; z++) {
49 res += me.matrix[x][z] * matrix[z][y];
57 prepend: function(a, b, c, d, e, f) {
60 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
66 for (x = 0; x < 3; x++) {
67 for (y = 0; y < 3; y++) {
69 for (z = 0; z < 3; z++) {
70 res += matrix[x][z] * me.matrix[z][y];
79 var matrix = this.matrix,
87 return new Ext.draw.Matrix(d / x, -b / x, -c / x, a / x, (c * f - d * e) / x, (b * e - a * f) / x);
91 var matrix = this.matrix,
98 return new Ext.draw.Matrix(a, b, c, d, e, f);
101 translate: function(x, y) {
102 this.prepend(1, 0, 0, 1, x, y);
105 scale: function(x, y, cx, cy) {
110 me.add(1, 0, 0, 1, cx, cy);
111 me.add(x, 0, 0, y, 0, 0);
112 me.add(1, 0, 0, 1, -cx, -cy);
115 rotate: function(a, x, y) {
116 a = Ext.draw.Draw.rad(a);
118 cos = +Math.cos(a).toFixed(9),
119 sin = +Math.sin(a).toFixed(9);
120 me.add(cos, sin, -sin, cos, x, y);
121 me.add(1, 0, 0, 1, -x, -y);
125 var matrix = this.matrix;
126 return x * matrix[0][0] + y * matrix[0][1] + matrix[0][2];
130 var matrix = this.matrix;
131 return x * matrix[1][0] + y * matrix[1][1] + matrix[1][2];
134 get: function(i, j) {
135 return + this.matrix[i][j].toFixed(4);
138 toString: function() {
140 return [me.get(0, 0), me.get(0, 1), me.get(1, 0), me.get(1, 1), 0, 0].join();
145 return "matrix(" + [me.get(0, 0), me.get(1, 0), me.get(0, 1), me.get(1, 1), me.get(0, 2), me.get(1, 2)].join() + ")";
148 toFilter: function() {
150 return "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand',FilterType=bilinear,M11=" + me.get(0, 0) +
151 ", M12=" + me.get(0, 1) + ", M21=" + me.get(1, 0) + ", M22=" + me.get(1, 1) +
152 ", Dx=" + me.get(0, 2) + ", Dy=" + me.get(1, 2) + ")";
156 var matrix = this.matrix;
157 return [(matrix[0][2] || 0).toFixed(4), (matrix[1][2] || 0).toFixed(4)];
160 // Split matrix into Translate Scale, Shear, and Rotate
163 return a[0] * a[0] + a[1] * a[1];
165 function normalize(a) {
166 var mag = Math.sqrt(norm(a));
170 var matrix = this.matrix,
172 translateX: matrix[0][2],
173 translateY: matrix[1][2]
178 row = [[matrix[0][0], matrix[0][1]], [matrix[1][0], matrix[1][1]]];
179 out.scaleX = Math.sqrt(norm(row[0]));
182 out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
183 row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
185 out.scaleY = Math.sqrt(norm(row[1]));
187 out.shear /= out.scaleY;
190 out.rotate = Math.asin(-row[0][1]);
192 out.isSimple = !+out.shear.toFixed(9) && (out.scaleX.toFixed(9) == out.scaleY.toFixed(9) || !out.rotate);