Skip to content

Commit 697c073

Browse files
committed
fix mat4 tests
1 parent d88420a commit 697c073

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/mat4-impl.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,11 @@ function setAxis<T extends Mat4Arg = MatType>(m: Mat4Arg, v: Vec3Arg, axis: numb
687687
return newDst;
688688
}
689689

690-
///**
691-
// * Returns the scaling component of the matrix
692-
// * @param m - The Matrix
693-
// * @param dst - The vector to set. If not passed a new one is created.
694-
// */
690+
/**
691+
* Returns the "3d" scaling component of the matrix
692+
* @param m - The Matrix
693+
* @param dst - The vector to set. If not passed a new one is created.
694+
*/
695695
function getScaling<T extends Vec3Arg = MatType>(m: Mat4Arg, dst?: T) {
696696
const newDst = (dst ?? vec3.create()) as T;
697697

test/tests/mat4-test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@ function check(mat4, Type) {
2020
12, 13, 14, 15,
2121
];
2222

23+
function createCopyOfType(v) {
24+
return Type === Array ? new Type(...v) : new Type(v);
25+
}
26+
2327
function testMat4WithoutDest(func, expected, ...args) {
2428
const d = func(...args);
2529
assertEqualApproximately(d, expected);
2630
}
2731

2832
function testMat4WithDest(func, expected, ...args) {
29-
expected = new Float32Array(expected);
30-
const d = new Float32Array(16);
33+
expected = createCopyOfType(expected);
34+
const d = new Type(16).fill(0);
3135
const c = func(...args, d);
3236
assertStrictEqual(c, d);
3337
assertEqualApproximately(c, expected);
3438
}
3539

3640
function testMat4WithAndWithoutDest(func, expected, ...args) {
37-
if (mat4.identity() instanceof Float32Array) {
38-
//expected = new Float32Array(expected);
39-
}
4041
testMat4WithoutDest(func, expected, ...args);
4142
testMat4WithDest(func, expected, ...args);
4243
}
@@ -47,14 +48,14 @@ function check(mat4, Type) {
4748
}
4849

4950
function testVec3WithDest(func, expected) {
50-
const d = new Float32Array(3);
51+
const d = new Type(3).fill(0);
5152
const c = func(d);
5253
assertStrictEqual(c, d);
5354
assertEqualApproximately(c, expected, 2e7);
5455
}
5556

5657
function testVec3WithAndWithoutDest(func, expected) {
57-
expected = new Float32Array(expected);
58+
expected = createCopyOfType(expected);
5859
testVec3WithoutDest(func, expected);
5960
testVec3WithDest(func, expected);
6061
}
@@ -361,7 +362,7 @@ function check(mat4, Type) {
361362
Math.sqrt(1 * 1 + 2 * 2 + 3 * 3),
362363
Math.sqrt(5 * 5 + 6 * 6 + 7 * 7),
363364
Math.sqrt(9 * 9 + 10 * 10 + 11 * 11),
364-
].map(v => new Type([v])[0]);
365+
];
365366
testVec3WithAndWithoutDest((newDst) => {
366367
return mat4.getScaling(m, newDst);
367368
}, expected);

0 commit comments

Comments
 (0)