| 2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.gfx.tests.decompose"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.gfx.tests.decompose"] = true;
|
|
|
3 |
dojo.provide("dojox.gfx.tests.decompose");
|
|
|
4 |
dojo.require("dojox.gfx.decompose");
|
|
|
5 |
|
|
|
6 |
(function(){
|
|
|
7 |
var m = dojox.gfx.matrix;
|
|
|
8 |
var eq = function(t, a, b){ t.t(2 * Math.abs(a - b) / ((a < 1 && b < 1) ? 1 : a + b) < 1e-6); };
|
|
|
9 |
var eqM = function(t, a, b){
|
|
|
10 |
eq(t, a.xx, b.xx);
|
|
|
11 |
eq(t, a.yy, b.yy);
|
|
|
12 |
eq(t, a.xy, b.xy);
|
|
|
13 |
eq(t, a.yx, b.yx);
|
|
|
14 |
eq(t, a.dx, b.dx);
|
|
|
15 |
eq(t, a.dy, b.dy);
|
|
|
16 |
};
|
|
|
17 |
var compose = function(r){
|
|
|
18 |
return m.normalize([
|
|
|
19 |
m.translate(r.dx, r.dy),
|
|
|
20 |
m.rotate(r.angle2),
|
|
|
21 |
m.scale(r.sx, r.sy),
|
|
|
22 |
m.rotate(r.angle1)
|
|
|
23 |
]);
|
|
|
24 |
};
|
|
|
25 |
var reconstruct = function(a){
|
|
|
26 |
return compose(dojox.gfx.decompose(a));
|
|
|
27 |
};
|
|
|
28 |
var compare = function(t, a){
|
|
|
29 |
var A = m.normalize(a);
|
|
|
30 |
eqM(t, A, reconstruct(A));
|
|
|
31 |
};
|
|
|
32 |
tests.register("dojox.gfx.tests.decompose", [
|
|
|
33 |
function IdentityTest(t){
|
|
|
34 |
compare(t, m.identity);
|
|
|
35 |
},
|
|
|
36 |
function FlipXTest(t){
|
|
|
37 |
compare(t, m.flipX);
|
|
|
38 |
},
|
|
|
39 |
function FlipYTest(t){
|
|
|
40 |
compare(t, m.flipY);
|
|
|
41 |
},
|
|
|
42 |
function FlipXYTest(t){
|
|
|
43 |
compare(t, m.flipXY);
|
|
|
44 |
},
|
|
|
45 |
function TranslationTest(t){
|
|
|
46 |
compare(t, m.translate(45, -15));
|
|
|
47 |
},
|
|
|
48 |
function RotationTest(t){
|
|
|
49 |
compare(t, m.rotateg(35));
|
|
|
50 |
},
|
|
|
51 |
function SkewXTest(t){
|
|
|
52 |
compare(t, m.skewXg(35));
|
|
|
53 |
},
|
|
|
54 |
function SkewYTest(t){
|
|
|
55 |
compare(t, m.skewYg(35));
|
|
|
56 |
},
|
|
|
57 |
function ReflectTest(t){
|
|
|
58 |
compare(t, m.reflect(13, 27));
|
|
|
59 |
},
|
|
|
60 |
function ProjectTest(t){
|
|
|
61 |
compare(t, m.project(13, 27));
|
|
|
62 |
},
|
|
|
63 |
function ScaleTest1(t){
|
|
|
64 |
compare(t, m.scale(3));
|
|
|
65 |
},
|
|
|
66 |
function ScaleTest2(t){
|
|
|
67 |
compare(t, m.scale(3, -1));
|
|
|
68 |
},
|
|
|
69 |
function ScaleTest3(t){
|
|
|
70 |
compare(t, m.scale(-3, 1));
|
|
|
71 |
},
|
|
|
72 |
function ScaleTest4(t){
|
|
|
73 |
compare(t, m.scale(-3, -1));
|
|
|
74 |
},
|
|
|
75 |
function ScaleRotateTest1(t){
|
|
|
76 |
compare(t, [m.scale(3), m.rotateAt(35, 13, 27)]);
|
|
|
77 |
},
|
|
|
78 |
function ScaleRotateTest2(t){
|
|
|
79 |
compare(t, [m.scale(3, -1), m.rotateAt(35, 13, 27)]);
|
|
|
80 |
},
|
|
|
81 |
function ScaleRotateTest3(t){
|
|
|
82 |
compare(t, [m.scale(-3, 1), m.rotateAt(35, 13, 27)]);
|
|
|
83 |
},
|
|
|
84 |
function ScaleRotateTest4(t){
|
|
|
85 |
compare(t, [m.scale(-3, -1), m.rotateAt(35, 13, 27)]);
|
|
|
86 |
},
|
|
|
87 |
function RotateScaleTest1(t){
|
|
|
88 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(3)]);
|
|
|
89 |
},
|
|
|
90 |
function RotateScaleTest2(t){
|
|
|
91 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(3, -1)]);
|
|
|
92 |
},
|
|
|
93 |
function RotateScaleTest3(t){
|
|
|
94 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(-3, 1)]);
|
|
|
95 |
},
|
|
|
96 |
function RotateScaleTest4(t){
|
|
|
97 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(-3, -1)]);
|
|
|
98 |
},
|
|
|
99 |
function RotateScaleRotateTest1(t){
|
|
|
100 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(3), m.rotateAt(-15, 163, -287)]);
|
|
|
101 |
},
|
|
|
102 |
function RotateScaleRotateTest2(t){
|
|
|
103 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(3, -1), m.rotateAt(-15, 163, -287)]);
|
|
|
104 |
},
|
|
|
105 |
function RotateScaleRotateTest3(t){
|
|
|
106 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(-3, 1), m.rotateAt(-15, 163, -287)]);
|
|
|
107 |
},
|
|
|
108 |
function RotateScaleRotateTest4(t){
|
|
|
109 |
compare(t, [m.rotateAt(35, 13, 27), m.scale(-3, -1), m.rotateAt(-15, 163, -287)]);
|
|
|
110 |
}
|
|
|
111 |
]);
|
|
|
112 |
})();
|
|
|
113 |
|
|
|
114 |
}
|