From 288eb6f4cb561134ecde3d6e37362aa0a033290c Mon Sep 17 00:00:00 2001 From: Andy Wong Date: Sat, 16 Mar 2024 15:27:58 -0700 Subject: [PATCH] fix mat and add tests --- dist/index.js | 2 +- dist/wasm/mat.js | 4 +- js/wasm/__tests__/mat.spec.ts | 189 ++++++++++++++++++++++++++++++++++ js/wasm/mat.ts | 19 ++-- 4 files changed, 204 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4a5be0b..e968602 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ export*from"./wasm/index.js";export*from"./scalar.js";export*from"./types.js"; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vanMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSAnLi93YXNtL2luZGV4LnRzJztcbmV4cG9ydCAqIGZyb20gJy4vc2NhbGFyLnRzJztcbmV4cG9ydCAqIGZyb20gJy4vdHlwZXMudHMnO1xuIl0sIm1hcHBpbmdzIjoiIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vanMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBNaW5pbWFsaXN0aWMgbnVtZXJpY2FsIGxpYnJhcnkgZm9yIGhpZ2gtcGVyZm9ybWFuY2UgM0QgbWF0aCwgcG93ZXJlZCBieSBSdXN0IFdlYkFzc2VtYmx5IGJpbmRpbmdzLlxuICogQHBhY2thZ2VEb2N1bWVudGF0aW9uXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi93YXNtL2luZGV4LnRzJztcbmV4cG9ydCAqIGZyb20gJy4vc2NhbGFyLnRzJztcbmV4cG9ydCAqIGZyb20gJy4vdHlwZXMudHMnO1xuIl0sIm1hcHBpbmdzIjoiIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file diff --git a/dist/wasm/mat.js b/dist/wasm/mat.js index 1598295..3c69746 100644 --- a/dist/wasm/mat.js +++ b/dist/wasm/mat.js @@ -1,2 +1,2 @@ -import{mat2identity,mat2add,mat2det,mat2frommat3,mat2invert,mat2mul,mat2scale,mat2sub,mat2transpose,mat3identity,mat3add,mat3det,mat3frommat2,mat3frommat4,mat3invert,mat3mul,mat3scale,mat3sub,mat3transpose,mat4identity,mat4add,mat4det,mat4frommat3,mat4invert,mat4mul,mat4scale,mat4sub,mat4transpose}from"../../wasm/index.js";import{ManagedFloat64Array}from"./memory.js";export class Mat2 extends ManagedFloat64Array{static identity(){return new Mat2(mat2identity())}static fromMat3(m){return new Mat2(mat2frommat3(m.byteOffset))}constructor(ptr){super(4,ptr)}add(rhs){mat2add(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}sub(rhs){mat2sub(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}mul(m){mat2mul(this.byteOffset,m.byteOffset,this.byteOffset);return this}scale(factor){mat2scale(this.byteOffset,this.byteOffset,factor);return this}transpose(){mat2transpose(this.byteOffset,this.byteOffset)}invert(){return!!mat2invert(this.byteOffset,this.byteOffset)}det(){return mat2det(this.byteOffset)}}export class Mat3 extends ManagedFloat64Array{static identity(){return new Mat3(mat3identity())}static fromMat2(m){return new Mat3(mat3frommat2(m.byteOffset))}static fromMat4(m){return new Mat3(mat3frommat4(m.byteOffset))}constructor(ptr){super(9,ptr)}add(rhs){mat3add(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}sub(rhs){mat3sub(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}mul(m){mat3mul(this.byteOffset,m.byteOffset,this.byteOffset);return this}scale(factor){mat3scale(this.byteOffset,this.byteOffset,factor);return this}transpose(){mat3transpose(this.byteOffset,this.byteOffset)}invert(){return!!mat3invert(this.byteOffset,this.byteOffset)}det(){return mat3det(this.byteOffset)}}export class Mat4 extends ManagedFloat64Array{static identity(){return new Mat4(mat4identity())}static fromMat3(m){return new Mat4(mat4frommat3(m.byteOffset))}constructor(ptr){super(16,ptr)}add(rhs){mat4add(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}sub(rhs){mat4sub(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}mul(m){mat4mul(this.byteOffset,m.byteOffset,this.byteOffset);return this}scale(factor){mat4scale(this.byteOffset,this.byteOffset,factor);return this}transpose(){mat4transpose(this.byteOffset,this.byteOffset)}invert(){return!!mat4invert(this.byteOffset,this.byteOffset)}det(){return mat4det(this.byteOffset)}} -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJtYXQyaWRlbnRpdHkiLCJtYXQyYWRkIiwibWF0MmRldCIsIm1hdDJmcm9tbWF0MyIsIm1hdDJpbnZlcnQiLCJtYXQybXVsIiwibWF0MnNjYWxlIiwibWF0MnN1YiIsIm1hdDJ0cmFuc3Bvc2UiLCJtYXQzaWRlbnRpdHkiLCJtYXQzYWRkIiwibWF0M2RldCIsIm1hdDNmcm9tbWF0MiIsIm1hdDNmcm9tbWF0NCIsIm1hdDNpbnZlcnQiLCJtYXQzbXVsIiwibWF0M3NjYWxlIiwibWF0M3N1YiIsIm1hdDN0cmFuc3Bvc2UiLCJtYXQ0aWRlbnRpdHkiLCJtYXQ0YWRkIiwibWF0NGRldCIsIm1hdDRmcm9tbWF0MyIsIm1hdDRpbnZlcnQiLCJtYXQ0bXVsIiwibWF0NHNjYWxlIiwibWF0NHN1YiIsIm1hdDR0cmFuc3Bvc2UiLCJNYW5hZ2VkRmxvYXQ2NEFycmF5IiwiTWF0MiIsImlkZW50aXR5IiwiZnJvbU1hdDMiLCJtIiwiYnl0ZU9mZnNldCIsImNvbnN0cnVjdG9yIiwicHRyIiwiYWRkIiwicmhzIiwic3ViIiwibXVsIiwic2NhbGUiLCJmYWN0b3IiLCJ0cmFuc3Bvc2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EdBQVMsQ0FBUSxDQUMxQlgsT0FBTyxDQUFDLElBQUksQ0FBQ08sVUFBVSxDQUFFLElBQUksQ0FBQ0EsVUFBVSxDQUFFSSxHQUFHLENBQUNKLFVBQVUsQ0FBQyxDQUN6RCxNQUFPLEtBQ1QsQ0FFT00sR0FBR0EsQ0FBQ1AsQ0FBTyxDQUFRLENBQ3hCUixPQUFPLENBQUMsSUFBSSxDQUFDUyxVQUFVLENBQUVELENBQUMsQ0FBQ0MsVUFBVSxDQUFFLElBQUksQ0FBQ0EsVUFBVSxDQUFDLENBQ3ZELE1BQU8sS0FDVCxDQUVPTyxLQUFLQSxDQUFDQyxNQUFjLENBQVEsQ0FDakNoQixTQUFTLENBQUMsSUFBSSxDQUFDUSxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQUVRLE1BQU0sQ0FBQyxDQUNuRCxNQUFPLEtBQ1QsQ0FFT0MsU0FBU0EsQ0FBQSxDQUFTLENBQ3ZCZixhQUFhLENBQUMsSUFBSSxDQUFDTSxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQ2hELENBRU9VLE1BQU1BLENBQUEsQ0FBWSxDQUN2QixNQUFPLENBQUMsQ0FBQ3BCLFVBQVUsQ0FBQyxJQUFJLENBQUNVLFVBQVUsQ0FBRSxJQUFJLENBQUNBLFVBQVUsQ0FDdEQsQ0FFT1csR0FBR0EsQ0FBQSxDQUFXLENBQ25CLE1BQU8sQ0FBQXZCLE9BQU8sQ0FBQyxJQUFJLENBQUNZLFVBQVUsQ0FDaEMsQ0FDRiIsImlnbm9yZUxpc3QiOltdfQ== \ No newline at end of file +import{mat2identity,mat2add,mat2det,mat2frommat3,mat2invert,mat2mul,mat2scale,mat2sub,mat2transpose,mat3identity,mat3add,mat3det,mat3frommat2,mat3frommat4,mat3invert,mat3mul,mat3scale,mat3sub,mat3transpose,mat4identity,mat4add,mat4det,mat4frommat3,mat4invert,mat4mul,mat4scale,mat4sub,mat4transpose,normalmat3}from"../../wasm/index.js";import{ManagedFloat64Array}from"./memory.js";export class Mat2 extends ManagedFloat64Array{static identity(){return new Mat2(mat2identity())}static fromMat3(m){return new Mat2(mat2frommat3(m.byteOffset))}constructor(ptr){super(4,ptr)}add(rhs){mat2add(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}sub(rhs){mat2sub(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}mul(rhs){mat2mul(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}scale(factor){mat2scale(this.byteOffset,this.byteOffset,factor);return this}transpose(){mat2transpose(this.byteOffset,this.byteOffset)}invert(){return!!mat2invert(this.byteOffset,this.byteOffset)}det(){return mat2det(this.byteOffset)}}export class Mat3 extends ManagedFloat64Array{static identity(){return new Mat3(mat3identity())}static fromMat2(m){return new Mat3(mat3frommat2(m.byteOffset))}static fromMat4(m){return new Mat3(mat3frommat4(m.byteOffset))}constructor(ptr){super(9,ptr)}add(rhs){mat3add(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}sub(rhs){mat3sub(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}mul(rhs){mat3mul(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}scale(factor){mat3scale(this.byteOffset,this.byteOffset,factor);return this}transpose(){mat3transpose(this.byteOffset,this.byteOffset)}invert(){return!!mat3invert(this.byteOffset,this.byteOffset)}det(){return mat3det(this.byteOffset)}normalMat(){return!!normalmat3(this.byteOffset,this.byteOffset)}}export class Mat4 extends ManagedFloat64Array{static identity(){return new Mat4(mat4identity())}static fromMat3(m){return new Mat4(mat4frommat3(m.byteOffset))}constructor(ptr){super(16,ptr)}add(rhs){mat4add(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}sub(rhs){mat4sub(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}mul(rhs){mat4mul(this.byteOffset,this.byteOffset,rhs.byteOffset);return this}scale(factor){mat4scale(this.byteOffset,this.byteOffset,factor);return this}transpose(){mat4transpose(this.byteOffset,this.byteOffset)}invert(){return!!mat4invert(this.byteOffset,this.byteOffset)}det(){return mat4det(this.byteOffset)}} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJtYXQyaWRlbnRpdHkiLCJtYXQyYWRkIiwibWF0MmRldCIsIm1hdDJmcm9tbWF0MyIsIm1hdDJpbnZlcnQiLCJtYXQybXVsIiwibWF0MnNjYWxlIiwibWF0MnN1YiIsIm1hdDJ0cmFuc3Bvc2UiLCJtYXQzaWRlbnRpdHkiLCJtYXQzYWRkIiwibWF0M2RldCIsIm1hdDNmcm9tbWF0MiIsIm1hdDNmcm9tbWF0NCIsIm1hdDNpbnZlcnQiLCJtYXQzbXVsIiwibWF0M3NjYWxlIiwibWF0M3N1YiIsIm1hdDN0cmFuc3Bvc2UiLCJtYXQ0aWRlbnRpdHkiLCJtYXQ0YWRkIiwibWF0NGRldCIsIm1hdDRmcm9tbWF0MyIsIm1hdDRpbnZlcnQiLCJtYXQ0bXVsIiwibWF0NHNjYWxlIiwibWF0NHN1YiIsIm1hdDR0cmFuc3Bvc2UiLCJub3JtYWxtYXQzIiwiTWFuYWdlZEZsb2F0NjRBcnJheSIsIk1hdDIiLCJpZGVudGl0eSIsImZyb21NYXQzIiwibSIsImJ5dGVPZmZzZXQiLCJjb25zdHJ1Y3RvciIsInB0ciIsImFkZCIsInJocyIsInN1YiIsIm11bCIsInNjYWxlIiwiZmFjdG9yIiwidHJhbnNwb3NlIiwiaW52ZXJ0IiwiZGV0IiwiTWF0MyIsImZyb21NYXQyIiwiZnJvbU1hdDQiLCJub3JtYWxNYXQiLCJNYXQ0Il0sInNvdXJjZXMiOlsiLi4vLi4vanMvd2FzbS9tYXQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHtcbiAgbWF0MmlkZW50aXR5LCBtYXQyYWRkLCBtYXQyZGV0LCBtYXQyZnJvbW1hdDMsIG1hdDJpbnZlcnQsIG1hdDJtdWwsIG1hdDJzY2FsZSwgb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__tests__/mat.spec.ts +++ b/js/wasm/__tests__/mat.spec.ts @@ -17,6 +17,64 @@ describe('Mat2', () => { m.set([1, 2, 3, 4]); expectArrayEqual(m, [1, 2, 3, 4]); }); + + test('add', () => { + const m = Mat2.identity(); + const m2 = Mat2.identity(); + m.set([29, 31, 37, 41]); + m2.set([43, 47, 53, 59]); + expectArrayEqual(m.add(m2), [72, 78, 90, 100]); + }); + + test('sub', () => { + const m = Mat2.identity(); + const m2 = Mat2.identity(); + m.set([29, 31, 37, 41]); + m2.set([43, 47, 53, 59]); + expectArrayEqual(m.sub(m2), [-14, -16, -16, -18]); + }); + + test('mul', () => { + const m = Mat2.identity(); + const m2 = Mat2.identity(); + m.set([1, 2, 3, 4]); + m2.set([5, 6, 7, 8]); + expectArrayEqual(m.mul(m2), [23, 34, 31, 46]); + }); + + test('scale', () => { + const m = Mat2.identity(); + m.set([1, 2, 3, 4]); + expectArrayEqual(m.scale(2), [2, 4, 6, 8]); + }); + + test('transpose', () => { + const m = Mat2.identity(); + m.set([1, 2, 3, 4]); + m.transpose(); + expectArrayEqual(m, [1, 3, 2, 4]); + }); + + test('det', () => { + const m = Mat2.identity(); + m.set([1, 2, 3, 4]); + expect(m.det()).toBe(-2); + }); + + test('invert', () => { + const m = Mat2.identity(); + m.set([1, 2, 3, 4]); + expect(m.invert()).toBe(true); + expectArrayEqual(m, [-2, 1, 1.5, -0.5]); + }); + + test('invert non-invertible', () => { + const data = [1, 2, 2, 4]; + const m = Mat2.identity(); + m.set(data); + expect(m.invert()).toBe(false); + expectArrayEqual(m, data); + }); }); describe('Mat3', () => { @@ -41,6 +99,79 @@ describe('Mat3', () => { m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); expectArrayEqual(m, [1, 2, 3, 4, 5, 6, 7, 8, 9]); }); + + test('add', () => { + const m = Mat3.identity(); + const m2 = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + m2.set([0, 9, 7, 2, 1, 6, 3, 1, 8]); + expectArrayEqual(m.add(m2), [1, 11, 10, 6, 6, 12, 10, 9, 17]); + }); + + test('sub', () => { + const m = Mat3.identity(); + const m2 = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + m2.set([0, 9, 7, 2, 1, 6, 3, 1, 8]); + expectArrayEqual(m.sub(m2), [1, -7, -4, 2, 4, 0, 4, 7, 1]); + }); + + test('mul', () => { + const m = Mat3.identity(); + const m2 = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + m2.set([0, 9, 7, 2, 1, 6, 3, 1, 8]); + expectArrayEqual(m.mul(m2), [85, 101, 117, 48, 57, 66, 63, 75, 87]); + }); + + test('scale', () => { + const m = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + expectArrayEqual(m.scale(2), [2, 4, 6, 8, 10, 12, 14, 16, 18]); + }); + + test('transpose', () => { + const m = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + m.transpose(); + expectArrayEqual(m, [1, 4, 7, 2, 5, 8, 3, 6, 9]); + }); + + test('det', () => { + const m = Mat3.identity(); + m.set([1, 0, 5, 2, 1, 6, 3, 4, 0]); + expect(m.det()).toBe(1); + }); + + test('invert', () => { + const m = Mat3.identity(); + m.set([1, 0, 5, 2, 1, 6, 3, 4, 0]); + expect(m.invert()).toBe(true); + expectArrayEqual(m, [-24, 20, -5, 18, -15, 4, 5, -4, 1]); + }); + + test('invert non-invertible', () => { + const data = [1, 0, 1, 0, 1, 0, 0, 0, 0]; + const m = Mat3.identity(); + m.set(data); + expect(m.invert()).toBe(false); + expectArrayEqual(m, data); + }); + + test('normalMat', () => { + const m = Mat3.identity(); + m.set([0, 0, 1, 1, 0, 0, 0, 1, 0]); + expect(m.normalMat()).toBe(true); + expectArrayEqual(m, [0, 0, 1, 1, 0, 0, 0, 1, 0]); + }); + + test('normalMat for non-invertible', () => { + const data = [1, 0, 1, 0, 1, 0, 0, 0, 0]; + const m = Mat3.identity(); + m.set(data); + expect(m.normalMat()).toBe(false); + expectArrayEqual(m, data); + }); }); describe('Mat4', () => { @@ -59,4 +190,62 @@ describe('Mat4', () => { m.set([1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, 13, 14, 15, 16]); expectArrayEqual(m, [1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, 13, 14, 15, 16]); }); + + test('add', () => { + const m = Mat4.identity(); + const m2 = Mat4.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); + m2.set([0, 3, 2, 1, 7, 6, 5, 4, 9, 3, 2, 2, 0, 3, 3, 1]); + expectArrayEqual(m.add(m2), [1, 5, 5, 5, 12, 12, 12, 12, 18, 13, 13, 14, 13, 17, 18, 17]); + }); + + test('sub', () => { + const m = Mat4.identity(); + const m2 = Mat4.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); + m2.set([0, 3, 2, 1, 7, 6, 5, 4, 9, 3, 2, 2, 0, 3, 3, 1]); + expectArrayEqual(m.sub(m2), [1, -1, 1, 3, -2, 0, 2, 4, 0, 7, 9, 10, 13, 11, 12, 15]); + }); + + test('mul', () => { + const m = Mat4.identity(); + const m2 = Mat4.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); + m2.set([0, 3, 2, 1, 7, 6, 5, 4, 9, 3, 2, 2, 0, 3, 3, 1]); + expectArrayEqual(m.mul(m2), [46, 52, 58, 64, 134, 156, 178, 200, 68, 84, 100, 116, 55, 62, 69, 76]); + }); + + test('scale', () => { + const m = Mat4.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); + expectArrayEqual(m.scale(2), [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]); + }); + + test('transpose', () => { + const m = Mat4.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); + m.transpose(); + expectArrayEqual(m, [1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]); + }); + + test('det', () => { + const m = Mat4.identity(); + m.set([1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1]); + expect(m.det()).toBe(-16); + }); + + test('invert', () => { + const m = Mat4.identity(); + m.set([1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1]); + expect(m.invert()).toBe(true); + expectArrayEqual(m, [.25, .25, .25, -.25, .25, .25, -.25, .25, .25, -.25, .25, .25, -.25, .25, .25, .25]); + }); + + test('invert non-invertible', () => { + const data = [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 9, 10, 11, 12]; + const m = Mat4.identity(); + m.set(data); + expect(m.invert()).toBe(false); + expectArrayEqual(m, data); + }); }); diff --git a/js/wasm/mat.ts b/js/wasm/mat.ts index 14c0874..fc25adf 100644 --- a/js/wasm/mat.ts +++ b/js/wasm/mat.ts @@ -1,7 +1,7 @@ import { mat2identity, mat2add, mat2det, mat2frommat3, mat2invert, mat2mul, mat2scale, mat2sub, mat2transpose, mat3identity, mat3add, mat3det, mat3frommat2, mat3frommat4, mat3invert, mat3mul, mat3scale, mat3sub, mat3transpose, - mat4identity, mat4add, mat4det, mat4frommat3, mat4invert, mat4mul, mat4scale, mat4sub, mat4transpose, + mat4identity, mat4add, mat4det, mat4frommat3, mat4invert, mat4mul, mat4scale, mat4sub, mat4transpose, normalmat3, } from '../../wasm/index.js'; import { Indexable, Mat } from '../types.ts'; import { ManagedFloat64Array } from './memory.ts'; @@ -37,8 +37,8 @@ export class Mat2 extends ManagedFloat64Array<4> implements Mat<2>, Indexable<4> return this; } - public mul(m: Mat2): this { - mat2mul(this.byteOffset, m.byteOffset, this.byteOffset); + public mul(rhs: Mat2): this { + mat2mul(this.byteOffset, this.byteOffset, rhs.byteOffset); return this; } @@ -101,8 +101,8 @@ export class Mat3 extends ManagedFloat64Array<9> implements Mat<3>, Indexable<9> return this; } - public mul(m: Mat3): this { - mat3mul(this.byteOffset, m.byteOffset, this.byteOffset); + public mul(rhs: Mat3): this { + mat3mul(this.byteOffset, this.byteOffset, rhs.byteOffset); return this; } @@ -122,6 +122,11 @@ export class Mat3 extends ManagedFloat64Array<9> implements Mat<3>, Indexable<9> public det(): number { return mat3det(this.byteOffset); } + + /** Coverts this to a normal matrix, which is the inverse transpose matrix. */ + public normalMat(): boolean { + return !!normalmat3(this.byteOffset, this.byteOffset); + } } /** A 4x4 matrix. */ @@ -167,8 +172,8 @@ export class Mat4 extends ManagedFloat64Array<16> implements Mat<4>, Indexable<1 return this; } - public mul(m: Mat4): this { - mat4mul(this.byteOffset, m.byteOffset, this.byteOffset); + public mul(rhs: Mat4): this { + mat4mul(this.byteOffset, this.byteOffset, rhs.byteOffset); return this; }