From 697c07389cf2df7490cfe67d8c3c71aaaf1ec0c0 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Fri, 6 Sep 2024 17:01:28 -0700 Subject: [PATCH] fix mat4 tests --- src/mat4-impl.ts | 10 +++++----- test/tests/mat4-test.js | 17 +++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/mat4-impl.ts b/src/mat4-impl.ts index 6822b02..4d954b9 100644 --- a/src/mat4-impl.ts +++ b/src/mat4-impl.ts @@ -687,11 +687,11 @@ function setAxis(m: Mat4Arg, v: Vec3Arg, axis: numb return newDst; } -///** -// * Returns the scaling component of the matrix -// * @param m - The Matrix -// * @param dst - The vector to set. If not passed a new one is created. -// */ +/** + * Returns the "3d" scaling component of the matrix + * @param m - The Matrix + * @param dst - The vector to set. If not passed a new one is created. + */ function getScaling(m: Mat4Arg, dst?: T) { const newDst = (dst ?? vec3.create()) as T; diff --git a/test/tests/mat4-test.js b/test/tests/mat4-test.js index ce79fbc..467875f 100644 --- a/test/tests/mat4-test.js +++ b/test/tests/mat4-test.js @@ -20,23 +20,24 @@ function check(mat4, Type) { 12, 13, 14, 15, ]; + function createCopyOfType(v) { + return Type === Array ? new Type(...v) : new Type(v); + } + function testMat4WithoutDest(func, expected, ...args) { const d = func(...args); assertEqualApproximately(d, expected); } function testMat4WithDest(func, expected, ...args) { - expected = new Float32Array(expected); - const d = new Float32Array(16); + expected = createCopyOfType(expected); + const d = new Type(16).fill(0); const c = func(...args, d); assertStrictEqual(c, d); assertEqualApproximately(c, expected); } function testMat4WithAndWithoutDest(func, expected, ...args) { - if (mat4.identity() instanceof Float32Array) { - //expected = new Float32Array(expected); - } testMat4WithoutDest(func, expected, ...args); testMat4WithDest(func, expected, ...args); } @@ -47,14 +48,14 @@ function check(mat4, Type) { } function testVec3WithDest(func, expected) { - const d = new Float32Array(3); + const d = new Type(3).fill(0); const c = func(d); assertStrictEqual(c, d); assertEqualApproximately(c, expected, 2e7); } function testVec3WithAndWithoutDest(func, expected) { - expected = new Float32Array(expected); + expected = createCopyOfType(expected); testVec3WithoutDest(func, expected); testVec3WithDest(func, expected); } @@ -361,7 +362,7 @@ function check(mat4, Type) { Math.sqrt(1 * 1 + 2 * 2 + 3 * 3), Math.sqrt(5 * 5 + 6 * 6 + 7 * 7), Math.sqrt(9 * 9 + 10 * 10 + 11 * 11), - ].map(v => new Type([v])[0]); + ]; testVec3WithAndWithoutDest((newDst) => { return mat4.getScaling(m, newDst); }, expected);