Implement DOMMatrixReadOnly.transformPoint()
[WebKit-https.git] / LayoutTests / imported / blink / fast / dom / resources / geometry-interfaces-test-helpers.js
1 function assert_identity_2d_matrix(actual) {
2   assert_true(actual instanceof DOMMatrixReadOnly);
3   assert_true(actual.is2D, "is2D");
4   assert_true(actual.isIdentity, "isIdentity");
5   assert_identity_matrix(actual);
6 }
7
8 function assert_identity_3d_matrix(actual) {
9   assert_true(actual instanceof DOMMatrixReadOnly);
10   assert_false(actual.is2D, "is2D");
11   assert_true(actual.isIdentity, "isIdentity");
12   assert_identity_matrix(actual);
13 }
14
15 function assert_identity_matrix(actual) {
16   assert_array_equals(actual.toFloat64Array(), [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
17 }
18
19 function toArray(actual) {
20   var array = actual.toFloat64Array();
21   // Do not care negative zero for testing accommodation.
22   for (var i = 0; i < array.length; i++) {
23     if (array[i] === -0)
24       array[i] = 0;
25   }
26   return array;
27 }
28
29 function assert_2d_matrix_equals(actual, expected) {
30   assert_true(actual instanceof DOMMatrixReadOnly);
31   assert_true(Array.isArray(expected));
32   assert_equals(6, expected.length, "expected.length");
33   assert_true(actual.is2D, "is2D");
34   assert_false(actual.isIdentity, "isIdentity");
35   assert_array_equals(toArray(actual), [
36     expected[0], expected[1], 0, 0,
37     expected[2], expected[3], 0, 0,
38     0, 0, 1, 0,
39     expected[4], expected[5], 0, 1
40   ]);
41 }
42
43 function assert_3d_matrix_equals(actual, expected) {
44   assert_true(actual instanceof DOMMatrixReadOnly);
45   assert_true(Array.isArray(expected) );
46   assert_equals(16, expected.length, "expected.length");
47   assert_false(actual.is2D, "is2D");
48   assert_false(actual.isIdentity, "isIdentity");
49   assert_array_equals(toArray(actual), [
50     expected[0], expected[1], expected[2], expected[3],
51     expected[4], expected[5], expected[6], expected[7],
52     expected[8], expected[9], expected[10], expected[11],
53     expected[12], expected[13], expected[14], expected[15],
54   ]);
55 }
56
57 function assert_array_almost_equals(actual, expected) {
58   for (var i = 0; i < actual.length; i++) {
59     assert_equals(actual[i].toFixed(10), expected[i].toFixed(10));
60   }
61 }
62
63 function assert_matrix_almost_equals(actual, expected) {
64   assert_array_almost_equals(actual.toFloat64Array(), expected.toFloat64Array());
65 }
66
67 function assert_dom_point_equals(actual, expected) {
68   assert_true(actual instanceof DOMPointReadOnly);
69   if(Array.isArray(expected)) {
70     assert_equals(expected.length, 4);
71     assert_equals(actual.x, expected[0], "point equality: x differs");
72     assert_equals(actual.y, expected[1], "point equality: y differs");
73     assert_equals(actual.z, expected[2], "point equality: z differs");
74     assert_equals(actual.w, expected[3], "point equality: w differs");
75   } else if(expected instanceof DOMPointReadOnly) {
76     assert_equals(actual.x, expected.x, "point equality: x differs");
77     assert_equals(actual.y, expected.y, "point equality: y differs");
78     assert_equals(actual.z, expected.z, "point equality: z differs");
79     assert_equals(actual.w, expected.w, "point equality: w differs");
80   } else {
81     assert_unreached();
82   }
83 }
84  
85 function assert_dom_rect_equals(actual, expected) {
86   assert_true(actual instanceof DOMRectReadOnly);
87   if(Array.isArray(expected)) {
88     assert_equals(expected.length, 8);
89     assert_equals(actual.x, expected[0], "rect equality: x differs");
90     assert_equals(actual.y, expected[1], "rect equality: y differs");
91     assert_equals(actual.width, expected[2], "rect equality: width differs");
92     assert_equals(actual.height, expected[3], "rect equality: height differs");
93     assert_equals(actual.top, expected[4], "rect equality: top differs");
94     assert_equals(actual.right, expected[5], "rect equality: right differs");
95     assert_equals(actual.bottom, expected[6], "rect equality: bottom differs");
96     assert_equals(actual.left, expected[7], "rect equality: left differs");
97   } else if(expected instanceof DOMRectReadOnly) {
98     assert_equals(actual.x, expected.x, "rect equality: x differs");
99     assert_equals(actual.y, expected.y, "rect equality: y differs");
100     assert_equals(actual.width, expected.width, "rect equality: width differs");
101     assert_equals(actual.height, expected.height, "rect equality: height differs");
102     assert_equals(actual.top, expected.top, "rect equality: top differs");
103     assert_equals(actual.right, expected.right, "rect equality: right differs");
104     assert_equals(actual.bottom, expected.bottom, "rect equality: bottom differs");
105     assert_equals(actual.left, expected.left, "poirectnt equality: left differs");
106   } else {
107     assert_unreached();
108   }
109 }