summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/manual/transformations/2d.transformation.getTransform.html
blob: 664efd50e63dc0fc9396857d957cee0fe38f6901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Ensure that context2d.getTransform works
const epsilon = 1e-5;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');

test(function(t) {
  assert_array_equals(ctx.getTransform().toFloat32Array(),
    [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
    "Assert that an untransformed matrix is identity");

  ctx.scale(2, 3);
  transform = ctx.getTransform();
  assert_array_equals(ctx.getTransform().toFloat32Array(),
    [2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
    "Assert that context2d scaling works");

  ctx.rotate(Math.PI/2);
  transform = ctx.getTransform();
  assert_array_approx_equals(ctx.getTransform().toFloat32Array(),
    [0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], epsilon,
    "Assert that context2d rotate works");

  ctx.translate(1, -1);
  transform = ctx.getTransform();
  assert_array_approx_equals(ctx.getTransform().toFloat32Array(),
    [0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 2, 3, 0, 1], epsilon,
    "Assert context2d translate works.");

  ctx.resetTransform();
  assert_array_equals(ctx.getTransform().toFloat32Array(),
    [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
    "Assert that a reset matrix is identity");
}, 'This test ensures that getTransform works correctly.');
</script>
</body>