| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Geometry Interfaces: DOMMatrix</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <script> |
| |
| test(function() { |
| var matrix = new DOMMatrix(); |
| assert_equals(matrix.m11, 1); |
| assert_equals(matrix.m12, 0); |
| assert_equals(matrix.m13, 0); |
| assert_equals(matrix.m14, 0); |
| assert_equals(matrix.m21, 0); |
| assert_equals(matrix.m22, 1); |
| assert_equals(matrix.m23, 0); |
| assert_equals(matrix.m24, 0); |
| assert_equals(matrix.m31, 0); |
| assert_equals(matrix.m32, 0); |
| assert_equals(matrix.m33, 1); |
| assert_equals(matrix.m34, 0); |
| assert_equals(matrix.m41, 0); |
| assert_equals(matrix.m42, 0); |
| assert_equals(matrix.m43, 0); |
| assert_equals(matrix.m44, 1); |
| assert_true(matrix.is2D); |
| assert_true(matrix.isIdentity); |
| }, "DOMMatrix() constructor"); |
| |
| test(function() { |
| var other = new DOMMatrix(); |
| other.m11 = 10; |
| other.m12 = 20; |
| other.m24 = 2; |
| other.m33 = 3; |
| other.m42 = 3; |
| other.m44 = 9; |
| |
| var matrix = new DOMMatrix(other); |
| assert_equals(matrix.m11, 10); |
| assert_equals(matrix.m12, 20); |
| assert_equals(matrix.m13, 0); |
| assert_equals(matrix.m14, 0); |
| assert_equals(matrix.m21, 0); |
| assert_equals(matrix.m22, 1); |
| assert_equals(matrix.m23, 0); |
| assert_equals(matrix.m24, 2); |
| assert_equals(matrix.m31, 0); |
| assert_equals(matrix.m32, 0); |
| assert_equals(matrix.m33, 3); |
| assert_equals(matrix.m34, 0); |
| assert_equals(matrix.m41, 0); |
| assert_equals(matrix.m42, 3); |
| assert_equals(matrix.m43, 0); |
| assert_equals(matrix.m44, 9); |
| assert_false(matrix.is2D); |
| assert_false(matrix.isIdentity); |
| }, "DOMMatrix(other) constructor"); |
| |
| test(function() { |
| var float32Array = new Float32Array([1, 2, 3, 4, 5, 6]); |
| var matrix2d = DOMMatrix.fromFloat32Array(float32Array); |
| assert_true(matrix2d.is2D); |
| assert_equals(matrix2d.a, 1); |
| assert_equals(matrix2d.b, 2); |
| assert_equals(matrix2d.c, 3); |
| assert_equals(matrix2d.d, 4); |
| assert_equals(matrix2d.e, 5); |
| assert_equals(matrix2d.f, 6); |
| }, "DOMMatrix fromFloat32Array - 2D matrix"); |
| |
| test(function() { |
| // 3.1 is not representable as a 32-bit float |
| var float64Array = new Float64Array([1, 2, 3, 3.1, 4, 5]); |
| var matrix2d = DOMMatrix.fromFloat64Array(float64Array); |
| assert_true(matrix2d.is2D); |
| assert_equals(matrix2d.a, 1); |
| assert_equals(matrix2d.b, 2); |
| assert_equals(matrix2d.c, 3); |
| assert_equals(matrix2d.d, 3.1); |
| assert_equals(matrix2d.e, 4); |
| assert_equals(matrix2d.f, 5); |
| }, "DOMMatrix fromFloat64Array - 2D matrix"); |
| |
| test(function() { |
| var float32Array = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); |
| var matrix3d = DOMMatrix.fromFloat32Array(float32Array); |
| assert_false(matrix3d.is2D); |
| assert_equals(matrix3d.m11, 1); |
| assert_equals(matrix3d.m12, 2); |
| assert_equals(matrix3d.m13, 3); |
| assert_equals(matrix3d.m14, 4); |
| assert_equals(matrix3d.m21, 5); |
| assert_equals(matrix3d.m22, 6); |
| assert_equals(matrix3d.m23, 7); |
| assert_equals(matrix3d.m24, 8); |
| assert_equals(matrix3d.m31, 9); |
| assert_equals(matrix3d.m32, 10); |
| assert_equals(matrix3d.m33, 11); |
| assert_equals(matrix3d.m34, 12); |
| assert_equals(matrix3d.m41, 13); |
| assert_equals(matrix3d.m42, 14); |
| assert_equals(matrix3d.m43, 15); |
| assert_equals(matrix3d.m44, 16); |
| }, "DOMMatrix fromFloat32Array - 3D matrix"); |
| |
| test(function() { |
| // 10.1 and 16.6 are not representable as a 32-bit float |
| var float64Array = new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13, 14, 15, 16.6]); |
| var matrix3d = DOMMatrix.fromFloat64Array(float64Array); |
| assert_false(matrix3d.is2D); |
| assert_equals(matrix3d.m11, 1); |
| assert_equals(matrix3d.m12, 2); |
| assert_equals(matrix3d.m13, 3); |
| assert_equals(matrix3d.m14, 4); |
| assert_equals(matrix3d.m21, 5); |
| assert_equals(matrix3d.m22, 6); |
| assert_equals(matrix3d.m23, 7); |
| assert_equals(matrix3d.m24, 8); |
| assert_equals(matrix3d.m31, 9); |
| assert_equals(matrix3d.m32, 10.1); |
| assert_equals(matrix3d.m33, 11); |
| assert_equals(matrix3d.m34, 12); |
| assert_equals(matrix3d.m41, 13); |
| assert_equals(matrix3d.m42, 14); |
| assert_equals(matrix3d.m43, 15); |
| assert_equals(matrix3d.m44, 16.6); |
| }, "DOMMatrix fromFloat64Array - 3D matrix"); |
| |
| test(function() { |
| var matrix = new DOMMatrix(); |
| matrix.a = 10; |
| matrix.b = 20; |
| matrix.m24 = 2; |
| matrix.m33 = 3; |
| matrix.m42 = 3; |
| matrix.m44 = 9; |
| assert_equals(matrix.a, matrix.m11); |
| assert_equals(matrix.b, matrix.m12); |
| assert_equals(matrix.c, matrix.m21); |
| assert_equals(matrix.d, matrix.m22); |
| assert_equals(matrix.e, matrix.m41); |
| assert_equals(matrix.f, matrix.m42); |
| assert_equals(matrix.m11, 10); |
| assert_equals(matrix.m12, 20); |
| assert_equals(matrix.m13, 0); |
| assert_equals(matrix.m14, 0); |
| assert_equals(matrix.m21, 0); |
| assert_equals(matrix.m22, 1); |
| assert_equals(matrix.m23, 0); |
| assert_equals(matrix.m24, 2); |
| assert_equals(matrix.m31, 0); |
| assert_equals(matrix.m32, 0); |
| assert_equals(matrix.m33, 3); |
| assert_equals(matrix.m34, 0); |
| assert_equals(matrix.m41, 0); |
| assert_equals(matrix.m42, 3); |
| assert_equals(matrix.m43, 0); |
| assert_equals(matrix.m44, 9); |
| assert_false(matrix.is2D); |
| assert_false(matrix.isIdentity); |
| }, "DOMMatrix attributes"); |
| |
| test(function() { |
| var matrix = new DOMMatrix(); |
| assert_true(matrix.is2D); |
| assert_true(matrix.isIdentity); |
| matrix.m31 = 1; |
| matrix.m33 = 0; |
| assert_false(matrix.is2D); |
| assert_false(matrix.isIdentity); |
| matrix.m31 = 0; |
| matrix.m33 = 1; |
| assert_false(matrix.is2D); |
| assert_true(matrix.isIdentity); |
| }, "DOMMatrix.is2D can never be set to 'true' when it was set to 'false' before calling setMatrixValue()."); |
| |
| test(function() { |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array([1, 2, 3, 4, 5])); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array([1, 2, 3, 4, 5])); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array([1, 2, 3, 4, 5, 6 ,7])); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array([1, 2, 3, 4, 5, 6 ,7])); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| }, "DOMMatrix fromFloat*Array - invalid array size of nearby 6"); |
| |
| test(function() { |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15])); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15])); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| }, "DOMMatrix fromFloat*Array - invalid array size of nearby 16"); |
| |
| test(function() { |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array([])); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array([])); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array([1])); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array([1])); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat32Array(new Float32Array(65536)); }, |
| "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements."); |
| assert_throws(new TypeError(), function() { DOMMatrix.fromFloat64Array(new Float64Array(65536)); }, |
| "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements."); |
| }, "DOMMatrix fromFloat*Array - invalid array size"); |
| </script> |
| </body> |
| </html> |