OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Geometry Interfaces: DOMMatrix translate</title> |
| 5 <script src="../../resources/testharness.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 <script> |
| 9 |
| 10 function toArray(matrix) |
| 11 { |
| 12 return [ matrix.m11, matrix.m21, matrix.m31, matrix.m41, |
| 13 matrix.m12, matrix.m22, matrix.m32, matrix.m42, |
| 14 matrix.m13, matrix.m23, matrix.m33, matrix.m43, |
| 15 matrix.m14, matrix.m24, matrix.m34, matrix.m44 ]; |
| 16 } |
| 17 |
| 18 test(function() { |
| 19 var matrix = new DOMMatrix(); |
| 20 assert_true(matrix.is2D); |
| 21 assert_true(matrix.isIdentity); |
| 22 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 23 var result = matrix.translate(2, 3); |
| 24 assert_true(result.is2D); |
| 25 assert_false(result.isIdentity); |
| 26 assert_array_equals(toArray(result), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 27 assert_true(matrix.is2D); |
| 28 assert_true(matrix.isIdentity); |
| 29 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 30 }, "DOMMatrix.translate(tx, ty)"); |
| 31 |
| 32 test(function() { |
| 33 var matrix = new DOMMatrix(); |
| 34 matrix.translateSelf(2, 3); |
| 35 assert_true(matrix.is2D); |
| 36 assert_false(matrix.isIdentity); |
| 37 assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 38 var result = matrix.translate(4, 2); |
| 39 assert_true(result.is2D); |
| 40 assert_false(result.isIdentity); |
| 41 assert_array_equals(toArray(result), [ 1, 0, 0, 6, 0, 1, 0, 5, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 42 assert_true(matrix.is2D); |
| 43 assert_false(matrix.isIdentity); |
| 44 assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 45 }, "DOMMatrix.translate(tx, ty) with non-identity"); |
| 46 |
| 47 test(function() { |
| 48 var matrix = new DOMMatrix(); |
| 49 assert_true(matrix.is2D); |
| 50 assert_true(matrix.isIdentity); |
| 51 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 52 var result = matrix.translateSelf(4, 2); |
| 53 assert_true(result.is2D); |
| 54 assert_false(result.isIdentity); |
| 55 assert_array_equals(toArray(result), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 56 assert_true(matrix.is2D); |
| 57 assert_false(matrix.isIdentity); |
| 58 assert_array_equals(toArray(matrix), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 59 }, "DOMMatrix.translateSelf(tx, ty)"); |
| 60 |
| 61 test(function() { |
| 62 var matrix = new DOMMatrix(); |
| 63 assert_true(matrix.is2D); |
| 64 assert_true(matrix.isIdentity); |
| 65 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 66 var result = matrix.translate(2, 3, 4); |
| 67 assert_false(result.is2D); |
| 68 assert_false(result.isIdentity); |
| 69 assert_array_equals(toArray(result), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 4, 0,
0, 0, 1 ]); |
| 70 assert_true(matrix.is2D); |
| 71 assert_true(matrix.isIdentity); |
| 72 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 73 }, "DOMMatrix.translate(tx, ty, tz)"); |
| 74 |
| 75 test(function() { |
| 76 var matrix = new DOMMatrix(); |
| 77 matrix.translateSelf(2, 3); |
| 78 assert_true(matrix.is2D); |
| 79 assert_false(matrix.isIdentity); |
| 80 assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 81 var result = matrix.translate(4, 2, 3); |
| 82 assert_false(result.is2D); |
| 83 assert_false(result.isIdentity); |
| 84 assert_array_equals(toArray(result), [ 1, 0, 0, 6, 0, 1, 0, 5, 0, 0, 1, 3, 0,
0, 0, 1 ]); |
| 85 assert_true(matrix.is2D); |
| 86 assert_false(matrix.isIdentity); |
| 87 assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 88 }, "DOMMatrix.translate(tx, ty, tz) with non-identity"); |
| 89 |
| 90 test(function() { |
| 91 var matrix = new DOMMatrix(); |
| 92 assert_true(matrix.is2D); |
| 93 assert_true(matrix.isIdentity); |
| 94 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1 ]); |
| 95 var result = matrix.translateSelf(4, 2, 3); |
| 96 assert_false(result.is2D); |
| 97 assert_false(result.isIdentity); |
| 98 assert_array_equals(toArray(result), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 3, 0,
0, 0, 1 ]); |
| 99 assert_false(matrix.is2D); |
| 100 assert_false(matrix.isIdentity); |
| 101 assert_array_equals(toArray(matrix), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 3, 0,
0, 0, 1 ]); |
| 102 }, "DOMMatrix.translateSelf(tx, ty, tz)"); |
| 103 |
| 104 test(function() { |
| 105 var matrix = new DOMMatrix(); |
| 106 assert_true(matrix.is2D); |
| 107 assert_true(matrix.isIdentity); |
| 108 matrix.m14 = 2; |
| 109 matrix.m24 = 3; |
| 110 matrix.m34 = 4; |
| 111 matrix.m44 = 7; |
| 112 assert_false(matrix.is2D); |
| 113 assert_false(matrix.isIdentity); |
| 114 assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2,
3, 4, 7 ]); |
| 115 matrix.translateSelf(7, -8, 2); |
| 116 assert_false(matrix.is2D); |
| 117 assert_false(matrix.isIdentity); |
| 118 assert_array_equals(toArray(matrix), [ 1, 0, 0, 7, 0, 1, 0, -8, 0, 0, 1, 2, 2,
3, 4, 5 ]); |
| 119 }, "DOMMatrix.translateSelf(tx, ty, tz) Homogeneous Coordinates"); |
| 120 |
| 121 </script> |
| 122 </body> |
| 123 </html> |
OLD | NEW |