Skip to content

Commit

Permalink
fix mat4 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Sep 7, 2024
1 parent d88420a commit 697c073
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/mat4-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,11 @@ function setAxis<T extends Mat4Arg = MatType>(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<T extends Vec3Arg = MatType>(m: Mat4Arg, dst?: T) {
const newDst = (dst ?? vec3.create()) as T;

Expand Down
17 changes: 9 additions & 8 deletions test/tests/mat4-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 697c073

Please sign in to comment.