Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: LayoutTests/fast/dom/geometry-interfaces-dom-matrix-rotate.html

Issue 479863002: Implement rotate*() methods in DOMMatrix. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: use testharnessreport.js Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/dom/DOMMatrix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Geometry Interfaces: DOMMatrix rotate</title>
5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script>
7 </head>
8 <body>
9 <script>
10
11 function toArray(matrix)
12 {
13 return [ matrix.m11, matrix.m21, matrix.m31, matrix.m41,
14 matrix.m12, matrix.m22, matrix.m32, matrix.m42,
15 matrix.m13, matrix.m23, matrix.m33, matrix.m43,
16 matrix.m14, matrix.m24, matrix.m34, matrix.m44 ];
17 }
18
19 function deg2rad(degrees)
20 {
21 return degrees * Math.PI / 180;
22 }
23
24 function rad2deg(radians)
25 {
26 return radians * 180 / Math.PI
27 }
28
29 const COS_0_DEG = Math.cos(0);
30 const SIN_0_DEG = Math.sin(0);
31 const COS_30_DEG = Math.cos(deg2rad(30));
32 const SIN_30_DEG = Math.sin(deg2rad(30));
33 const COS_45_DEG = Math.cos(deg2rad(45));
34 const SIN_45_DEG = Math.sin(deg2rad(45));
35 const COS_60_DEG = Math.cos(deg2rad(60));
36 const SIN_60_DEG = Math.sin(deg2rad(60));
37 const COS_90_DEG = Math.cos(deg2rad(90));
38 const SIN_90_DEG = Math.sin(deg2rad(90));
39
40 test(function() {
41 var matrix = new DOMMatrix();
42 assert_true(matrix.is2D);
43 assert_true(matrix.isIdentity);
44 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
45 var result = matrix.rotate(60);
46 assert_true(result.is2D);
47 assert_false(result.isIdentity);
48 var m11 = COS_60_DEG;
49 var m12 = SIN_60_DEG;
50 var m21 = -SIN_60_DEG;
51 var m22 = COS_60_DEG;
52 assert_array_equals(toArray(result), [ m11, m21, 0, 0, m12, m22, 0, 0, 0, 0, 1 , 0, 0, 0, 0, 1 ]);
53 assert_true(matrix.is2D);
54 assert_true(matrix.isIdentity);
55 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
56 matrix.rotateSelf(60);
57 assert_true(matrix.is2D);
58 assert_false(matrix.isIdentity);
59 assert_array_equals(toArray(matrix), toArray(result));
60 }, "DOMMatrix.rotate(angle) and rotateSelf(angle)");
61
62 test(function() {
63 var matrix = new DOMMatrix();
64 matrix.m11 = 1;
65 matrix.m12 = 2;
66 matrix.m21 = 3;
67 matrix.m22 = 4;
68 assert_true(matrix.is2D);
69 assert_false(matrix.isIdentity);
70 assert_array_equals(toArray(matrix), [ 1, 3, 0, 0, 2, 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
71 var result = matrix.rotate(30);
72 assert_true(result.is2D);
73 assert_false(result.isIdentity);
74 var m11 = COS_30_DEG + SIN_30_DEG * 3;
75 var m12 = COS_30_DEG * 2 + SIN_30_DEG * 4;
76 var m21 = -SIN_30_DEG + COS_30_DEG * 3;
77 var m22 = -SIN_30_DEG * 2 + COS_30_DEG * 4;
78 assert_array_equals(toArray(result), [ m11, m21, 0, 0, m12, m22, 0, 0, 0, 0, 1 , 0, 0, 0, 0, 1 ]);
79 assert_true(matrix.is2D);
80 assert_false(matrix.isIdentity);
81 assert_array_equals(toArray(matrix), [ 1, 3, 0, 0, 2, 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
82 matrix.rotateSelf(30);
83 assert_true(matrix.is2D);
84 assert_false(matrix.isIdentity);
85 assert_array_equals(toArray(matrix), toArray(result));
86 }, "DOMMatrix.rotate(angle) and DOMMatrix.rotateSelf(angle) with non-identity");
87
88 test(function() {
89 var matrix = new DOMMatrix();
90 matrix.m11 = 1;
91 matrix.m12 = 2;
92 matrix.m21 = 3;
93 matrix.m22 = 4;
94 matrix.m13 = 5;
95 matrix.m23 = 6;
96 matrix.m33 = 7;
97 assert_false(matrix.is2D);
98 assert_false(matrix.isIdentity);
99 assert_array_equals(toArray(matrix), [ 1, 3, 0, 0, 2, 4, 0, 0, 5, 6, 7, 0, 0, 0, 0, 1 ]);
100 var result = matrix.rotate(30);
101 assert_false(result.is2D);
102 assert_false(result.isIdentity);
103 var m11 = COS_30_DEG + SIN_30_DEG * 3;
104 var m12 = COS_30_DEG * 2 + SIN_30_DEG * 4;
105 var m13 = COS_30_DEG * 5 + SIN_30_DEG * 6;
106 var m21 = -SIN_30_DEG + COS_30_DEG * 3;
107 var m22 = -SIN_30_DEG * 2 + COS_30_DEG * 4;
108 var m23 = -SIN_30_DEG * 5 + COS_30_DEG * 6;
109 assert_array_equals(toArray(result), [ m11, m21, 0, 0, m12, m22, 0, 0, m13, m2 3, 7, 0, 0, 0, 0, 1 ]);
110 assert_false(matrix.is2D);
111 assert_false(matrix.isIdentity);
112 assert_array_equals(toArray(matrix), [ 1, 3, 0, 0, 2, 4, 0, 0, 5, 6, 7, 0, 0, 0, 0, 1 ]);
113 matrix.rotateSelf(30);
114 assert_false(matrix.is2D);
115 assert_false(matrix.isIdentity);
116 assert_array_equals(toArray(matrix), toArray(result));
117 }, "DOMMatrix.rotate(angle) and DOMMatrix.rotateSelf(angle) when is2D property i s false");
118
119 test(function() {
120 var matrix = new DOMMatrix();
121 assert_true(matrix.is2D);
122 assert_true(matrix.isIdentity);
123 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
124 var result = matrix.rotate(45, 10, 10);
125 var expected = new DOMMatrix();
126 expected.translateSelf(10, 10);
127 expected.rotateSelf(45);
128 expected.translateSelf(-10, -10);
129 assert_true(result.is2D);
130 assert_false(result.isIdentity);
131 assert_array_equals(toArray(result), toArray(expected));
132 assert_true(matrix.is2D);
133 assert_true(matrix.isIdentity);
134 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
135 matrix.rotateSelf(45, 10, 10);
136 assert_true(matrix.is2D);
137 assert_false(matrix.isIdentity);
138 assert_array_equals(toArray(matrix), toArray(result));
139 }, "DOMMatrix.rotate(angle, ox, oy)");
140
141 test(function() {
142 var matrix = new DOMMatrix();
143 assert_true(matrix.is2D);
144 assert_true(matrix.isIdentity);
145 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
146 var result = matrix.rotateFromVector(4, 7);
147 var expected = new DOMMatrix();
148 expected.rotateSelf(rad2deg(Math.atan2(7, 4)));
149 assert_true(result.is2D);
150 assert_false(result.isIdentity);
151 assert_array_equals(toArray(result), toArray(expected));
152 assert_true(matrix.is2D);
153 assert_true(matrix.isIdentity);
154 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
155 matrix.rotateFromVectorSelf(4, 7);
156 assert_true(matrix.is2D);
157 assert_false(matrix.isIdentity);
158 assert_array_equals(toArray(matrix), toArray(result));
159 }, "DOMMatrix.rotateFromVector(x, y) and DOMMatrix.rotateFromVectorSelf(x, y)");
160
161 test(function() {
162 var matrix = new DOMMatrix();
163 assert_true(matrix.is2D);
164 assert_true(matrix.isIdentity);
165 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
166 var x_result = matrix.rotateAxisAngle(1, 0, 0, 30);
167 assert_false(x_result.is2D);
168 assert_false(x_result.isIdentity);
169 assert_array_equals(toArray(x_result), [ 1, 0, 0, 0, 0, COS_30_DEG, -SIN_30_DE G, 0, 0, SIN_30_DEG, COS_30_DEG, 0, 0, 0, 0, 1 ]);
170 var y_result = matrix.rotateAxisAngle(0, 1, 0, 45);
171 assert_false(y_result.is2D);
172 assert_false(y_result.isIdentity);
173 assert_array_equals(toArray(y_result), [ COS_45_DEG, 0, SIN_45_DEG, 0, 0, 1, 0 , 0, -SIN_45_DEG, 0, COS_45_DEG, 0, 0, 0, 0, 1 ]);
174 var z_result = matrix.rotateAxisAngle(0, 0, 1, 60);
175 assert_true(z_result.is2D);
176 assert_false(z_result.isIdentity);
177 assert_array_equals(toArray(z_result), [ COS_60_DEG, -SIN_60_DEG, 0, 0, SIN_60 _DEG, COS_60_DEG, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
178 var expected = new DOMMatrix();
179 expected.rotateSelf(60);
180 assert_array_equals(toArray(z_result), toArray(expected));
181 matrix.rotateAxisAngleSelf(1, 0, 0, 30);
182 assert_false(matrix.is2D);
183 assert_false(matrix.isIdentity);
184 assert_array_equals(toArray(matrix), toArray(x_result));
185 }, "DOMMatrix.rotateAxisAngle(x, y, z, angle) and DOMMatrix.rotateAxisAngleSelf( x, y, z, angle)");
186
187 </script>
188 </body>
189 </html>
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/DOMMatrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698