Commit 66e25541 authored by hs1217.lee's avatar hs1217.lee Committed by Commit bot

[GeometryInterface] Add rotate*(), rotateFromVector*() function.

rotate() and rotateSelf() function
1. If rotY and rotZ are both missing,
 set rotZ to the value of rotX and set rotX and rotY to zero.
2. If rotY is still missing, set rotY to zero.
3. If rotZ is still missing, set rotZ to zero.
4. If rotX or rotY are non-zero,
 set is2D of the current matrix to false.
5. Post-multiply a rotation transformation on the current matrix around the vector 0, 0, 1
 by the specified rotation rotZ in degrees.
6. Post-multiply a rotation transformation on the current matrix around the vector 0, 1, 0
 by the specified rotation rotY in degrees.
7. Post-multiply a rotation transformation on the current matrix around the vector 1, 0, 0
 by the specified rotation rotX in degrees.
8. Return the current matrix.

rotateFromVertor() and rotateFromVertorSelf() function
1. Post-multiply a rotation transformation on the current matrix.
 The rotation angle is determined by the angle between the vector (1,0)T and (x,y)T
 in the clockwise direction.
2. Return the current matrix.

spec list:
- https://drafts.fxtf.org/geometry/#dom-dommatrix-rotateself
- https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-rotate
- https://drafts.fxtf.org/geometry/#dom-dommatrix-rotatefromvectorself
- https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-rotatefromvector

BUG=388780, 645878, 645882

Review-Url: https://codereview.chromium.org/2444733002
Cr-Commit-Position: refs/heads/master@{#427289}
parent a9c75fd2
......@@ -8,6 +8,10 @@ function deg2rad(degrees) {
return degrees * Math.PI / 180;
}
function rad2deg(radians) {
return radians * 180 / Math.PI;
}
function getRotationMatrix(x, y, z, alpha_in_degrees) {
// Vector normalizing
var nx = x;
......@@ -46,321 +50,407 @@ function getRotationMatrix(x, y, z, alpha_in_degrees) {
return new DOMMatrix([m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44]);
}
test(() => {
var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
var rotateResult = matrix.rotate(60);
matrix.rotateSelf(60);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 60));
assert_matrix_almost_equals(rotateResult, expectedResult);
assert_matrix_almost_equals(matrix, expectedResult);
}, "DOMMatrix 2d - rotate(rotX) and rotateSelf(rotX)");
test(() => {
var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
var rotateResult = matrix.rotate(77);
matrix.rotateSelf(77);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 77));
assert_matrix_almost_equals(rotateResult, expectedResult);
assert_matrix_almost_equals(matrix, expectedResult);
}, "DOMMatrix 3d - rotate(rotX) and rotateSelf(rotX)");
test(() => {
var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
var rotateResult = matrix.rotate(10, 20);
matrix.rotateSelf(10, 20);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 1, 0, 20));
expectedResult.multiplySelf(getRotationMatrix(1, 0, 0, 10));
assert_matrix_almost_equals(rotateResult, expectedResult);
assert_matrix_almost_equals(matrix, expectedResult);
}, "DOMMatrix 2d - rotate(rotX, rotY) and rotateSelf(rotX, rotY)");
test(() => {
var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
var rotateResult = matrix.rotate(23, 50);
matrix.rotateSelf(23, 50);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 1, 0, 50));
expectedResult.multiplySelf(getRotationMatrix(1, 0, 0, 23));
assert_matrix_almost_equals(rotateResult, expectedResult);
assert_matrix_almost_equals(matrix, expectedResult);
}, "DOMMatrix 3d - rotate(rotX, rotY) and rotateSelf(rotX, rotY)");
test(() => {
var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
var rotateResult = matrix.rotate(39, 10, 50);
matrix.rotateSelf(39, 10, 50);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 50));
expectedResult.multiplySelf(getRotationMatrix(0, 1, 0, 10));
expectedResult.multiplySelf(getRotationMatrix(1, 0, 0, 39));
assert_matrix_almost_equals(rotateResult, expectedResult);
assert_matrix_almost_equals(matrix, expectedResult);
}, "DOMMatrix 2d - rotate(rotX, rotY, rotX) and rotateSelf(rotX, rotY, rotX)");
test(() => {
var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
var rotateResult = matrix.rotate(55, 66, 88);
matrix.rotateSelf(55, 66, 88);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 88));
expectedResult.multiplySelf(getRotationMatrix(0, 1, 0, 66));
expectedResult.multiplySelf(getRotationMatrix(1, 0, 0, 55));
assert_matrix_almost_equals(rotateResult, expectedResult);
assert_matrix_almost_equals(matrix, expectedResult);
}, "DOMMatrix 3d - rotate(rotX, rotY, rotX) and rotateSelf(rotX, rotY, rotX)");
test(function() {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
var rotateResult = matrix2d.rotateFromVector(4, 7);
var expected = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expected.rotateSelf(rad2deg(Math.atan2(7, 4)));
assert_matrix_almost_equals(rotateResult, expected);
matrix2d.rotateFromVectorSelf(4, 7);
assert_matrix_almost_equals(matrix2d, expected);
}, "DOMMatrix 2d - rotateFromVector(x, y) and rotateFromVectorSelf(x, y)");
test(function() {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
var rotateResult = matrix3d.rotateFromVector(4, 7);
var expected = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expected.rotateSelf(rad2deg(Math.atan2(7, 4)));
assert_matrix_almost_equals(rotateResult, expected);
matrix3d.rotateFromVectorSelf(4, 7);
assert_matrix_almost_equals(matrix3d, expected);
}, "DOMMatrix 3d - rotateFromVector(x, y) rotateFromVectorSelf(x, y)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf();
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 0, 0));
assert_true(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf()");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(0, 0, 1);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 0));
assert_true(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf(0, 0, 1)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(1, 1, 1);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 0));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(1, 1, 1, 0));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf(1, 1, 1, 0)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(1, 0, 0, 10);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 10));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(1, 0, 0, 10));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf(1, 0, 0, 10)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(0, 1, 0, 27);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 27));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 1, 0, 27));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf(0, 1, 0, 27)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(0, 0, 1, 38);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 38));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 38));
assert_true(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf(0, 0, 1, 38)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(1, 1, 1, 45);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 45));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
expectedResult.multiplySelf(getRotationMatrix(1, 1, 1, 45));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf(1, 1, 1, 45)");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf();
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 0, 0));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 0, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf()");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(0, 0, 1);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1)");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(0, 0, 1, 0);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 0));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1, 0)");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(1, 0, 0, 19);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(1, 0, 0, 19));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(1, 0, 0, 19));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf(1, 0, 0, 19)");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(0, 1, 0, 46);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 1, 0, 46));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 1, 0, 46));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 1, 0, 46)");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(0, 0, 1, 65);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(0, 0, 1, 65));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(0, 0, 1, 65));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf(0, 0, 1, 65)");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(1, 1, 1, 67);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix.multiplySelf(getRotationMatrix(1, 1, 1, 67));
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult.multiplySelf(getRotationMatrix(1, 1, 1, 67));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf(1, 1, 1, 67)");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle();
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 0, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 0, 0));
assert_true(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrixReadOnly 2d - rotateAxisAngle()");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(0, 0, 1);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 1, 0));
assert_true(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 0, 1)");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(1, 1, 1);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(1, 1, 1, 0));
}, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 1, 1, 0)");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(1, 0, 0, 21);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 0, 0, 21));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(1, 0, 0, 21));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 0, 0, 21)");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(0, 1, 0, 35);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 1, 0, 35));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 1, 0, 35));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 1, 0, 35)");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(0, 0, 1, 55);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 55));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 1, 55));
assert_true(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrixReadOnly 2d - rotateAxisAngle(0, 0, 1, 55)");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(1, 1, 1, 75);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 75));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
expectedResult = expectedResult.multiply(getRotationMatrix(1, 1, 1, 75));
assert_false(matrix2d.is2D);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrixReadOnly 2d - rotateAxisAngle(1, 1, 1, 75)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle();
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 0, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 0, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle()");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(0, 0, 1);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 1, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, 0);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 1, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1, 0)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, 0);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 0));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(1, 1, 1, 0));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 1, 1, 0)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(1, 0, 0, 105);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 0, 0, 105));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(1, 0, 0, 105));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 0, 0, 105)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(0, 1, 0, 45);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 1, 0, 45));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 1, 0, 45));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 1, 0, 45)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, 65);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(0, 0, 1, 65));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(0, 0, 1, 65));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(0, 0, 1, 65)");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, 78);
var expectedMatrix = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedMatrix = expectedMatrix.multiply(getRotationMatrix(1, 1, 1, 78));
var expectedResult = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
expectedResult = expectedResult.multiply(getRotationMatrix(1, 1, 1, 78));
assert_false(matrix3d.is2D);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrixReadOnly 3d - rotateAxisAngle(1, 1, 1, 78)");
test(() => {
var matrix2d = new DOMMatrix([1, 2, 3, 4, 5, 6]);
matrix2d.rotateAxisAngleSelf(1, 0, 0, 90);
matrix2d.rotateAxisAngleSelf(1, 0, 0, -90);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngleSelf() - do rotate +90,-90");
test(() => {
var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
matrix2d = matrix2d.rotateAxisAngle(0, 1, 0, -180);
matrix2d = matrix2d.rotateAxisAngle(0, 1, 0, +180);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
assert_matrix_almost_equals(matrix2d, expectedMatrix);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6]);
assert_matrix_almost_equals(matrix2d, expectedResult);
}, "DOMMatrix 2d - rotateAxisAngle() - do rotate -180,+180" );
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d.rotateAxisAngleSelf(1, 1, 0, 90);
matrix3d.rotateAxisAngleSelf(1, 1, 0, -90);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngleSelf() - do rotate +90,-90");
test(() => {
var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, -180);
matrix3d = matrix3d.rotateAxisAngle(1, 1, 1, +180);
var expectedMatrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
assert_matrix_almost_equals(matrix3d, expectedMatrix);
var expectedResult = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
assert_matrix_almost_equals(matrix3d, expectedResult);
}, "DOMMatrix 3d - rotateAxisAngle() - do rotate -180,+180");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
matrix3d = matrix3d.rotateAxisAngle(0, 0, 1, -90);
var expectedMatrix1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix1.toFloat64Array());
var expectedResult1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_matrix_almost_equals(matrix3d, expectedResult1);
matrix3d = matrix3d.rotateAxisAngle(1, 0, 0, -90);
var expectedMatrix2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]);
assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix2.toFloat64Array());
var expectedResult2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]);
assert_matrix_almost_equals(matrix3d, expectedResult2);
matrix3d = matrix3d.rotateAxisAngle(0, 1, 0, -90);
var expectedMatrix3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix3.toFloat64Array());
var expectedResult3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_matrix_almost_equals(matrix3d, expectedResult3);
}, "DOMMatrix 3d - rotateAxisAngle()");
test(() => {
var matrix3d = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
matrix3d.rotateAxisAngleSelf(0, 0, 1, -90);
var expectedMatrix1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix1.toFloat64Array());
var expectedResult1 = new DOMMatrix([0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_matrix_almost_equals(matrix3d, expectedResult1);
matrix3d.rotateAxisAngleSelf(1, 0, 0, -90);
var expectedMatrix2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]);
assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix2.toFloat64Array());
var expectedResult2 = new DOMMatrix([0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0]);
assert_matrix_almost_equals(matrix3d, expectedResult2);
matrix3d.rotateAxisAngleSelf(0, 1, 0, -90);
var expectedMatrix3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_array_almost_equals(matrix3d.toFloat64Array(), expectedMatrix3.toFloat64Array());
var expectedResult3 = new DOMMatrix([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_matrix_almost_equals(matrix3d, expectedResult3);
}, "DOMMatrix 3d - rotateAxisAngleSelf()");
</script>
......@@ -990,6 +990,8 @@ interface DOMMatrix : DOMMatrixReadOnly
method multiplySelf
method preMultiplySelf
method rotateAxisAngleSelf
method rotateFromVectorSelf
method rotateSelf
method scale3dSelf
method scaleSelf
method skewXSelf
......@@ -1051,7 +1053,9 @@ interface DOMMatrixReadOnly
method flipY
method inverse
method multiply
method rotate
method rotateAxisAngle
method rotateFromVector
method scale
method scale3d
method skewX
......
......@@ -183,6 +183,36 @@ DOMMatrix* DOMMatrix::scale3dSelf(double scale,
return scaleSelf(scale, scale, scale, ox, oy, oz);
}
DOMMatrix* DOMMatrix::rotateSelf(double rotX) {
return rotateSelf(0, 0, rotX);
}
DOMMatrix* DOMMatrix::rotateSelf(double rotX, double rotY) {
return rotateSelf(rotX, rotY, 0);
}
DOMMatrix* DOMMatrix::rotateSelf(double rotX, double rotY, double rotZ) {
if (rotZ)
m_matrix->rotate3d(0, 0, 1, rotZ);
if (rotY) {
m_matrix->rotate3d(0, 1, 0, rotY);
m_is2D = false;
}
if (rotX) {
m_matrix->rotate3d(1, 0, 0, rotX);
m_is2D = false;
}
return this;
}
DOMMatrix* DOMMatrix::rotateFromVectorSelf(double x, double y) {
m_matrix->rotate(rad2deg(atan2(y, x)));
return this;
}
DOMMatrix* DOMMatrix::rotateAxisAngleSelf(double x,
double y,
double z,
......
......@@ -92,6 +92,10 @@ class CORE_EXPORT DOMMatrix : public DOMMatrixReadOnly {
double ox = 0,
double oy = 0,
double oz = 0);
DOMMatrix* rotateSelf(double rotX);
DOMMatrix* rotateSelf(double rotX, double rotY);
DOMMatrix* rotateSelf(double rotX, double rotY, double rotZ);
DOMMatrix* rotateFromVectorSelf(double x, double y);
DOMMatrix* rotateAxisAngleSelf(double x = 0,
double y = 0,
double z = 0,
......
......@@ -63,6 +63,11 @@
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix rotateSelf(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);
DOMMatrix rotateFromVectorSelf(optional unrestricted double x = 0,
optional unrestricted double y = 0);
DOMMatrix rotateAxisAngleSelf(optional unrestricted double x = 0,
optional unrestricted double y = 0,
optional unrestricted double z = 0,
......
......@@ -173,6 +173,22 @@ DOMMatrix* DOMMatrixReadOnly::scale3d(double scale,
return DOMMatrix::create(this)->scale3dSelf(scale, ox, oy, oz);
}
DOMMatrix* DOMMatrixReadOnly::rotate(double rotX) {
return DOMMatrix::create(this)->rotateSelf(rotX);
}
DOMMatrix* DOMMatrixReadOnly::rotate(double rotX, double rotY) {
return DOMMatrix::create(this)->rotateSelf(rotX, rotY);
}
DOMMatrix* DOMMatrixReadOnly::rotate(double rotX, double rotY, double rotZ) {
return DOMMatrix::create(this)->rotateSelf(rotX, rotY, rotZ);
}
DOMMatrix* DOMMatrixReadOnly::rotateFromVector(double x, double y) {
return DOMMatrix::create(this)->rotateFromVectorSelf(x, y);
}
DOMMatrix* DOMMatrixReadOnly::rotateAxisAngle(double x,
double y,
double z,
......
......@@ -66,6 +66,10 @@ class CORE_EXPORT DOMMatrixReadOnly
double oy = 0,
double oz = 0);
DOMMatrix* scale3d(double scale, double ox = 0, double oy = 0, double oz = 0);
DOMMatrix* rotate(double rotX);
DOMMatrix* rotate(double rotX, double rotY);
DOMMatrix* rotate(double rotX, double rotY, double rotZ);
DOMMatrix* rotateFromVector(double x, double y);
DOMMatrix* rotateAxisAngle(double x = 0,
double y = 0,
double z = 0,
......
......@@ -61,6 +61,11 @@
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix rotate(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);
DOMMatrix rotateFromVector(optional unrestricted double x = 0,
optional unrestricted double y = 0);
DOMMatrix rotateAxisAngle(optional unrestricted double x = 0,
optional unrestricted double y = 0,
optional unrestricted double z = 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment