math 0.0.3 → 0.1.0

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 (203) hide show
  1. package/API.md +1605 -0
  2. package/LICENSE +21 -0
  3. package/README.md +197 -0
  4. package/dist/color/color.js +136 -0
  5. package/dist/color/color.js.map +1 -0
  6. package/dist/color/colorspace.js +43 -0
  7. package/dist/color/colorspace.js.map +1 -0
  8. package/dist/color/hsl.js +123 -0
  9. package/dist/color/hsl.js.map +1 -0
  10. package/dist/color/index.js +7 -0
  11. package/dist/color/index.js.map +1 -0
  12. package/dist/color/parse.js +276 -0
  13. package/dist/color/parse.js.map +1 -0
  14. package/dist/core/angle.js +43 -0
  15. package/dist/core/angle.js.map +1 -0
  16. package/dist/core/euler.js +212 -0
  17. package/dist/core/euler.js.map +1 -0
  18. package/dist/core/mat2.js +385 -0
  19. package/dist/core/mat2.js.map +1 -0
  20. package/dist/core/mat2d.js +422 -0
  21. package/dist/core/mat2d.js.map +1 -0
  22. package/dist/core/mat3.js +749 -0
  23. package/dist/core/mat3.js.map +1 -0
  24. package/dist/core/mat4.js +2197 -0
  25. package/dist/core/mat4.js.map +1 -0
  26. package/dist/core/polar.js +200 -0
  27. package/dist/core/polar.js.map +1 -0
  28. package/dist/core/quat.js +730 -0
  29. package/dist/core/quat.js.map +1 -0
  30. package/dist/core/quat2.js +883 -0
  31. package/dist/core/quat2.js.map +1 -0
  32. package/dist/core/scalar.js +112 -0
  33. package/dist/core/scalar.js.map +1 -0
  34. package/dist/core/spherical.js +248 -0
  35. package/dist/core/spherical.js.map +1 -0
  36. package/dist/core/vec2.js +597 -0
  37. package/dist/core/vec2.js.map +1 -0
  38. package/dist/core/vec3.js +916 -0
  39. package/dist/core/vec3.js.map +1 -0
  40. package/dist/core/vec4.js +573 -0
  41. package/dist/core/vec4.js.map +1 -0
  42. package/dist/geometry/circumcircle.js +39 -0
  43. package/dist/geometry/circumcircle.js.map +1 -0
  44. package/dist/geometry/index.js +6 -0
  45. package/dist/geometry/index.js.map +1 -0
  46. package/dist/geometry/polygon2-decompose.js +411 -0
  47. package/dist/geometry/polygon2-decompose.js.map +1 -0
  48. package/dist/geometry/polygon2-triangulate.js +222 -0
  49. package/dist/geometry/polygon2-triangulate.js.map +1 -0
  50. package/dist/geometry/quickhull2.js +123 -0
  51. package/dist/geometry/quickhull2.js.map +1 -0
  52. package/dist/geometry/quickhull3.js +605 -0
  53. package/dist/geometry/quickhull3.js.map +1 -0
  54. package/dist/ik/fabrik2.js +675 -0
  55. package/dist/ik/fabrik2.js.map +1 -0
  56. package/dist/ik/fabrik3.js +912 -0
  57. package/dist/ik/fabrik3.js.map +1 -0
  58. package/dist/ik/index.js +5 -0
  59. package/dist/ik/index.js.map +1 -0
  60. package/dist/index.js +27 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/noise/fractal.js +185 -0
  63. package/dist/noise/fractal.js.map +1 -0
  64. package/dist/noise/index.js +16 -0
  65. package/dist/noise/index.js.map +1 -0
  66. package/dist/noise/perlin2d.js +50 -0
  67. package/dist/noise/perlin2d.js.map +1 -0
  68. package/dist/noise/perlin3d.js +72 -0
  69. package/dist/noise/perlin3d.js.map +1 -0
  70. package/dist/noise/permutation.js +120 -0
  71. package/dist/noise/permutation.js.map +1 -0
  72. package/dist/noise/simplex2d.js +84 -0
  73. package/dist/noise/simplex2d.js.map +1 -0
  74. package/dist/noise/simplex3d.js +147 -0
  75. package/dist/noise/simplex3d.js.map +1 -0
  76. package/dist/noise/simplex4d.js +149 -0
  77. package/dist/noise/simplex4d.js.map +1 -0
  78. package/dist/noise/worley2d.js +50 -0
  79. package/dist/noise/worley2d.js.map +1 -0
  80. package/dist/noise/worley3d.js +61 -0
  81. package/dist/noise/worley3d.js.map +1 -0
  82. package/dist/random/index.js +9 -0
  83. package/dist/random/index.js.map +1 -0
  84. package/dist/random/isaac32.js +164 -0
  85. package/dist/random/isaac32.js.map +1 -0
  86. package/dist/random/isaac64.js +215 -0
  87. package/dist/random/isaac64.js.map +1 -0
  88. package/dist/random/mulberry32.js +48 -0
  89. package/dist/random/mulberry32.js.map +1 -0
  90. package/dist/random/random.js +120 -0
  91. package/dist/random/random.js.map +1 -0
  92. package/dist/shapes/box2.js +300 -0
  93. package/dist/shapes/box2.js.map +1 -0
  94. package/dist/shapes/box3.js +550 -0
  95. package/dist/shapes/box3.js.map +1 -0
  96. package/dist/shapes/circle.js +6 -0
  97. package/dist/shapes/circle.js.map +1 -0
  98. package/dist/shapes/frustum.js +662 -0
  99. package/dist/shapes/frustum.js.map +1 -0
  100. package/dist/shapes/index.js +25 -0
  101. package/dist/shapes/index.js.map +1 -0
  102. package/dist/shapes/obb3.js +557 -0
  103. package/dist/shapes/obb3.js.map +1 -0
  104. package/dist/shapes/plane3.js +267 -0
  105. package/dist/shapes/plane3.js.map +1 -0
  106. package/dist/shapes/polygon2.js +451 -0
  107. package/dist/shapes/polygon2.js.map +1 -0
  108. package/dist/shapes/raycast3.js +164 -0
  109. package/dist/shapes/raycast3.js.map +1 -0
  110. package/dist/shapes/segment2.js +82 -0
  111. package/dist/shapes/segment2.js.map +1 -0
  112. package/dist/shapes/sphere.js +23 -0
  113. package/dist/shapes/sphere.js.map +1 -0
  114. package/dist/shapes/triangle2.js +79 -0
  115. package/dist/shapes/triangle2.js.map +1 -0
  116. package/dist/shapes/triangle3.js +60 -0
  117. package/dist/shapes/triangle3.js.map +1 -0
  118. package/dist/src/color/color.d.ts +50 -0
  119. package/dist/src/color/colorspace.d.ts +15 -0
  120. package/dist/src/color/hsl.d.ts +28 -0
  121. package/dist/src/color/index.d.ts +5 -0
  122. package/dist/src/color/parse.d.ts +15 -0
  123. package/dist/src/core/angle.d.ts +29 -0
  124. package/dist/src/core/arrays.d.ts +4 -0
  125. package/dist/src/core/euler.d.ts +78 -0
  126. package/dist/src/core/index.d.ts +27 -0
  127. package/dist/src/core/mat2.d.ts +217 -0
  128. package/dist/src/core/mat2d.d.ts +218 -0
  129. package/dist/src/core/mat3.d.ts +295 -0
  130. package/dist/src/core/mat4.d.ts +667 -0
  131. package/dist/src/core/polar.d.ts +151 -0
  132. package/dist/src/core/quat.d.ts +370 -0
  133. package/dist/src/core/quat2.d.ts +344 -0
  134. package/dist/src/core/scalar.d.ts +75 -0
  135. package/dist/src/core/spherical.d.ts +165 -0
  136. package/dist/src/core/vec2.d.ts +403 -0
  137. package/dist/src/core/vec3.d.ts +493 -0
  138. package/dist/src/core/vec4.d.ts +336 -0
  139. package/dist/src/geometry/circumcircle.d.ts +9 -0
  140. package/dist/src/geometry/index.d.ts +5 -0
  141. package/dist/src/geometry/polygon2-decompose.d.ts +25 -0
  142. package/dist/src/geometry/polygon2-triangulate.d.ts +15 -0
  143. package/dist/src/geometry/quickhull2.d.ts +10 -0
  144. package/dist/src/geometry/quickhull3.d.ts +27 -0
  145. package/dist/src/ik/fabrik2.d.ts +314 -0
  146. package/dist/src/ik/fabrik3.d.ts +371 -0
  147. package/dist/src/ik/index.d.ts +2 -0
  148. package/dist/src/index.d.ts +1 -0
  149. package/dist/src/noise/fractal.d.ts +95 -0
  150. package/dist/src/noise/index.d.ts +9 -0
  151. package/dist/src/noise/perlin2d.d.ts +19 -0
  152. package/dist/src/noise/perlin3d.d.ts +20 -0
  153. package/dist/src/noise/permutation.d.ts +22 -0
  154. package/dist/src/noise/simplex2d.d.ts +19 -0
  155. package/dist/src/noise/simplex3d.d.ts +20 -0
  156. package/dist/src/noise/simplex4d.d.ts +24 -0
  157. package/dist/src/noise/worley2d.d.ts +22 -0
  158. package/dist/src/noise/worley3d.d.ts +23 -0
  159. package/dist/src/random/index.d.ts +8 -0
  160. package/dist/src/random/isaac32.d.ts +62 -0
  161. package/dist/src/random/isaac64.d.ts +75 -0
  162. package/dist/src/random/mulberry32.d.ts +43 -0
  163. package/dist/src/random/random.d.ts +67 -0
  164. package/dist/src/shapes/box2.d.ts +174 -0
  165. package/dist/src/shapes/box3.d.ts +213 -0
  166. package/dist/src/shapes/circle.d.ts +7 -0
  167. package/dist/src/shapes/frustum.d.ts +147 -0
  168. package/dist/src/shapes/index.d.ts +20 -0
  169. package/dist/src/shapes/obb3.d.ts +105 -0
  170. package/dist/src/shapes/plane3.d.ts +130 -0
  171. package/dist/src/shapes/polygon2.d.ts +155 -0
  172. package/dist/src/shapes/raycast3.d.ts +42 -0
  173. package/dist/src/shapes/segment2.d.ts +34 -0
  174. package/dist/src/shapes/sphere.d.ts +19 -0
  175. package/dist/src/shapes/triangle2.d.ts +53 -0
  176. package/dist/src/shapes/triangle3.d.ts +29 -0
  177. package/dist/src/time/easing.d.ts +21 -0
  178. package/dist/src/time/index.d.ts +6 -0
  179. package/dist/src/time/spring-core.d.ts +15 -0
  180. package/dist/src/time/spring.d.ts +36 -0
  181. package/dist/src/time/spring2.d.ts +11 -0
  182. package/dist/src/time/spring3.d.ts +11 -0
  183. package/dist/src/time/spring4.d.ts +11 -0
  184. package/dist/time/easing.js +24 -0
  185. package/dist/time/easing.js.map +1 -0
  186. package/dist/time/index.js +11 -0
  187. package/dist/time/index.js.map +1 -0
  188. package/dist/time/spring-core.js +48 -0
  189. package/dist/time/spring-core.js.map +1 -0
  190. package/dist/time/spring.js +62 -0
  191. package/dist/time/spring.js.map +1 -0
  192. package/dist/time/spring2.js +31 -0
  193. package/dist/time/spring2.js.map +1 -0
  194. package/dist/time/spring3.js +32 -0
  195. package/dist/time/spring3.js.map +1 -0
  196. package/dist/time/spring4.js +32 -0
  197. package/dist/time/spring4.js.map +1 -0
  198. package/package.json +90 -16
  199. package/skills/math/SKILL.md +140 -0
  200. package/AUTHORS +0 -1
  201. package/Cakefile +0 -28
  202. package/math.coffee +0 -112
  203. package/math.js +0 -141
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raycast3.js","sources":["../../src/shapes/raycast3.ts"],"sourcesContent":["import type { Vec3 } from '../core/vec3';\nimport type { Box3 } from './box3';\n\n/**\n * Result of a ray-triangle intersection test\n * @see createIntersectsTriangleResult\n * @see intersectsTriangle\n */\nexport type IntersectsTriangleResult = {\n fraction: number;\n hit: boolean;\n frontFacing: boolean;\n};\n\n/**\n * Creates a new IntersectsTriangleResult with default values.\n * @returns A new IntersectsTriangleResult.\n */\nexport function createIntersectsTriangleResult(): IntersectsTriangleResult {\n return {\n fraction: 0,\n hit: false,\n frontFacing: false,\n };\n}\n\n/**\n * Ray-triangle intersection test.\n * Based on https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h\n *\n * @param out output object to store result (hit boolean, fraction, frontFacing)\n * @param origin ray origin\n * @param direction ray direction\n * @param length ray length\n * @param a first vertex of triangle\n * @param b second vertex of triangle\n * @param c third vertex of triangle\n * @param backfaceCulling if true, backfaces will not be considered hits\n */\nexport function intersectsTriangle(\n out: IntersectsTriangleResult,\n origin: Vec3,\n direction: Vec3,\n length: number,\n a: Vec3,\n b: Vec3,\n c: Vec3,\n backfaceCulling: boolean,\n): void {\n // compute edge1 = b - a\n const e1x = b[0] - a[0];\n const e1y = b[1] - a[1];\n const e1z = b[2] - a[2];\n\n // compute edge2 = c - a\n const e2x = c[0] - a[0];\n const e2y = c[1] - a[1];\n const e2z = c[2] - a[2];\n\n // compute normal = edge1 × edge2\n const nx = e1y * e2z - e1z * e2y;\n const ny = e1z * e2x - e1x * e2z;\n const nz = e1x * e2y - e1y * e2x;\n\n // determine front vs back facing\n const dx = direction[0];\n const dy = direction[1];\n const dz = direction[2];\n let DdN = dx * nx + dy * ny + dz * nz;\n let sign: number;\n\n if (DdN > 0) {\n // backface\n if (backfaceCulling) {\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n return;\n }\n sign = 1;\n } else if (DdN < 0) {\n // frontface\n sign = -1;\n DdN = -DdN;\n } else {\n // ray is parallel to triangle\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n return;\n }\n\n // compute diff = origin - a\n const diffx = origin[0] - a[0];\n const diffy = origin[1] - a[1];\n const diffz = origin[2] - a[2];\n\n // compute barycentric coordinate b1\n // DdQxE2 = sign * D · (diff × edge2)\n const diffCrossE2x = diffy * e2z - diffz * e2y;\n const diffCrossE2y = diffz * e2x - diffx * e2z;\n const diffCrossE2z = diffx * e2y - diffy * e2x;\n const DdQxE2 = sign * (dx * diffCrossE2x + dy * diffCrossE2y + dz * diffCrossE2z);\n\n if (DdQxE2 < 0) {\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n return;\n }\n\n // compute barycentric coordinate b2\n // DdE1xQ = sign * D · (edge1 × diff)\n const e1CrossDiffx = e1y * diffz - e1z * diffy;\n const e1CrossDiffy = e1z * diffx - e1x * diffz;\n const e1CrossDiffz = e1x * diffy - e1y * diffx;\n const DdE1xQ = sign * (dx * e1CrossDiffx + dy * e1CrossDiffy + dz * e1CrossDiffz);\n\n if (DdE1xQ < 0) {\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n return;\n }\n\n // check if b1 + b2 > 1\n if (DdQxE2 + DdE1xQ > DdN) {\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n return;\n }\n\n // compute intersection distance\n const QdN = -sign * (diffx * nx + diffy * ny + diffz * nz);\n\n if (QdN < 0) {\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n return;\n }\n\n const t = QdN / DdN;\n\n // check if intersection is within ray length\n if (t <= length) {\n out.hit = true;\n out.fraction = t / length;\n out.frontFacing = sign < 0;\n } else {\n out.hit = false;\n out.fraction = 0;\n out.frontFacing = false;\n }\n}\n\n/**\n * Test if a ray intersects an axis-aligned bounding box.\n * Uses slab-based algorithm that handles parallel rays correctly.\n *\n * @param origin ray origin\n * @param direction ray direction\n * @param length ray length\n * @param aabb AABB to test against\n * @returns true if ray intersects the AABB, false otherwise\n */\nexport function intersectsBox3(origin: Vec3, direction: Vec3, length: number, aabb: Box3): boolean {\n let tmin = 0;\n let tmax = length;\n\n for (let i = 0; i < 3; i++) {\n const d = direction[i];\n\n if (Math.abs(d) < 1e-10) {\n // ray is parallel to slab: check if origin is within slab\n if (origin[i] < aabb[i] || origin[i] > aabb[i + 3]) {\n return false;\n }\n } else {\n // compute intersection times with slab\n const invD = 1 / d;\n let t0 = (aabb[i] - origin[i]) * invD;\n let t1 = (aabb[i + 3] - origin[i]) * invD;\n\n if (invD < 0) {\n const temp = t0;\n t0 = t1;\n t1 = temp;\n }\n\n tmin = Math.max(tmin, t0);\n tmax = Math.min(tmax, t1);\n\n if (tmax < tmin) {\n return false;\n }\n }\n }\n\n return true;\n}\n"],"names":[],"mappings":"AAcA;;;AAGG;SACa,8BAA8B,GAAA;IAC1C,OAAO;AACH,QAAA,QAAQ,EAAE,CAAC;AACX,QAAA,GAAG,EAAE,KAAK;AACV,QAAA,WAAW,EAAE,KAAK;KACrB;AACL;AAEA;;;;;;;;;;;;AAYG;SACa,kBAAkB,CAC9B,GAA6B,EAC7B,MAAY,EACZ,SAAe,EACf,MAAc,EACd,CAAO,EACP,CAAO,EACP,CAAO,EACP,eAAwB,EAAA;;IAGxB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;IAGvB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;IAGvB,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG;IAChC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG;IAChC,MAAM,EAAE,GAAG,GA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GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI;AAEzC,YAAA,IAAI,IAAI,GAAG,CAAC,EAAE;gBACV,MAAM,IAAI,GAAG,EAAE;gBACf,EAAE,GAAG,EAAE;gBACP,EAAE,GAAG,IAAI;YACb;YAEA,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YACzB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;AAEzB,YAAA,IAAI,IAAI,GAAG,IAAI,EAAE;AACb,gBAAA,OAAO,KAAK;YAChB;QACJ;IACJ;AAEA,IAAA,OAAO,IAAI;AACf;;;;"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Calculates the closest point on a line segment to a given point
3
+ * @param out Output parameter for the closest point
4
+ * @param point The point
5
+ * @param a First endpoint of the segment
6
+ * @param b Second endpoint of the segment
7
+ */
8
+ function closestPoint(out, point, a, b) {
9
+ const pqx = b[0] - a[0];
10
+ const pqz = b[1] - a[1];
11
+ const dx = point[0] - a[0];
12
+ const dz = point[1] - a[1];
13
+ const d = pqx * pqx + pqz * pqz;
14
+ let t = pqx * dx + pqz * dz;
15
+ if (d > 0)
16
+ t /= d;
17
+ if (t < 0)
18
+ t = 0;
19
+ else if (t > 1)
20
+ t = 1;
21
+ out[0] = a[0] + t * pqx;
22
+ out[1] = a[1] + t * pqz;
23
+ return out;
24
+ }
25
+ /**
26
+ * Tests whether the two closed segments a-b and c-d intersect. Collinear
27
+ * (overlapping) segments are treated as non-intersecting; touching at an
28
+ * endpoint counts as an intersection.
29
+ *
30
+ * @param a first endpoint of the first segment
31
+ * @param b second endpoint of the first segment
32
+ * @param c first endpoint of the second segment
33
+ * @param d second endpoint of the second segment
34
+ * @returns true if the segments intersect
35
+ */
36
+ function intersects(a, b, c, d) {
37
+ const rx = b[0] - a[0];
38
+ const ry = b[1] - a[1];
39
+ const ex = d[0] - c[0];
40
+ const ey = d[1] - c[1];
41
+ const denom = rx * ey - ry * ex;
42
+ if (denom === 0)
43
+ return false; // parallel or collinear
44
+ const wx = c[0] - a[0];
45
+ const wy = c[1] - a[1];
46
+ const u = (wx * ey - wy * ex) / denom; // parameter along a-b
47
+ const v = (wx * ry - wy * rx) / denom; // parameter along c-d
48
+ return u >= 0 && u <= 1 && v >= 0 && v <= 1;
49
+ }
50
+ /**
51
+ * Computes the intersection point of the two closed segments a-b and c-d,
52
+ * writing it to `out`. Returns `out` when the segments intersect, or `null`
53
+ * when they do not (including parallel/collinear segments).
54
+ *
55
+ * @param out output parameter for the intersection point
56
+ * @param a first endpoint of the first segment
57
+ * @param b second endpoint of the first segment
58
+ * @param c first endpoint of the second segment
59
+ * @param d second endpoint of the second segment
60
+ * @returns out if the segments intersect, otherwise null
61
+ */
62
+ function intersection(out, a, b, c, d) {
63
+ const rx = b[0] - a[0];
64
+ const ry = b[1] - a[1];
65
+ const ex = d[0] - c[0];
66
+ const ey = d[1] - c[1];
67
+ const denom = rx * ey - ry * ex;
68
+ if (denom === 0)
69
+ return null;
70
+ const wx = c[0] - a[0];
71
+ const wy = c[1] - a[1];
72
+ const u = (wx * ey - wy * ex) / denom;
73
+ const v = (wx * ry - wy * rx) / denom;
74
+ if (u < 0 || u > 1 || v < 0 || v > 1)
75
+ return null;
76
+ out[0] = a[0] + u * rx;
77
+ out[1] = a[1] + u * ry;
78
+ return out;
79
+ }
80
+
81
+ export { closestPoint, intersection, intersects };
82
+ //# sourceMappingURL=segment2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segment2.js","sources":["../../src/shapes/segment2.ts"],"sourcesContent":["import type { Vec2 } from '../core/vec2';\n\n/**\n * Calculates the closest point on a line segment to a given point\n * @param out Output parameter for the closest point\n * @param point The point\n * @param a First endpoint of the segment\n * @param b Second endpoint of the segment\n */\nexport function closestPoint(out: Vec2, point: Vec2, a: Vec2, b: Vec2): Vec2 {\n const pqx = b[0] - a[0];\n const pqz = b[1] - a[1];\n const dx = point[0] - a[0];\n const dz = point[1] - a[1];\n\n const d = pqx * pqx + pqz * pqz;\n let t = pqx * dx + pqz * dz;\n if (d > 0) t /= d;\n if (t < 0) t = 0;\n else if (t > 1) t = 1;\n\n out[0] = a[0] + t * pqx;\n out[1] = a[1] + t * pqz;\n\n return out;\n}\n\n/**\n * Tests whether the two closed segments a-b and c-d intersect. Collinear\n * (overlapping) segments are treated as non-intersecting; touching at an\n * endpoint counts as an intersection.\n *\n * @param a first endpoint of the first segment\n * @param b second endpoint of the first segment\n * @param c first endpoint of the second segment\n * @param d second endpoint of the second segment\n * @returns true if the segments intersect\n */\nexport function intersects(a: Vec2, b: Vec2, c: Vec2, d: Vec2): boolean {\n const rx = b[0] - a[0];\n const ry = b[1] - a[1];\n const ex = d[0] - c[0];\n const ey = d[1] - c[1];\n\n const denom = rx * ey - ry * ex;\n if (denom === 0) return false; // parallel or collinear\n\n const wx = c[0] - a[0];\n const wy = c[1] - a[1];\n const u = (wx * ey - wy * ex) / denom; // parameter along a-b\n const v = (wx * ry - wy * rx) / denom; // parameter along c-d\n\n return u >= 0 && u <= 1 && v >= 0 && v <= 1;\n}\n\n/**\n * Computes the intersection point of the two closed segments a-b and c-d,\n * writing it to `out`. Returns `out` when the segments intersect, or `null`\n * when they do not (including parallel/collinear segments).\n *\n * @param out output parameter for the intersection point\n * @param a first endpoint of the first segment\n * @param b second endpoint of the first segment\n * @param c first endpoint of the second segment\n * @param d second endpoint of the second segment\n * @returns out if the segments intersect, otherwise null\n */\nexport function intersection(out: Vec2, a: Vec2, b: Vec2, c: Vec2, d: Vec2): Vec2 | null {\n const rx = b[0] - a[0];\n const ry = b[1] - a[1];\n const ex = d[0] - c[0];\n const ey = d[1] - c[1];\n\n const denom = rx * ey - ry * ex;\n if (denom === 0) return null;\n\n const wx = c[0] - a[0];\n const wy = c[1] - a[1];\n const u = (wx * ey - wy * ex) / denom;\n const v = (wx * ry - wy * rx) / denom;\n\n if (u < 0 || u > 1 || v < 0 || v > 1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EAAE;IAC/B,IAAI,KAAK,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;IAE5B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACtB,IAAA,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK;AACrC,IAAA,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK;AAErC,IAAA,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,IAAI;AAEjD,IAAA,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE;AACtB,IAAA,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE;AACtB,IAAA,OAAO,GAAG;AACd;;;;"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Creates a new sphere with a default center 0,0,0 and radius 1
3
+ * @returns A new sphere.
4
+ */
5
+ function create() {
6
+ return { center: [0, 0, 0], radius: 1 };
7
+ }
8
+ /**
9
+ * Returns true if a point lies inside (or on the surface of) the sphere.
10
+ *
11
+ * @param sphere the sphere
12
+ * @param point the point to test
13
+ * @returns true if the point is within the sphere's radius
14
+ */
15
+ function containsPoint(sphere, point) {
16
+ const dx = point[0] - sphere.center[0];
17
+ const dy = point[1] - sphere.center[1];
18
+ const dz = point[2] - sphere.center[2];
19
+ return dx * dx + dy * dy + dz * dz <= sphere.radius * sphere.radius;
20
+ }
21
+
22
+ export { containsPoint, create };
23
+ //# sourceMappingURL=sphere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sphere.js","sources":["../../src/shapes/sphere.ts"],"sourcesContent":["import type { Vec3 } from '../core/vec3';\n\n/** A sphere in 3D space */\nexport type Sphere = { center: Vec3; radius: number };\n\n/**\n * Creates a new sphere with a default center 0,0,0 and radius 1\n * @returns A new sphere.\n */\nexport function create(): Sphere {\n return { center: [0, 0, 0], radius: 1 };\n}\n\n/**\n * Returns true if a point lies inside (or on the surface of) the sphere.\n *\n * @param sphere the sphere\n * @param point the point to test\n * @returns true if the point is within the sphere's radius\n */\nexport function containsPoint(sphere: Sphere, point: Vec3): boolean {\n const dx = point[0] - sphere.center[0];\n const dy = point[1] - sphere.center[1];\n const dz = point[2] - sphere.center[2];\n return dx * dx + dy * dy + dz * dz <= sphere.radius * sphere.radius;\n}\n"],"names":[],"mappings":"AAKA;;;AAGG;SACa,MAAM,GAAA;AAClB,IAAA,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;AAC3C;AAEA;;;;;;AAMG;AACG,SAAU,aAAa,CAAC,MAAc,EAAE,KAAW,EAAA;AACrD,IAAA,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACtC,IAAA,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACtC,IAAA,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACtC,IAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;AACvE;;;;"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Returns the signed area of the triangle (a, b, c). The result is positive when
3
+ * the vertices wind counter-clockwise, negative when they wind clockwise, and
4
+ * zero when the three points are collinear.
5
+ *
6
+ * @param a the first vertex of the triangle.
7
+ * @param b the second vertex of the triangle.
8
+ * @param c the third vertex of the triangle.
9
+ * @returns the signed area.
10
+ */
11
+ function signedArea(a, b, c) {
12
+ return ((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1])) / 2;
13
+ }
14
+ /**
15
+ * Returns the (non-negative) area of the triangle (a, b, c).
16
+ *
17
+ * @param a the first vertex of the triangle.
18
+ * @param b the second vertex of the triangle.
19
+ * @param c the third vertex of the triangle.
20
+ * @returns the absolute area.
21
+ */
22
+ function area(a, b, c) {
23
+ return Math.abs(signedArea(a, b, c));
24
+ }
25
+ /**
26
+ * Computes the centroid of the triangle (a, b, c).
27
+ *
28
+ * @param out the output vector to store the result.
29
+ * @param a the first vertex of the triangle.
30
+ * @param b the second vertex of the triangle.
31
+ * @param c the third vertex of the triangle.
32
+ * @returns out.
33
+ */
34
+ function centroid(out, a, b, c) {
35
+ out[0] = (a[0] + b[0] + c[0]) / 3;
36
+ out[1] = (a[1] + b[1] + c[1]) / 3;
37
+ return out;
38
+ }
39
+ /**
40
+ * Computes the axis-aligned bounding box of the triangle (a, b, c).
41
+ *
42
+ * @param out the output box to store the result.
43
+ * @param a the first vertex of the triangle.
44
+ * @param b the second vertex of the triangle.
45
+ * @param c the third vertex of the triangle.
46
+ * @returns out.
47
+ */
48
+ function bounds(out, a, b, c) {
49
+ out[0] = Math.min(a[0], b[0], c[0]);
50
+ out[1] = Math.min(a[1], b[1], c[1]);
51
+ out[2] = Math.max(a[0], b[0], c[0]);
52
+ out[3] = Math.max(a[1], b[1], c[1]);
53
+ return out;
54
+ }
55
+ /**
56
+ * Tests whether a point lies inside the triangle (a, b, c). Works for either
57
+ * winding order; points on an edge or vertex are considered inside.
58
+ *
59
+ * @param a the first vertex of the triangle.
60
+ * @param b the second vertex of the triangle.
61
+ * @param c the third vertex of the triangle.
62
+ * @param point the point to test.
63
+ * @returns true if the point is inside (or on the boundary of) the triangle.
64
+ */
65
+ function containsPoint(a, b, c, point) {
66
+ const px = point[0];
67
+ const py = point[1];
68
+ // Sign of the point relative to each directed edge. Inside iff the point is
69
+ // on the same side of all three (allowing zero for the boundary).
70
+ const d1 = (px - b[0]) * (a[1] - b[1]) - (a[0] - b[0]) * (py - b[1]);
71
+ const d2 = (px - c[0]) * (b[1] - c[1]) - (b[0] - c[0]) * (py - c[1]);
72
+ const d3 = (px - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (py - a[1]);
73
+ const hasNeg = d1 < 0 || d2 < 0 || d3 < 0;
74
+ const hasPos = d1 > 0 || d2 > 0 || d3 > 0;
75
+ return !(hasNeg && hasPos);
76
+ }
77
+
78
+ export { area, bounds, centroid, containsPoint, signedArea };
79
+ //# sourceMappingURL=triangle2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triangle2.js","sources":["../../src/shapes/triangle2.ts"],"sourcesContent":["import type { Vec2 } from '../core/vec2';\nimport type { Box2 } from './box2';\n\n/**\n * Returns the signed area of the triangle (a, b, c). The result is positive when\n * the vertices wind counter-clockwise, negative when they wind clockwise, and\n * zero when the three points are collinear.\n *\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns the signed area.\n */\nexport function signedArea(a: Vec2, b: Vec2, c: Vec2): number {\n return ((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1])) / 2;\n}\n\n/**\n * Returns the (non-negative) area of the triangle (a, b, c).\n *\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns the absolute area.\n */\nexport function area(a: Vec2, b: Vec2, c: Vec2): number {\n return Math.abs(signedArea(a, b, c));\n}\n\n/**\n * Computes the centroid of the triangle (a, b, c).\n *\n * @param out the output vector to store the result.\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns out.\n */\nexport function centroid(out: Vec2, a: Vec2, b: Vec2, c: Vec2): Vec2 {\n out[0] = (a[0] + b[0] + c[0]) / 3;\n out[1] = (a[1] + b[1] + c[1]) / 3;\n return out;\n}\n\n/**\n * Computes the axis-aligned bounding box of the triangle (a, b, c).\n *\n * @param out the output box to store the result.\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns out.\n */\nexport function bounds(out: Box2, a: Vec2, b: Vec2, c: Vec2): Box2 {\n out[0] = Math.min(a[0], b[0], c[0]);\n out[1] = Math.min(a[1], b[1], c[1]);\n out[2] = Math.max(a[0], b[0], c[0]);\n out[3] = Math.max(a[1], b[1], c[1]);\n return out;\n}\n\n/**\n * Tests whether a point lies inside the triangle (a, b, c). Works for either\n * winding order; points on an edge or vertex are considered inside.\n *\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @param point the point to test.\n * @returns true if the point is inside (or on the boundary of) the triangle.\n */\nexport function containsPoint(a: Vec2, b: Vec2, c: Vec2, point: Vec2): boolean {\n const px = point[0];\n const py = point[1];\n\n // Sign of the point relative to each directed edge. Inside iff the point is\n // on the same side of all three (allowing zero for the boundary).\n const d1 = (px - b[0]) * (a[1] - b[1]) - (a[0] - b[0]) * (py - b[1]);\n const d2 = (px - c[0]) * (b[1] - c[1]) - (b[0] - c[0]) * (py - c[1]);\n const d3 = (px - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (py - a[1]);\n\n const hasNeg = d1 < 0 || d2 < 0 || d3 < 0;\n const hasPos = d1 > 0 || d2 > 0 || d3 > 0;\n\n return !(hasNeg && hasPos);\n}\n"],"names":[],"mappings":"AAGA;;;;;;;;;AASG;SACa,UAAU,CAAC,CAAO,EAAE,CAAO,EAAE,CAAO,EAAA;IAChD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAA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,MAAM,MAAM,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;AACzC,IAAA,MAAM,MAAM,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;AAEzC,IAAA,OAAO,EAAE,MAAM,IAAI,MAAM,CAAC;AAC9B;;;;"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Computes the axis-aligned bounding box of a triangle defined by three vertices.
3
+ * @param out the output box to store the result.
4
+ * @param a the first vertex of the triangle.
5
+ * @param b the second vertex of the triangle.
6
+ * @param c the third vertex of the triangle.
7
+ * @returns the output box containing the axis-aligned bounding box of the triangle.
8
+ */
9
+ function bounds(out, a, b, c) {
10
+ out[0] = Math.min(a[0], b[0], c[0]);
11
+ out[1] = Math.min(a[1], b[1], c[1]);
12
+ out[2] = Math.min(a[2], b[2], c[2]);
13
+ out[3] = Math.max(a[0], b[0], c[0]);
14
+ out[4] = Math.max(a[1], b[1], c[1]);
15
+ out[5] = Math.max(a[2], b[2], c[2]);
16
+ return out;
17
+ }
18
+ /**
19
+ * Computes the normal vector of a triangle defined by three vertices.
20
+ * @param out the output vector to store the result.
21
+ * @param a the first vertex of the triangle.
22
+ * @param b the second vertex of the triangle.
23
+ * @param c the third vertex of the triangle.
24
+ * @returns the output vector containing the normal of the triangle.
25
+ */
26
+ function normal(out, a, b, c) {
27
+ const abx = b[0] - a[0];
28
+ const aby = b[1] - a[1];
29
+ const abz = b[2] - a[2];
30
+ const acx = c[0] - a[0];
31
+ const acy = c[1] - a[1];
32
+ const acz = c[2] - a[2];
33
+ out[0] = aby * acz - abz * acy;
34
+ out[1] = abz * acx - abx * acz;
35
+ out[2] = abx * acy - aby * acx;
36
+ const length = Math.sqrt(out[0] * out[0] + out[1] * out[1] + out[2] * out[2]);
37
+ if (length > 0) {
38
+ out[0] /= length;
39
+ out[1] /= length;
40
+ out[2] /= length;
41
+ }
42
+ return out;
43
+ }
44
+ /**
45
+ * Computes the centroid of a triangle defined by three vertices.
46
+ * @param out the output vector to store the result.
47
+ * @param a the first vertex of the triangle.
48
+ * @param b the second vertex of the triangle.
49
+ * @param c the third vertex of the triangle.
50
+ * @returns the output vector containing the centroid of the triangle.
51
+ */
52
+ function centroid(out, a, b, c) {
53
+ out[0] = (a[0] + b[0] + c[0]) / 3;
54
+ out[1] = (a[1] + b[1] + c[1]) / 3;
55
+ out[2] = (a[2] + b[2] + c[2]) / 3;
56
+ return out;
57
+ }
58
+
59
+ export { bounds, centroid, normal };
60
+ //# sourceMappingURL=triangle3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triangle3.js","sources":["../../src/shapes/triangle3.ts"],"sourcesContent":["import type { Vec3 } from '../core/vec3';\nimport type { Box3 } from './box3';\n\n/**\n * Computes the axis-aligned bounding box of a triangle defined by three vertices.\n * @param out the output box to store the result.\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns the output box containing the axis-aligned bounding box of the triangle.\n */\nexport function bounds(out: Box3, a: Vec3, b: Vec3, c: Vec3): Box3 {\n out[0] = Math.min(a[0], b[0], c[0]);\n out[1] = Math.min(a[1], b[1], c[1]);\n out[2] = Math.min(a[2], b[2], c[2]);\n\n out[3] = Math.max(a[0], b[0], c[0]);\n out[4] = Math.max(a[1], b[1], c[1]);\n out[5] = Math.max(a[2], b[2], c[2]);\n\n return out;\n}\n\n/**\n * Computes the normal vector of a triangle defined by three vertices.\n * @param out the output vector to store the result.\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns the output vector containing the normal of the triangle.\n */\nexport function normal(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3 {\n const abx = b[0] - a[0];\n const aby = b[1] - a[1];\n const abz = b[2] - a[2];\n\n const acx = c[0] - a[0];\n const acy = c[1] - a[1];\n const acz = c[2] - a[2];\n\n out[0] = aby * acz - abz * acy;\n out[1] = abz * acx - abx * acz;\n out[2] = abx * acy - aby * acx;\n\n const length = Math.sqrt(out[0] * out[0] + out[1] * out[1] + out[2] * out[2]);\n\n if (length > 0) {\n out[0] /= length;\n out[1] /= length;\n out[2] /= length;\n }\n\n return out;\n}\n\n/**\n * Computes the centroid of a triangle defined by three vertices.\n * @param out the output vector to store the result.\n * @param a the first vertex of the triangle.\n * @param b the second vertex of the triangle.\n * @param c the third vertex of the triangle.\n * @returns the output vector containing the centroid of the triangle.\n */\nexport function centroid(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3 {\n out[0] = (a[0] + b[0] + c[0]) / 3;\n out[1] = (a[1] + b[1] + c[1]) / 3;\n out[2] = (a[2] + b[2] + c[2]) / 3;\n\n return out;\n}\n"],"names":[],"mappings":"AAGA;;;;;;;AAOG;AACG,SAAU,MAAM,CAAC,GAAS,EAAE,CAAO,EAAE,CAAO,EAAE,CAAO,EAAA;IACvD,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GA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AAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAE7E,IAAA,IAAI,MAAM,GAAG,CAAC,EAAE;AACZ,QAAA,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM;AAChB,QAAA,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM;AAChB,QAAA,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM;IACpB;AAEA,IAAA,OAAO,GAAG;AACd;AAEA;;;;;;;AAOG;AACG,SAAU,QAAQ,CAAC,GAAS,EAAE,CAAO,EAAE,CAAO,EAAE,CAAO,EAAA;IACzD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAEjC,IAAA,OAAO,GAAG;AACd;;;;"}
@@ -0,0 +1,50 @@
1
+ export * from './parse.js';
2
+ /** A linear-sRGB color: [r, g, b] floats in [0, 1]. */
3
+ export type Color = [r: number, g: number, b: number];
4
+ /** Accepted input types for creating or parsing a Color. */
5
+ export type ColorInput = string | number | [number, number, number];
6
+ /** Create a new Color initialized to black [0, 0, 0]. */
7
+ export declare function create(): Color;
8
+ /** Create a new Color with the given linear r, g, b values. */
9
+ export declare function fromValues(r: number, g: number, b: number): Color;
10
+ /** Create a new Color that is a copy of `c`. */
11
+ export declare function clone(c: Color): Color;
12
+ /** Copy the values from `src` into `out`. Returns `out`. */
13
+ export declare function copy(out: Color, src: Color): Color;
14
+ /** Set the linear r, g, b components of `out` directly. Returns `out`. */
15
+ export declare function set(out: Color, r: number, g: number, b: number): Color;
16
+ /** Set all three channels of `out` to the same linear value `s` (a gray). Returns `out`. */
17
+ export declare function setScalar(out: Color, s: number): Color;
18
+ /**
19
+ * Set `out` from an sRGB gamma-encoded [r, g, b] array with values in [0, 1].
20
+ * Converts from sRGB gamma space to linear. Returns `out`.
21
+ */
22
+ export declare function setFromSRGB(out: Color, srgb: [number, number, number]): Color;
23
+ /** Create a new Color from an sRGB gamma-encoded [r, g, b] array with values in [0, 1]. */
24
+ export declare function fromSRGB(srgb: [number, number, number]): Color;
25
+ /** Write the sRGB gamma-encoded [r, g, b] of a linear Color into `out` (values [0, 1]). */
26
+ export declare function toSRGB(out: [number, number, number], c: Color): [number, number, number];
27
+ /** Create a CSS `rgb(...)` string in sRGB gamma space (for HTML/canvas use). */
28
+ export declare function toCSS(c: Color): string;
29
+ /** Convert to a 0xRRGGBB integer in sRGB gamma space. */
30
+ export declare function toHex(c: Color): number;
31
+ /** Convert to a 6-digit sRGB hex string without a leading '#', e.g. 'ff8800'. */
32
+ export declare function toHexString(c: Color): string;
33
+ /** Add `a + b` component-wise into `out`. Returns `out`. */
34
+ export declare function add(out: Color, a: Color, b: Color): Color;
35
+ /** Add scalar `s` to each channel of `a` into `out`. Returns `out`. */
36
+ export declare function addScalar(out: Color, a: Color, s: number): Color;
37
+ /** Subtract `a - b` component-wise into `out`. Returns `out`. */
38
+ export declare function sub(out: Color, a: Color, b: Color): Color;
39
+ /** Multiply `a * b` component-wise into `out` (tinting). Returns `out`. */
40
+ export declare function multiply(out: Color, a: Color, b: Color): Color;
41
+ /** Scale each channel of `a` by `s` into `out` (brightness). Returns `out`. */
42
+ export declare function multiplyScalar(out: Color, a: Color, s: number): Color;
43
+ /** Linearly interpolate from `a` to `b` by `t` into `out` (physically-correct blend). Returns `out`. */
44
+ export declare function lerp(out: Color, a: Color, b: Color, t: number): Color;
45
+ /** Clamp each channel of `c` to [0, 1] into `out`. Returns `out`. */
46
+ export declare function clamp(out: Color, c: Color): Color;
47
+ /** Whether `a` and `b` are equal, within an optional per-channel `epsilon` (default exact). */
48
+ export declare function equals(a: Color, b: Color, epsilon?: number): boolean;
49
+ /** Relative luminance in [0, 1] (Rec. 709 weights, on linear light). */
50
+ export declare function luminance(c: Color): number;
@@ -0,0 +1,15 @@
1
+ import type { Color } from './color.js';
2
+ /** Convert a single sRGB gamma-encoded channel [0, 1] to linear light [0, 1]. */
3
+ export declare function srgbToLinear(c: number): number;
4
+ /** Convert a single linear light channel [0, 1] to sRGB gamma-encoded [0, 1]. */
5
+ export declare function linearToSrgb(c: number): number;
6
+ /**
7
+ * Convert a linear-sRGB Color to linear Display-P3 primaries, into `out`. Returns `out`.
8
+ * (Both spaces share the sRGB transfer curve; this changes only the primaries.)
9
+ */
10
+ export declare function linearSrgbToLinearDisplayP3(out: Color, c: Color): Color;
11
+ /**
12
+ * Convert a linear Display-P3 Color to linear-sRGB primaries, into `out`. Returns `out`.
13
+ * Colors outside the sRGB gamut yield channels outside [0, 1] — clamp if needed.
14
+ */
15
+ export declare function linearDisplayP3ToLinearSrgb(out: Color, c: Color): Color;
@@ -0,0 +1,28 @@
1
+ import type { Color } from './color.js';
2
+ /** A hue-saturation-lightness color: [h, s, l], all in [0, 1] (hue wraps). */
3
+ export type HSL = [hue: number, saturation: number, lightness: number];
4
+ /** Create a new HSL initialized to [0, 0, 0] (black). */
5
+ export declare function create(): HSL;
6
+ /** Create a new HSL with the given h, s, l values (all in [0, 1]). */
7
+ export declare function fromValues(h: number, s: number, l: number): HSL;
8
+ /** Create a new HSL that is a copy of `a`. */
9
+ export declare function clone(a: HSL): HSL;
10
+ /** Copy the values from `src` into `out`. Returns `out`. */
11
+ export declare function copy(out: HSL, src: HSL): HSL;
12
+ /** Set the h, s, l components of `out` directly. Returns `out`. */
13
+ export declare function set(out: HSL, h: number, s: number, l: number): HSL;
14
+ /** Write the HSL of a linear Color into `out`. Returns `out`. */
15
+ export declare function fromColor(out: HSL, c: Color): HSL;
16
+ /** Write the linear Color of an HSL into `out`. Returns `out`. */
17
+ export declare function toColor(out: Color, a: HSL): Color;
18
+ /**
19
+ * Interpolate from `a` to `b` by `t` into `out`, taking the shortest path around
20
+ * the hue wheel (so e.g. 350°→10° passes through 0°, not all the way back).
21
+ * Returns `out`.
22
+ */
23
+ export declare function lerp(out: HSL, a: HSL, b: HSL, t: number): HSL;
24
+ /**
25
+ * Offset `a` by (dh, ds, dl) into `out`: hue wraps into [0, 1), saturation and
26
+ * lightness are clamped to [0, 1]. Returns `out`.
27
+ */
28
+ export declare function offset(out: HSL, a: HSL, dh: number, ds: number, dl: number): HSL;
@@ -0,0 +1,5 @@
1
+ export * as color from './color.js';
2
+ export * as colorspace from './colorspace.js';
3
+ export * as hsl from './hsl.js';
4
+ export type { Color, ColorInput } from './color.js';
5
+ export type { HSL } from './hsl.js';
@@ -0,0 +1,15 @@
1
+ import type { Color, ColorInput } from './color.js';
2
+ /**
3
+ * Parse any supported color input and write the result into `out`. Returns `out`.
4
+ *
5
+ * Supported inputs:
6
+ * - CSS hex strings: '#f00', '#ff0000'
7
+ * - CSS rgb(): 'rgb(255, 0, 0)', 'rgb(100%, 0%, 0%)'
8
+ * - CSS hsl(): 'hsl(0, 100%, 50%)'
9
+ * - 0xRRGGBB integers: 0xff0000 (sRGB gamma)
10
+ * - Named CSS colors: 'red', 'lime', 'deepskyblue', ...
11
+ * - [r, g, b] array: treated as already-linear [0, 1]
12
+ */
13
+ export declare function setFromColorInput(out: Color, input: ColorInput): Color;
14
+ /** Parse any supported color input into a new Color, or null if unrecognised. */
15
+ export declare function fromColorInput(input: ColorInput): Color | null;
@@ -0,0 +1,29 @@
1
+ export declare const DEGREES_TO_RADIANS: number;
2
+ export declare const RADIANS_TO_DEGREES: number;
3
+ /**
4
+ * Converts Degrees To Radians
5
+ *
6
+ * @param a Angle in Degrees
7
+ */
8
+ export declare function degreesToRadians(degrees: number): number;
9
+ /**
10
+ * Converts Radians To Degrees
11
+ *
12
+ * @param a Angle in Radians
13
+ */
14
+ export declare function radiansToDegrees(radians: number): number;
15
+ /**
16
+ * Wraps an angle (in radians) into the range (-π, π].
17
+ *
18
+ * @param a the angle to wrap
19
+ * @returns the angle wrapped into (-π, π]
20
+ */
21
+ export declare function wrapAngle(a: number): number;
22
+ /**
23
+ * Calculates the shortest signed difference between two angles (in radians).
24
+ *
25
+ * @param current the current angle
26
+ * @param target the target angle
27
+ * @returns the shortest signed difference in (-π, π]
28
+ */
29
+ export declare function deltaAngle(current: number, target: number): number;
@@ -0,0 +1,4 @@
1
+ export type MutableArrayLike<T> = {
2
+ [index: number]: T;
3
+ length: number;
4
+ };
@@ -0,0 +1,78 @@
1
+ import type { Mat4 } from './mat4.js';
2
+ import type { Quat } from './quat.js';
3
+ /** Euler orders */
4
+ export type EulerOrder = 'xyz' | 'xzy' | 'yxz' | 'yzx' | 'zxy' | 'zyx';
5
+ /** A Euler in 3D space, with an optional order (default is 'xyz') */
6
+ export type Euler = [x: number, y: number, z: number, order?: EulerOrder];
7
+ /**
8
+ * Creates a new Euler with default values (0, 0, 0, 'xyz').
9
+ */
10
+ export declare function create(): Euler;
11
+ /**
12
+ * Creates a new Euler from the given values.
13
+ * @param x The x rotation in radians.
14
+ * @param y The y rotation in radians.
15
+ * @param z The z rotation in radians.
16
+ * @param order The order of rotation.
17
+ * @returns A new Euler.
18
+ */
19
+ export declare function fromValues(x: number, y: number, z: number, order: EulerOrder): Euler;
20
+ /**
21
+ * Sets a given Euler from the given values.
22
+ * @param x The x rotation in radians.
23
+ * @param y The y rotation in radians.
24
+ * @param z The z rotation in radians.
25
+ * @param order The order of rotation.
26
+ * @returns The output Euler.
27
+ */
28
+ export declare function set(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler;
29
+ /**
30
+ * Sets Euler angle radians from given degrees
31
+ * @param out The output Euler.
32
+ * @param x The x rotation in degrees.
33
+ * @param y The y rotation in degrees.
34
+ * @param z The z rotation in degrees.
35
+ * @param order The order of rotation.
36
+ * @returns The output Euler.
37
+ */
38
+ export declare function fromDegrees(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler;
39
+ /**
40
+ * Sets the Euler angles from a rotation matrix.
41
+ * @param out The output Euler.
42
+ * @param rotationMatrix The input rotation matrix.
43
+ * @param order The order of the Euler angles.
44
+ * @returns The output Euler.
45
+ */
46
+ export declare function fromRotationMat4(out: Euler, rotationMatrix: Mat4, order?: EulerOrder): Euler;
47
+ /**
48
+ * Returns whether or not the euler angles have exactly the same elements in the same position (when compared with ===)
49
+ *
50
+ * @param a The first euler.
51
+ * @param b The second euler.
52
+ * @returns True if the euler angles are equal, false otherwise.
53
+ */
54
+ export declare function exactEquals(a: Euler, b: Euler): boolean;
55
+ /**
56
+ * Returns whether or not the euler angles have approximately the same elements in the same position.
57
+ *
58
+ * @param a The first euler.
59
+ * @param b The second euler.
60
+ * @returns True if the euler angles are equal, false otherwise.
61
+ */
62
+ export declare function equals(a: Euler, b: Euler): boolean;
63
+ /**
64
+ * Sets the Euler angles from a quaternion.
65
+ * @param out The output Euler.
66
+ * @param q The input quaternion. Assumed to be normalized (unit length).
67
+ * @param order The order of the Euler.
68
+ * @returns The output Euler
69
+ */
70
+ export declare function fromQuat(out: Euler, q: Quat, order: EulerOrder): Euler;
71
+ /**
72
+ * Reorders the Euler based on the specified order.
73
+ * @param out The output Euler.
74
+ * @param a The input Euler.
75
+ * @param order The order of the Euler.
76
+ * @returns The output Euler.
77
+ */
78
+ export declare function reorder(out: Euler, a: Euler, order: EulerOrder): Euler;
@@ -0,0 +1,27 @@
1
+ export * from './scalar.js';
2
+ export * from './angle.js';
3
+ export type { MutableArrayLike } from './arrays.js';
4
+ export * as vec2 from './vec2.js';
5
+ export type { Vec2 } from './vec2.js';
6
+ export * as vec3 from './vec3.js';
7
+ export type { Vec3 } from './vec3.js';
8
+ export * as vec4 from './vec4.js';
9
+ export type { Vec4 } from './vec4.js';
10
+ export * as euler from './euler.js';
11
+ export type { Euler, EulerOrder } from './euler.js';
12
+ export * as quat from './quat.js';
13
+ export type { Quat } from './quat.js';
14
+ export * as quat2 from './quat2.js';
15
+ export type { Quat2 } from './quat2.js';
16
+ export * as mat2 from './mat2.js';
17
+ export type { Mat2 } from './mat2.js';
18
+ export * as mat2d from './mat2d.js';
19
+ export type { Mat2d } from './mat2d.js';
20
+ export * as mat3 from './mat3.js';
21
+ export type { Mat3 } from './mat3.js';
22
+ export * as mat4 from './mat4.js';
23
+ export type { Mat4 } from './mat4.js';
24
+ export * as spherical from './spherical.js';
25
+ export type { Spherical } from './spherical.js';
26
+ export * as polar from './polar.js';
27
+ export type { Polar } from './polar.js';