@forgeax/engine-math 0.0.0-dev.8d955ade1c79

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 (150) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +294 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/_arbs.d.ts +36 -0
  5. package/dist/__tests__/_arbs.d.ts.map +1 -0
  6. package/dist/__tests__/_fixtures.d.ts +61 -0
  7. package/dist/__tests__/_fixtures.d.ts.map +1 -0
  8. package/dist/__tests__/bounds2.test.d.ts +2 -0
  9. package/dist/__tests__/bounds2.test.d.ts.map +1 -0
  10. package/dist/__tests__/box3.test.d.ts +2 -0
  11. package/dist/__tests__/box3.test.d.ts.map +1 -0
  12. package/dist/__tests__/easing.test.d.ts +2 -0
  13. package/dist/__tests__/easing.test.d.ts.map +1 -0
  14. package/dist/__tests__/euler.test-d.d.ts +2 -0
  15. package/dist/__tests__/euler.test-d.d.ts.map +1 -0
  16. package/dist/__tests__/mat3.test-d.d.ts +2 -0
  17. package/dist/__tests__/mat3.test-d.d.ts.map +1 -0
  18. package/dist/__tests__/mat4.property.test.d.ts +2 -0
  19. package/dist/__tests__/mat4.property.test.d.ts.map +1 -0
  20. package/dist/__tests__/mat4.test-d.d.ts +2 -0
  21. package/dist/__tests__/mat4.test-d.d.ts.map +1 -0
  22. package/dist/__tests__/mat4.test.d.ts +2 -0
  23. package/dist/__tests__/mat4.test.d.ts.map +1 -0
  24. package/dist/__tests__/noise.test.d.ts +2 -0
  25. package/dist/__tests__/noise.test.d.ts.map +1 -0
  26. package/dist/__tests__/quat.basis.test.d.ts +2 -0
  27. package/dist/__tests__/quat.basis.test.d.ts.map +1 -0
  28. package/dist/__tests__/quat.interpolation.test.d.ts +2 -0
  29. package/dist/__tests__/quat.interpolation.test.d.ts.map +1 -0
  30. package/dist/__tests__/quat.lookat.test.d.ts +2 -0
  31. package/dist/__tests__/quat.lookat.test.d.ts.map +1 -0
  32. package/dist/__tests__/quat.property.test.d.ts +2 -0
  33. package/dist/__tests__/quat.property.test.d.ts.map +1 -0
  34. package/dist/__tests__/quat.rotateaxis.test.d.ts +2 -0
  35. package/dist/__tests__/quat.rotateaxis.test.d.ts.map +1 -0
  36. package/dist/__tests__/quat.test-d.d.ts +2 -0
  37. package/dist/__tests__/quat.test-d.d.ts.map +1 -0
  38. package/dist/__tests__/ray.property.test.d.ts +2 -0
  39. package/dist/__tests__/ray.property.test.d.ts.map +1 -0
  40. package/dist/__tests__/ray.test.d.ts +2 -0
  41. package/dist/__tests__/ray.test.d.ts.map +1 -0
  42. package/dist/__tests__/types.test-d.d.ts +2 -0
  43. package/dist/__tests__/types.test-d.d.ts.map +1 -0
  44. package/dist/__tests__/vec-catmull-rom.test.d.ts +2 -0
  45. package/dist/__tests__/vec-catmull-rom.test.d.ts.map +1 -0
  46. package/dist/__tests__/vec-smooth-damp.test.d.ts +2 -0
  47. package/dist/__tests__/vec-smooth-damp.test.d.ts.map +1 -0
  48. package/dist/__tests__/vec2.test-d.d.ts +2 -0
  49. package/dist/__tests__/vec2.test-d.d.ts.map +1 -0
  50. package/dist/__tests__/vec3.property.test.d.ts +2 -0
  51. package/dist/__tests__/vec3.property.test.d.ts.map +1 -0
  52. package/dist/__tests__/vec3.test-d.d.ts +2 -0
  53. package/dist/__tests__/vec3.test-d.d.ts.map +1 -0
  54. package/dist/__tests__/vec4.test-d.d.ts +2 -0
  55. package/dist/__tests__/vec4.test-d.d.ts.map +1 -0
  56. package/dist/_internal/epsilon.d.ts +9 -0
  57. package/dist/_internal/epsilon.d.ts.map +1 -0
  58. package/dist/_internal/scalar.d.ts +40 -0
  59. package/dist/_internal/scalar.d.ts.map +1 -0
  60. package/dist/box2.d.ts +35 -0
  61. package/dist/box2.d.ts.map +1 -0
  62. package/dist/box3.d.ts +76 -0
  63. package/dist/box3.d.ts.map +1 -0
  64. package/dist/circle2.d.ts +29 -0
  65. package/dist/circle2.d.ts.map +1 -0
  66. package/dist/color.d.ts +64 -0
  67. package/dist/color.d.ts.map +1 -0
  68. package/dist/easing.d.ts +18 -0
  69. package/dist/easing.d.ts.map +1 -0
  70. package/dist/euler.d.ts +51 -0
  71. package/dist/euler.d.ts.map +1 -0
  72. package/dist/f32-to-f16-bytes.d.ts +10 -0
  73. package/dist/f32-to-f16-bytes.d.ts.map +1 -0
  74. package/dist/frustum.d.ts +49 -0
  75. package/dist/frustum.d.ts.map +1 -0
  76. package/dist/index.d.ts +20 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.mjs +3688 -0
  79. package/dist/index.mjs.map +1 -0
  80. package/dist/mat3.d.ts +70 -0
  81. package/dist/mat3.d.ts.map +1 -0
  82. package/dist/mat4.d.ts +329 -0
  83. package/dist/mat4.d.ts.map +1 -0
  84. package/dist/noise.d.ts +12 -0
  85. package/dist/noise.d.ts.map +1 -0
  86. package/dist/quat.d.ts +312 -0
  87. package/dist/quat.d.ts.map +1 -0
  88. package/dist/ray.d.ts +144 -0
  89. package/dist/ray.d.ts.map +1 -0
  90. package/dist/ray2.d.ts +38 -0
  91. package/dist/ray2.d.ts.map +1 -0
  92. package/dist/sphere.d.ts +41 -0
  93. package/dist/sphere.d.ts.map +1 -0
  94. package/dist/types.d.ts +57 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/vec2.d.ts +76 -0
  97. package/dist/vec2.d.ts.map +1 -0
  98. package/dist/vec3.d.ts +82 -0
  99. package/dist/vec3.d.ts.map +1 -0
  100. package/dist/vec4.d.ts +61 -0
  101. package/dist/vec4.d.ts.map +1 -0
  102. package/package.json +57 -0
  103. package/src/__tests__/_arbs.ts +149 -0
  104. package/src/__tests__/_fixtures.ts +118 -0
  105. package/src/__tests__/bounds2.test.ts +146 -0
  106. package/src/__tests__/box3.test.ts +277 -0
  107. package/src/__tests__/easing.test.ts +109 -0
  108. package/src/__tests__/euler.test-d.ts +63 -0
  109. package/src/__tests__/mat3.test-d.ts +47 -0
  110. package/src/__tests__/mat4.property.test.ts +256 -0
  111. package/src/__tests__/mat4.test-d.ts +130 -0
  112. package/src/__tests__/mat4.test.ts +162 -0
  113. package/src/__tests__/noise.test.ts +75 -0
  114. package/src/__tests__/quat.basis.test.ts +134 -0
  115. package/src/__tests__/quat.interpolation.test.ts +45 -0
  116. package/src/__tests__/quat.lookat.test.ts +103 -0
  117. package/src/__tests__/quat.property.test.ts +150 -0
  118. package/src/__tests__/quat.rotateaxis.test.ts +149 -0
  119. package/src/__tests__/quat.test-d.ts +138 -0
  120. package/src/__tests__/ray.property.test.ts +105 -0
  121. package/src/__tests__/ray.test.ts +539 -0
  122. package/src/__tests__/types.test-d.ts +64 -0
  123. package/src/__tests__/vec-catmull-rom.test.ts +125 -0
  124. package/src/__tests__/vec-smooth-damp.test.ts +167 -0
  125. package/src/__tests__/vec2.test-d.ts +59 -0
  126. package/src/__tests__/vec3.property.test.ts +72 -0
  127. package/src/__tests__/vec3.test-d.ts +65 -0
  128. package/src/__tests__/vec4.test-d.ts +61 -0
  129. package/src/_internal/epsilon.ts +29 -0
  130. package/src/_internal/scalar.ts +90 -0
  131. package/src/box2.ts +168 -0
  132. package/src/box3.ts +372 -0
  133. package/src/circle2.ts +134 -0
  134. package/src/color.ts +177 -0
  135. package/src/easing.ts +49 -0
  136. package/src/euler.ts +239 -0
  137. package/src/f32-to-f16-bytes.ts +71 -0
  138. package/src/frustum.ts +240 -0
  139. package/src/index.ts +65 -0
  140. package/src/mat3.ts +286 -0
  141. package/src/mat4.ts +1334 -0
  142. package/src/noise.ts +78 -0
  143. package/src/quat.ts +847 -0
  144. package/src/ray.ts +575 -0
  145. package/src/ray2.ts +198 -0
  146. package/src/sphere.ts +138 -0
  147. package/src/types.ts +78 -0
  148. package/src/vec2.ts +229 -0
  149. package/src/vec3.ts +294 -0
  150. package/src/vec4.ts +235 -0
@@ -0,0 +1,51 @@
1
+ import type { Euler, EulerOrder, Mat3Like, Quat, QuatLike } from './types';
2
+ export type { Euler, EulerOrder };
3
+ /** Create an Euler, defaulting to (0, 0, 0, 'XYZ'). */
4
+ export declare function create(): Euler;
5
+ /** Allocate a new Euler copy. */
6
+ export declare function clone(a: Euler): Euler;
7
+ /** out.x/y/z/order = inputs; returns out (in-place). */
8
+ export declare function set(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler;
9
+ /**
10
+ * out (Quat) = quaternion from euler. Returns out.
11
+ *
12
+ * Routes directly to quat.fromEuler (D-P2 + 6-order coverage already implemented inside quat).
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * euler.toQuat(quatBuf, eulerInstance);
17
+ * ```
18
+ */
19
+ export declare function toQuat(out: Quat, e: Euler): Quat;
20
+ /**
21
+ * out (Euler) = euler angles from quaternion in given order. Returns out.
22
+ *
23
+ * Implementation path: quat → 3x3 column-major rotation matrix → fromRotationMatrix(order).
24
+ * This concentrates the 6-order formulas in fromRotationMatrix and avoids dual maintenance.
25
+ *
26
+ * @degrade gimbal lock (pitch ≈ ±π/2, sin/cos critical) → set yaw to 0 and let roll absorb the
27
+ * full rotation (registry #16; same equivalent-branch semantics as Three.js; no throw).
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * euler.fromQuat(out, q, 'XYZ');
32
+ * ```
33
+ */
34
+ export declare function fromQuat(out: Euler, q: QuatLike, order: EulerOrder): Euler;
35
+ /**
36
+ * out (Euler) = euler from a 3x3 rotation matrix m (column-major, length 9) in `order`. Returns out.
37
+ *
38
+ * Uses the Three.js Euler.setFromRotationMatrix formulas (intrinsic rotation + Hamilton convention).
39
+ * Each of the 6 orders has an analytic formula; near gimbal-lock (middle axis sin/cos near ±1)
40
+ * an equivalent branch is selected.
41
+ *
42
+ * @degrade gimbal lock → middle axis is fixed at ±π/2; the remaining two axes degenerate
43
+ * (one is set to 0; the other absorbs the rotation).
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * euler.fromRotationMatrix(out, mat3InstanceColumnMajor, 'XYZ');
48
+ * ```
49
+ */
50
+ export declare function fromRotationMatrix(out: Euler, m: Mat3Like, order: EulerOrder): Euler;
51
+ //# sourceMappingURL=euler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"euler.d.ts","sourceRoot":"","sources":["../src/euler.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3E,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAElC,uDAAuD;AACvD,wBAAgB,MAAM,IAAI,KAAK,CAE9B;AAED,iCAAiC;AACjC,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAErC;AAED,wDAAwD;AACxD,wBAAgB,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,CAMzF;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,GAAG,IAAI,CAEhD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,CAiC1E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,CAmGpF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Convert a packed float32 RGBA byte buffer into the equivalent float16 RGBA
3
+ * byte buffer (IEEE 754 binary16, little-endian). The output length is
4
+ * `src.byteLength / 2`.
5
+ *
6
+ * @param src A Uint8Array whose underlying buffer is an interleaved Float32Array.
7
+ * @returns A Uint8Array of packed binary16 pixels, exactly half the length.
8
+ */
9
+ export declare function f32ToF16Bytes(src: Uint8Array): Uint8Array;
10
+ //# sourceMappingURL=f32-to-f16-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"f32-to-f16-bytes.d.ts","sourceRoot":"","sources":["../src/f32-to-f16-bytes.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CA+CzD"}
@@ -0,0 +1,49 @@
1
+ import type { Box3Like } from './box3';
2
+ import type { Mat4Like, Vec3Like } from './types';
3
+ /**
4
+ * Frustum storage: Float32Array(24) — 6 planes × 4 floats each (nx, ny, nz, d).
5
+ * Local brand (not part of the seven-piece SSOT; same rationale as Box3).
6
+ */
7
+ export type Frustum = Float32Array & {
8
+ readonly __frustum: void;
9
+ };
10
+ /** Allocate a new Frustum (zero-initialized 6 planes). */
11
+ export declare function create(): Frustum;
12
+ /**
13
+ * Extract 6 frustum planes (left, right, bottom, top, near, far) from a
14
+ * combined view-projection matrix (column-major, right-handed).
15
+ *
16
+ * Uses Gribb/Hartmann method: each plane = sum or difference of VP rows,
17
+ * then normalized so (nx, ny, nz) is a unit vector and d is the signed
18
+ * distance from origin. Plane inside-half-space is nx*x + ny*y + nz*z + d > 0.
19
+ *
20
+ * Writes to `out` and returns it.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const view = mat4.lookAt(mat4.create(), [0, 0, 5], [0, 0, 0], [0, 1, 0]);
25
+ * const proj = mat4.perspective(mat4.create(), Math.PI / 2, 1, 0.1, 100);
26
+ * const vp = mat4.create();
27
+ * mat4.multiply(vp, proj, view);
28
+ * const f = frustum.fromViewProjection(frustum.create(), vp);
29
+ * ```
30
+ */
31
+ export declare function fromViewProjection(out: Frustum, vp: Mat4Like): Frustum;
32
+ /**
33
+ * Test whether an AABB intersects the frustum. Conservative: returns `true` when
34
+ * the box straddles a plane boundary, even if partially outside.
35
+ *
36
+ * For each plane, the signed distance of both the positive-most corner (p-vertex)
37
+ * and negative-most corner (n-vertex) are tested. The box is outside only when
38
+ * the p-vertex is on the negative side of any plane.
39
+ */
40
+ export declare function intersectsBox(f: Frustum, box: Box3Like): boolean;
41
+ /**
42
+ * Test whether a sphere intersects the frustum. Conservative: returns `true`
43
+ * when the sphere straddles a plane boundary.
44
+ *
45
+ * Computes signed distance from the sphere center to each plane;
46
+ * outside when distance < -radius.
47
+ */
48
+ export declare function intersectsSphere(f: Frustum, center: Vec3Like, radius: number): boolean;
49
+ //# sourceMappingURL=frustum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frustum.d.ts","sourceRoot":"","sources":["../src/frustum.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAElE,0DAA0D;AAC1D,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CA+HtE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CA2BhE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAkBtF"}
@@ -0,0 +1,20 @@
1
+ export type { Color, ColorLike, Euler, EulerOrder, Mat3, Mat3Like, Mat4, Mat4Like, Quat, QuatLike, Vec2, Vec2Like, Vec3, Vec3Like, Vec4, Vec4Like, } from './types';
2
+ export * as box2 from './box2';
3
+ export * as box3 from './box3';
4
+ export * as circle2 from './circle2';
5
+ export * as color from './color';
6
+ export * as easing from './easing';
7
+ export * as euler from './euler';
8
+ export * as halfFloat from './f32-to-f16-bytes';
9
+ export * as frustum from './frustum';
10
+ export * as mat3 from './mat3';
11
+ export * as mat4 from './mat4';
12
+ export * as noise from './noise';
13
+ export * as quat from './quat';
14
+ export * as ray from './ray';
15
+ export * as ray2 from './ray2';
16
+ export * as sphere from './sphere';
17
+ export * as vec2 from './vec2';
18
+ export * as vec3 from './vec3';
19
+ export * as vec4 from './vec4';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,YAAY,EACV,KAAK,EACL,SAAS,EACT,KAAK,EACL,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,GACT,MAAM,SAAS,CAAC;AAYjB,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}