Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | "use strict"; |
michael@0 | 4 | |
michael@0 | 5 | function test() { |
michael@0 | 6 | let m1 = mat4.create(); |
michael@0 | 7 | |
michael@0 | 8 | ok(m1, "Should have created a matrix with mat4.create()."); |
michael@0 | 9 | is(m1.length, 16, "A mat4 should have 16 elements."); |
michael@0 | 10 | |
michael@0 | 11 | ok(isApproxVec(m1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), |
michael@0 | 12 | "When created, a mat4 should have the values default to identity."); |
michael@0 | 13 | |
michael@0 | 14 | mat4.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], m1); |
michael@0 | 15 | ok(isApproxVec(m1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), |
michael@0 | 16 | "The mat4.set() function didn't set the values correctly."); |
michael@0 | 17 | |
michael@0 | 18 | mat4.transpose(m1); |
michael@0 | 19 | ok(isApproxVec(m1, [1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]), |
michael@0 | 20 | "The mat4.transpose() function didn't set the values correctly."); |
michael@0 | 21 | |
michael@0 | 22 | mat4.identity(m1); |
michael@0 | 23 | ok(isApproxVec(m1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), |
michael@0 | 24 | "The mat4.identity() function didn't set the values correctly."); |
michael@0 | 25 | |
michael@0 | 26 | ok(isApprox(mat4.determinant(m1), 1), |
michael@0 | 27 | "The mat4.determinant() function didn't calculate the value correctly."); |
michael@0 | 28 | |
michael@0 | 29 | let m2 = mat4.inverse([1, 3, 1, 1, 1, 1, 2, 1, 2, 3, 4, 1, 1, 1, 1, 1]); |
michael@0 | 30 | ok(isApproxVec(m2, [ |
michael@0 | 31 | -1, -3, 1, 3, 0.5, 0, 0, -0.5, 0, 1, 0, -1, 0.5, 2, -1, -0.5 |
michael@0 | 32 | ]), "The mat4.inverse() function didn't calculate the values correctly."); |
michael@0 | 33 | |
michael@0 | 34 | let m3 = mat4.toRotationMat([ |
michael@0 | 35 | 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]); |
michael@0 | 36 | ok(isApproxVec(m3, [ |
michael@0 | 37 | 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 0, 0, 0, 1 |
michael@0 | 38 | ]), "The mat4.toRotationMat() func. didn't calculate the values correctly."); |
michael@0 | 39 | |
michael@0 | 40 | let m4 = mat4.toMat3([ |
michael@0 | 41 | 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]); |
michael@0 | 42 | ok(isApproxVec(m4, [1, 5, 9, 2, 6, 10, 3, 7, 11]), |
michael@0 | 43 | "The mat4.toMat3() function didn't set the values correctly."); |
michael@0 | 44 | |
michael@0 | 45 | let m5 = mat4.toInverseMat3([ |
michael@0 | 46 | 1, 3, 1, 1, 1, 1, 2, 1, 2, 3, 4, 1, 1, 1, 1, 1]); |
michael@0 | 47 | ok(isApproxVec(m5, [2, 9, -5, 0, -2, 1, -1, -3, 2]), |
michael@0 | 48 | "The mat4.toInverseMat3() function didn't set the values correctly."); |
michael@0 | 49 | } |