Skip to content

Commit

Permalink
merge JSMath and Maths and toolchain TS into AMD modules
Browse files Browse the repository at this point in the history
production build achieved from assembly
  • Loading branch information
Huguenin-Elie Steve committed Apr 1, 2021
1 parent 0749891 commit 36ecee9
Show file tree
Hide file tree
Showing 16 changed files with 7,901 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
.rvmrc
.DS_Store
tmp
Expand Down
6 changes: 3 additions & 3 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"gzipped": 13273
},
"dist\\gl-matrix-min.js": {
"bundled": 2167,
"minified": 1888,
"gzipped": 980
"bundled": 223200,
"minified": 52941,
"gzipped": 13521
}
}
11 changes: 5 additions & 6 deletions assembly/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
// prettier-ignore

/**
* JS Importations
* Extended Math functions
* @module glMatrix
*/
export declare namespace JSMath {

export namespace Maths {
// @ts-ignore decorator
@external("Math", "hypot")
function hypot(a: f64, b: f64, c?: f64, d?: f64, e?: f64, f?: f64, g?: f64, h?: f64, i?: f64, j?: f64, k?: f64, l?: f64, m?: f64, n?: f64, o?: f64, p?: f64): f64;
}
export declare function hypot(a: f64, b: f64, c?: f64, d?: f64, e?: f64, f?: f64, g?: f64, h?: f64, i?: f64, j?: f64, k?: f64, l?: f64, m?: f64, n?: f64, o?: f64, p?: f64): f64;

export namespace Maths {
export function min(a: i32, b: i32): i32 {
return a < b ? a : b;
}

export function max(a: f64, b: f64, c: f64): f64 {
const q = Math.max(b, c)
const q = Math.max(b, c);
return Math.max(a, q);
}
}
Expand Down
4 changes: 2 additions & 2 deletions assembly/mat2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IndexedCollection, JSMath, Maths } from "./imports";
import { IndexedCollection, Maths } from "./imports";
import { ReadonlyVec2 } from "./vec2";

export type mat2 = IndexedCollection;
Expand Down Expand Up @@ -313,7 +313,7 @@ export function str(a: ReadonlyMat2): string {
* @returns {Number} Frobenius norm
*/
export function frob(a: ReadonlyMat2): f64 {
return JSMath.hypot(a[0], a[1], a[2], a[3]);
return Maths.hypot(a[0], a[1], a[2], a[3]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions assembly/mat2d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IndexedCollection, JSMath, Maths } from "./imports";
import { IndexedCollection, Maths } from "./imports";
import { ReadonlyVec2 } from "./vec2";

export type mat2d = IndexedCollection;
Expand Down Expand Up @@ -381,7 +381,7 @@ export function str(a: ReadonlyMat2d): string {
* @returns {Number} Frobenius norm
*/
export function frob(a: ReadonlyMat2d): f64 {
return JSMath.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);
return Maths.hypot(a[0], a[1], a[2], a[3], a[4], a[5], 1);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions assembly/mat3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IndexedCollection, JSMath, Maths } from "./imports";
import { IndexedCollection, Maths } from "./imports";
import { ReadonlyMat2 } from "./mat2";
import { ReadonlyMat4 } from "./mat4";
import { ReadonlyVec2 } from "./vec2";
Expand Down Expand Up @@ -704,7 +704,7 @@ export function str(a: ReadonlyMat3): string {
* @returns {Number} Frobenius norm
*/
export function frob(a: ReadonlyMat3): f64 {
return JSMath.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
return Maths.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
}

/**
Expand Down
26 changes: 13 additions & 13 deletions assembly/mat4.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IndexedCollection, JSMath, Maths } from "./imports";
import { IndexedCollection, Maths } from "./imports";
import * as quat from "./quat";
import { ReadonlyQuat2 } from "./quat2";
import * as vec3 from "./vec3";
Expand Down Expand Up @@ -634,7 +634,7 @@ export function rotate(out: mat4, a: ReadonlyMat4, rad: f64, axis: vec3.Readonly
let x = axis[0],
y = axis[1],
z = axis[2];
let len = JSMath.hypot(x, y, z);
let len = Maths.hypot(x, y, z);
let s: f64, c: f64, t: f64;
let a00: f64, a01: f64, a02: f64, a03: f64;
let a10: f64, a11: f64, a12: f64, a13: f64;
Expand Down Expand Up @@ -914,7 +914,7 @@ export function fromRotation(out: mat4, rad: f64, axis: vec3.ReadonlyVec3): mat4
let x = axis[0],
y = axis[1],
z = axis[2];
let len = JSMath.hypot(x, y, z);
let len = Maths.hypot(x, y, z);
let s: f64, c: f64, t: f64;

if (len < glMatrix.EPSILON) {
Expand Down Expand Up @@ -1181,9 +1181,9 @@ export function getScaling(out: mat4, mat: ReadonlyMat4): mat4 {
let m32 = mat[9];
let m33 = mat[10];

out[0] = JSMath.hypot(m11, m12, m13);
out[1] = JSMath.hypot(m21, m22, m23);
out[2] = JSMath.hypot(m31, m32, m33);
out[0] = Maths.hypot(m11, m12, m13);
out[1] = Maths.hypot(m21, m22, m23);
out[2] = Maths.hypot(m31, m32, m33);

return out;
}
Expand Down Expand Up @@ -1271,9 +1271,9 @@ export function decompose(out_r: quat.quat, out_t: vec3.vec3, out_s: vec3.vec3,
let m32 = mat[9];
let m33 = mat[10];

out_s[0] = JSMath.hypot(m11, m12, m13);
out_s[1] = JSMath.hypot(m21, m22, m23);
out_s[2] = JSMath.hypot(m31, m32, m33);
out_s[0] = Maths.hypot(m11, m12, m13);
out_s[1] = Maths.hypot(m21, m22, m23);
out_s[2] = Maths.hypot(m31, m32, m33);

let is1 = 1 / out_s[0];
let is2 = 1 / out_s[1];
Expand Down Expand Up @@ -1786,15 +1786,15 @@ export function lookAt(out: mat4, eye: vec3.ReadonlyVec3, center: vec3.ReadonlyV
z1 = eyey - centery;
z2 = eyez - centerz;

len = 1 / JSMath.hypot(z0, z1, z2);
len = 1 / Maths.hypot(z0, z1, z2);
z0 *= len;
z1 *= len;
z2 *= len;

x0 = upy * z2 - upz * z1;
x1 = upz * z0 - upx * z2;
x2 = upx * z1 - upy * z0;
len = JSMath.hypot(x0, x1, x2);
len = Maths.hypot(x0, x1, x2);
if (!len) {
x0 = 0;
x1 = 0;
Expand All @@ -1810,7 +1810,7 @@ export function lookAt(out: mat4, eye: vec3.ReadonlyVec3, center: vec3.ReadonlyV
y1 = z2 * x0 - z0 * x2;
y2 = z0 * x1 - z1 * x0;

len = JSMath.hypot(y0, y1, y2);
len = Maths.hypot(y0, y1, y2);
if (!len) {
y0 = 0;
y1 = 0;
Expand Down Expand Up @@ -1953,7 +1953,7 @@ export function str(a: ReadonlyMat4): string {
* @returns {Number} Frobenius norm
*/
export function frob(a: ReadonlyMat4): f64 {
return JSMath.hypot(
return Maths.hypot(
a[0],
a[1],
a[2],
Expand Down
4 changes: 2 additions & 2 deletions assembly/quat2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IndexedCollection, JSMath, Maths } from "./imports";
import { IndexedCollection, Maths } from "./imports";
import * as mat4 from "./mat4";
import * as quat from "./quat";
import * as vec3 from "./vec3";
Expand Down Expand Up @@ -543,7 +543,7 @@ export function rotateAroundAxis(out: quat2, a: ReadonlyQuat2, axis: vec3.Readon
if (Math.abs(rad) < glMatrix.EPSILON) {
return copy(out, a);
}
let axisLength = JSMath.hypot(axis[0], axis[1], axis[2]);
let axisLength = Maths.hypot(axis[0], axis[1], axis[2]);

rad = rad * 0.5;
let s = Math.sin(rad);
Expand Down
4 changes: 2 additions & 2 deletions assembly/vec2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IArguments, IndexedCollection, JSMath, Maths } from "./imports";
import { IArguments, IndexedCollection, Maths } from "./imports";
import { ReadonlyMat2 } from "./mat2";
import { ReadonlyMat2d } from "./mat2d";
import { ReadonlyMat3 } from "./mat3";
Expand Down Expand Up @@ -244,7 +244,7 @@ export function scaleAndAdd(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, scale:
export function distance(a: ReadonlyVec2, b: ReadonlyVec2): f64 {
var x = b[0] - a[0],
y = b[1] - a[1];
return JSMath.hypot(x, y);
return Maths.hypot(x, y);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions assembly/vec3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IArguments, IndexedCollection, JSMath, Maths } from "./imports";
import { IArguments, IndexedCollection, Maths } from "./imports";
import { ReadonlyMat3 } from "./mat3";
import { ReadonlyMat4 } from "./mat4";
import { ReadonlyQuat } from "./quat";
Expand Down Expand Up @@ -52,7 +52,7 @@ export function length(a: ReadonlyVec3): f64 {
let x = a[0];
let y = a[1];
let z = a[2];
return JSMath.hypot(x, y, z);
return Maths.hypot(x, y, z);
}

/**
Expand Down Expand Up @@ -275,7 +275,7 @@ export function distance(a: ReadonlyVec3, b: ReadonlyVec3): f64 {
let x = b[0] - a[0];
let y = b[1] - a[1];
let z = b[2] - a[2];
return JSMath.hypot(x, y, z);
return Maths.hypot(x, y, z);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions assembly/vec4.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glMatrix from "./common";
import { IArguments, IndexedCollection, JSMath, Maths } from "./imports";
import { IArguments, IndexedCollection, Maths } from "./imports";
import { ReadonlyQuat } from "./quat";

export type vec4 = IndexedCollection;
Expand Down Expand Up @@ -279,7 +279,7 @@ export function distance(a: ReadonlyVec4, b: ReadonlyVec4): f64 {
let y = b[1] - a[1];
let z = b[2] - a[2];
let w = b[3] - a[3];
return JSMath.hypot(x, y, z, w);
return Maths.hypot(x, y, z, w);
}

/**
Expand Down Expand Up @@ -308,7 +308,7 @@ export function length(a: ReadonlyVec4): f64 {
let y = a[1];
let z = a[2];
let w = a[3];
return JSMath.hypot(x, y, z, w);
return Maths.hypot(x, y, z, w);
}

/**
Expand Down
Loading

0 comments on commit 36ecee9

Please sign in to comment.