diff --git a/README.md b/README.md index d8d659f..dc61116 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,6 @@ ## Overview `munum` is a minimalistic numerical library for high-performance 3D math with Rust, WebAssembly and JavaScript bindings. -WIP v0.2: unification of Rust and JS source - ## Documentation - Docs.rs: https://docs.rs/munum - TSDoc: http://andykswong.github.io/munum @@ -60,6 +58,9 @@ using viewProj = perspective(aspectRatio, yfov, znear, zfar).mul(view); Note the use of `using` (which automatically calls `.free()` when out of scope). When using JavaScript binding, `munum` resources are allocated on WebAssembly memory which need to be deallocated later. `munum` uses `FinalizationRegistry` for automatic memory management, so explicit memory management with `using` or `.free()` is not required through recommended. +## Usage (Pure JavaScript) +Import from `munum/js` for pure JavaScript implementation. + ## Usage (Rust) Sample usage to build a perspective camera view-projection matrix: diff --git a/as-pect.config.cjs b/as-pect.config.cjs deleted file mode 100644 index b49f5fb..0000000 --- a/as-pect.config.cjs +++ /dev/null @@ -1,40 +0,0 @@ -module.exports = { - /** - * A set of globs passed to the glob package that qualify typescript files for testing. - */ - include: ["assembly/__tests__/**/*.spec.ts"], - /** - * A set of globs passed to the glob package that quality files to be added to each test. - */ - add: ["assembly/__tests__/**/*.include.ts"], - /** - * All the compiler flags needed for this test suite. Make sure that a binary file is output. - */ - flags: { - /** To output a wat file, uncomment the following line. */ - // "--textFile": ["output.wat"], - /** A runtime must be provided here. */ - "--runtime": ["incremental"], // Acceptable values are: "incremental", "minimal", and "stub" - }, - /** - * A set of regexp that will disclude source files from testing. - */ - disclude: [/node_modules/], - /** - * Add your required AssemblyScript imports here. - */ - imports(memory, createImports, instantiateSync, binary) { - let instance; // Imports can reference this - const myImports = { - // put your web assembly imports here, and return the module - }; - instance = instantiateSync(binary, createImports(myImports)); - return instance; - }, - /** Enable code coverage. */ - // coverage: ["assembly/**/*.ts"], - /** - * Specify if the binary wasm file should be written to the file system. - */ - outputBinary: false, -}; diff --git a/assembly/index.ts b/assembly/index.ts index 6500e4e..4cd4a20 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -1,3 +1,9 @@ +/** + * Deprecated - This will be removed once the new code base reaches feature parity. + * + * @packageDocumentation + */ + import * as aabb from './aabb'; import * as frustum from './frustum'; import * as mat from './mat'; diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..1bdb619 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,12 @@ +comment: + layout: "header, diff, flags" +coverage: + status: + project: + default: + target: 90% + threshold: 2% + patch: + default: + target: 90% + threshold: 2% diff --git a/dist/js/helpers.js b/dist/js/helpers.js new file mode 100644 index 0000000..82b7b0b --- /dev/null +++ b/dist/js/helpers.js @@ -0,0 +1,2 @@ +import{lerp as lerpNum}from"../scalar.js";import{BYTES_PER_FLOAT64,memoryManager}from"./memory.js";const TEMP=Array(16);export function add(lhs,rhs){const left=lhs.byteOffset/BYTES_PER_FLOAT64|0;const right=rhs.byteOffset/BYTES_PER_FLOAT64|0;const view=memoryManager.view;for(let i=0;iview.length){memory.grow(1);view=new Float64Array(memory.buffer)}const offset=next;next+=size;return offset*BYTES_PER_FLOAT64},free:function(byteOffset,size){const offset=Math.ceil(byteOffset/BYTES_PER_FLOAT64);if(offset+size>view.length){return}view[offset]=freeList[size]||0;freeList[size]=offset+1}};setMemoryManager(memoryManager);export{ManagedFloat64Array,setMemoryManager,useFinalizationRegistry}; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJNYW5hZ2VkRmxvYXQ2NEFycmF5Iiwic2V0TWVtb3J5TWFuYWdlciIsInVzZUZpbmFsaXphdGlvblJlZ2lzdHJ5IiwiQllURVNfUEVSX0ZMT0FUNjQiLCJtZW1vcnkiLCJXZWJBc3NlbWJseSIsIk1lbW9yeSIsImluaXRpYWwiLCJmcmVlTGlzdCIsInZpZXciLCJGbG9hdDY0QXJyYXkiLCJidWZmZXIiLCJuZXh0IiwibWVtb3J5TWFuYWdlciIsImNyZWF0ZSIsInNpemUiLCJvZmZzZXQiLC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QU8sQ0FBQUMsTUFBTSxDQUFHYixpQkFDbEIsQ0FBQyxDQUNEZ0IsSUFBSSxDQUFFLFFBQUFBLENBQVVDLFVBQWtCLENBQUVMLElBQVksQ0FBUSxDQUN0RCxLQUFNLENBQUFDLE1BQU0sQ0FBR0ssSUFBSSxDQUFDQyxJQUFJLENBQUNGLFVBQVUsQ0FBR2pCLGlCQUFpQixDQUFDLENBQ3hELEdBQUlhLE1BQU0sQ0FBR0QsSUFBSSxDQUFHTixJQUFJLENBQUNRLE1BQU0sQ0FBRSxDQUMvQixNQUNGLENBQ0FSLElBQUksQ0FBQ08sTUFBTSxDQUFDLENBQUdSLFFBQVEsQ0FBQ08sSUFBSSxDQUFDLEVBQUksQ0FBQyxDQUNsQ1AsUUFBUSxDQUFDTyxJQUFJLENBQUMsQ0FBR0MsTUFBTSxDQUFHLENBQzVCLENBQ0YsQ0FBQyxDQUVEZixnQkFBZ0IsQ0FBQ1ksYUFBYSxDQUFDLENBRy9CLE9BQVNiLG1CQUFtQixDQUFFQyxnQkFBZ0IsQ0FBRUMsdUJBQXVCIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file diff --git a/dist/js/vec.js b/dist/js/vec.js new file mode 100644 index 0000000..7faca0d --- /dev/null +++ b/dist/js/vec.js @@ -0,0 +1,2 @@ +import{add,dot,lerp,mul,normalize,scale,sub}from"./helpers.js";import{BYTES_PER_FLOAT64,ManagedFloat64Array,memoryManager}from"./memory.js";const TEMP=Array(4);export class Vec2 extends ManagedFloat64Array{constructor(x=0,y=0){super(memoryManager.create(2));this.set([x,y])}get length(){return 2}add(rhs){add(this,rhs);return this}sub(rhs){sub(this,rhs);return this}mul(m){mul(m,this,2,true);return this}mulMat3(m){const left=m.byteOffset/BYTES_PER_FLOAT64|0;const right=this.byteOffset/BYTES_PER_FLOAT64|0;const view=memoryManager.view;for(let i=0;i<2;++i){let f=0;for(let j=0;j<2;++j){f+=view[left+j*3+i]*view[right+j]}f+=view[left+2*3+i];TEMP[i]=f}view[right+0]=TEMP[0];view[right+1]=TEMP[1];return this}dot(rhs){return dot(this,rhs)}lerp(rhs,t){lerp(this,rhs,t);return this}scale(factor){scale(this,factor);return this}normalize(){return normalize(this)}}export class Vec3 extends ManagedFloat64Array{constructor(x=0,y=0,z=0){super(memoryManager.create(3));this.set([x,y,z])}get length(){return 3}add(rhs){add(this,rhs);return this}sub(rhs){sub(this,rhs);return this}mul(m){mul(m,this,3,true);return this}mulMat4(m){const left=m.byteOffset/BYTES_PER_FLOAT64|0;const right=this.byteOffset/BYTES_PER_FLOAT64|0;const view=memoryManager.view;for(let i=0;i<3;++i){let f=0;for(let j=0;j<3;++j){f+=view[left+j*4+i]*view[right+j]}f+=view[left+3*4+i];TEMP[i]=f}view[right+0]=TEMP[0];view[right+1]=TEMP[1];view[right+2]=TEMP[2];return this}cross(rhs){const left=this.byteOffset/BYTES_PER_FLOAT64|0;const right=rhs.byteOffset/BYTES_PER_FLOAT64|0;const view=memoryManager.view;const y=view[left+2]*view[right+0]-view[right+2]*view[left+0];const z=view[left+0]*view[right+1]-view[right+0]*view[left+1];view[left+0]=view[left+1]*view[right+2]-view[right+1]*view[left+2];view[left+1]=y;view[left+2]=z;return this}dot(rhs){return dot(this,rhs)}lerp(rhs,t){lerp(this,rhs,t);return this}scale(factor){scale(this,factor);return this}normalize(){return normalize(this)}}export class Vec4 extends ManagedFloat64Array{constructor(x=0,y=0,z=0,w=0){super(memoryManager.create(4));this.set([x,y,z,w])}get length(){return 4}add(rhs){add(this,rhs);return this}sub(rhs){sub(this,rhs);return this}mul(m){mul(m,this,4,true);return this}dot(rhs){return dot(this,rhs)}lerp(rhs,t){lerp(this,rhs,t);return this}scale(factor){scale(this,factor);return this}normalize(){return normalize(this)}} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhZGQiLCJkb3QiLCJsZXJwIiwibXVsIiwibm9ybWFsaXplIiwic2NhbGUiLCJzdWIiLCJCWVRFU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FDZCxNQUFPLEtBQ1QsQ0FFT2IsR0FBR0EsQ0FBQ2EsR0FBUyxDQUFRLENBQzFCYixHQUFHLENBQUMsSUFBSSxDQUFFYSxHQUFHLENBQUMsQ0FDZCxNQUFPLEtBQ1QsQ0FFT2hCLEdBQUdBLENBQUNpQixDQUFPLENBQVEsQ0FDeEJqQixHQUFHLENBQUNpQixDQUFDLENBQUUsSUFBSSxDQUFFLENBQUMsQ0FBRSxJQUFJLENBQUMsQ0FDckIsTUFBTyxLQUNULENBRU9uQixHQUFHQSxDQUFDa0IsR0FBUyxDQUFVLENBQzVCLE1BQU8sQ0FBQWxCLEdBQUcsQ0FBQyxJQUFJLENBQUVrQixHQUFHLENBQ3RCLENBRU9qQixJQUFJQSxDQUFDaUIsR0FBUyxDQUFFVSxDQUFTLENBQVEsQ0FDdEMzQixJQUFJLENBQUMsSUFBSSxDQUFFaUIsR0FBRyxDQUFFVSxDQUFDLENBQUMsQ0FDbEIsTUFBTyxLQUNULENBRU94QixLQUFLQSxDQUFDeUIsTUFBYyxDQUFRLENBQ2pDekIsS0FBSyxDQUFDLElBQUksQ0FBRXlCLE1BQU0sQ0FBQyxDQUNuQixNQUFPLEtBQ1QsQ0FFTzFCLFNBQVNBLENBQUEsQ0FBWSxDQUMxQixNQUFPLENBQUFBLFNBQVMsQ0FBQyxJQUFJLENBQ3ZCLENBQ0YiLCJpZ25vcmVMaXN0IjpbXX0= \ No newline at end of file diff --git a/dist/types.js b/dist/types.js index 5c14de8..505330b 100644 --- a/dist/types.js +++ b/dist/types.js @@ -1,2 +1,2 @@ export{}; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vanMvdHlwZXMudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqIEEgTiB4IE4gbWF0cml4LiAqL1xuZXhwb3J0IGludGVyZmFjZSBNYXQ8TiBleHRlbmRzIDIgfCAzIHwgND4ge1xuICA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IHQ6IG51bWJlcik6IHRoaXM7XG5cbiAgLyoqIENvbXB1dGVzIHRoZSBzaHBlcmljIGludGVycG9sYXRpb24gYmV0d2VlbiB0aGlzIGFuZCBSSFMuICovXG4gIHNsZXJwKHJoczogSVF1YXQsIHQ6IG51bWJlcik6IHRoaXM7XG5cbiAgLyoqIE5vcm1hbGl6ZXMgdGhpcy4gKi9cbiAgbm9ybWFsaXplKCk6IGJvb2xlYW47XG5cbiAgLyoqIEludmVydHMgdGhpcy4gKi9cbiAgaW52ZXJ0KCk6IGJvb2xlYW47XG59XG4iXSwibWFwcGluZ3MiOiIiLCJpZ25vcmVMaXN0IjpbXX0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vanMvdHlwZXMudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqIEEgTiB4IE4gbWF0cml4LiAqL1xuZXhwb3J0IGludGVyZmFjZSBNYXQ8TiBleHRlbmRzIDIgfCAzIHwgND4ge1xuICAvKiogQWRkcyBSSFMgdG8gdGhpcyBtYXRyaXguICovXG4gIGFkZChyaHM6IE1hdDxOPik6IHRoaXM7XG5cbiAgLyoqIFN1YnRyYWN0cyBSSFMgZnJvbSB0aGlzIG1hdHJpeC4gKi9cbiAgc3ViKHJoczogTWF0PE4+KTogdGhpcztcblxuICAvKiogTXVsdGlwbGllcyBSSFMgdG8gdGhpcy4gKi9cbiAgbXVsKHJoczogTWF0PE4+KTogdGhpcztcblxuICAvKiogU2NhbGVzIHRoaXMgbWF0cml4IGJ5IGdpdmVuIGZhY3Rvci4gKi9cbiAgc2NhbGUoZmFjdG9yOiBudW1iZXIpOiB0aGlzO1xuXG4gIC8qKiBUcmFuc3Bvc2VzIHRoaXMgbWF0cml4LiAqL1xuICB0cmFuc3Bvc2UoKTogdGhpcztcblxuICAvKiogSW52ZXJ0cyB0aGlzIG1hdHJpeC4gKi9cbiAgaW52Z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UuICovXG5leHBvcnQgaW50ZXJmYWNlIElRdWF0IHtcbiAgLyoqIFJldHVybnMgdGhlIGxlbmd0aCBvZiBRdWF0LiAqL1xuICByZWFkb25seSBsZW5ndGg6IDQ7XG5cbiAgLyoqIEFzc2lnbnMgdGhlIEhhbWlsdG9uIHByb2R1Y3Qgd2l0aCBSSFMgdG8gdGhpcy4gKi9cbiAgbXVsKHJoczogSVF1YXQpOiB0aGlzO1xuXG4gIC8qKiBSb3RhdGVzIGdpdmVuIDNEIHZlY3RvciBtdXRhYmx5IHVzaW5nIHRoaXMuICovXG4gIHJvdGF0ZSh2OiBWZWM8Mz4pOiBWZWM8Mz47XG5cbiAgLyoqIENvbXB1dGVzIHRoZSBkb3QgcHJvZHVjdCBvZiB0aGlzIHdpdGggUkhTLiAqL1xuICBkb3QocmhzOiBJUXVhdCk6IG51bWJlcjtcblxuICAvKiogQ29tcHV0ZXMgdGhlIGxpbmVhciBpbnRlcnBvbGF0aW9uIGJldHdlZW4gdGhpcyBhbmQgUkhTLiAqL1xuICBsZXJwKHJoczogSVF1YXQsIHQ6IG51bWJlcik6IHRoaXM7XG5cbiAgLyoqIENvbXB1dGVzIHRoZSBzaHBlcmljIGludGVycG9sYXRpb24gYmV0d2VlbiB0aGlzIGFuZCBSSFMuICovXG4gIHNsZXJwKHJoczogSVF1YXQsIHQ6IG51bWJlcik6IHRoaXM7XG5cbiAgLyoqIE5vcm1hbGl6ZXMgdGhpcy4gKi9cbiAgbm9ybWFsaXplKCk6IGJvb2xlYW47XG5cbiAgLyoqIEludmVydHMgdGhpcy4gKi9cbiAgaW52ZXJ0KCk6IGJvb2xlYW47XG59XG4iXSwibWFwcGluZ3MiOiIiLCJpZ25vcmVMaXN0IjpbXX0= \ No newline at end of file diff --git a/dist/wasm/mat.js b/dist/wasm/mat.js index 3824f88..e686752 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,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(ptr)}get length(){return 4}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(ptr)}get length(){return 9}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(ptr)}get length(){return 16}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,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJtYXQyaWRlbnRpdHkiLCJtYXQyYWRkIiwibWF0MmRldCIsIm1hdDJmcm9tbWF0MyIsIm1hdDJpbnZlcnQiLCJtYXQybXVsIiwibWF0MnNjYWxlIiwibWF0MnN1YiIsIm1hdDJ0cmFuc3Bvc2UiLCJtYXQzaWRlbnRpdHkiLCJtYXQzYWRkIiwibWF0M2RldCIsIm1hdDNmcm9tbWF0MiIsIm1hdDNmcm9tbWF0NCIsIm1hdDNpbnZlcnQiLCJtYXQzbXVsIiwibWF0M3NjYWxlIiwibWF0M3N1YiIsIm1hdDN0cmFuc3Bvc2UiLCJtYXQ0aWRlbnRpdHkiLCJtYXQ0YWRkIiwibWF0NGRldCIsIm1hdDRmcm9tbWF0MyIsIm1hdDRpbnZlcnQiLCJtYXQ0bXVsIiwibWF0NHNjYWxlIiwibWF0NHN1YiIsIm1hdDR0cmFuc3Bvc2UiLCJub3JtYWxtYXQzIiwiTWFuYWdlZEZsb2F0NjRBcnJheSIsIk1hdDIiLCJpZGVudGl0eSIsImZyb21NYXQzIiwibSIsImJ5dGVPZmZzZXQiLCJjb25zdHJ1Y3RvciIsInB0ciIsImxlbmd0aCIsImFkZCIsInJocyIsInN1YiIsIm11bCIsInNjYWxlIiwiZmFjdG9yIiwidHJhbnNwb3NlIiwiaW52ZXJ0IiwiZGV0IiwiTWF0MyIsImZyb21NYXQyIiwiZnJvbU1hdDQiLCJub3JtYWxNYXQiLCJNYXQ0Il0sInN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PLEtBQ1QsQ0FFT08sR0FBR0EsQ0FBQ0YsR0FBUyxDQUFRLENBQzFCZixPQUFPLENBQUMsSUFBSSxDQUFDVSxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQUVLLEdBQUcsQ0FBQ0wsVUFBVSxDQUFDLENBQ3pELE1BQU8sS0FDVCxDQUVPUSxLQUFLQSxDQUFDQyxNQUFjLENBQVEsQ0FDakNsQixTQUFTLENBQUMsSUFBSSxDQUFDUyxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQUVTLE1BQU0sQ0FBQyxDQUNuRCxNQUFPLEtBQ1QsQ0FFT0MsU0FBU0EsQ0FBQSxDQUFTLENBQ3ZCakIsYUFBYSxDQUFDLElBQUksQ0FBQ08sVUFBVSxDQUFFLElBQUksQ0FBQ0EsVUFBVSxDQUNoRCxDQUVPVyxNQUFNQSxDQUFBLENBQVksQ0FDdkIsTUFBTyxDQUFDLENBQUN0QixVQUFVLENBQUMsSUFBSSxDQUFDVyxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQ3RELENBRU9ZLEdBQUdBLENBQUEsQ0FBVyxDQUNuQixNQUFPLENBQUF6QixPQUFPLENBQUMsSUFBSSxDQUFDYSxVQUFVLENBQ2hDLENBQ0YiLCJpZ25vcmVMaXN0IjpbXX0= \ 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(ptr)}get length(){return 4}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);return this}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(ptr)}get length(){return 9}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);return this}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(ptr)}get length(){return 16}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);return this}invert(){return!!mat4invert(this.byteOffset,this.byteOffset)}det(){return mat4det(this.byteOffset)}} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJtYXQyaWRlbnRpdH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SxDQUFDQyxNQUFjLENBQVEsQ0FDakNsQixTQUFTLENBQUMsSUFBSSxDQUFDUyxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQUVTLE1BQU0sQ0FBQyxDQUNuRCxNQUFPLEtBQ1QsQ0FFT0MsU0FBU0EsQ0FBQSxDQUFTLENBQ3ZCakIsYUFBYSxDQUFDLElBQUksQ0FBQ08sVUFBVSxDQUFFLElBQUksQ0FBQ0EsVUFBVSxDQUFDLENBQy9DLE1BQU8sS0FDVCxDQUVPVyxNQUFNQSxDQUFBLENBQVksQ0FDdkIsTUFBTyxDQUFDLENBQUN0QixVQUFVLENBQUMsSUFBSSxDQUFDVyxVQUFVLENBQUUsSUFBSSxDQUFDQSxVQUFVLENBQ3RELENBRU9ZLEdBQUdBLENBQUEsQ0FBVyxDQUNuQixNQUFPLENBQUF6QixPQUFPLENBQUMsSUFBSSxDQUFDYSxVQUFVLENBQ2hDLENBQ0YiLCJpZ25vcmVMaXN0IjpbXX0= \ No newline at end of file diff --git a/js/js/__tests__/mat.spec.ts b/js/js/__tests__/mat.spec.ts new file mode 100644 index 0000000..33a58cd --- /dev/null +++ b/js/js/__tests__/mat.spec.ts @@ -0,0 +1,248 @@ +import { expectArrayEqual } from '../../__tests__/test-utils.ts'; +import { Mat2, Mat3, Mat4 } from '../mat.ts'; + +describe('Mat2', () => { + test('identity', () => { + expectArrayEqual(Mat2.identity(), [1, 0, 0, 1]); + }); + + test('fromMat3', () => { + const m = Mat3.identity(); + m.set([1, 2, 0, 3, 4, 0, 5, 6, 1]); + expectArrayEqual(Mat2.fromMat3(m), [1, 2, 3, 4]); + }); + + test('set', () => { + const m = Mat2.identity(); + 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]); + expectArrayEqual(m.transpose(), [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', () => { + test('identity', () => { + expectArrayEqual(Mat3.identity(), [1, 0, 0, 0, 1, 0, 0, 0, 1]); + }); + + test('fromMat2', () => { + const m = Mat2.identity(); + m.set([1, 2, 3, 4]); + expectArrayEqual(Mat3.fromMat2(m), [1, 2, 0, 3, 4, 0, 0, 0, 1]); + }); + + test('fromMat4', () => { + const m = Mat4.identity(); + m.set([1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, 13, 14, 15, 16]); + expectArrayEqual(Mat3.fromMat4(m), [1, 2, 3, 4, 5, 6, 7, 8, 9]); + }); + + test('set', () => { + const m = Mat3.identity(); + 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]); + expectArrayEqual(m.transpose(), [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', () => { + test('identity', () => { + expectArrayEqual(Mat4.identity(), [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); + }); + + test('fromMat3', () => { + const m = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + expectArrayEqual(Mat4.fromMat3(m), [1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 1]); + }); + + test('set', () => { + const m = Mat4.identity(); + 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]); + expectArrayEqual(m.transpose(), [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/js/__tests__/vec.spec.ts b/js/js/__tests__/vec.spec.ts new file mode 100644 index 0000000..8d027ec --- /dev/null +++ b/js/js/__tests__/vec.spec.ts @@ -0,0 +1,254 @@ +import { expectArrayEqual } from '../../__tests__/test-utils.ts'; +import { Mat2, Mat3, Mat4 } from '../mat.ts'; +import { memoryManager } from '../memory.ts'; +import { Vec2, Vec3, Vec4 } from '../vec.ts'; + +describe('Vec2', () => { + test('constructor', () => { + using v = new Vec2(); + expectArrayEqual(v, [0, 0]); + }); + + test('free', () => { + const v2 = new Vec2(1, 2); + expectArrayEqual(v2, [1, 2]); + v2.free(); + expect(v2.valid).toBe(false); + expectArrayEqual(v2, []); + }); + + test('ArrayBufferView', () => { + const v = new Vec2(1, 2); + expect(v.byteLength).toBe(16); + expect(v.buffer).toBe(memoryManager.buffer); + }); + + test('copy', () => { + const v = new Vec2(3, 5); + const v2 = new Vec2(7, 9); + v.copy(v2); + expectArrayEqual(v, v2); + }); + + test('at', () => { + const v = new Vec2(3, 5); + expect(v.at(0)).toBe(3); + expect(v.at(1)).toBe(5); + expect(v.at(2)).toBeUndefined(); + }); + + test('set', () => { + const v = new Vec2(3, 5); + v.set([0, 0]); + expectArrayEqual(v, [0, 0]); + v.set([1, 2]); + expectArrayEqual(v, [1, 2]); + }); + + test('add', () => { + const v = new Vec2(1, 2); + const v2 = new Vec2(3, 5); + expectArrayEqual(v.add(v2), [4, 7]); + }); + + test('sub', () => { + const v = new Vec2(1, 2); + const v2 = new Vec2(3, 5); + expectArrayEqual(v.sub(v2), [-2, -3]); + }); + + test('scale', () => { + const v = new Vec2(1, 2); + expectArrayEqual(v.scale(2), [2, 4]); + }); + + test('dot', () => { + const v = new Vec2(1, 2); + const v2 = new Vec2(3, 5); + expect(v.dot(v2)).toBe(13); + }); + + test('lerp', () => { + const v = new Vec2(1, 2); + const v2 = new Vec2(3, 5); + expectArrayEqual(v.lerp(v2, .5), [2, 3.5]); + }); + + test('mulMat3', () => { + const v = new Vec2(7, 3); + const m = Mat3.identity(); + m.set([2, 5, 0, 3, 11, 0, -4, 7, 1]); + expectArrayEqual(v.mulMat3(m), [19, 75]); + }); + + test('mul', () => { + const v = new Vec2(7, 3); + const m = Mat2.identity(); + m.set([2, 5, 7, 3]); + expectArrayEqual(v.mul(m), [35, 44]); + }); + + test('dot', () => { + const v = new Vec2(3, 4); + const v2 = new Vec2(5, 7); + expect(v.dot(v2)).toBe(43); + }); + + test('norm', () => { + const v = new Vec2(5, 12); + expect(v.normalize()).toBe(true); + expectArrayEqual(v, [5 / 13, 12 / 13]); + + v.set([0, 0]); + expect(v.normalize()).toBe(false); + }); +}); + +describe('Vec3', () => { + test('constructor', () => { + using v = new Vec3(); + using v2 = new Vec3(1, 2, 3); + expectArrayEqual(v, [0, 0, 0]); + expectArrayEqual(v2, [1, 2, 3]); + }); + + test('set', () => { + const v = new Vec3(3, 4, 5); + v.set([0, 0, 0]); + expectArrayEqual(v, [0, 0, 0]); + v.set([1, 2, 3]); + expectArrayEqual(v, [1, 2, 3]); + }); + + test('add', () => { + const v = new Vec3(1, 2, 3); + const v2 = new Vec3(3, 5, 7); + expectArrayEqual(v.add(v2), [4, 7, 10]); + }); + + test('sub', () => { + const v = new Vec3(1, 2, 3); + const v2 = new Vec3(3, 5, 7); + expectArrayEqual(v.sub(v2), [-2, -3, -4]); + }); + + test('scale', () => { + const v = new Vec3(1, 2, 3); + expectArrayEqual(v.scale(2), [2, 4, 6]); + }); + + test('dot', () => { + const v = new Vec3(1, 2, 3); + const v2 = new Vec3(3, 5, 7); + expect(v.dot(v2)).toBe(34); + }); + + test('lerp', () => { + const v = new Vec3(7, 11, 13); + const v2 = new Vec3(17, 19, 23); + expectArrayEqual(v.lerp(v2, .5), [12, 15, 18]); + }); + + test('mulMat4', () => { + const v = new Vec3(7, 3, 5); + const m = Mat4.identity(); + m.set([2, 7, -19, 0, 3, -11, 23, 0, -4, 13, 31, 0, 5, 17, -29, 1]); + expectArrayEqual(v.mulMat4(m), [8, 98, 62]); + }); + + test('mul', () => { + const v = new Vec3(10, 11, 12); + const m = Mat3.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9]); + expectArrayEqual(v.mul(m), [138, 171, 204]); + }); + + test('dot', () => { + const v = new Vec3(7, 11, 13); + const v2 = new Vec3(17, 19, 23); + expect(v.dot(v2)).toBe(627); + }); + + test('norm', () => { + const v = new Vec3(3, 4, 12); + expect(v.normalize()).toBe(true); + expectArrayEqual(v, [3 / 13, 4 / 13, 12 / 13]); + + v.set([0, 0, 0]); + expect(v.normalize()).toBe(false); + }); + + test('cross', () => { + const v = new Vec3(1, 2, 3); + const v2 = new Vec3(11, 5, 7); + expectArrayEqual(v.cross(v2), [-1, 26, -17]); + }); +}); + +describe('Vec4', () => { + test('constructor', () => { + using v = new Vec4(); + using v2 = new Vec4(1, 2, 3, 4); + expectArrayEqual(v, [0, 0, 0, 0]); + expectArrayEqual(v2, [1, 2, 3, 4]); + }); + + test('set', () => { + const v = new Vec4(3, 4, 5, 7); + v.set([0, 0, 0, 0]); + expectArrayEqual(v, [0, 0, 0, 0]); + v.set([1, 2, 3, 4]); + expectArrayEqual(v, [1, 2, 3, 4]); + }); + + test('add', () => { + const v = new Vec4(1, 2, 3, 4); + const v2 = new Vec4(3, 5, 7, 9); + expectArrayEqual(v.add(v2), [4, 7, 10, 13]); + }); + + test('sub', () => { + const v = new Vec4(1, 2, 3, 4); + const v2 = new Vec4(3, 5, 7, 9); + expectArrayEqual(v.sub(v2), [-2, -3, -4, -5]); + }); + + test('scale', () => { + const v = new Vec4(1, 2, 3, 4); + expectArrayEqual(v.scale(2), [2, 4, 6, 8]); + }); + + test('dot', () => { + const v = new Vec4(1, 2, 3, 4); + const v2 = new Vec4(3, 5, 7, 9); + expect(v.dot(v2)).toBe(70); + }); + + test('lerp', () => { + const v = new Vec4(29, 31, 37, 41); + const v2 = new Vec4(43, 47, 53, 59); + expectArrayEqual(v.lerp(v2, .5), [36, 39, 45, 50]); + }); + + test('mul', () => { + const v = new Vec4(17, 18, 19, 20); + const m = Mat4.identity(); + m.set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); + expectArrayEqual(v.mul(m), [538, 612, 686, 760]); + }); + + test('dot', () => { + const v = new Vec4(29, 31, 37, 41); + const v2 = new Vec4(43, 47, 53, 59); + expect(v.dot(v2)).toBe(7084); + }); + + test('norm', () => { + const v = new Vec4(2, 5, 14, 8); + expect(v.normalize()).toBe(true); + expectArrayEqual(v, [2 / 17, 5 / 17, 14 / 17, 8 / 17]); + + v.set([0, 0, 0, 0]); + expect(v.normalize()).toBe(false); + }); +}); diff --git a/js/js/helpers.ts b/js/js/helpers.ts new file mode 100644 index 0000000..670f408 --- /dev/null +++ b/js/js/helpers.ts @@ -0,0 +1,105 @@ +import { lerp as lerpNum } from '../scalar.ts'; +import { BYTES_PER_FLOAT64, ManagedFloat64Array, memoryManager } from './memory.ts'; + +const TEMP = Array(16); + +export function add(lhs: ManagedFloat64Array, rhs: ManagedFloat64Array) { + const left = (lhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (rhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let i = 0; i < lhs.length; ++i) { + view[left + i] += view[right + i]; + } +} + +export function sub(lhs: ManagedFloat64Array, rhs: ManagedFloat64Array) { + const left = (lhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (rhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let i = 0; i < lhs.length; ++i) { + view[left + i] -= view[right + i]; + } +} + +export function scale(lhs: ManagedFloat64Array, factor: number) { + const left = (lhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let i = 0; i < lhs.length; ++i) { + view[left + i] *= factor; + } +} + +export function dot(lhs: ManagedFloat64Array, rhs: ManagedFloat64Array): number { + const left = (lhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (rhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + let result = 0; + for (let i = 0; i < lhs.length; ++i) { + result += view[left + i] * view[right + i]; + } + return result; +} + +export function normalize(v: ManagedFloat64Array): boolean { + const sqrLen = dot(v, v); + if (sqrLen === 0) { + return false; + } + const len = Math.sqrt(sqrLen); + + const ptr = (v.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let i = 0; i < v.length; ++i) { + view[ptr + i] /= len; + } + return true; +} + +export function lerp(lhs: ManagedFloat64Array, rhs: ManagedFloat64Array, t: number) { + const left = (lhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (rhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let i = 0; i < lhs.length; ++i) { + view[left + i] = lerpNum(view[left + i], view[right + i], t); + } +} + +export function mul( + lhs: ManagedFloat64Array, rhs: ManagedFloat64Array, n: number, assignRight = false +) { + const rr = (lhs.length / n); + const rc = (rhs.length / n); + const left = (lhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (rhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + + for (let i = 0; i < rc; ++i) { + for (let j = 0; j < rr; ++j) { + let f = 0; + for (let k = 0; k < n; ++k) { + f += view[left + k * rr + j] * view[right + i * n + k]; + } + TEMP[i * rr + j] = f; + } + } + + const target = assignRight ? rhs : lhs; + const targetPtr = assignRight ? right : left; + for (let i = 0; i < target.length; ++i) { + view[targetPtr + i] = TEMP[i]; + } +} + +export function transpose(m: ManagedFloat64Array, n: number) { + const ptr = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + + for (let i = 0; i < n; ++i) { + for (let j = i; j < n; ++j) { + // Swap mij and mji + const f = view[ptr + j * n + i]; + view[ptr + j * n + i] = view[ptr + i * n + j]; + view[ptr + i * n + j] = f; + } + } +} diff --git a/js/js/index.ts b/js/js/index.ts index 3f15145..5de0ac0 100644 --- a/js/js/index.ts +++ b/js/js/index.ts @@ -1,6 +1,10 @@ /** - * WIP: Pure JS implementation of munum. + * Pure JS implementation of munum. * @packageDocumentation */ export * from '../scalar.ts'; +export * from '../types.ts'; +export * from './mat.ts'; +export * from './memory.ts'; +export * from './vec.ts'; diff --git a/js/js/mat.ts b/js/js/mat.ts new file mode 100644 index 0000000..45d2f24 --- /dev/null +++ b/js/js/mat.ts @@ -0,0 +1,341 @@ +import { Mat } from '../types.ts'; +import { add, sub, scale, mul, transpose } from './helpers.ts'; +import { BYTES_PER_FLOAT64, ManagedFloat64Array, memoryManager } from './memory.ts'; + +const TEMP = Array(16); +const MAT2_ID = [1, 0, 0, 1]; +const MAT3_ID = [1, 0, 0, 0, 1, 0, 0, 0, 1]; +const MAT4_ID = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; + +/** A 2x2 matrix. */ +export class Mat2 extends ManagedFloat64Array<4> implements Mat<2> { + /** Return an identity Mat2. */ + public static identity(): Mat2 { + const m = new Mat2(memoryManager.create(4)); + m.set(MAT2_ID); + return m; + } + + /** Return a Mat2 from Mat3. */ + public static fromMat3(m: Mat3): Mat2 { + const ptr = memoryManager.create(4); + const left = (ptr / BYTES_PER_FLOAT64) | 0; + const right = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let c = 0; c < 2; ++c) { + for (let r = 0; r < 2; ++r) { + view[left + c * 2 + r] = view[right + c * 3 + r]; + } + } + return new Mat2(ptr); + } + + private constructor(ptr: number) { + super(ptr); + } + + public override get length(): 4 { + return 4; + } + + public add(rhs: Mat2): this { + add(this, rhs); + return this; + } + + public sub(rhs: Mat2): this { + sub(this, rhs); + return this; + } + + public mul(rhs: Mat2): this { + mul(this, rhs, 2); + return this; + } + + public scale(factor: number): this { + scale(this, factor); + return this; + } + + public transpose(): this { + transpose(this, 2); + return this; + } + + public invert(): boolean { + const detA = this.det(); + if (!detA) { + return false; + } + + const ptr = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + TEMP[0] = view[ptr + 3] / detA, + TEMP[1] = -view[ptr + 1] / detA, + TEMP[2] = -view[ptr + 2] / detA, + TEMP[3] = view[ptr + 0] / detA; + + for (let i = 0; i < 4; ++i) { + view[ptr + i] = TEMP[i]; + } + + return true; + } + + public det(): number { + const ptr = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + + return view[ptr + 0] * view[ptr + 3] - view[ptr + 2] * view[ptr + 1]; + } +} + +/** A 3x3 matrix. */ +export class Mat3 extends ManagedFloat64Array<9> implements Mat<3> { + /** Return an identity Mat3. */ + public static identity(): Mat3 { + const m = new Mat3(memoryManager.create(9)); + m.set(MAT3_ID); + return m; + } + + /** Return a Mat3 from Mat2. */ + public static fromMat2(m: Mat2): Mat3 { + const ptr = memoryManager.create(9); + const left = (ptr / BYTES_PER_FLOAT64) | 0; + const right = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let c = 0; c < 2; ++c) { + for (let r = 0; r < 2; ++r) { + view[left + c * 3 + r] = view[right + c * 2 + r]; + } + view[left + c * 3 + 2] = 0; + } + view[left + 6] = 0; + view[left + 7] = 0; + view[left + 8] = 1; + return new Mat3(ptr); + } + + /** Return a Mat3 from Mat4. */ + public static fromMat4(m: Mat4): Mat3 { + const ptr = memoryManager.create(9); + const left = (ptr / BYTES_PER_FLOAT64) | 0; + const right = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let c = 0; c < 3; ++c) { + for (let r = 0; r < 3; ++r) { + view[left + c * 3 + r] = view[right + c * 4 + r]; + } + } + return new Mat3(ptr); + } + + private constructor(ptr: number) { + super(ptr); + } + + public override get length(): 9 { + return 9; + } + + public add(rhs: Mat3): this { + add(this, rhs); + return this; + } + + public sub(rhs: Mat3): this { + sub(this, rhs); + return this; + } + + public mul(rhs: Mat3): this { + mul(this, rhs, 3); + return this; + } + + public scale(factor: number): this { + scale(this, factor); + return this; + } + + public transpose(): this { + transpose(this, 3); + return this; + } + + /** + * Inverts this Mat3. + * @see https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3_%C3%97_3_matrices + */ + public invert(): boolean { + const detA = this.det(); + if (!detA) { + return false; + } + + const ptr = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + TEMP[0] = +(view[ptr + 4] * view[ptr + 8] - view[ptr + 7] * view[ptr + 5]); + TEMP[1] = -(view[ptr + 1] * view[ptr + 8] - view[ptr + 7] * view[ptr + 2]); + TEMP[2] = +(view[ptr + 1] * view[ptr + 5] - view[ptr + 4] * view[ptr + 2]); + TEMP[3] = -(view[ptr + 3] * view[ptr + 8] - view[ptr + 6] * view[ptr + 5]); + TEMP[4] = +(view[ptr + 0] * view[ptr + 8] - view[ptr + 6] * view[ptr + 2]); + TEMP[5] = -(view[ptr + 0] * view[ptr + 5] - view[ptr + 3] * view[ptr + 2]); + TEMP[6] = +(view[ptr + 3] * view[ptr + 7] - view[ptr + 6] * view[ptr + 4]); + TEMP[7] = -(view[ptr + 0] * view[ptr + 7] - view[ptr + 6] * view[ptr + 1]); + TEMP[8] = +(view[ptr + 0] * view[ptr + 4] - view[ptr + 3] * view[ptr + 1]); + + for (let i = 0; i < 9; ++i) { + view[ptr + i] = TEMP[i]; + } + + return true; + } + + public det(): number { + const ptr = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + return ( + view[ptr + 0] * +(view[ptr + 4] * view[ptr + 8] - view[ptr + 7] * view[ptr + 5]) + + view[ptr + 3] * -(view[ptr + 1] * view[ptr + 8] - view[ptr + 7] * view[ptr + 2]) + + view[ptr + 6] * +(view[ptr + 1] * view[ptr + 5] - view[ptr + 4] * view[ptr + 2]) + ) + } + + /** Coverts this to a normal matrix, which is the inverse transpose matrix. */ + public normalMat(): boolean { + if (!this.invert()) { + return false; + } + this.transpose(); + return true; + } +} + +/** A 4x4 matrix. */ +export class Mat4 extends ManagedFloat64Array<16> implements Mat<4> { + /** Return an identity Mat4. */ + public static identity(): Mat4 { + const m = new Mat4(memoryManager.create(16)); + m.set(MAT4_ID); + return m; + } + + /** Return a Mat4 from Mat3. */ + public static fromMat3(m: Mat3): Mat4 { + const ptr = memoryManager.create(16); + const left = (ptr / BYTES_PER_FLOAT64) | 0; + const right = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + for (let c = 0; c < 3; ++c) { + for (let r = 0; r < 3; ++r) { + view[left + c * 4 + r] = view[right + c * 3 + r]; + } + view[left + c * 4 + 3] = 0; + } + view[left + 12] = 0; + view[left + 13] = 0; + view[left + 14] = 0; + view[left + 15] = 1; + return new Mat4(ptr); + } + + private constructor(ptr: number) { + super(ptr); + } + + public override get length(): 16 { + return 16; + } + + public add(rhs: Mat4): this { + add(this, rhs); + return this; + } + + public sub(rhs: Mat4): this { + sub(this, rhs); + return this; + } + + public mul(rhs: Mat4): this { + mul(this, rhs, 4); + return this; + } + + public scale(factor: number): this { + scale(this, factor); + return this; + } + + public transpose(): this { + transpose(this, 4); + return this; + } + + public invert(): boolean { + const ptr = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + const fA0 = (view[ptr + 0] * view[ptr + 5] - view[ptr + 4] * view[ptr + 1]); + const fA1 = (view[ptr + 0] * view[ptr + 9] - view[ptr + 8] * view[ptr + 1]); + const fA2 = (view[ptr + 0] * view[ptr + 13] - view[ptr + 12] * view[ptr + 1]); + const fA3 = (view[ptr + 4] * view[ptr + 9] - view[ptr + 8] * view[ptr + 5]); + const fA4 = (view[ptr + 4] * view[ptr + 13] - view[ptr + 12] * view[ptr + 5]); + const fA5 = (view[ptr + 8] * view[ptr + 13] - view[ptr + 12] * view[ptr + 9]); + const fB0 = (view[ptr + 2] * view[ptr + 7] - view[ptr + 6] * view[ptr + 3]); + const fB1 = (view[ptr + 2] * view[ptr + 11] - view[ptr + 10] * view[ptr + 3]); + const fB2 = (view[ptr + 2] * view[ptr + 15] - view[ptr + 14] * view[ptr + 3]); + const fB3 = (view[ptr + 6] * view[ptr + 11] - view[ptr + 10] * view[ptr + 7]); + const fB4 = (view[ptr + 6] * view[ptr + 15] - view[ptr + 14] * view[ptr + 7]); + const fB5 = (view[ptr + 10] * view[ptr + 15] - view[ptr + 14] * view[ptr + 11]); + + const detA = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; + if (!detA) { + return false; + } + + TEMP[0] = +view[ptr + 5] * fB5 - view[ptr + 9] * fB4 + view[ptr + 13] * fB3; + TEMP[1] = -view[ptr + 1] * fB5 + view[ptr + 9] * fB2 - view[ptr + 13] * fB1; + TEMP[2] = +view[ptr + 1] * fB4 - view[ptr + 5] * fB2 + view[ptr + 13] * fB0; + TEMP[3] = -view[ptr + 1] * fB3 + view[ptr + 5] * fB1 - view[ptr + 9] * fB0; + TEMP[4] = -view[ptr + 4] * fB5 + view[ptr + 8] * fB4 - view[ptr + 12] * fB3; + TEMP[5] = +view[ptr + 0] * fB5 - view[ptr + 8] * fB2 + view[ptr + 12] * fB1; + TEMP[6] = -view[ptr + 0] * fB4 + view[ptr + 4] * fB2 - view[ptr + 12] * fB0; + TEMP[7] = +view[ptr + 0] * fB3 - view[ptr + 4] * fB1 + view[ptr + 8] * fB0; + TEMP[8] = +view[ptr + 7] * fA5 - view[ptr + 11] * fA4 + view[ptr + 15] * fA3; + TEMP[9] = -view[ptr + 3] * fA5 + view[ptr + 11] * fA2 - view[ptr + 15] * fA1; + TEMP[10] = +view[ptr + 3] * fA4 - view[ptr + 7] * fA2 + view[ptr + 15] * fA0; + TEMP[11] = -view[ptr + 3] * fA3 + view[ptr + 7] * fA1 - view[ptr + 11] * fA0; + TEMP[12] = -view[ptr + 6] * fA5 + view[ptr + 10] * fA4 - view[ptr + 14] * fA3; + TEMP[13] = +view[ptr + 2] * fA5 - view[ptr + 10] * fA2 + view[ptr + 14] * fA1; + TEMP[14] = -view[ptr + 2] * fA4 + view[ptr + 6] * fA2 - view[ptr + 14] * fA0; + TEMP[15] = +view[ptr + 2] * fA3 - view[ptr + 6] * fA1 + view[ptr + 10] * fA0; + + for (let i = 0; i < 16; ++i) { + view[ptr + i] = TEMP[i] / detA; + } + + return true; + } + + public det(): number { + const ptr = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + const fA0 = (view[ptr + 0] * view[ptr + 5] - view[ptr + 4] * view[ptr + 1]); + const fA1 = (view[ptr + 0] * view[ptr + 9] - view[ptr + 8] * view[ptr + 1]); + const fA2 = (view[ptr + 0] * view[ptr + 13] - view[ptr + 12] * view[ptr + 1]); + const fA3 = (view[ptr + 4] * view[ptr + 9] - view[ptr + 8] * view[ptr + 5]); + const fA4 = (view[ptr + 4] * view[ptr + 13] - view[ptr + 12] * view[ptr + 5]); + const fA5 = (view[ptr + 8] * view[ptr + 13] - view[ptr + 12] * view[ptr + 9]); + const fB0 = (view[ptr + 2] * view[ptr + 7] - view[ptr + 6] * view[ptr + 3]); + const fB1 = (view[ptr + 2] * view[ptr + 11] - view[ptr + 10] * view[ptr + 3]); + const fB2 = (view[ptr + 2] * view[ptr + 15] - view[ptr + 14] * view[ptr + 3]); + const fB3 = (view[ptr + 6] * view[ptr + 11] - view[ptr + 10] * view[ptr + 7]); + const fB4 = (view[ptr + 6] * view[ptr + 15] - view[ptr + 14] * view[ptr + 7]); + const fB5 = (view[ptr + 10] * view[ptr + 15] - view[ptr + 14] * view[ptr + 11]); + + return fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; + } +} diff --git a/js/js/memory.ts b/js/js/memory.ts new file mode 100644 index 0000000..e0da7d8 --- /dev/null +++ b/js/js/memory.ts @@ -0,0 +1,46 @@ +import { ManagedFloat64Array, MemoryManager, setMemoryManager, useFinalizationRegistry } from '../memory.ts'; + +export const BYTES_PER_FLOAT64 = 8; +const memory = new WebAssembly.Memory({ initial: 0 }); +const freeList: Record = {}; +let view = new Float64Array(memory.buffer); +let next = 0; + +/** Free-list allocator using WASM growable memory. */ +export const memoryManager: MemoryManager = { + get buffer() { + return memory.buffer; + }, + get view() { + return view; + }, + create: function (size: number): number { + if (freeList[size]) { + const offset = freeList[size] - 1; + freeList[size] = view[offset]; + return offset * BYTES_PER_FLOAT64; + } + + if (next + size > view.length) { + memory.grow(1); + view = new Float64Array(memory.buffer); + } + + const offset = next; + next += size; + return offset * BYTES_PER_FLOAT64; + }, + free: function (byteOffset: number, size: number): void { + const offset = Math.ceil(byteOffset / BYTES_PER_FLOAT64); + if (offset + size > view.length) { + return; + } + view[offset] = freeList[size] || 0; + freeList[size] = offset + 1; + } +}; + +setMemoryManager(memoryManager); + +export type { MemoryManager }; +export { ManagedFloat64Array, setMemoryManager, useFinalizationRegistry }; diff --git a/js/js/vec.ts b/js/js/vec.ts new file mode 100644 index 0000000..0347776 --- /dev/null +++ b/js/js/vec.ts @@ -0,0 +1,195 @@ +import { Vec } from '../types.ts'; +import { add, dot, lerp, mul, normalize, scale, sub } from './helpers.ts'; +import { Mat2, Mat3, Mat4 } from './mat.ts'; +import { BYTES_PER_FLOAT64, ManagedFloat64Array, memoryManager } from './memory.ts'; + +const TEMP = Array(4); + +/** A 2D vector. */ +export class Vec2 extends ManagedFloat64Array<2> implements Vec<2> { + public constructor(x = 0, y = 0) { + super(memoryManager.create(2)); + this.set([x, y]); + } + + public override get length(): 2 { + return 2; + } + + public add(rhs: Vec2): this { + add(this, rhs); + return this; + } + + public sub(rhs: Vec2): this { + sub(this, rhs); + return this; + } + + public mul(m: Mat2): this { + mul(m, this, 2, true); + return this; + } + + /** Premultiplies 3x3 matrix to this. */ + public mulMat3(m: Mat3): this { + const left = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + + for (let i = 0; i < 2; ++i) { + let f = 0; + for (let j = 0; j < 2; ++j) { + f += view[left + j * 3 + i] * view[right + j]; + } + f += view[left + 2 * 3 + i]; + TEMP[i] = f; + } + + view[right + 0] = TEMP[0]; + view[right + 1] = TEMP[1]; + return this; + } + + public dot(rhs: Vec2): number { + return dot(this, rhs); + } + + public lerp(rhs: Vec2, t: number): this { + lerp(this, rhs, t); + return this; + } + + public scale(factor: number): this { + scale(this, factor); + return this; + } + + public normalize(): boolean { + return normalize(this); + } +} + +/** A 3D vector. */ +export class Vec3 extends ManagedFloat64Array<3> implements Vec<3> { + public constructor(x = 0, y = 0, z = 0) { + super(memoryManager.create(3)); + this.set([x, y, z]); + } + + public override get length(): 3 { + return 3; + } + + public add(rhs: Vec3): this { + add(this, rhs); + return this; + } + + public sub(rhs: Vec3): this { + sub(this, rhs); + return this; + } + + public mul(m: Mat3): this { + mul(m, this, 3, true); + return this; + } + + /** Premultiplies 4x4 matrix to this. */ + public mulMat4(m: Mat4): this { + const left = (m.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + + for (let i = 0; i < 3; ++i) { + let f = 0; + for (let j = 0; j < 3; ++j) { + f += view[left + j * 4 + i] * view[right + j]; + } + f += view[left + 3 * 4 + i]; + TEMP[i] = f; + } + + view[right + 0] = TEMP[0]; + view[right + 1] = TEMP[1]; + view[right + 2] = TEMP[2]; + return this; + } + + /** Assign cross product of this with RHS to this. */ + public cross(rhs: Vec3): this { + const left = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + const right = (rhs.byteOffset / BYTES_PER_FLOAT64) | 0; + const view = memoryManager.view; + const y = view[left + 2] * view[right + 0] - view[right + 2] * view[left + 0]; + const z = view[left + 0] * view[right + 1] - view[right + 0] * view[left + 1]; + view[left + 0] = view[left + 1] * view[right + 2] - view[right + 1] * view[left + 2]; + view[left + 1] = y; + view[left + 2] = z; + return this; + } + + public dot(rhs: Vec3): number { + return dot(this, rhs); + } + + public lerp(rhs: Vec3, t: number): this { + lerp(this, rhs, t); + return this; + } + + public scale(factor: number): this { + scale(this, factor); + return this; + } + + public normalize(): boolean { + return normalize(this); + } +} + +/** A 4D vector. */ +export class Vec4 extends ManagedFloat64Array<4> implements Vec<4> { + public constructor(x = 0, y = 0, z = 0, w = 0) { + super(memoryManager.create(4)); + this.set([x, y, z, w]); + } + + public override get length(): 4 { + return 4; + } + + public add(rhs: Vec4): this { + add(this, rhs); + return this; + } + + public sub(rhs: Vec4): this { + sub(this, rhs); + return this; + } + + public mul(m: Mat4): this { + mul(m, this, 4, true); + return this; + } + + public dot(rhs: Vec4): number { + return dot(this, rhs); + } + + public lerp(rhs: Vec4, t: number): this { + lerp(this, rhs, t); + return this; + } + + public scale(factor: number): this { + scale(this, factor); + return this; + } + + public normalize(): boolean { + return normalize(this); + } +} diff --git a/js/types.ts b/js/types.ts index 357a3ee..c97acb6 100644 --- a/js/types.ts +++ b/js/types.ts @@ -13,7 +13,7 @@ export interface Mat { scale(factor: number): this; /** Transposes this matrix. */ - transpose(): void; + transpose(): this; /** Inverts this matrix. */ invert(): boolean; diff --git a/js/wasm/__tests__/mat.spec.ts b/js/wasm/__tests__/mat.spec.ts index 8cbd982..33a58cd 100644 --- a/js/wasm/__tests__/mat.spec.ts +++ b/js/wasm/__tests__/mat.spec.ts @@ -51,8 +51,7 @@ describe('Mat2', () => { test('transpose', () => { const m = Mat2.identity(); m.set([1, 2, 3, 4]); - m.transpose(); - expectArrayEqual(m, [1, 3, 2, 4]); + expectArrayEqual(m.transpose(), [1, 3, 2, 4]); }); test('det', () => { @@ -133,8 +132,7 @@ describe('Mat3', () => { 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]); + expectArrayEqual(m.transpose(), [1, 4, 7, 2, 5, 8, 3, 6, 9]); }); test('det', () => { @@ -224,8 +222,7 @@ describe('Mat4', () => { 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]); + expectArrayEqual(m.transpose(), [1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16]); }); test('det', () => { diff --git a/js/wasm/mat.ts b/js/wasm/mat.ts index 4639b11..155ae6d 100644 --- a/js/wasm/mat.ts +++ b/js/wasm/mat.ts @@ -46,8 +46,9 @@ export class Mat2 extends ManagedFloat64Array<4> implements Mat<2> { return this; } - public transpose(): void { + public transpose(): this { mat2transpose(this.byteOffset, this.byteOffset); + return this; } public invert(): boolean { @@ -104,8 +105,9 @@ export class Mat3 extends ManagedFloat64Array<9> implements Mat<3> { return this; } - public transpose(): void { + public transpose(): this { mat3transpose(this.byteOffset, this.byteOffset); + return this; } public invert(): boolean { @@ -162,8 +164,9 @@ export class Mat4 extends ManagedFloat64Array<16> implements Mat<4> { return this; } - public transpose(): void { + public transpose(): this { mat4transpose(this.byteOffset, this.byteOffset); + return this; } public invert(): boolean { diff --git a/package.json b/package.json index 83cb7c4..19fbbec 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,9 @@ "exports": { ".": "./dist/index.js", "./js": "./dist/js/index.js", - "./wasm": "./wasm/index.js", - "./assembly": { - "import": "./assembly" - } + "./wasm": "./wasm/index.js" }, "files": [ - "/assembly", "/dist", "/wasm", "/wit"