diff --git a/src/wgpu-matrix.ts b/src/wgpu-matrix.ts index 055a283..d757056 100644 --- a/src/wgpu-matrix.ts +++ b/src/wgpu-matrix.ts @@ -74,10 +74,10 @@ function wgpuMatrixAPI< Vec4Ctor: BaseCtor, ) { return { - /** @namespace mat4 */ - mat4: getMat4API(Mat3Ctor), /** @namespace mat3 */ - mat3: getMat3API(Mat4Ctor), + mat3: getMat3API(Mat3Ctor), + /** @namespace mat4 */ + mat4: getMat4API(Mat4Ctor), /** @namespace quat */ quat: getQuatAPI(QuatCtor), /** @namespace vec2 */ @@ -91,15 +91,15 @@ function wgpuMatrixAPI< export const { /** - * 4x4 Matrix functions that default to returning `Float32Array` + * 3x3 Matrix functions that default to returning `Float32Array` * @namespace */ - mat4, + mat3, /** - * 3x3 Matrix functions that default to returning `Float32Array` + * 4x4 Matrix functions that default to returning `Float32Array` * @namespace */ - mat3, + mat4, /** * Quaternion functions that default to returning `Float32Array` * @namespace @@ -126,15 +126,15 @@ export const { export const { /** - * 4x4 Matrix functions that default to returning `Float64Array` + * 3x3 Matrix functions that default to returning `Float64Array` * @namespace */ - mat4: mat4d, + mat3: mat3d, /** - * 3x3 Matrix functions that default to returning `Float64Array` + * 4x4 Matrix functions that default to returning `Float64Array` * @namespace */ - mat3: mat3d, + mat4: mat4d, /** * Quaternion functions that default to returning `Float64Array` * @namespace @@ -161,15 +161,15 @@ export const { export const { /** - * 4x4 Matrix functions that default to returning `number[]` + * 3x3 Matrix functions that default to returning `number[]` * @namespace */ - mat4: mat4n, + mat3: mat3n, /** - * 3x3 Matrix functions that default to returning `number[]` + * 4x4 Matrix functions that default to returning `number[]` * @namespace */ - mat3: mat3n, + mat4: mat4n, /** * Quaternion functions that default to returning `number[]` * @namespace diff --git a/test/tests/mat3-test.js b/test/tests/mat3-test.js index 0a37afb..a93df57 100644 --- a/test/tests/mat3-test.js +++ b/test/tests/mat3-test.js @@ -21,7 +21,7 @@ function assertMat3EqualApproximately(a, b) { } } -function check(Type) { +function check(mat3, Type) { describe('using ' + Type, () => { const m = [ 0, 1, 2, 0, @@ -29,23 +29,25 @@ function check(Type) { 8, 9, 10, 0, ]; + function createCopyOfType(v) { + return Type === Array ? new Type(...v) : new Type(v); + } + function testM3WithoutDest(func, expected, ...args) { const d = func(...args); assertMat3EqualApproximately(d, expected); } function testM3WithDest(func, expected, ...args) { - expected = new Float32Array(expected); - const d = new Float32Array(12); + expected = createCopyOfType(expected); + const d = new Type(12).fill(0); const c = func(...args, d); assertStrictEqual(c, d); assertMat3EqualApproximately(c, expected); } function testMat3WithAndWithoutDest(func, expected, ...args) { - if (Type === Float32Array) { - expected = new Float32Array(expected); - } + expected = createCopyOfType(expected); testM3WithoutDest(func, expected, ...args); testM3WithDest(func, expected, ...args); } @@ -56,14 +58,14 @@ function check(Type) { } function testV2WithDest(func, expected) { - const d = new Float32Array(2); + const d = new Type(2).fill(0); const c = func(d); assertStrictEqual(c, d); assertEqual(c, expected); } function testV2WithAndWithoutDest(func, expected) { - expected = new Float32Array(expected); + expected = createCopyOfType(expected); testV2WithoutDest(func, expected); testV2WithDest(func, expected); } @@ -90,9 +92,9 @@ function check(Type) { it('should negate', () => { const expected = [ - -0, -1, -2, -3, - -4, -5, -6, -7, - -8, -9, -10, -11, + -0, -1, -2, 0, + -4, -5, -6, 0, + -8, -9, -10, 0, ]; testMat3WithAndWithoutDest((newDst) => { return mat3.negate(m, newDst); @@ -350,12 +352,12 @@ function check(Type) { it('should get scaling', () => { const m = [ - 1, 2, 3, 0, + 2, 8, 3, 0, 5, 6, 7, 0, 9, 10, 11, 0, ]; const expected = [ - Math.sqrt(1 * 1 + 2 * 2), + Math.sqrt(2 * 2 + 8 * 8), Math.sqrt(5 * 5 + 6 * 6), ]; testV2WithAndWithoutDest((newDst) => { @@ -491,8 +493,8 @@ function check(Type) { } describe('mat3', () => { - check(mat3n); - check(mat3); - check(mat3d); + check(mat3n, Array); + check(mat3, Float32Array); + check(mat3d, Float64Array); }); diff --git a/test/tests/mat4-test.js b/test/tests/mat4-test.js index 8707b04..ce79fbc 100644 --- a/test/tests/mat4-test.js +++ b/test/tests/mat4-test.js @@ -12,7 +12,6 @@ import {describe, it} from '../mocha-support.js'; function check(mat4, Type) { - describe('using ' + Type, () => { const m = [ 0, 1, 2, 3,