@thi.ng/matrices 2.2.12 → 2.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/add.js +10 -13
  4. package/addn.js +10 -13
  5. package/alignment-quat.js +10 -16
  6. package/api.js +0 -1
  7. package/column.js +21 -13
  8. package/compile/emit.js +20 -3
  9. package/concat.js +4 -11
  10. package/conjugate.js +4 -1
  11. package/constants.js +35 -13
  12. package/determinant.js +51 -27
  13. package/diag.js +12 -11
  14. package/div.js +10 -13
  15. package/divn.js +10 -13
  16. package/fit.js +16 -24
  17. package/frustum.js +38 -28
  18. package/identity.js +12 -8
  19. package/invert.js +100 -45
  20. package/lookat.js +26 -15
  21. package/m22-m23.js +4 -8
  22. package/m23-m22.js +4 -8
  23. package/m23-m44.js +26 -16
  24. package/m33-m44.js +26 -16
  25. package/m44-m33.js +4 -11
  26. package/matn.js +10 -4
  27. package/matv.js +10 -36
  28. package/mixq.js +18 -28
  29. package/mul.js +10 -15
  30. package/mulm.js +67 -45
  31. package/muln.js +10 -13
  32. package/mulq.js +13 -12
  33. package/mulv.js +58 -77
  34. package/mulvm.js +16 -46
  35. package/normal-mat.js +10 -23
  36. package/orthagonal.js +17 -25
  37. package/ortho.js +26 -17
  38. package/outer-product.js +48 -10
  39. package/package.json +10 -7
  40. package/perspective.js +6 -13
  41. package/project.js +20 -51
  42. package/quat-axis-angle.js +13 -23
  43. package/quat-euler.js +16 -18
  44. package/quat-m33.js +29 -21
  45. package/quat-m44.js +36 -22
  46. package/rotation-around-axis.js +27 -32
  47. package/rotation.js +41 -79
  48. package/row.js +12 -13
  49. package/scale-center.js +16 -16
  50. package/scale.js +32 -42
  51. package/set.js +13 -6
  52. package/shear.js +35 -18
  53. package/skew.js +52 -17
  54. package/sub.js +10 -13
  55. package/subn.js +10 -13
  56. package/trace.js +4 -6
  57. package/transform.js +19 -23
  58. package/translation.js +6 -14
  59. package/transpose.js +26 -24
  60. package/viewport.js +9 -16
package/mulv.js CHANGED
@@ -1,82 +1,63 @@
1
1
  import { dotS2, dotS3, dotS4 } from "@thi.ng/vectors/dots";
2
2
  import { setC2, setC3, setC4 } from "@thi.ng/vectors/setc";
3
3
  import { vop } from "@thi.ng/vectors/vop";
4
- /**
5
- * Matrix-vector multiplication. Supports in-place modification, i.e. if
6
- * `out === v`.
7
- *
8
- * @param out -
9
- * @param m -
10
- * @param v -
11
- */
12
- export const mulV = vop(1);
13
- /**
14
- * Multiplies 2x2 matrix `m` with 2D vector `v`. Supports in-place
15
- * modification, i.e. if `out === v`.
16
- *
17
- * @param out -
18
- * @param m -
19
- * @param v -
20
- */
21
- export const mulV22 = mulV.add(4, (out, m, v) => setC2(out || v, dotS2(m, v, 0, 0, 2), dotS2(m, v, 1, 0, 2)));
22
- /**
23
- * Multiplies 2x3 matrix `m` with 2D vector `v`. Supports in-place
24
- * modification, i.e. if `out === v`.
25
- *
26
- * @param out -
27
- * @param m -
28
- * @param v -
29
- */
30
- export const mulV23 = mulV.add(6, (out, m, v) => setC2(out || v, dotS2(m, v, 0, 0, 2) + m[4], dotS2(m, v, 1, 0, 2) + m[5]));
31
- /**
32
- * Multiplies 3x3 matrix `m` with 3D vector `v`. Supports in-place
33
- * modification, i.e. if `out === v`.
34
- *
35
- * @param out -
36
- * @param m -
37
- * @param v -
38
- */
39
- export const mulV33 = mulV.add(9, (out, m, v) => setC3(out || v, dotS3(m, v, 0, 0, 3), dotS3(m, v, 1, 0, 3), dotS3(m, v, 2, 0, 3)));
40
- /**
41
- * Multiplies 4x4 matrix `m` with 4D vector `v`. Supports in-place
42
- * modification, i.e. if `out === v`.
43
- *
44
- * @param out -
45
- * @param m -
46
- * @param v -
47
- */
48
- export const mulV44 = mulV.add(16, (out, m, v) => setC4(out || v, dotS4(m, v, 0, 0, 4), dotS4(m, v, 1, 0, 4), dotS4(m, v, 2, 0, 4), dotS4(m, v, 3, 0, 4)));
49
- /**
50
- * Multiplies 4x4 matrix `m` with 3D vector `v` and assumes initial
51
- * `w=1`, i.e. the vector is interpreted as `[x,y,z,1]`. After
52
- * transformation applies perspective divide of the resulting XYZ
53
- * components. Returns `undefined` if the computed perspective divisor
54
- * is zero (and would cause `NaN` results).
55
- *
56
- * @param out -
57
- * @param m -
58
- * @param v -
59
- */
60
- export const mulV344 = (out, m, v) => {
61
- const w = dotS3(m, v, 3, 0, 4) + m[15];
62
- return w !== 0
63
- ? setC3(out || v, (dotS3(m, v, 0, 0, 4) + m[12]) / w, (dotS3(m, v, 1, 0, 4) + m[13]) / w, (dotS3(m, v, 2, 0, 4) + m[14]) / w)
64
- : undefined;
4
+ const mulV = vop(1);
5
+ const mulV22 = mulV.add(
6
+ 4,
7
+ (out, m, v) => setC2(out || v, dotS2(m, v, 0, 0, 2), dotS2(m, v, 1, 0, 2))
8
+ );
9
+ const mulV23 = mulV.add(
10
+ 6,
11
+ (out, m, v) => setC2(out || v, dotS2(m, v, 0, 0, 2) + m[4], dotS2(m, v, 1, 0, 2) + m[5])
12
+ );
13
+ const mulV33 = mulV.add(
14
+ 9,
15
+ (out, m, v) => setC3(
16
+ out || v,
17
+ dotS3(m, v, 0, 0, 3),
18
+ dotS3(m, v, 1, 0, 3),
19
+ dotS3(m, v, 2, 0, 3)
20
+ )
21
+ );
22
+ const mulV44 = mulV.add(
23
+ 16,
24
+ (out, m, v) => setC4(
25
+ out || v,
26
+ dotS4(m, v, 0, 0, 4),
27
+ dotS4(m, v, 1, 0, 4),
28
+ dotS4(m, v, 2, 0, 4),
29
+ dotS4(m, v, 3, 0, 4)
30
+ )
31
+ );
32
+ const mulV344 = (out, m, v) => {
33
+ const w = dotS3(m, v, 3, 0, 4) + m[15];
34
+ return w !== 0 ? setC3(
35
+ out || v,
36
+ (dotS3(m, v, 0, 0, 4) + m[12]) / w,
37
+ (dotS3(m, v, 1, 0, 4) + m[13]) / w,
38
+ (dotS3(m, v, 2, 0, 4) + m[14]) / w
39
+ ) : void 0;
65
40
  };
66
- /**
67
- * Multiplies quaternion `q` with 3D vector `v`. Returns transformed
68
- * vector or modifies in-place if `out` is null or `v`.
69
- *
70
- * @param out -
71
- * @param q -
72
- * @param v -
73
- */
74
- export const mulVQ = (out, q, v) => {
75
- const { 0: px, 1: py, 2: pz } = v;
76
- const { 0: qx, 1: qy, 2: qz, 3: qw } = q;
77
- const ix = qw * px + qy * pz - qz * py;
78
- const iy = qw * py + qz * px - qx * pz;
79
- const iz = qw * pz + qx * py - qy * px;
80
- const iw = -qx * px - qy * py - qz * pz;
81
- return setC3(out || v, ix * qw + iw * -qx + iy * -qz - iz * -qy, iy * qw + iw * -qy + iz * -qx - ix * -qz, iz * qw + iw * -qz + ix * -qy - iy * -qx);
41
+ const mulVQ = (out, q, v) => {
42
+ const { 0: px, 1: py, 2: pz } = v;
43
+ const { 0: qx, 1: qy, 2: qz, 3: qw } = q;
44
+ const ix = qw * px + qy * pz - qz * py;
45
+ const iy = qw * py + qz * px - qx * pz;
46
+ const iz = qw * pz + qx * py - qy * px;
47
+ const iw = -qx * px - qy * py - qz * pz;
48
+ return setC3(
49
+ out || v,
50
+ ix * qw + iw * -qx + iy * -qz - iz * -qy,
51
+ iy * qw + iw * -qy + iz * -qx - ix * -qz,
52
+ iz * qw + iw * -qz + ix * -qy - iy * -qx
53
+ );
54
+ };
55
+ export {
56
+ mulV,
57
+ mulV22,
58
+ mulV23,
59
+ mulV33,
60
+ mulV344,
61
+ mulV44,
62
+ mulVQ
82
63
  };
package/mulvm.js CHANGED
@@ -1,49 +1,19 @@
1
1
  import { dot2, dot3, dot4 } from "@thi.ng/vectors/dot";
2
2
  import { dotS2, dotS3, dotS4 } from "@thi.ng/vectors/dots";
3
3
  import { setC2, setC3, setC4 } from "@thi.ng/vectors/setc";
4
- /**
5
- * Same as:
6
- *
7
- * @example
8
- * ```ts
9
- * out[0] = dot(v, column(m, 0))
10
- * out[1] = dot(v, column(m, 1))
11
- * ```
12
- *
13
- * @param out -
14
- * @param v -
15
- * @param m -
16
- */
17
- export const mulVM22 = (out, v, m) => setC2(out, dot2(v, m), dotS2(v, m, 0, 2));
18
- export const mulVM23 = mulVM22;
19
- /**
20
- * Same as:
21
- *
22
- * @example
23
- * ```ts
24
- * out[0] = dot(v, column(m, 0))
25
- * out[1] = dot(v, column(m, 1))
26
- * out[2] = dot(v, column(m, 2))
27
- * ```
28
- *
29
- * @param out -
30
- * @param v -
31
- * @param m -
32
- */
33
- export const mulVM33 = (out, v, m) => setC3(out, dot3(v, m), dotS3(v, m, 0, 3), dotS3(v, m, 0, 6));
34
- /**
35
- * Same as:
36
- *
37
- * @example
38
- * ```ts
39
- * out[0] = dot(v, column(m, 0))
40
- * out[1] = dot(v, column(m, 1))
41
- * out[2] = dot(v, column(m, 2))
42
- * out[3] = dot(v, column(m, 3))
43
- * ```
44
- *
45
- * @param out -
46
- * @param v -
47
- * @param m -
48
- */
49
- export const mulVM44 = (out, v, m) => setC4(out, dot4(v, m), dotS4(v, m, 0, 4), dotS4(v, m, 0, 8), dotS4(v, m, 0, 12));
4
+ const mulVM22 = (out, v, m) => setC2(out, dot2(v, m), dotS2(v, m, 0, 2));
5
+ const mulVM23 = mulVM22;
6
+ const mulVM33 = (out, v, m) => setC3(out, dot3(v, m), dotS3(v, m, 0, 3), dotS3(v, m, 0, 6));
7
+ const mulVM44 = (out, v, m) => setC4(
8
+ out,
9
+ dot4(v, m),
10
+ dotS4(v, m, 0, 4),
11
+ dotS4(v, m, 0, 8),
12
+ dotS4(v, m, 0, 12)
13
+ );
14
+ export {
15
+ mulVM22,
16
+ mulVM23,
17
+ mulVM33,
18
+ mulVM44
19
+ };
package/normal-mat.js CHANGED
@@ -1,28 +1,15 @@
1
1
  import { invert33, invert44 } from "./invert.js";
2
2
  import { mat44to33 } from "./m44-m33.js";
3
3
  import { transpose33, transpose44 } from "./transpose.js";
4
- /**
5
- * Converts given 4x4 matrix to a 3x3 normal matrix, i.e. the transposed
6
- * inverse of its upper-left 3x3 region. If `out` is null a new result
7
- * matrix will be created. Returns `undefined` if matrix inversion
8
- * failed.
9
- *
10
- * @param out -
11
- * @param m -
12
- */
13
- export const normal33 = (out, m) => {
14
- out = invert33(null, mat44to33(out, m));
15
- return out ? transpose33(null, out) : undefined;
4
+ const normal33 = (out, m) => {
5
+ out = invert33(null, mat44to33(out, m));
6
+ return out ? transpose33(null, out) : void 0;
16
7
  };
17
- /**
18
- * Converts given 4x4 matrix to a 4x4 matrix normal matrix, i.e. the
19
- * transposed inverse. Writes results to `m` if `out` is null. Returns
20
- * `undefined` if matrix inversion failed.
21
- *
22
- * @param out -
23
- * @param m -
24
- */
25
- export const normal44 = (out, m) => {
26
- out = invert44(out, m);
27
- return out ? transpose44(null, out) : undefined;
8
+ const normal44 = (out, m) => {
9
+ out = invert44(out, m);
10
+ return out ? transpose44(null, out) : void 0;
11
+ };
12
+ export {
13
+ normal33,
14
+ normal44
28
15
  };
package/orthagonal.js CHANGED
@@ -1,29 +1,21 @@
1
1
  import { EPS } from "@thi.ng/math/api";
2
2
  import { eqDelta } from "@thi.ng/math/eqdelta";
3
- /**
4
- * Returns true, if given square matrix of size `n` is orthagonal, i.e. check if
5
- * `A * AT = I`.
6
- *
7
- * https://en.wikipedia.org/wiki/Orthogonal_matrix
8
- *
9
- * @param m -
10
- * @param n -
11
- * @param eps -
12
- */
13
- export const isOrthagonal = (m, n, eps = EPS) => {
14
- for (let i = 0; i < n; i++) {
15
- const ii = i * n;
16
- for (let j = 0; j < n; j++) {
17
- const jj = j * n;
18
- let acc = 0;
19
- for (let k = 0; k < n; k++) {
20
- acc += m[ii + k] * m[jj + k];
21
- }
22
- if ((i == j && !eqDelta(acc, 1, eps)) ||
23
- (i != j && !eqDelta(acc, 0, eps))) {
24
- return false;
25
- }
26
- }
3
+ const isOrthagonal = (m, n, eps = EPS) => {
4
+ for (let i = 0; i < n; i++) {
5
+ const ii = i * n;
6
+ for (let j = 0; j < n; j++) {
7
+ const jj = j * n;
8
+ let acc = 0;
9
+ for (let k = 0; k < n; k++) {
10
+ acc += m[ii + k] * m[jj + k];
11
+ }
12
+ if (i == j && !eqDelta(acc, 1, eps) || i != j && !eqDelta(acc, 0, eps)) {
13
+ return false;
14
+ }
27
15
  }
28
- return true;
16
+ }
17
+ return true;
18
+ };
19
+ export {
20
+ isOrthagonal
29
21
  };
package/ortho.js CHANGED
@@ -1,19 +1,28 @@
1
1
  import { setC } from "@thi.ng/vectors/setc";
2
- /**
3
- * Creates a 4x4 matrix orthographic projection matrix and writes result
4
- * to `out`.
5
- *
6
- * @param out -
7
- * @param left -
8
- * @param right -
9
- * @param bottom -
10
- * @param top -
11
- * @param near -
12
- * @param far -
13
- */
14
- export const ortho = (out, left, right, bottom, top, near, far) => {
15
- const dx = 1 / (right - left);
16
- const dy = 1 / (top - bottom);
17
- const dz = 1 / (far - near);
18
- return setC(out || [], 2 * dx, 0, 0, 0, 0, 2 * dy, 0, 0, 0, 0, -2 * dz, 0, -(left + right) * dx, -(top + bottom) * dy, -(far + near) * dz, 1);
2
+ const ortho = (out, left, right, bottom, top, near, far) => {
3
+ const dx = 1 / (right - left);
4
+ const dy = 1 / (top - bottom);
5
+ const dz = 1 / (far - near);
6
+ return setC(
7
+ out || [],
8
+ 2 * dx,
9
+ 0,
10
+ 0,
11
+ 0,
12
+ 0,
13
+ 2 * dy,
14
+ 0,
15
+ 0,
16
+ 0,
17
+ 0,
18
+ -2 * dz,
19
+ 0,
20
+ -(left + right) * dx,
21
+ -(top + bottom) * dy,
22
+ -(far + near) * dz,
23
+ 1
24
+ );
25
+ };
26
+ export {
27
+ ortho
19
28
  };
package/outer-product.js CHANGED
@@ -1,12 +1,50 @@
1
1
  import { setC, setC4 } from "@thi.ng/vectors/setc";
2
2
  import { vop } from "@thi.ng/vectors/vop";
3
- /**
4
- * Computes outer/tensor product of vectors `u` and `v`. Returns square matrix
5
- * of same dimensions as vectors, e.g. 3x3 matrix for 3D vectors.
6
- *
7
- * https://en.wikipedia.org/wiki/Outer_product
8
- */
9
- export const outerProduct = vop(1);
10
- export const outerProduct2 = outerProduct.add(2, (out, [ux, uy], [vx, vy]) => setC4(out || [], ux * vx, uy * vx, ux * vy, uy * vy));
11
- export const outerProduct3 = outerProduct.add(3, (out, [ux, uy, uz], [vx, vy, vz]) => setC(out || [], ux * vx, uy * vx, uz * vx, ux * vy, uy * vy, uz * vy, ux * vz, uy * vz, uz * vz));
12
- export const outerProduct4 = outerProduct.add(4, (out, [ux, uy, uz, uw], [vx, vy, vz, vw]) => setC(out || [], ux * vx, uy * vx, uz * vx, uw * vx, ux * vy, uy * vy, uz * vy, uw * vy, ux * vz, uy * vz, uz * vz, uw * vz, ux * vw, uy * vw, uz * vw, uw * vw));
3
+ const outerProduct = vop(1);
4
+ const outerProduct2 = outerProduct.add(
5
+ 2,
6
+ (out, [ux, uy], [vx, vy]) => setC4(out || [], ux * vx, uy * vx, ux * vy, uy * vy)
7
+ );
8
+ const outerProduct3 = outerProduct.add(
9
+ 3,
10
+ (out, [ux, uy, uz], [vx, vy, vz]) => setC(
11
+ out || [],
12
+ ux * vx,
13
+ uy * vx,
14
+ uz * vx,
15
+ ux * vy,
16
+ uy * vy,
17
+ uz * vy,
18
+ ux * vz,
19
+ uy * vz,
20
+ uz * vz
21
+ )
22
+ );
23
+ const outerProduct4 = outerProduct.add(
24
+ 4,
25
+ (out, [ux, uy, uz, uw], [vx, vy, vz, vw]) => setC(
26
+ out || [],
27
+ ux * vx,
28
+ uy * vx,
29
+ uz * vx,
30
+ uw * vx,
31
+ ux * vy,
32
+ uy * vy,
33
+ uz * vy,
34
+ uw * vy,
35
+ ux * vz,
36
+ uy * vz,
37
+ uz * vz,
38
+ uw * vz,
39
+ ux * vw,
40
+ uy * vw,
41
+ uz * vw,
42
+ uw * vw
43
+ )
44
+ );
45
+ export {
46
+ outerProduct,
47
+ outerProduct2,
48
+ outerProduct3,
49
+ outerProduct4
50
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/matrices",
3
- "version": "2.2.12",
3
+ "version": "2.2.14",
4
4
  "description": "Matrix & quaternion operations for 2D/3D geometry processing",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc compile",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,13 +35,14 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/math": "^5.7.6",
39
- "@thi.ng/vectors": "^7.8.8"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/checks": "^3.4.12",
40
+ "@thi.ng/math": "^5.7.7",
41
+ "@thi.ng/vectors": "^7.8.10"
40
42
  },
41
43
  "devDependencies": {
42
44
  "@microsoft/api-extractor": "^7.38.3",
45
+ "esbuild": "^0.19.8",
43
46
  "rimraf": "^5.0.5",
44
47
  "tools": "^0.0.1",
45
48
  "typedoc": "^0.25.4",
@@ -270,5 +273,5 @@
270
273
  ],
271
274
  "year": 2018
272
275
  },
273
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
276
+ "gitHead": "22e36fa838e5431d40165384918b395603bbd92f\n"
274
277
  }
package/perspective.js CHANGED
@@ -1,15 +1,8 @@
1
1
  import { frustum, frustumBounds } from "./frustum.js";
2
- /**
3
- * Creates a 4x4 matrix perspective projection matrix and writes result
4
- * to `out`.
5
- *
6
- * @param out -
7
- * @param fov -
8
- * @param aspect -
9
- * @param near -
10
- * @param far -
11
- */
12
- export const perspective = (out, fov, aspect, near, far) => {
13
- const f = frustumBounds(fov, aspect, near, far);
14
- return frustum(out, f.left, f.right, f.bottom, f.top, f.near, f.far);
2
+ const perspective = (out, fov, aspect, near, far) => {
3
+ const f = frustumBounds(fov, aspect, near, far);
4
+ return frustum(out, f.left, f.right, f.bottom, f.top, f.near, f.far);
5
+ };
6
+ export {
7
+ perspective
15
8
  };
package/project.js CHANGED
@@ -1,56 +1,25 @@
1
1
  import { fromHomogeneous4 } from "@thi.ng/vectors/homogeneous";
2
2
  import { invert23, invert44 } from "./invert.js";
3
3
  import { mulV23, mulV344, mulV44 } from "./mulv.js";
4
- /**
5
- * Transforms given point `p` (4D, homogeneous coordinates) with 4x4
6
- * matrix `mvp`, applies perspective divide and then transforms XY
7
- * components with 2x3 matrix `view` matrix. Returns 3D vector. The
8
- * result Z component can be used for depth sorting.
9
- *
10
- * @param out -
11
- * @param mvp - 4x4 matrix
12
- * @param view - 2x3 matrix
13
- * @param p -
14
- */
15
- export const project = (out, mvp, view, p) => (!out && (out = []),
16
- mulV23(out, view, fromHomogeneous4(out, mulV44([], mvp, p))));
17
- /**
18
- * Same as {@link project}, but slightly faster and more convenient for
19
- * the most common use case of projecting a 3D input point (assumes
20
- * `w=1` for its homogeneous coordinate, i.e. `[x,y,z,1]`). Returns
21
- * `undefined` if the computed perspective divisor is zero (and would
22
- * cause in `NaN` results).
23
- *
24
- * @param out -
25
- * @param mvp - 4x4 matrix
26
- * @param view - 2x3 matrix
27
- * @param p -
28
- */
29
- export const project3 = (out, mvp, view, p) => {
30
- !out && (out = []);
31
- const q = mulV344(out, mvp, p);
32
- return q ? mulV23(q, view, q) : undefined;
4
+ const project = (out, mvp, view, p) => (!out && (out = []), mulV23(out, view, fromHomogeneous4(out, mulV44([], mvp, p))));
5
+ const project3 = (out, mvp, view, p) => {
6
+ !out && (out = []);
7
+ const q = mulV344(out, mvp, p);
8
+ return q ? mulV23(q, view, q) : void 0;
33
9
  };
34
- /**
35
- * Reverse operation of {@link project3}. If `invert` is true (default:
36
- * false), both `mvp` and `view` matrices will be inverted first
37
- * (non-destructively), else they're both assumed to be inverted
38
- * already.
39
- *
40
- * @param out -
41
- * @param mvp - 4x4 matrix
42
- * @param view - 2x3 matrix
43
- * @param p -
44
- * @param invert -
45
- */
46
- export const unproject = (out, mvp, view, p, doInvert = false) => {
47
- if (doInvert) {
48
- const _mvp = invert44([], mvp);
49
- const _view = invert23([], view);
50
- if (!_mvp || !_view)
51
- return;
52
- mvp = _mvp;
53
- view = _view;
54
- }
55
- return mulV344(out, mvp, mulV23([0, 0, p[2] * 2 - 1], view, p));
10
+ const unproject = (out, mvp, view, p, doInvert = false) => {
11
+ if (doInvert) {
12
+ const _mvp = invert44([], mvp);
13
+ const _view = invert23([], view);
14
+ if (!_mvp || !_view)
15
+ return;
16
+ mvp = _mvp;
17
+ view = _view;
18
+ }
19
+ return mulV344(out, mvp, mulV23([0, 0, p[2] * 2 - 1], view, p));
20
+ };
21
+ export {
22
+ project,
23
+ project3,
24
+ unproject
56
25
  };
@@ -1,27 +1,17 @@
1
1
  import { EPS } from "@thi.ng/math/api";
2
2
  import { normalize3, normalize4 } from "@thi.ng/vectors/normalize";
3
- /**
4
- * Computes a quaternion representing the rotation `theta` around
5
- * `axis`.
6
- *
7
- * @param axis -
8
- * @param theta -
9
- */
10
- export const quatFromAxisAngle = (axis, theta) => {
11
- theta *= 0.5;
12
- return normalize3([0, 0, 0, Math.cos(theta)], axis, Math.sin(theta));
3
+ const quatFromAxisAngle = (axis, theta) => {
4
+ theta *= 0.5;
5
+ return normalize3([0, 0, 0, Math.cos(theta)], axis, Math.sin(theta));
13
6
  };
14
- /**
15
- * Decomposes quaternion into `[axis, theta]` tuple.
16
- *
17
- * @param quat -
18
- */
19
- export const quatToAxisAngle = (quat) => {
20
- const n = normalize4([], quat);
21
- const w = n[3];
22
- const m = Math.sqrt(1 - w * w);
23
- const theta = 2 * Math.acos(w);
24
- return m > EPS
25
- ? [[n[0] / m, n[1] / m, n[2] / m], theta]
26
- : [[n[0], n[1], n[2]], theta];
7
+ const quatToAxisAngle = (quat) => {
8
+ const n = normalize4([], quat);
9
+ const w = n[3];
10
+ const m = Math.sqrt(1 - w * w);
11
+ const theta = 2 * Math.acos(w);
12
+ return m > EPS ? [[n[0] / m, n[1] / m, n[2] / m], theta] : [[n[0], n[1], n[2]], theta];
13
+ };
14
+ export {
15
+ quatFromAxisAngle,
16
+ quatToAxisAngle
27
17
  };
package/quat-euler.js CHANGED
@@ -2,23 +2,21 @@ import { X3, Y3, Z3 } from "@thi.ng/vectors/api";
2
2
  import { mulQ } from "./mulq.js";
3
3
  import { quatFromAxisAngle } from "./quat-axis-angle.js";
4
4
  const axisOrder = {
5
- xyz: [X3, Y3, Z3],
6
- yxz: [Y3, X3, Z3],
7
- xzy: [X3, Z3, Y3],
8
- zxy: [Z3, X3, Y3],
9
- yzx: [Y3, Z3, X3],
10
- zyx: [Z3, Y3, X3],
5
+ xyz: [X3, Y3, Z3],
6
+ yxz: [Y3, X3, Z3],
7
+ xzy: [X3, Z3, Y3],
8
+ zxy: [Z3, X3, Y3],
9
+ yzx: [Y3, Z3, X3],
10
+ zyx: [Z3, Y3, X3]
11
11
  };
12
- /**
13
- * Constructs a quaternion from given rotation angles in specified
14
- * `order`.
15
- *
16
- * @param order -
17
- * @param a -
18
- * @param b -
19
- * @param c -
20
- */
21
- export const quatFromEuler = (order, a, b, c) => {
22
- const [aa, ab, ac] = axisOrder[order];
23
- return mulQ(null, mulQ([], quatFromAxisAngle(aa, a), quatFromAxisAngle(ab, b)), quatFromAxisAngle(ac, c));
12
+ const quatFromEuler = (order, a, b, c) => {
13
+ const [aa, ab, ac] = axisOrder[order];
14
+ return mulQ(
15
+ null,
16
+ mulQ([], quatFromAxisAngle(aa, a), quatFromAxisAngle(ab, b)),
17
+ quatFromAxisAngle(ac, c)
18
+ );
19
+ };
20
+ export {
21
+ quatFromEuler
24
22
  };