source: Dev/trunk/src/client/dojox/gfx/tests/decompose.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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