Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE HTML> | |
| 2 <script src="../../resources/testharness.js"></script> | |
| 3 <script src="../../resources/testharnessreport.js"></script> | |
| 4 <script src="./resources/geometry-interfaces-test-helpers.js"></script> | |
| 5 <script> | |
| 6 | |
| 7 function deg2rad(degrees) { | |
| 8 return degrees * Math.PI / 180; | |
| 9 } | |
| 10 | |
| 11 function getRotationMatrix(x, y, z, alpha_in_degrees) { | |
| 12 // Vector normalizing | |
| 13 var nx = x; | |
| 14 var ny = y; | |
| 15 var nz = z; | |
| 16 var length = Math.sqrt(x * x + y * y + z * z); | |
| 17 if(length != 0) { | |
| 18 nx = x / length; | |
| 19 ny = y / length; | |
| 20 nz = z / length; | |
| 21 } | |
| 22 | |
| 23 // The 3D rotation matrix is described in CSS Transforms with alpha. | |
| 24 // Please see: https://drafts.csswg.org/css-transforms-1/#Rotate3dDefined | |
| 25 var alpha_in_radian = deg2rad(alpha_in_degrees / 2); | |
| 26 var sc = Math.sin(alpha_in_radian) * Math.cos(alpha_in_radian); | |
| 27 var sq = Math.sin(alpha_in_radian) * Math.sin(alpha_in_radian); | |
| 28 | |
| 29 var m11 = 1 - 2 * (ny * ny + nz * nz) * sq; | |
| 30 var m12 = 2 * (nx * ny * sq + nz * sc); | |
| 31 var m13 = 2 * (nx * nz * sq - ny * sc); | |
| 32 var m14 = 0; | |
| 33 var m21 = 2 * (nx * ny * sq - nz * sc); | |
| 34 var m22 = 1 - 2 * (nx * nx + nz * nz) * sq; | |
| 35 var m23 = 2 * (ny * nz * sq + nx * sc); | |
| 36 var m24 = 0; | |
| 37 var m31 = 2 * (nx * nz * sq + ny * sc); | |
| 38 var m32 = 2 * (ny * nz * sq - nx * sc); | |
| 39 var m33 = 1 - 2 * (nx * nx + ny * ny) * sq; | |
| 40 var m34 = 0; | |
| 41 var m41 = 0; | |
| 42 var m42 = 0; | |
| 43 var m43 = 0; | |
| 44 var m44 = 1; | |
| 45 | |
| 46 return initDomMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m 34, m41, m42, m43, m44]); | |
| 47 } | |
| 48 | |
| 49 function initDomMatrix(values) { | |
| 50 return DOMMatrix.fromFloat64Array(new Float64Array(values)); | |
| 51 } | |
| 52 | |
| 53 function initDOMMatrixReadOnly(values) { | |
| 54 return DOMMatrixReadOnly.fromFloat64Array(new Float64Array(values)); | |
| 55 } | |
| 56 | |
| 57 function initDomMatrixFor2DTest() { | |
| 58 return initDomMatrix([1, 2, 3, 4, 5, 6]); | |
| 59 } | |
| 60 | |
| 61 function initDomMatrixFor3DTest() { | |
| 62 return initDomMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
| 63 } | |
| 64 | |
| 65 function initDOMMatrixReadOnlyFor2DTest() { | |
| 66 return initDOMMatrixReadOnly([1, 2, 3, 4, 5, 6]); | |
| 67 } | |
| 68 | |
| 69 function initDOMMatrixReadOnlyFor3DTest() { | |
| 70 return initDOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1 5, 16]); | |
| 71 } | |
| 72 | |
| 73 test(() => { | |
| 74 var matrix2d = initDomMatrixFor2DTest(); | |
|
zino
2016/09/24 17:38:20
Let's use new DOMMatrix([arrays]) after landing yo
Hwanseung Lee
2016/09/25 00:50:54
i added comment about TODO.
if this CL merged firs
| |
| 75 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 76 matrix2d.rotateAxisAngleSelf(); | |
| 77 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0)); | |
| 78 assert_true(matrix2d.is2D); | |
| 79 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 80 }, "DOMMatrix 2d - rotateAxisAngleSelf()"); | |
| 81 | |
| 82 test(() => { | |
| 83 var matrix2d = initDomMatrixFor2DTest(); | |
| 84 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 85 matrix2d.rotateAxisAngleSelf(0, 0, 1); | |
| 86 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0)); | |
| 87 assert_true(matrix2d.is2D); | |
| 88 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 89 }, "DOMMatrix 2d - rotateAxisAngleSelf(0, 0, 1)"); | |
| 90 | |
| 91 test(() => { | |
| 92 var matrix2d = initDomMatrixFor2DTest(); | |
| 93 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 94 matrix2d.rotateAxisAngleSelf(1, 1, 1); | |
| 95 expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 0)); | |
| 96 assert_false(matrix2d.is2D); | |
| 97 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 98 }, "DOMMatrix 2d - rotateAxisAngleSelf(1, 1, 1, 0)"); | |
| 99 | |
| 100 test(() => { | |
| 101 var matrix2d = initDomMatrixFor2DTest(); | |
| 102 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 103 matrix2d.rotateAxisAngleSelf(1, 0, 0, 10); | |
| 104 expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 10)); | |
| 105 assert_false(matrix2d.is2D); | |
| 106 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 107 }, "DOMMatrix 2d - rotateAxisAngleSelf(1, 0, 0, 10)"); | |
| 108 | |
| 109 test(() => { | |
| 110 var matrix2d = initDomMatrixFor2DTest(); | |
| 111 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 112 matrix2d.rotateAxisAngleSelf(0, 1, 0, 27); | |
| 113 expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 27)); | |
| 114 assert_false(matrix2d.is2D); | |
| 115 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 116 }, "DOMMatrix 2d - rotateAxisAngleSelf(0, 1, 0, 27)"); | |
| 117 | |
| 118 test(() => { | |
| 119 var matrix2d = initDomMatrixFor2DTest(); | |
| 120 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 121 matrix2d.rotateAxisAngleSelf(0, 0, 1, 38); | |
| 122 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 38)); | |
| 123 assert_true(matrix2d.is2D); | |
| 124 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 125 }, "DOMMatrix 2d - rotateAxisAngleSelf(0, 0, 1, 38)"); | |
| 126 | |
| 127 test(() => { | |
| 128 var matrix2d = initDomMatrixFor2DTest(); | |
| 129 var expectedMatrix = initDomMatrixFor2DTest(); | |
| 130 matrix2d.rotateAxisAngleSelf(1, 1, 1, 45); | |
| 131 expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 45)); | |
| 132 assert_false(matrix2d.is2D); | |
| 133 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 134 }, "DOMMatrix 2d - rotateAxisAngleSelf(1, 1, 1, 45)"); | |
| 135 | |
| 136 test(() => { | |
| 137 var matrix3d = initDomMatrixFor3DTest(); | |
| 138 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 139 matrix3d.rotateAxisAngleSelf(); | |
| 140 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0)); | |
| 141 assert_false(matrix3d.is2D); | |
| 142 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 143 }, "DOMMatrix 3d - rotateAxisAngleSelf()"); | |
| 144 | |
| 145 test(() => { | |
| 146 var matrix3d = initDomMatrixFor3DTest(); | |
| 147 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 148 matrix3d.rotateAxisAngleSelf(0, 0, 1); | |
| 149 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0)); | |
| 150 assert_false(matrix3d.is2D); | |
| 151 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 152 }, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1)"); | |
| 153 | |
| 154 test(() => { | |
| 155 var matrix3d = initDomMatrixFor3DTest(); | |
| 156 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 157 matrix3d.rotateAxisAngleSelf(0, 0, 1, 0); | |
| 158 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0)); | |
| 159 assert_false(matrix3d.is2D); | |
| 160 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 161 }, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1, 0)"); | |
| 162 | |
| 163 test(() => { | |
| 164 var matrix3d = initDomMatrixFor3DTest(); | |
| 165 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 166 matrix3d.rotateAxisAngleSelf(1, 0, 0, 19); | |
| 167 expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 19)); | |
| 168 assert_false(matrix3d.is2D); | |
| 169 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 170 }, "DOMMatrix 3d - rotateAxisAngleSelf(1, 0, 0, 19)"); | |
| 171 | |
| 172 test(() => { | |
| 173 var matrix3d = initDomMatrixFor3DTest(); | |
| 174 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 175 matrix3d.rotateAxisAngleSelf(0, 1, 0, 46); | |
| 176 expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 46)); | |
| 177 assert_false(matrix3d.is2D); | |
| 178 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 179 }, "DOMMatrix 3d - rotateAxisAngleSelf(0, 1, 0, 46)"); | |
| 180 | |
| 181 test(() => { | |
| 182 var matrix3d = initDomMatrixFor3DTest(); | |
| 183 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 184 matrix3d.rotateAxisAngleSelf(0, 0, 1, 65); | |
| 185 expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 65)); | |
| 186 assert_false(matrix3d.is2D); | |
| 187 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 188 }, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1, 65)"); | |
| 189 | |
| 190 test(() => { | |
| 191 var matrix3d = initDomMatrixFor3DTest(); | |
| 192 var expectedMatrix = initDomMatrixFor3DTest(); | |
| 193 matrix3d.rotateAxisAngleSelf(1, 1, 1, 67); | |
| 194 expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 67)); | |
| 195 assert_false(matrix3d.is2D); | |
| 196 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 197 }, "DOMMatrix 3d - rotateAxisAngleSelf(1, 1, 1, 67)"); | |
| 198 | |
| 199 test(() => { | |
| 200 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 201 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 202 matrix2d = matrix2d.rotateAxisAngle(); | |
| 203 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 0, 0)); | |
| 204 assert_true(matrix2d.is2D); | |
| 205 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 206 }, "DOMMatrixReadOnly 2d - rotateAxisAngle()"); | |
| 207 | |
| 208 test(() => { | |
| 209 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 210 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 211 matrix2d = matrix2d.rotateAxisAngle(0, 0, 1); | |
| 212 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0)); | |
| 213 assert_true(matrix2d.is2D); | |
| 214 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 215 }, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 0, 1)"); | |
| 216 | |
| 217 test(() => { | |
| 218 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 219 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 220 matrix2d = matrix2d.rotateAxisAngle(1, 1, 1); | |
| 221 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 0)); | |
| 222 }, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 1, 1, 0)"); | |
| 223 | |
| 224 test(() => { | |
| 225 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 226 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 227 matrix2d = matrix2d.rotateAxisAngle(1, 0, 0, 21); | |
| 228 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 0, 0, 21)); | |
| 229 assert_false(matrix2d.is2D); | |
| 230 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 231 }, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 0, 0, 21)"); | |
| 232 | |
| 233 test(() => { | |
| 234 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 235 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 236 matrix2d = matrix2d.rotateAxisAngle(0, 1, 0, 35); | |
| 237 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 1, 0, 35)); | |
| 238 assert_false(matrix2d.is2D); | |
| 239 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 240 }, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 1, 0, 35)"); | |
| 241 | |
| 242 test(() => { | |
| 243 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 244 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 245 matrix2d = matrix2d.rotateAxisAngle(0, 0, 1, 55); | |
| 246 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 55)); | |
| 247 assert_true(matrix2d.is2D); | |
| 248 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 249 }, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 0, 1, 55)"); | |
| 250 | |
| 251 test(() => { | |
| 252 var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | |
| 253 var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | |
| 254 matrix2d = matrix2d.rotateAxisAngle(1, 1, 1, 75); | |
| 255 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 75)); | |
| 256 assert_false(matrix2d.is2D); | |
| 257 assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 258 }, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 1, 1, 75)"); | |
| 259 | |
| 260 test(() => { | |
| 261 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 262 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 263 matrix3d = matrix3d.rotateAxisAngle(); | |
| 264 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 0, 0)); | |
| 265 assert_false(matrix3d.is2D); | |
| 266 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 267 }, "DOMMatrixReadOnly 3d - rotateAxisAngle()"); | |
| 268 | |
| 269 test(() => { | |
| 270 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 271 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 272 matrix3d = matrix3d.rotateAxisAngle(0, 0, 1); | |
| 273 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0)); | |
| 274 assert_false(matrix3d.is2D); | |
| 275 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 276 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1)"); | |
| 277 | |
| 278 test(() => { | |
| 279 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 280 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 281 matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, 0); | |
| 282 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0)); | |
| 283 assert_false(matrix3d.is2D); | |
| 284 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 285 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1, 0)"); | |
| 286 | |
| 287 test(() => { | |
| 288 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 289 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 290 matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, 0); | |
| 291 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 0)); | |
| 292 assert_false(matrix3d.is2D); | |
| 293 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 294 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 1, 1, 0)"); | |
| 295 | |
| 296 test(() => { | |
| 297 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 298 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 299 matrix3d = matrix3d.rotateAxisAngle(1, 0, 0, 105); | |
| 300 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 0, 0, 105)); | |
| 301 assert_false(matrix3d.is2D); | |
| 302 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 303 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 0, 0, 105)"); | |
| 304 | |
| 305 test(() => { | |
| 306 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 307 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 308 matrix3d = matrix3d.rotateAxisAngle(0, 1, 0, 45); | |
| 309 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 1, 0, 45)); | |
| 310 assert_false(matrix3d.is2D); | |
| 311 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 312 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 1, 0, 45)"); | |
| 313 | |
| 314 test(() => { | |
| 315 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 316 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 317 matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, 65); | |
| 318 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 65)); | |
| 319 assert_false(matrix3d.is2D); | |
| 320 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 321 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1, 65)"); | |
| 322 | |
| 323 test(() => { | |
| 324 var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | |
| 325 var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | |
| 326 matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, 78); | |
| 327 expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 78)); | |
| 328 assert_false(matrix3d.is2D); | |
| 329 assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64 Array()); | |
| 330 }, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 1, 1, 78)"); | |
| 331 | |
| 332 </script> | |
| OLD | NEW |