 Chromium Code Reviews
 Chromium Code Reviews Issue 2365153002:
  [GeometryInterface] Add rotateAxisAngle*(x,y,z,angle) function.  (Closed)
    
  
    Issue 2365153002:
  [GeometryInterface] Add rotateAxisAngle*(x,y,z,angle) function.  (Closed) 
  | Index: third_party/WebKit/LayoutTests/fast/dom/geometry-interfaces-dom-matrix-rotate.html | 
| diff --git a/third_party/WebKit/LayoutTests/fast/dom/geometry-interfaces-dom-matrix-rotate.html b/third_party/WebKit/LayoutTests/fast/dom/geometry-interfaces-dom-matrix-rotate.html | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..eb140a5e8aabdeb8a91dfba9138ba9fc955c778b | 
| --- /dev/null | 
| +++ b/third_party/WebKit/LayoutTests/fast/dom/geometry-interfaces-dom-matrix-rotate.html | 
| @@ -0,0 +1,333 @@ | 
| +<!DOCTYPE HTML> | 
| +<script src="../../resources/testharness.js"></script> | 
| +<script src="../../resources/testharnessreport.js"></script> | 
| +<script src="./resources/geometry-interfaces-test-helpers.js"></script> | 
| +<script> | 
| + | 
| +function deg2rad(degrees) { | 
| + return degrees * Math.PI / 180; | 
| +} | 
| + | 
| +function getRotationMatrix(x, y, z, alpha_in_degrees) { | 
| + // Vector normalizing | 
| + var nx = x; | 
| + var ny = y; | 
| + var nz = z; | 
| + var length = Math.sqrt(x * x + y * y + z * z); | 
| + if(length != 0) { | 
| 
dominicc (has gone to gerrit)
2016/09/28 08:16:06
Space before (
Maybe if (length) is more succinct
 
Hwanseung Lee
2016/09/28 16:20:56
Done.
 | 
| + nx = x / length; | 
| + ny = y / length; | 
| + nz = z / length; | 
| + } | 
| + | 
| + // The 3D rotation matrix is described in CSS Transforms with alpha. | 
| + // Please see: https://drafts.csswg.org/css-transforms-1/#Rotate3dDefined | 
| + var alpha_in_radian = deg2rad(alpha_in_degrees / 2); | 
| 
dominicc (has gone to gerrit)
2016/09/28 08:16:06
radian -> radians
 
Hwanseung Lee
2016/09/28 16:20:56
Done.
 | 
| + var sc = Math.sin(alpha_in_radian) * Math.cos(alpha_in_radian); | 
| + var sq = Math.sin(alpha_in_radian) * Math.sin(alpha_in_radian); | 
| + | 
| + var m11 = 1 - 2 * (ny * ny + nz * nz) * sq; | 
| + var m12 = 2 * (nx * ny * sq + nz * sc); | 
| + var m13 = 2 * (nx * nz * sq - ny * sc); | 
| + var m14 = 0; | 
| + var m21 = 2 * (nx * ny * sq - nz * sc); | 
| + var m22 = 1 - 2 * (nx * nx + nz * nz) * sq; | 
| + var m23 = 2 * (ny * nz * sq + nx * sc); | 
| + var m24 = 0; | 
| + var m31 = 2 * (nx * nz * sq + ny * sc); | 
| + var m32 = 2 * (ny * nz * sq - nx * sc); | 
| + var m33 = 1 - 2 * (nx * nx + ny * ny) * sq; | 
| + var m34 = 0; | 
| + var m41 = 0; | 
| + var m42 = 0; | 
| + var m43 = 0; | 
| + var m44 = 1; | 
| + | 
| + return initDomMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44]); | 
| +} | 
| + | 
| +// TODO(hs1217.lee): create the DOMMatrix directly when the sequence constructor is supported. | 
| +function initDomMatrix(values) { | 
| + return DOMMatrix.fromFloat64Array(new Float64Array(values)); | 
| +} | 
| + | 
| +function initDOMMatrixReadOnly(values) { | 
| + return DOMMatrixReadOnly.fromFloat64Array(new Float64Array(values)); | 
| +} | 
| + | 
| +function initDomMatrixFor2DTest() { | 
| + return initDomMatrix([1, 2, 3, 4, 5, 6]); | 
| +} | 
| + | 
| +function initDomMatrixFor3DTest() { | 
| + return initDomMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | 
| +} | 
| + | 
| +function initDOMMatrixReadOnlyFor2DTest() { | 
| + return initDOMMatrixReadOnly([1, 2, 3, 4, 5, 6]); | 
| +} | 
| + | 
| +function initDOMMatrixReadOnlyFor3DTest() { | 
| + return initDOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | 
| +} | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0)); | 
| + assert_true(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf()"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(0, 0, 1); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0)); | 
| + assert_true(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf(0, 0, 1)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(1, 1, 1); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 0)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf(1, 1, 1, 0)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(1, 0, 0, 10); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 10)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf(1, 0, 0, 10)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(0, 1, 0, 27); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 27)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf(0, 1, 0, 27)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(0, 0, 1, 38); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 38)); | 
| + assert_true(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf(0, 0, 1, 38)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDomMatrixFor2DTest(); | 
| + var expectedMatrix = initDomMatrixFor2DTest(); | 
| + matrix2d.rotateAxisAngleSelf(1, 1, 1, 45); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 45)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 2d - rotateAxisAngleSelf(1, 1, 1, 45)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf()"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(0, 0, 1); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(0, 0, 1, 0); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1, 0)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(1, 0, 0, 19); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 19)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf(1, 0, 0, 19)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(0, 1, 0, 46); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 46)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 1, 0, 46)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(0, 0, 1, 65); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 65)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1, 65)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDomMatrixFor3DTest(); | 
| + var expectedMatrix = initDomMatrixFor3DTest(); | 
| + matrix3d.rotateAxisAngleSelf(1, 1, 1, 67); | 
| + expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 67)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrix 3d - rotateAxisAngleSelf(1, 1, 1, 67)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 0, 0)); | 
| + assert_true(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle()"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(0, 0, 1); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0)); | 
| + assert_true(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 0, 1)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(1, 1, 1); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 0)); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 1, 1, 0)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(1, 0, 0, 21); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 0, 0, 21)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 0, 0, 21)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(0, 1, 0, 35); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 1, 0, 35)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 1, 0, 35)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(0, 0, 1, 55); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 55)); | 
| + assert_true(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 0, 1, 55)"); | 
| + | 
| +test(() => { | 
| + var matrix2d = initDOMMatrixReadOnlyFor2DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor2DTest(); | 
| + matrix2d = matrix2d.rotateAxisAngle(1, 1, 1, 75); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 75)); | 
| + assert_false(matrix2d.is2D); | 
| + assert_array_almost_equals(matrix2d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 1, 1, 75)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 0, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle()"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(0, 0, 1); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, 0); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1, 0)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, 0); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 0)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 1, 1, 0)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(1, 0, 0, 105); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 0, 0, 105)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 0, 0, 105)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(0, 1, 0, 45); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 1, 0, 45)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 1, 0, 45)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, 65); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 65)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1, 65)"); | 
| + | 
| +test(() => { | 
| + var matrix3d = initDOMMatrixReadOnlyFor3DTest(); | 
| + var expectedMatrix = initDOMMatrixReadOnlyFor3DTest(); | 
| + matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, 78); | 
| + expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 78)); | 
| + assert_false(matrix3d.is2D); | 
| + assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix.toFloat64Array()); | 
| +}, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 1, 1, 78)"); | 
| + | 
| +</script> |