OLD | NEW |
---|---|
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
3 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
4 <script src="./resources/geometry-interfaces-test-helpers.js"></script> | 4 <script src="./resources/geometry-interfaces-test-helpers.js"></script> |
5 <script> | 5 <script> |
6 | 6 |
7 function deg2rad(degrees) { | 7 function deg2rad(degrees) { |
8 return degrees * Math.PI / 180; | 8 return degrees * Math.PI / 180; |
9 } | 9 } |
10 | 10 |
11 function rad2deg(radians) { | |
12 return radians * 180 / Math.PI; | |
13 } | |
14 | |
11 function getRotationMatrix(x, y, z, alpha_in_degrees) { | 15 function getRotationMatrix(x, y, z, alpha_in_degrees) { |
12 // Vector normalizing | 16 // Vector normalizing |
13 var nx = x; | 17 var nx = x; |
14 var ny = y; | 18 var ny = y; |
15 var nz = z; | 19 var nz = z; |
16 var length = Math.sqrt(x * x + y * y + z * z); | 20 var length = Math.sqrt(x * x + y * y + z * z); |
17 if (length) { | 21 if (length) { |
18 nx = x / length; | 22 nx = x / length; |
19 ny = y / length; | 23 ny = y / length; |
20 nz = z / length; | 24 nz = z / length; |
(...skipping 19 matching lines...) Expand all Loading... | |
40 var m34 = 0; | 44 var m34 = 0; |
41 var m41 = 0; | 45 var m41 = 0; |
42 var m42 = 0; | 46 var m42 = 0; |
43 var m43 = 0; | 47 var m43 = 0; |
44 var m44 = 1; | 48 var m44 = 1; |
45 | 49 |
46 return new DOMMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m 34, m41, m42, m43, m44]); | 50 return new DOMMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m 34, m41, m42, m43, m44]); |
47 } | 51 } |
48 | 52 |
49 test(() => { | 53 test(() => { |
54 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
55 var result = matrix.rotate(60); | |
56 matrix.rotateSelf(60); | |
57 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
58 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 60)); | |
59 assert_matrix_almost_equals(result, expectedMatrix); | |
60 assert_matrix_almost_equals(matrix, expectedMatrix); | |
meade_UTC10
2016/10/24 05:37:11
I had to think for a moment to figure out what the
Hwanseung Lee
2016/10/24 14:33:43
Done.
| |
61 }, "DOMMatrix 2d - rotate(rotX) and rotateSelf(rotX)"); | |
62 | |
63 test(() => { | |
64 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
65 var result = matrix.rotate(77); | |
66 matrix.rotateSelf(77); | |
67 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
68 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 77)); | |
69 assert_matrix_almost_equals(result, expectedMatrix); | |
70 assert_matrix_almost_equals(matrix, expectedMatrix); | |
71 }, "DOMMatrix 3d - rotate(rotX) and rotateSelf(rotX)"); | |
72 | |
73 test(() => { | |
74 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
75 var result = matrix.rotate(10, 20); | |
76 matrix.rotateSelf(10, 20); | |
77 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
78 expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 20)); | |
79 expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 10)); | |
80 assert_matrix_almost_equals(result, expectedMatrix); | |
81 assert_matrix_almost_equals(matrix, expectedMatrix); | |
82 }, "DOMMatrix 2d - rotate(rotX, rotY) and rotateSelf(rotX, rotY)"); | |
83 | |
84 test(() => { | |
85 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
86 var result = matrix.rotate(23, 50); | |
87 matrix.rotateSelf(23, 50); | |
88 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
89 expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 50)); | |
90 expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 23)); | |
91 assert_matrix_almost_equals(result, expectedMatrix); | |
92 assert_matrix_almost_equals(matrix, expectedMatrix); | |
93 }, "DOMMatrix 3d - rotate(rotX, rotY) and rotateSelf(rotX, rotY)"); | |
94 | |
95 test(() => { | |
96 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
97 var result = matrix.rotate(39, 10, 50); | |
98 matrix.rotateSelf(39, 10, 50); | |
99 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
100 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 50)); | |
101 expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 10)); | |
102 expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 39)); | |
103 assert_matrix_almost_equals(result, expectedMatrix); | |
104 assert_matrix_almost_equals(matrix, expectedMatrix); | |
105 }, "DOMMatrix 2d - rotate(rotX, rotY, rotX) and rotateSelf(rotX, rotY, rotX)"); | |
106 | |
107 test(() => { | |
108 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
109 var result = matrix.rotate(55, 66, 88); | |
110 matrix.rotateSelf(55, 66, 88); | |
111 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
112 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 88)); | |
113 expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 66)); | |
114 expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 55)); | |
115 assert_matrix_almost_equals(result, expectedMatrix); | |
116 assert_matrix_almost_equals(matrix, expectedMatrix); | |
117 }, "DOMMatrix 3d - rotate(rotX, rotY, rotX) and rotateSelf(rotX, rotY, rotX)"); | |
118 | |
119 test(function() { | |
120 var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
121 var result = matrix2d.rotateFromVector(4, 7); | |
122 var expected = new DOMMatrix([1, 2, 3, 4, 5, 6]); | |
123 expected.rotateSelf(rad2deg(Math.atan2(7, 4))); | |
124 assert_matrix_almost_equals(result, expected); | |
125 matrix2d.rotateFromVectorSelf(4, 7); | |
126 assert_matrix_almost_equals(matrix2d, expected); | |
127 }, "DOMMatrix 2d - rotateFromVector(x, y) and rotateFromVectorSelf(x, y)"); | |
128 | |
129 test(function() { | |
130 var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1 5, 16]); | |
131 var result = matrix3d.rotateFromVector(4, 7); | |
132 var expected = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1 5, 16]); | |
133 expected.rotateSelf(rad2deg(Math.atan2(7, 4))); | |
134 assert_matrix_almost_equals(result, expected); | |
135 matrix3d.rotateFromVectorSelf(4, 7); | |
136 assert_matrix_almost_equals(matrix3d, expected); | |
137 }, "DOMMatrix 3d - rotateFromVector(x, y) rotateFromVectorSelf(x, y)"); | |
138 | |
139 test(() => { | |
50 var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]); | 140 var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]); |
51 matrix2d.rotateAxisAngleSelf(); | 141 matrix2d.rotateAxisAngleSelf(); |
52 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | 142 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); |
53 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0)); | 143 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0)); |
54 assert_true(matrix2d.is2D); | 144 assert_true(matrix2d.is2D); |
55 assert_matrix_almost_equals(matrix2d, expectedMatrix); | 145 assert_matrix_almost_equals(matrix2d, expectedMatrix); |
56 }, "DOMMatrix 2d - rotateAxisAngleSelf()"); | 146 }, "DOMMatrix 2d - rotateAxisAngleSelf()"); |
57 | 147 |
58 test(() => { | 148 test(() => { |
59 var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]); | 149 var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, -180); | 424 matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, -180); |
335 matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, +180); | 425 matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, +180); |
336 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | 426 var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); |
337 assert_matrix_almost_equals(matrix3d, expectedMatrix); | 427 assert_matrix_almost_equals(matrix3d, expectedMatrix); |
338 }, "DOMMatrix 3d - rotateAxisAngle() - do rotate -180,+180"); | 428 }, "DOMMatrix 3d - rotateAxisAngle() - do rotate -180,+180"); |
339 | 429 |
340 test(() => { | 430 test(() => { |
341 var matrix3d = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) ; | 431 var matrix3d = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) ; |
342 matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, -90); | 432 matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, -90); |
343 var expectedMatrix1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]); | 433 var expectedMatrix1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]); |
344 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix1.toFloat6 4Array()); | 434 assert_matrix_almost_equals(matrix3d, expectedMatrix1); |
345 matrix3d = matrix3d.rotateAxisAngle(1, 0, 0, -90); | 435 matrix3d = matrix3d.rotateAxisAngle(1, 0, 0, -90); |
346 var expectedMatrix2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]); | 436 var expectedMatrix2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]); |
347 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix2.toFloat6 4Array()); | 437 assert_matrix_almost_equals(matrix3d, expectedMatrix2); |
348 matrix3d = matrix3d.rotateAxisAngle(0, 1, 0, -90); | 438 matrix3d = matrix3d.rotateAxisAngle(0, 1, 0, -90); |
349 var expectedMatrix3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | 439 var expectedMatrix3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
350 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix3.toFloat6 4Array()); | 440 assert_matrix_almost_equals(matrix3d, expectedMatrix3); |
351 }, "DOMMatrix 3d - rotateAxisAngle()"); | 441 }, "DOMMatrix 3d - rotateAxisAngle()"); |
352 | 442 |
353 test(() => { | 443 test(() => { |
354 var matrix3d = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) ; | 444 var matrix3d = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) ; |
355 matrix3d.rotateAxisAngleSelf(0, 0, 1, -90); | 445 matrix3d.rotateAxisAngleSelf(0, 0, 1, -90); |
356 var expectedMatrix1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]); | 446 var expectedMatrix1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]); |
357 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix1.toFloat6 4Array()); | 447 assert_matrix_almost_equals(matrix3d, expectedMatrix1); |
358 matrix3d.rotateAxisAngleSelf(1, 0, 0, -90); | 448 matrix3d.rotateAxisAngleSelf(1, 0, 0, -90); |
359 var expectedMatrix2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]); | 449 var expectedMatrix2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]); |
360 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix2.toFloat6 4Array()); | 450 assert_matrix_almost_equals(matrix3d, expectedMatrix2); |
361 matrix3d.rotateAxisAngleSelf(0, 1, 0, -90); | 451 matrix3d.rotateAxisAngleSelf(0, 1, 0, -90); |
362 var expectedMatrix3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | 452 var expectedMatrix3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
363 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix3.toFloat6 4Array()); | 453 assert_matrix_almost_equals(matrix3d, expectedMatrix3); |
364 }, "DOMMatrix 3d - rotateAxisAngleSelf()"); | 454 }, "DOMMatrix 3d - rotateAxisAngleSelf()"); |
365 | 455 |
366 </script> | 456 </script> |
OLD | NEW |