browser/devtools/tilt/test/browser_tilt_math04.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/test/browser_tilt_math04.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +"use strict";
     1.7 +
     1.8 +function test() {
     1.9 +  let m1 = mat4.create();
    1.10 +
    1.11 +  ok(m1, "Should have created a matrix with mat4.create().");
    1.12 +  is(m1.length, 16, "A mat4 should have 16 elements.");
    1.13 +
    1.14 +  ok(isApproxVec(m1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
    1.15 +    "When created, a mat4 should have the values default to identity.");
    1.16 +
    1.17 +  mat4.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], m1);
    1.18 +  ok(isApproxVec(m1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
    1.19 +    "The mat4.set() function didn't set the values correctly.");
    1.20 +
    1.21 +  mat4.transpose(m1);
    1.22 +  ok(isApproxVec(m1, [1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]),
    1.23 +    "The mat4.transpose() function didn't set the values correctly.");
    1.24 +
    1.25 +  mat4.identity(m1);
    1.26 +  ok(isApproxVec(m1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
    1.27 +    "The mat4.identity() function didn't set the values correctly.");
    1.28 +
    1.29 +  ok(isApprox(mat4.determinant(m1), 1),
    1.30 +    "The mat4.determinant() function didn't calculate the value correctly.");
    1.31 +
    1.32 +  let m2 = mat4.inverse([1, 3, 1, 1, 1, 1, 2, 1, 2, 3, 4, 1, 1, 1, 1, 1]);
    1.33 +  ok(isApproxVec(m2, [
    1.34 +    -1, -3, 1, 3, 0.5, 0, 0, -0.5, 0, 1, 0, -1, 0.5, 2, -1, -0.5
    1.35 +  ]), "The mat4.inverse() function didn't calculate the values correctly.");
    1.36 +
    1.37 +  let m3 = mat4.toRotationMat([
    1.38 +    1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]);
    1.39 +  ok(isApproxVec(m3, [
    1.40 +    1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 0, 0, 0, 1
    1.41 +  ]), "The mat4.toRotationMat() func. didn't calculate the values correctly.");
    1.42 +
    1.43 +  let m4 = mat4.toMat3([
    1.44 +    1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]);
    1.45 +  ok(isApproxVec(m4, [1, 5, 9, 2, 6, 10, 3, 7, 11]),
    1.46 +    "The mat4.toMat3() function didn't set the values correctly.");
    1.47 +
    1.48 +  let m5 = mat4.toInverseMat3([
    1.49 +    1, 3, 1, 1, 1, 1, 2, 1, 2, 3, 4, 1, 1, 1, 1, 1]);
    1.50 +  ok(isApproxVec(m5, [2, 9, -5, 0, -2, 1, -1, -3, 2]),
    1.51 +    "The mat4.toInverseMat3() function didn't set the values correctly.");
    1.52 +}

mercurial