browser/devtools/tilt/test/browser_tilt_math02.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     5 function test() {
     6   let v1 = vec3.create();
     8   ok(v1, "Should have created a vector with vec3.create().");
     9   is(v1.length, 3, "A vec3 should have 3 elements.");
    11   ok(isApproxVec(v1, [0, 0, 0]),
    12     "When created, a vec3 should have the values default to 0.");
    14   vec3.set([1, 2, 3], v1);
    15   ok(isApproxVec(v1, [1, 2, 3]),
    16     "The vec3.set() function didn't set the values correctly.");
    18   vec3.zero(v1);
    19   ok(isApproxVec(v1, [0, 0, 0]),
    20     "The vec3.zero() function didn't set the values correctly.");
    22   let v2 = vec3.create([4, 5, 6]);
    23   ok(isApproxVec(v2, [4, 5, 6]),
    24     "When cloning arrays, a vec3 should have the values copied.");
    26   let v3 = vec3.create(v2);
    27   ok(isApproxVec(v3, [4, 5, 6]),
    28     "When cloning vectors, a vec3 should have the values copied.");
    30   vec3.add(v2, v3);
    31   ok(isApproxVec(v2, [8, 10, 12]),
    32     "The vec3.add() function didn't set the x value correctly.");
    34   vec3.subtract(v2, v3);
    35   ok(isApproxVec(v2, [4, 5, 6]),
    36     "The vec3.subtract() function didn't set the values correctly.");
    38   vec3.negate(v2);
    39   ok(isApproxVec(v2, [-4, -5, -6]),
    40     "The vec3.negate() function didn't set the values correctly.");
    42   vec3.scale(v2, -2);
    43   ok(isApproxVec(v2, [8, 10, 12]),
    44     "The vec3.scale() function didn't set the values correctly.");
    46   vec3.normalize(v1);
    47   ok(isApproxVec(v1, [0, 0, 0]),
    48     "Normalizing a vector with zero length should return [0, 0, 0].");
    50   vec3.normalize(v2);
    51   ok(isApproxVec(v2, [
    52     0.4558423161506653, 0.5698028802871704, 0.6837634444236755
    53   ]), "The vec3.normalize() function didn't set the values correctly.");
    55   vec3.cross(v2, v3);
    56   ok(isApproxVec(v2, [
    57     5.960464477539063e-8, -1.1920928955078125e-7, 5.960464477539063e-8
    58   ]), "The vec3.cross() function didn't set the values correctly.");
    60   vec3.dot(v2, v3);
    61   ok(isApproxVec(v2, [
    62     5.960464477539063e-8, -1.1920928955078125e-7, 5.960464477539063e-8
    63   ]), "The vec3.dot() function didn't set the values correctly.");
    65   ok(isApproxVec([vec3.length(v2)], [1.4600096599955427e-7]),
    66     "The vec3.length() function didn't calculate the value correctly.");
    68   vec3.direction(v2, v3);
    69   ok(isApproxVec(v2, [
    70     -0.4558422863483429, -0.5698028802871704, -0.6837634444236755
    71   ]), "The vec3.direction() function didn't set the values correctly.");
    73   vec3.lerp(v2, v3, 0.5);
    74   ok(isApproxVec(v2, [
    75     1.7720788717269897, 2.2150986194610596, 2.65811824798584
    76   ]), "The vec3.lerp() function didn't set the values correctly.");
    79   vec3.project([100, 100, 10], [0, 0, 100, 100],
    80     mat4.create(), mat4.perspective(45, 1, 0.1, 100), v1);
    81   ok(isApproxVec(v1, [-1157.10693359375, 1257.10693359375, 0]),
    82     "The vec3.project() function didn't set the values correctly.");
    84   vec3.unproject([100, 100, 1], [0, 0, 100, 100],
    85     mat4.create(), mat4.perspective(45, 1, 0.1, 100), v1);
    86   ok(isApproxVec(v1, [
    87     41.420406341552734, -41.420406341552734, -99.99771118164062
    88   ]), "The vec3.project() function didn't set the values correctly.");
    91   let ray = vec3.createRay([10, 10, 0], [100, 100, 1], [0, 0, 100, 100],
    92     mat4.create(), mat4.perspective(45, 1, 0.1, 100));
    94   ok(isApproxVec(ray.origin, [
    95     -0.03313708305358887, 0.03313708305358887, -0.1000000014901161
    96   ]), "The vec3.createRay() function didn't create the position correctly.");
    97   ok(isApproxVec(ray.direction, [
    98     0.35788586614428364, -0.35788586614428364, -0.862458934459091
    99   ]), "The vec3.createRay() function didn't create the direction correctly.");
   102   is(vec3.str([0, 0, 0]), "[0, 0, 0]",
   103     "The vec3.str() function didn't work properly.");
   104 }

mercurial