Skip to content

Commit 36ecee9

Browse files
author
Huguenin-Elie Steve
committed
merge JSMath and Maths and toolchain TS into AMD modules
production build achieved from assembly
1 parent 0749891 commit 36ecee9

File tree

16 files changed

+7901
-111
lines changed

16 files changed

+7901
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vscode
12
.rvmrc
23
.DS_Store
34
tmp

.size-snapshot.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"gzipped": 13273
66
},
77
"dist\\gl-matrix-min.js": {
8-
"bundled": 2167,
9-
"minified": 1888,
10-
"gzipped": 980
8+
"bundled": 223200,
9+
"minified": 52941,
10+
"gzipped": 13521
1111
}
1212
}

assembly/imports.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@
55
// prettier-ignore
66

77
/**
8-
* JS Importations
8+
* Extended Math functions
99
* @module glMatrix
1010
*/
11-
export declare namespace JSMath {
11+
12+
export namespace Maths {
1213
// @ts-ignore decorator
1314
@external("Math", "hypot")
14-
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;
15-
}
15+
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;
1616

17-
export namespace Maths {
1817
export function min(a: i32, b: i32): i32 {
1918
return a < b ? a : b;
2019
}
2120

2221
export function max(a: f64, b: f64, c: f64): f64 {
23-
const q = Math.max(b, c)
22+
const q = Math.max(b, c);
2423
return Math.max(a, q);
2524
}
2625
}

assembly/mat2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IndexedCollection, Maths } from "./imports";
33
import { ReadonlyVec2 } from "./vec2";
44

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

319319
/**

assembly/mat2d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IndexedCollection, Maths } from "./imports";
33
import { ReadonlyVec2 } from "./vec2";
44

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

387387
/**

assembly/mat3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IndexedCollection, Maths } from "./imports";
33
import { ReadonlyMat2 } from "./mat2";
44
import { ReadonlyMat4 } from "./mat4";
55
import { ReadonlyVec2 } from "./vec2";
@@ -704,7 +704,7 @@ export function str(a: ReadonlyMat3): string {
704704
* @returns {Number} Frobenius norm
705705
*/
706706
export function frob(a: ReadonlyMat3): f64 {
707-
return JSMath.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
707+
return Maths.hypot(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
708708
}
709709

710710
/**

assembly/mat4.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IndexedCollection, Maths } from "./imports";
33
import * as quat from "./quat";
44
import { ReadonlyQuat2 } from "./quat2";
55
import * as vec3 from "./vec3";
@@ -634,7 +634,7 @@ export function rotate(out: mat4, a: ReadonlyMat4, rad: f64, axis: vec3.Readonly
634634
let x = axis[0],
635635
y = axis[1],
636636
z = axis[2];
637-
let len = JSMath.hypot(x, y, z);
637+
let len = Maths.hypot(x, y, z);
638638
let s: f64, c: f64, t: f64;
639639
let a00: f64, a01: f64, a02: f64, a03: f64;
640640
let a10: f64, a11: f64, a12: f64, a13: f64;
@@ -914,7 +914,7 @@ export function fromRotation(out: mat4, rad: f64, axis: vec3.ReadonlyVec3): mat4
914914
let x = axis[0],
915915
y = axis[1],
916916
z = axis[2];
917-
let len = JSMath.hypot(x, y, z);
917+
let len = Maths.hypot(x, y, z);
918918
let s: f64, c: f64, t: f64;
919919

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

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

11881188
return out;
11891189
}
@@ -1271,9 +1271,9 @@ export function decompose(out_r: quat.quat, out_t: vec3.vec3, out_s: vec3.vec3,
12711271
let m32 = mat[9];
12721272
let m33 = mat[10];
12731273

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

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

1789-
len = 1 / JSMath.hypot(z0, z1, z2);
1789+
len = 1 / Maths.hypot(z0, z1, z2);
17901790
z0 *= len;
17911791
z1 *= len;
17921792
z2 *= len;
17931793

17941794
x0 = upy * z2 - upz * z1;
17951795
x1 = upz * z0 - upx * z2;
17961796
x2 = upx * z1 - upy * z0;
1797-
len = JSMath.hypot(x0, x1, x2);
1797+
len = Maths.hypot(x0, x1, x2);
17981798
if (!len) {
17991799
x0 = 0;
18001800
x1 = 0;
@@ -1810,7 +1810,7 @@ export function lookAt(out: mat4, eye: vec3.ReadonlyVec3, center: vec3.ReadonlyV
18101810
y1 = z2 * x0 - z0 * x2;
18111811
y2 = z0 * x1 - z1 * x0;
18121812

1813-
len = JSMath.hypot(y0, y1, y2);
1813+
len = Maths.hypot(y0, y1, y2);
18141814
if (!len) {
18151815
y0 = 0;
18161816
y1 = 0;
@@ -1953,7 +1953,7 @@ export function str(a: ReadonlyMat4): string {
19531953
* @returns {Number} Frobenius norm
19541954
*/
19551955
export function frob(a: ReadonlyMat4): f64 {
1956-
return JSMath.hypot(
1956+
return Maths.hypot(
19571957
a[0],
19581958
a[1],
19591959
a[2],

assembly/quat2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IndexedCollection, Maths } from "./imports";
33
import * as mat4 from "./mat4";
44
import * as quat from "./quat";
55
import * as vec3 from "./vec3";
@@ -543,7 +543,7 @@ export function rotateAroundAxis(out: quat2, a: ReadonlyQuat2, axis: vec3.Readon
543543
if (Math.abs(rad) < glMatrix.EPSILON) {
544544
return copy(out, a);
545545
}
546-
let axisLength = JSMath.hypot(axis[0], axis[1], axis[2]);
546+
let axisLength = Maths.hypot(axis[0], axis[1], axis[2]);
547547

548548
rad = rad * 0.5;
549549
let s = Math.sin(rad);

assembly/vec2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IArguments, IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IArguments, IndexedCollection, Maths } from "./imports";
33
import { ReadonlyMat2 } from "./mat2";
44
import { ReadonlyMat2d } from "./mat2d";
55
import { ReadonlyMat3 } from "./mat3";
@@ -244,7 +244,7 @@ export function scaleAndAdd(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, scale:
244244
export function distance(a: ReadonlyVec2, b: ReadonlyVec2): f64 {
245245
var x = b[0] - a[0],
246246
y = b[1] - a[1];
247-
return JSMath.hypot(x, y);
247+
return Maths.hypot(x, y);
248248
}
249249

250250
/**

assembly/vec3.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as glMatrix from "./common";
2-
import { IArguments, IndexedCollection, JSMath, Maths } from "./imports";
2+
import { IArguments, IndexedCollection, Maths } from "./imports";
33
import { ReadonlyMat3 } from "./mat3";
44
import { ReadonlyMat4 } from "./mat4";
55
import { ReadonlyQuat } from "./quat";
@@ -52,7 +52,7 @@ export function length(a: ReadonlyVec3): f64 {
5252
let x = a[0];
5353
let y = a[1];
5454
let z = a[2];
55-
return JSMath.hypot(x, y, z);
55+
return Maths.hypot(x, y, z);
5656
}
5757

5858
/**
@@ -275,7 +275,7 @@ export function distance(a: ReadonlyVec3, b: ReadonlyVec3): f64 {
275275
let x = b[0] - a[0];
276276
let y = b[1] - a[1];
277277
let z = b[2] - a[2];
278-
return JSMath.hypot(x, y, z);
278+
return Maths.hypot(x, y, z);
279279
}
280280

281281
/**

0 commit comments

Comments
 (0)