4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js">/*
19 * @class Ext.draw.Matrix
22 Ext.define('Ext.draw.Matrix', {
24 /* Begin Definitions */
26 requires: ['Ext.draw.Draw'],
30 constructor: function(a, b, c, d, e, f) {
32 this.matrix = [[a, c, e], [b, d, f], [0, 0, 1]];
35 this.matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
39 add: function(a, b, c, d, e, f) {
42 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
48 for (x = 0; x < 3; x++) {
49 for (y = 0; y < 3; y++) {
51 for (z = 0; z < 3; z++) {
52 res += me.matrix[x][z] * matrix[z][y];
60 prepend: function(a, b, c, d, e, f) {
63 matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
69 for (x = 0; x < 3; x++) {
70 for (y = 0; y < 3; y++) {
72 for (z = 0; z < 3; z++) {
73 res += matrix[x][z] * me.matrix[z][y];
82 var matrix = this.matrix,
90 return new Ext.draw.Matrix(d / x, -b / x, -c / x, a / x, (c * f - d * e) / x, (b * e - a * f) / x);
94 var matrix = this.matrix,
101 return new Ext.draw.Matrix(a, b, c, d, e, f);
104 translate: function(x, y) {
105 this.prepend(1, 0, 0, 1, x, y);
108 scale: function(x, y, cx, cy) {
113 me.add(1, 0, 0, 1, cx, cy);
114 me.add(x, 0, 0, y, 0, 0);
115 me.add(1, 0, 0, 1, -cx, -cy);
118 rotate: function(a, x, y) {
119 a = Ext.draw.Draw.rad(a);
121 cos = +Math.cos(a).toFixed(9),
122 sin = +Math.sin(a).toFixed(9);
123 me.add(cos, sin, -sin, cos, x, y);
124 me.add(1, 0, 0, 1, -x, -y);
128 var matrix = this.matrix;
129 return x * matrix[0][0] + y * matrix[0][1] + matrix[0][2];
133 var matrix = this.matrix;
134 return x * matrix[1][0] + y * matrix[1][1] + matrix[1][2];
137 get: function(i, j) {
138 return + this.matrix[i][j].toFixed(4);
141 toString: function() {
143 return [me.get(0, 0), me.get(0, 1), me.get(1, 0), me.get(1, 1), 0, 0].join();
148 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() + ")";
151 toFilter: function() {
153 return "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand',FilterType=bilinear,M11=" + me.get(0, 0) +
154 ", M12=" + me.get(0, 1) + ", M21=" + me.get(1, 0) + ", M22=" + me.get(1, 1) +
155 ", Dx=" + me.get(0, 2) + ", Dy=" + me.get(1, 2) + ")";
159 var matrix = this.matrix;
160 return [(matrix[0][2] || 0).toFixed(4), (matrix[1][2] || 0).toFixed(4)];
163 // Split matrix into Translate Scale, Shear, and Rotate
166 return a[0] * a[0] + a[1] * a[1];
168 function normalize(a) {
169 var mag = Math.sqrt(norm(a));
173 var matrix = this.matrix,
175 translateX: matrix[0][2],
176 translateY: matrix[1][2]
181 row = [[matrix[0][0], matrix[0][1]], [matrix[1][0], matrix[1][1]]];
182 out.scaleX = Math.sqrt(norm(row[0]));
185 out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
186 row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
188 out.scaleY = Math.sqrt(norm(row[1]));
190 out.shear /= out.scaleY;
193 out.rotate = Math.asin(-row[0][1]);
195 out.isSimple = !+out.shear.toFixed(9) && (out.scaleX.toFixed(9) == out.scaleY.toFixed(9) || !out.rotate);