OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | |
3 <head> | |
4 <title>Geometry Interfaces: DOMMatrix</title> | |
5 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
7 <script src="./resources/geometry-interfaces-test-helpers.js"></script> | 4 <script src="./resources/geometry-interfaces-test-helpers.js"></script> |
8 </head> | |
9 <body> | |
10 <script> | 5 <script> |
11 | |
12 test(() => { | 6 test(() => { |
13 var matrix = new DOMMatrix(); | 7 var matrix = new DOMMatrix(); |
14 assert_equals(matrix.m11, 1); | 8 assert_identity_2d_matrix(matrix); |
15 assert_equals(matrix.m12, 0); | |
16 assert_equals(matrix.m13, 0); | |
17 assert_equals(matrix.m14, 0); | |
18 assert_equals(matrix.m21, 0); | |
19 assert_equals(matrix.m22, 1); | |
20 assert_equals(matrix.m23, 0); | |
21 assert_equals(matrix.m24, 0); | |
22 assert_equals(matrix.m31, 0); | |
23 assert_equals(matrix.m32, 0); | |
24 assert_equals(matrix.m33, 1); | |
25 assert_equals(matrix.m34, 0); | |
26 assert_equals(matrix.m41, 0); | |
27 assert_equals(matrix.m42, 0); | |
28 assert_equals(matrix.m43, 0); | |
29 assert_equals(matrix.m44, 1); | |
30 assert_true(matrix.is2D); | |
31 assert_true(matrix.isIdentity); | |
32 }, "DOMMatrix() constructor"); | 9 }, "DOMMatrix() constructor"); |
33 | 10 |
34 test(() => { | 11 test(() => { |
35 var other = new DOMMatrix(); | 12 var other = new DOMMatrix(); |
36 other.m11 = 10; | 13 other.m11 = 10; |
37 other.m12 = 20; | 14 other.m12 = 20; |
38 other.m24 = 2; | 15 other.m24 = 2; |
39 other.m33 = 3; | 16 other.m33 = 3; |
40 other.m42 = 3; | 17 other.m42 = 3; |
41 other.m44 = 9; | 18 other.m44 = 9; |
42 | |
43 var matrix = new DOMMatrix(other); | 19 var matrix = new DOMMatrix(other); |
44 assert_equals(matrix.m11, 10); | 20 assert_3d_matrix_equals(matrix, [10, 20, 0, 0, 0, 1, 0, 2, 0, 0, 3, 0, 0, 3, 0
, 9]); |
45 assert_equals(matrix.m12, 20); | |
46 assert_equals(matrix.m13, 0); | |
47 assert_equals(matrix.m14, 0); | |
48 assert_equals(matrix.m21, 0); | |
49 assert_equals(matrix.m22, 1); | |
50 assert_equals(matrix.m23, 0); | |
51 assert_equals(matrix.m24, 2); | |
52 assert_equals(matrix.m31, 0); | |
53 assert_equals(matrix.m32, 0); | |
54 assert_equals(matrix.m33, 3); | |
55 assert_equals(matrix.m34, 0); | |
56 assert_equals(matrix.m41, 0); | |
57 assert_equals(matrix.m42, 3); | |
58 assert_equals(matrix.m43, 0); | |
59 assert_equals(matrix.m44, 9); | |
60 assert_false(matrix.is2D); | |
61 assert_false(matrix.isIdentity); | |
62 }, "DOMMatrix(other) constructor"); | 21 }, "DOMMatrix(other) constructor"); |
63 | 22 |
64 test(() => { | 23 test(() => { |
65 var float32Array = new Float32Array([1, 2, 3, 4, 5, 6]); | 24 var float32Array = new Float32Array([1, 2, 3, 4, 5, 6]); |
66 var matrix2d = DOMMatrix.fromFloat32Array(float32Array); | 25 var matrix2d = DOMMatrix.fromFloat32Array(float32Array); |
67 assert_2d_matrix_equals(matrix2d, [1, 2, 3, 4, 5, 6]) | 26 assert_2d_matrix_equals(matrix2d, [1, 2, 3, 4, 5, 6]); |
68 }, "DOMMatrix fromFloat32Array - 2D matrix"); | 27 }, "DOMMatrix fromFloat32Array - 2D matrix"); |
69 | 28 |
70 test(() => { | 29 test(() => { |
71 // 3.1 is not representable as a 32-bit float | 30 // 3.1 is not representable as a 32-bit float |
72 var float64Array = new Float64Array([1, 2, 3, 3.1, 4, 5]); | 31 var float64Array = new Float64Array([1, 2, 3, 3.1, 4, 5]); |
73 var matrix2d = DOMMatrix.fromFloat64Array(float64Array); | 32 var matrix2d = DOMMatrix.fromFloat64Array(float64Array); |
74 assert_2d_matrix_equals(matrix2d, [1, 2, 3, 3.1, 4, 5]) | 33 assert_2d_matrix_equals(matrix2d, [1, 2, 3, 3.1, 4, 5]); |
75 }, "DOMMatrix fromFloat64Array - 2D matrix"); | 34 }, "DOMMatrix fromFloat64Array - 2D matrix"); |
76 | 35 |
77 test(() => { | 36 test(() => { |
78 var float32Array = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
, 14, 15, 16]); | 37 var float32Array = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
, 14, 15, 16]); |
79 var matrix3d = DOMMatrix.fromFloat32Array(float32Array); | 38 var matrix3d = DOMMatrix.fromFloat32Array(float32Array); |
80 assert_3d_matrix_equals(matrix3d, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16]) | 39 assert_3d_matrix_equals(matrix3d, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16]); |
81 }, "DOMMatrix fromFloat32Array - 3D matrix"); | 40 }, "DOMMatrix fromFloat32Array - 3D matrix"); |
82 | 41 |
83 test(() => { | 42 test(() => { |
84 // 10.1 and 16.6 are not representable as a 32-bit float | 43 // 10.1 and 16.6 are not representable as a 32-bit float |
85 var float64Array = new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12,
13, 14, 15, 16.6]); | 44 var float64Array = new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12,
13, 14, 15, 16.6]); |
86 var matrix3d = DOMMatrix.fromFloat64Array(float64Array); | 45 var matrix3d = DOMMatrix.fromFloat64Array(float64Array); |
87 assert_3d_matrix_equals(matrix3d, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13
, 14, 15, 16.6]) | 46 assert_3d_matrix_equals(matrix3d, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13
, 14, 15, 16.6]); |
88 }, "DOMMatrix fromFloat64Array - 3D matrix"); | 47 }, "DOMMatrix fromFloat64Array - 3D matrix"); |
89 | 48 |
90 test(() => { | 49 test(() => { |
91 var matrix = new DOMMatrix(); | 50 var matrix = new DOMMatrix(); |
92 matrix.a = 10; | 51 matrix.a = 10; |
93 matrix.b = 20; | 52 matrix.b = 20; |
94 matrix.m24 = 2; | 53 matrix.m24 = 2; |
95 matrix.m33 = 3; | 54 matrix.m33 = 3; |
96 matrix.m42 = 3; | 55 matrix.m42 = 3; |
97 matrix.m44 = 9; | 56 matrix.m44 = 9; |
98 assert_equals(matrix.a, matrix.m11); | 57 assert_3d_matrix_equals(matrix, [10, 20, 0, 0, 0, 1, 0, 2, 0, 0, 3, 0, 0, 3, 0
, 9]); |
99 assert_equals(matrix.b, matrix.m12); | |
100 assert_equals(matrix.c, matrix.m21); | |
101 assert_equals(matrix.d, matrix.m22); | |
102 assert_equals(matrix.e, matrix.m41); | |
103 assert_equals(matrix.f, matrix.m42); | |
104 assert_equals(matrix.m11, 10); | |
105 assert_equals(matrix.m12, 20); | |
106 assert_equals(matrix.m13, 0); | |
107 assert_equals(matrix.m14, 0); | |
108 assert_equals(matrix.m21, 0); | |
109 assert_equals(matrix.m22, 1); | |
110 assert_equals(matrix.m23, 0); | |
111 assert_equals(matrix.m24, 2); | |
112 assert_equals(matrix.m31, 0); | |
113 assert_equals(matrix.m32, 0); | |
114 assert_equals(matrix.m33, 3); | |
115 assert_equals(matrix.m34, 0); | |
116 assert_equals(matrix.m41, 0); | |
117 assert_equals(matrix.m42, 3); | |
118 assert_equals(matrix.m43, 0); | |
119 assert_equals(matrix.m44, 9); | |
120 assert_false(matrix.is2D); | |
121 assert_false(matrix.isIdentity); | |
122 }, "DOMMatrix attributes"); | 58 }, "DOMMatrix attributes"); |
123 | 59 |
124 test(() => { | 60 test(() => { |
125 var matrix = new DOMMatrix(); | 61 var matrix = new DOMMatrix(); |
126 assert_true(matrix.is2D); | 62 assert_true(matrix.is2D); |
127 assert_true(matrix.isIdentity); | 63 assert_true(matrix.isIdentity); |
128 matrix.m31 = 1; | 64 matrix.m31 = 1; |
129 matrix.m33 = 0; | 65 matrix.m33 = 0; |
130 assert_false(matrix.is2D); | 66 assert_false(matrix.is2D); |
131 assert_false(matrix.isIdentity); | 67 assert_false(matrix.isIdentity); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 test(() => { | 119 test(() => { |
184 assert_identity_2d_matrix(DOMMatrix.fromMatrix(undefined)); | 120 assert_identity_2d_matrix(DOMMatrix.fromMatrix(undefined)); |
185 }, "DOMMatrix.fromMatrix() with undefined."); | 121 }, "DOMMatrix.fromMatrix() with undefined."); |
186 | 122 |
187 test(() => { | 123 test(() => { |
188 assert_identity_2d_matrix(DOMMatrix.fromMatrix({})); | 124 assert_identity_2d_matrix(DOMMatrix.fromMatrix({})); |
189 }, "DOMMatrix.fromMatrix() with empty object."); | 125 }, "DOMMatrix.fromMatrix() with empty object."); |
190 | 126 |
191 test(() => { | 127 test(() => { |
192 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}); | 128 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}); |
193 assert_2d_matrix_equals(matrix, { | 129 assert_2d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6]); |
194 m11: 1, m12: 2, | |
195 m21: 3, m22: 4, | |
196 m41: 5, m42: 6 | |
197 }); | |
198 }, "DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}) should create a 2
D DOMMatrix."); | 130 }, "DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}) should create a 2
D DOMMatrix."); |
199 | 131 |
200 test(() => { | 132 test(() => { |
201 var matrix = DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43
: 6}); | 133 var matrix = DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43
: 6}); |
202 assert_3d_matrix_equals(matrix, { | 134 assert_3d_matrix_equals(matrix, [1, 0, 0, 0, 0, 2, 5, 0, 0, 0, 3, 0, 0, 0, 6,
4]); |
203 m11: 1, m12: 0, m13: 0, m14: 0, | |
204 m21: 0, m22: 2, m23: 5, m24: 0, | |
205 m31: 0, m32: 0, m33: 3, m34: 0, | |
206 m41: 0, m42: 0, m43: 6, m44: 4 | |
207 }); | |
208 }, "DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43: 6}) shoul
d create a 3D DOMMatrix."); | 135 }, "DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43: 6}) shoul
d create a 3D DOMMatrix."); |
209 | 136 |
210 test(() => { | 137 test(() => { |
211 var matrix = DOMMatrix.fromMatrix({a: 7, c: 9}); | 138 var matrix = DOMMatrix.fromMatrix({a: 7, c: 9}); |
212 assert_2d_matrix_equals(matrix, { | 139 assert_2d_matrix_equals(matrix, [7, 0, 9, 1, 0, 0]); |
213 m11: 7, m12: 0, | |
214 m21: 9, m22: 1, | |
215 m41: 0, m42: 0 | |
216 }); | |
217 }, "If 2d related properties don't be set, should set to fallback."); | 140 }, "If 2d related properties don't be set, should set to fallback."); |
218 | 141 |
219 test(() => { | 142 test(() => { |
220 var matrix = DOMMatrix.fromMatrix({ | 143 var matrix = DOMMatrix.fromMatrix({ |
221 m11: NaN, m12: NaN, m13: NaN, m14: NaN, | 144 m11: NaN, m12: NaN, m13: NaN, m14: NaN, |
222 m21: NaN, m22: NaN, m23: NaN, m24: NaN, | 145 m21: NaN, m22: NaN, m23: NaN, m24: NaN, |
223 m31: NaN, m32: NaN, m33: NaN, m34: NaN, | 146 m31: NaN, m32: NaN, m33: NaN, m34: NaN, |
224 m41: NaN, m42: NaN, m43: NaN, m44: NaN, | 147 m41: NaN, m42: NaN, m43: NaN, m44: NaN, |
225 is2D: false | 148 is2D: false |
226 }); | 149 }); |
227 assert_equals(matrix.a, matrix.m11); | 150 assert_3d_matrix_equals(matrix, [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN]); |
228 assert_equals(matrix.b, matrix.m12); | |
229 assert_equals(matrix.c, matrix.m21); | |
230 assert_equals(matrix.d, matrix.m22); | |
231 assert_equals(matrix.e, matrix.m41); | |
232 assert_equals(matrix.f, matrix.m42); | |
233 assert_3d_matrix_equals(matrix, { | |
234 m11: NaN, m12: NaN, m13: NaN, m14: NaN, | |
235 m21: NaN, m22: NaN, m23: NaN, m24: NaN, | |
236 m31: NaN, m32: NaN, m33: NaN, m34: NaN, | |
237 m41: NaN, m42: NaN, m43: NaN, m44: NaN | |
238 }); | |
239 }, "DOMMatrix.fromMatrix(): NaN test"); | 151 }, "DOMMatrix.fromMatrix(): NaN test"); |
240 | 152 |
241 test(() => { | 153 test(() => { |
242 assert_throws(new TypeError(), () => { | 154 assert_throws(new TypeError(), () => { |
243 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m33: 3, m44: 4, is2D: tru
e}); | 155 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m33: 3, m44: 4, is2D: true}); |
244 }, "The 'is2D' property is set to true but the input matrix is 3d matrix."
); | 156 }, "The 'is2D' property is set to true but the input matrix is 3d matrix."); |
245 assert_throws(new TypeError(), () => { | 157 assert_throws(new TypeError(), () => { |
246 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m11: 3}); | 158 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m11: 3}); |
247 }, "The 'a' property should equal the 'm11' property."); | 159 }, "The 'a' property should equal the 'm11' property."); |
248 }, "DOMMatrix.fromMatrix(): Exception test."); | 160 }, "DOMMatrix.fromMatrix(): Exception test."); |
249 | |
250 </script> | 161 </script> |
251 </body> | |
252 </html> | |
OLD | NEW |