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,120 @@
1
+ /**
2
+ * Returns a random float in the range [min, max).
3
+ * @param random the random generator to use
4
+ * @param min the minimum value (inclusive)
5
+ * @param max the maximum value (exclusive)
6
+ */
7
+ function float(random, min, max) {
8
+ return random() * (max - min) + min;
9
+ }
10
+ /**
11
+ * Returns a random integer in the range [min, max] (inclusive).
12
+ * @param random the random generator to use
13
+ * @param min the minimum value (inclusive)
14
+ * @param max the maximum value (inclusive)
15
+ */
16
+ function int(random, min, max) {
17
+ return Math.floor(random() * (max - min + 1)) + min;
18
+ }
19
+ /**
20
+ * Returns a random boolean.
21
+ * @param random the random generator to use
22
+ * @param chance the probability of returning true, in the range [0, 1]. Defaults to 0.5.
23
+ */
24
+ function bool(random, chance = 0.5) {
25
+ return random() < chance;
26
+ }
27
+ /**
28
+ * Returns a random sign, either 1 or -1.
29
+ * @param random the random generator to use
30
+ * @param plusChance the probability of returning 1, in the range [0, 1]. Defaults to 0.5.
31
+ */
32
+ function sign(random, plusChance = 0.5) {
33
+ return random() < plusChance ? 1 : -1;
34
+ }
35
+ /**
36
+ * Returns a random item from an array.
37
+ * @param random the random generator to use
38
+ * @param items the array to choose from
39
+ * @throws if the array is empty
40
+ */
41
+ function choice(random, items) {
42
+ if (items.length === 0) {
43
+ throw new Error('cannot choose from an empty array');
44
+ }
45
+ return items[Math.floor(random() * items.length) % items.length];
46
+ }
47
+ /**
48
+ * Writes a random unit-length Vec2 into out.
49
+ * @param out the receiving vector
50
+ * @param random the random generator to use
51
+ * @returns out
52
+ */
53
+ function vec2(out, random) {
54
+ const r = random() * 2.0 * Math.PI;
55
+ out[0] = Math.cos(r);
56
+ out[1] = Math.sin(r);
57
+ return out;
58
+ }
59
+ /**
60
+ * Writes a random unit-length Vec3 into out.
61
+ * @param out the receiving vector
62
+ * @param random the random generator to use
63
+ * @returns out
64
+ */
65
+ function vec3(out, random) {
66
+ const r = random() * 2.0 * Math.PI;
67
+ const z = random() * 2.0 - 1.0;
68
+ const zScale = Math.sqrt(1.0 - z * z);
69
+ out[0] = Math.cos(r) * zScale;
70
+ out[1] = Math.sin(r) * zScale;
71
+ out[2] = z;
72
+ return out;
73
+ }
74
+ /**
75
+ * Writes a random unit-length Vec4 into out.
76
+ * @param out the receiving vector
77
+ * @param random the random generator to use
78
+ * @returns out
79
+ */
80
+ function vec4(out, random) {
81
+ // Marsaglia, George. Choosing a Point from the Surface of a
82
+ // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.
83
+ // http://projecteuclid.org/euclid.aoms/1177692644;
84
+ let rand = random();
85
+ const v1 = rand * 2 - 1;
86
+ const v2 = (4 * random() - 2) * Math.sqrt(rand * -rand + rand);
87
+ const s1 = v1 * v1 + v2 * v2;
88
+ rand = random();
89
+ const v3 = rand * 2 - 1;
90
+ const v4 = (4 * random() - 2) * Math.sqrt(rand * -rand + rand);
91
+ const s2 = v3 * v3 + v4 * v4;
92
+ const d = Math.sqrt((1 - s1) / s2);
93
+ out[0] = v1;
94
+ out[1] = v2;
95
+ out[2] = v3 * d;
96
+ out[3] = v4 * d;
97
+ return out;
98
+ }
99
+ /**
100
+ * Writes a random unit quaternion into out.
101
+ * @param out the receiving quaternion
102
+ * @param random the random generator to use
103
+ * @returns out
104
+ */
105
+ function quat(out, random) {
106
+ // Implementation of http://planning.cs.uiuc.edu/node198.html
107
+ const u1 = random();
108
+ const u2 = random();
109
+ const u3 = random();
110
+ const sqrt1MinusU1 = Math.sqrt(1 - u1);
111
+ const sqrtU1 = Math.sqrt(u1);
112
+ out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
113
+ out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
114
+ out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
115
+ out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
116
+ return out;
117
+ }
118
+
119
+ export { bool, choice, float, int, quat, sign, vec2, vec3, vec4 };
120
+ //# sourceMappingURL=random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.js","sources":["../../src/random/random.ts"],"sourcesContent":["import type { Quat } from '../core/quat';\nimport type { Vec2 } from '../core/vec2';\nimport type { Vec3 } from '../core/vec3';\nimport type { Vec4 } from '../core/vec4';\n\n/** A function that returns a random number in the range [0, 1). */\nexport type RandomGenerator = () => number;\n\n/**\n * Returns a random float in the range [min, max).\n * @param random the random generator to use\n * @param min the minimum value (inclusive)\n * @param max the maximum value (exclusive)\n */\nexport function float(random: RandomGenerator, min: number, max: number): number {\n return random() * (max - min) + min;\n}\n\n/**\n * Returns a random integer in the range [min, max] (inclusive).\n * @param random the random generator to use\n * @param min the minimum value (inclusive)\n * @param max the maximum value (inclusive)\n */\nexport function int(random: RandomGenerator, min: number, max: number): number {\n return Math.floor(random() * (max - min + 1)) + min;\n}\n\n/**\n * Returns a random boolean.\n * @param random the random generator to use\n * @param chance the probability of returning true, in the range [0, 1]. Defaults to 0.5.\n */\nexport function bool(random: RandomGenerator, chance = 0.5): boolean {\n return random() < chance;\n}\n\n/**\n * Returns a random sign, either 1 or -1.\n * @param random the random generator to use\n * @param plusChance the probability of returning 1, in the range [0, 1]. Defaults to 0.5.\n */\nexport function sign(random: RandomGenerator, plusChance = 0.5): number {\n return random() < plusChance ? 1 : -1;\n}\n\n/**\n * Returns a random item from an array.\n * @param random the random generator to use\n * @param items the array to choose from\n * @throws if the array is empty\n */\nexport function choice<T>(random: RandomGenerator, items: T[]): T {\n if (items.length === 0) {\n throw new Error('cannot choose from an empty array');\n }\n return items[Math.floor(random() * items.length) % items.length];\n}\n\n/**\n * Writes a random unit-length Vec2 into out.\n * @param out the receiving vector\n * @param random the random generator to use\n * @returns out\n */\nexport function vec2(out: Vec2, random: RandomGenerator): Vec2 {\n const r = random() * 2.0 * Math.PI;\n out[0] = Math.cos(r);\n out[1] = Math.sin(r);\n return out;\n}\n\n/**\n * Writes a random unit-length Vec3 into out.\n * @param out the receiving vector\n * @param random the random generator to use\n * @returns out\n */\nexport function vec3(out: Vec3, random: RandomGenerator): Vec3 {\n const r = random() * 2.0 * Math.PI;\n const z = random() * 2.0 - 1.0;\n const zScale = Math.sqrt(1.0 - z * z);\n\n out[0] = Math.cos(r) * zScale;\n out[1] = Math.sin(r) * zScale;\n out[2] = z;\n return out;\n}\n\n/**\n * Writes a random unit-length Vec4 into out.\n * @param out the receiving vector\n * @param random the random generator to use\n * @returns out\n */\nexport function vec4(out: Vec4, random: RandomGenerator): Vec4 {\n // Marsaglia, George. Choosing a Point from the Surface of a\n // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.\n // http://projecteuclid.org/euclid.aoms/1177692644;\n let rand = random();\n const v1 = rand * 2 - 1;\n const v2 = (4 * random() - 2) * Math.sqrt(rand * -rand + rand);\n const s1 = v1 * v1 + v2 * v2;\n\n rand = random();\n const v3 = rand * 2 - 1;\n const v4 = (4 * random() - 2) * Math.sqrt(rand * -rand + rand);\n const s2 = v3 * v3 + v4 * v4;\n\n const d = Math.sqrt((1 - s1) / s2);\n out[0] = v1;\n out[1] = v2;\n out[2] = v3 * d;\n out[3] = v4 * d;\n return out;\n}\n\n/**\n * Writes a random unit quaternion into out.\n * @param out the receiving quaternion\n * @param random the random generator to use\n * @returns out\n */\nexport function quat(out: Quat, random: RandomGenerator): Quat {\n // Implementation of http://planning.cs.uiuc.edu/node198.html\n const u1 = random();\n const u2 = random();\n const u3 = random();\n\n const sqrt1MinusU1 = Math.sqrt(1 - u1);\n const sqrtU1 = Math.sqrt(u1);\n\n out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);\n out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);\n out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);\n out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);\n return out;\n}\n"],"names":[],"mappings":"AAQA;;;;;AAKG;SACa,KAAK,CAAC,MAAuB,EAAE,GAAW,EAAE,GAAW,EAAA;IACnE,OAAO,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG;AACvC;AAEA;;;;;AAKG;SACa,GAAG,CAAC,MAAuB,EAAE,GAAW,EAAE,GAAW,EAAA;AACjE,IAAA,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,C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d;AAEA;;;;;AAKG;AACG,SAAU,IAAI,CAAC,GAAS,EAAE,MAAuB,EAAA;;AAEnD,IAAA,MAAM,EAAE,GAAG,MAAM,EAAE;AACnB,IAAA,MAAM,EAAE,GAAG,MAAM,EAAE;AACnB,IAAA,MAAM,EAAE,GAAG,MAAM,EAAE;IAEnB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;IACtC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAE5B,IAAA,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACpD,IAAA,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACpD,IAAA,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AAC9C,IAAA,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AAC9C,IAAA,OAAO,GAAG;AACd;;;;"}
@@ -0,0 +1,300 @@
1
+ import { EPSILON } from '../core/scalar.js';
2
+
3
+ /**
4
+ * Create a new empty Box2 with "min" set to positive infinity and "max" set to negative infinity
5
+ * @returns A new Box2
6
+ */
7
+ function create() {
8
+ return [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];
9
+ }
10
+ /**
11
+ * Clones a Box2
12
+ * @param box - A Box2 to clone
13
+ * @returns a clone of box
14
+ */
15
+ function clone(box) {
16
+ return [box[0], box[1], box[2], box[3]];
17
+ }
18
+ /**
19
+ * Copies a Box2 to another Box2
20
+ * @param out the output Box2
21
+ * @param box the input Box2
22
+ * @returns the output Box2
23
+ */
24
+ function copy(out, box) {
25
+ out[0] = box[0];
26
+ out[1] = box[1];
27
+ out[2] = box[2];
28
+ out[3] = box[3];
29
+ return out;
30
+ }
31
+ /**
32
+ * Sets the min and max values of a Box2
33
+ * @param out - The output Box2
34
+ * @param minX - The minimum X coordinate
35
+ * @param minY - The minimum Y coordinate
36
+ * @param maxX - The maximum X coordinate
37
+ * @param maxY - The maximum Y coordinate
38
+ * @returns The updated Box2
39
+ */
40
+ function set(out, minX, minY, maxX, maxY) {
41
+ out[0] = minX;
42
+ out[1] = minY;
43
+ out[2] = maxX;
44
+ out[3] = maxY;
45
+ return out;
46
+ }
47
+ /**
48
+ * Sets the min and max values of a Box2 from Vec2 vectors
49
+ * @param out - The output Box2
50
+ * @param min - The minimum corner
51
+ * @param max - The maximum corner
52
+ * @returns The updated Box2
53
+ */
54
+ function setFromVectors(out, min, max) {
55
+ out[0] = min[0];
56
+ out[1] = min[1];
57
+ out[2] = max[0];
58
+ out[3] = max[1];
59
+ return out;
60
+ }
61
+ /**
62
+ * Extracts the minimum corner of a Box2
63
+ * @param out - The output Vec2 for the minimum corner
64
+ * @param box - The input Box2
65
+ * @returns The minimum corner
66
+ */
67
+ function min(out, box) {
68
+ out[0] = box[0];
69
+ out[1] = box[1];
70
+ return out;
71
+ }
72
+ /**
73
+ * Extracts the maximum corner of a Box2
74
+ * @param out - The output Vec2 for the maximum corner
75
+ * @param box - The input Box2
76
+ * @returns The maximum corner
77
+ */
78
+ function max(out, box) {
79
+ out[0] = box[2];
80
+ out[1] = box[3];
81
+ return out;
82
+ }
83
+ /**
84
+ * Set a Box2 to empty (min to positive infinity, max to negative infinity)
85
+ * @param out - The Box2 to make empty
86
+ * @returns The emptied Box2
87
+ */
88
+ function empty(out) {
89
+ out[0] = Number.POSITIVE_INFINITY;
90
+ out[1] = Number.POSITIVE_INFINITY;
91
+ out[2] = Number.NEGATIVE_INFINITY;
92
+ out[3] = Number.NEGATIVE_INFINITY;
93
+ return out;
94
+ }
95
+ /**
96
+ * Returns whether or not the boxes have exactly the same elements in the same position (when compared with ===)
97
+ * @param a - The first box
98
+ * @param b - The second box
99
+ * @returns True if the boxes are equal, false otherwise
100
+ */
101
+ function exactEquals(a, b) {
102
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
103
+ }
104
+ /**
105
+ * Returns whether or not the boxes have approximately the same elements in the same position
106
+ * @param a - The first box
107
+ * @param b - The second box
108
+ * @returns True if the boxes are equal, false otherwise
109
+ */
110
+ function equals(a, b) {
111
+ const a0 = a[0];
112
+ const a1 = a[1];
113
+ const a2 = a[2];
114
+ const a3 = a[3];
115
+ const b0 = b[0];
116
+ const b1 = b[1];
117
+ const b2 = b[2];
118
+ const b3 = b[3];
119
+ return (Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
120
+ Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
121
+ Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
122
+ Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)));
123
+ }
124
+ /**
125
+ * Sets the box from a center point and size
126
+ * @param out - The output Box2
127
+ * @param center - The center point
128
+ * @param size - The size of the box
129
+ * @returns The updated Box2
130
+ */
131
+ function setFromCenterAndSize(out, center, size) {
132
+ const hx = size[0] * 0.5;
133
+ const hy = size[1] * 0.5;
134
+ out[0] = center[0] - hx;
135
+ out[1] = center[1] - hy;
136
+ out[2] = center[0] + hx;
137
+ out[3] = center[1] + hy;
138
+ return out;
139
+ }
140
+ /**
141
+ * Expands a Box2 to include a point
142
+ * @param out - The output Box2
143
+ * @param box - The input Box2
144
+ * @param point - The point to include
145
+ * @returns The expanded Box2
146
+ */
147
+ function expandByPoint(out, box, point) {
148
+ out[0] = Math.min(box[0], point[0]);
149
+ out[1] = Math.min(box[1], point[1]);
150
+ out[2] = Math.max(box[2], point[0]);
151
+ out[3] = Math.max(box[3], point[1]);
152
+ return out;
153
+ }
154
+ /**
155
+ * Widens a Box2 by a vector on both sides
156
+ * Subtracts the vector from min and adds it to max
157
+ * @param out - The output Box2
158
+ * @param box - The input Box2
159
+ * @param vector - The vector to expand by
160
+ * @returns The expanded Box2
161
+ */
162
+ function expandByExtents(out, box, vector) {
163
+ out[0] = box[0] - vector[0];
164
+ out[1] = box[1] - vector[1];
165
+ out[2] = box[2] + vector[0];
166
+ out[3] = box[3] + vector[1];
167
+ return out;
168
+ }
169
+ /**
170
+ * Expands a Box2 uniformly by a scalar margin on all sides
171
+ * Subtracts the margin from min and adds it to max on each axis
172
+ * @param out - The output Box2
173
+ * @param box - The input Box2
174
+ * @param margin - The uniform margin to expand by
175
+ * @returns The expanded Box2
176
+ */
177
+ function expandByMargin(out, box, margin) {
178
+ out[0] = box[0] - margin;
179
+ out[1] = box[1] - margin;
180
+ out[2] = box[2] + margin;
181
+ out[3] = box[3] + margin;
182
+ return out;
183
+ }
184
+ /**
185
+ * Computes the union of two bounding boxes
186
+ * Returns a Box2 that encompasses both input boxes
187
+ * @param out - The output Box2
188
+ * @param boxA - The first Box2
189
+ * @param boxB - The second Box2
190
+ * @returns The union Box2
191
+ */
192
+ function union(out, boxA, boxB) {
193
+ out[0] = Math.min(boxA[0], boxB[0]);
194
+ out[1] = Math.min(boxA[1], boxB[1]);
195
+ out[2] = Math.max(boxA[2], boxB[2]);
196
+ out[3] = Math.max(boxA[3], boxB[3]);
197
+ return out;
198
+ }
199
+ /**
200
+ * Calculate the center point of a bounding box
201
+ * @param out - The output Vec2 for the center
202
+ * @param box - The input Box2
203
+ * @returns The center point
204
+ */
205
+ function center(out, box) {
206
+ out[0] = (box[0] + box[2]) * 0.5;
207
+ out[1] = (box[1] + box[3]) * 0.5;
208
+ return out;
209
+ }
210
+ /**
211
+ * Calculate the extents (half-size) of a bounding box
212
+ * @param out - The output Vec2 for the extents
213
+ * @param box - The input Box2
214
+ * @returns The extents (distance from center to each edge)
215
+ */
216
+ function extents(out, box) {
217
+ out[0] = (box[2] - box[0]) * 0.5;
218
+ out[1] = (box[3] - box[1]) * 0.5;
219
+ return out;
220
+ }
221
+ /**
222
+ * Calculate the size (dimensions) of a bounding box
223
+ * @param out - The output Vec2 for the size
224
+ * @param box - The input Box2
225
+ * @returns The size (width, height)
226
+ */
227
+ function size(out, box) {
228
+ out[0] = box[2] - box[0];
229
+ out[1] = box[3] - box[1];
230
+ return out;
231
+ }
232
+ /**
233
+ * Calculate the area of a bounding box
234
+ * @param box - The input Box2
235
+ * @returns The area (width * height)
236
+ */
237
+ function area(box) {
238
+ return (box[2] - box[0]) * (box[3] - box[1]);
239
+ }
240
+ /**
241
+ * Scale a bounding box by a vector, handling non-uniform and negative scaling
242
+ * @param out - The output Box2
243
+ * @param box - The input Box2
244
+ * @param scale - The scale to apply (as a Vec2)
245
+ * @returns The scaled Box2
246
+ */
247
+ function scale(out, box, scale) {
248
+ const minX = box[0] * scale[0];
249
+ const maxX = box[2] * scale[0];
250
+ const minY = box[1] * scale[1];
251
+ const maxY = box[3] * scale[1];
252
+ // handle negative scaling by ensuring min <= max for each axis
253
+ out[0] = Math.min(minX, maxX);
254
+ out[2] = Math.max(minX, maxX);
255
+ out[1] = Math.min(minY, maxY);
256
+ out[3] = Math.max(minY, maxY);
257
+ return out;
258
+ }
259
+ /**
260
+ * Test if a point is contained within the bounding box
261
+ * @param box - The bounding box
262
+ * @param point - The point to test
263
+ * @returns true if the point is inside or on the boundary of the box
264
+ */
265
+ function containsPoint(box, point) {
266
+ return point[0] >= box[0] && point[0] <= box[2] && point[1] >= box[1] && point[1] <= box[3];
267
+ }
268
+ /**
269
+ * Test if one Box2 completely contains another Box2
270
+ * @param container - The potentially containing Box2
271
+ * @param contained - The Box2 that might be contained
272
+ * @returns true if the container Box2 completely contains the contained Box2
273
+ */
274
+ function containsBox2(container, contained) {
275
+ return (contained[0] >= container[0] &&
276
+ contained[2] <= container[2] &&
277
+ contained[1] >= container[1] &&
278
+ contained[3] <= container[3]);
279
+ }
280
+ /**
281
+ * Check whether two bounding boxes intersect
282
+ */
283
+ function intersectsBox2(boxA, boxB) {
284
+ return boxA[0] <= boxB[2] && boxA[2] >= boxB[0] && boxA[1] <= boxB[3] && boxA[3] >= boxB[1];
285
+ }
286
+ /**
287
+ * Test intersection between an axis-aligned bounding box and a circle.
288
+ */
289
+ function intersectsCircle(box, circle) {
290
+ const { center, radius } = circle;
291
+ const cx = center[0];
292
+ const cy = center[1];
293
+ // distance from the circle centre to the box along each axis (0 when inside)
294
+ const dx = cx < box[0] ? box[0] - cx : cx > box[2] ? cx - box[2] : 0;
295
+ const dy = cy < box[1] ? box[1] - cy : cy > box[3] ? cy - box[3] : 0;
296
+ return dx * dx + dy * dy <= radius * radius;
297
+ }
298
+
299
+ export { area, center, clone, containsBox2, containsPoint, copy, create, empty, equals, exactEquals, expandByExtents, expandByMargin, expandByPoint, extents, intersectsBox2, intersectsCircle, max, min, scale, set, setFromCenterAndSize, setFromVectors, size, union };
300
+ //# sourceMappingURL=box2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box2.js","sources":["../../src/shapes/box2.ts"],"sourcesContent":["import { EPSILON } from '../core/scalar';\nimport type { Vec2 } from '../core/vec2';\nimport type { Circle } from './circle';\n\n/** An axis-aligned box in 2D space, as [minX, minY, maxX, maxY] */\nexport type Box2 = [minX: number, minY: number, maxX: number, maxY: number];\n\n/**\n * Create a new empty Box2 with \"min\" set to positive infinity and \"max\" set to negative infinity\n * @returns A new Box2\n */\nexport function create(): Box2 {\n return [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];\n}\n\n/**\n * Clones a Box2\n * @param box - A Box2 to clone\n * @returns a clone of box\n */\nexport function clone(box: Box2): Box2 {\n return [box[0], box[1], box[2], box[3]];\n}\n\n/**\n * Copies a Box2 to another Box2\n * @param out the output Box2\n * @param box the input Box2\n * @returns the output Box2\n */\nexport function copy(out: Box2, box: Box2): Box2 {\n out[0] = box[0];\n out[1] = box[1];\n out[2] = box[2];\n out[3] = box[3];\n return out;\n}\n\n/**\n * Sets the min and max values of a Box2\n * @param out - The output Box2\n * @param minX - The minimum X coordinate\n * @param minY - The minimum Y coordinate\n * @param maxX - The maximum X coordinate\n * @param maxY - The maximum Y coordinate\n * @returns The updated Box2\n */\nexport function set(out: Box2, minX: number, minY: number, maxX: number, maxY: number): Box2 {\n out[0] = minX;\n out[1] = minY;\n out[2] = maxX;\n out[3] = maxY;\n return out;\n}\n\n/**\n * Sets the min and max values of a Box2 from Vec2 vectors\n * @param out - The output Box2\n * @param min - The minimum corner\n * @param max - The maximum corner\n * @returns The updated Box2\n */\nexport function setFromVectors(out: Box2, min: Vec2, max: Vec2): Box2 {\n out[0] = min[0];\n out[1] = min[1];\n out[2] = max[0];\n out[3] = max[1];\n return out;\n}\n\n/**\n * Extracts the minimum corner of a Box2\n * @param out - The output Vec2 for the minimum corner\n * @param box - The input Box2\n * @returns The minimum corner\n */\nexport function min(out: Vec2, box: Box2): Vec2 {\n out[0] = box[0];\n out[1] = box[1];\n return out;\n}\n\n/**\n * Extracts the maximum corner of a Box2\n * @param out - The output Vec2 for the maximum corner\n * @param box - The input Box2\n * @returns The maximum corner\n */\nexport function max(out: Vec2, box: Box2): Vec2 {\n out[0] = box[2];\n out[1] = box[3];\n return out;\n}\n\n/**\n * Set a Box2 to empty (min to positive infinity, max to negative infinity)\n * @param out - The Box2 to make empty\n * @returns The emptied Box2\n */\nexport function empty(out: Box2): Box2 {\n out[0] = Number.POSITIVE_INFINITY;\n out[1] = Number.POSITIVE_INFINITY;\n out[2] = Number.NEGATIVE_INFINITY;\n out[3] = Number.NEGATIVE_INFINITY;\n return out;\n}\n\n/**\n * Returns whether or not the boxes have exactly the same elements in the same position (when compared with ===)\n * @param a - The first box\n * @param b - The second box\n * @returns True if the boxes are equal, false otherwise\n */\nexport function exactEquals(a: Box2, b: Box2): boolean {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n\n/**\n * Returns whether or not the boxes have approximately the same elements in the same position\n * @param a - The first box\n * @param b - The second box\n * @returns True if the boxes are equal, false otherwise\n */\nexport function equals(a: Box2, b: Box2): boolean {\n const a0 = a[0];\n const a1 = a[1];\n const a2 = a[2];\n const a3 = a[3];\n const b0 = b[0];\n const b1 = b[1];\n const b2 = b[2];\n const b3 = b[3];\n return (\n Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&\n Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&\n Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&\n Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3))\n );\n}\n\n/**\n * Sets the box from a center point and size\n * @param out - The output Box2\n * @param center - The center point\n * @param size - The size of the box\n * @returns The updated Box2\n */\nexport function setFromCenterAndSize(out: Box2, center: Vec2, size: Vec2): Box2 {\n const hx = size[0] * 0.5;\n const hy = size[1] * 0.5;\n out[0] = center[0] - hx;\n out[1] = center[1] - hy;\n out[2] = center[0] + hx;\n out[3] = center[1] + hy;\n return out;\n}\n\n/**\n * Expands a Box2 to include a point\n * @param out - The output Box2\n * @param box - The input Box2\n * @param point - The point to include\n * @returns The expanded Box2\n */\nexport function expandByPoint(out: Box2, box: Box2, point: Vec2): Box2 {\n out[0] = Math.min(box[0], point[0]);\n out[1] = Math.min(box[1], point[1]);\n out[2] = Math.max(box[2], point[0]);\n out[3] = Math.max(box[3], point[1]);\n return out;\n}\n\n/**\n * Widens a Box2 by a vector on both sides\n * Subtracts the vector from min and adds it to max\n * @param out - The output Box2\n * @param box - The input Box2\n * @param vector - The vector to expand by\n * @returns The expanded Box2\n */\nexport function expandByExtents(out: Box2, box: Box2, vector: Vec2): Box2 {\n out[0] = box[0] - vector[0];\n out[1] = box[1] - vector[1];\n out[2] = box[2] + vector[0];\n out[3] = box[3] + vector[1];\n return out;\n}\n\n/**\n * Expands a Box2 uniformly by a scalar margin on all sides\n * Subtracts the margin from min and adds it to max on each axis\n * @param out - The output Box2\n * @param box - The input Box2\n * @param margin - The uniform margin to expand by\n * @returns The expanded Box2\n */\nexport function expandByMargin(out: Box2, box: Box2, margin: number): Box2 {\n out[0] = box[0] - margin;\n out[1] = box[1] - margin;\n out[2] = box[2] + margin;\n out[3] = box[3] + margin;\n return out;\n}\n\n/**\n * Computes the union of two bounding boxes\n * Returns a Box2 that encompasses both input boxes\n * @param out - The output Box2\n * @param boxA - The first Box2\n * @param boxB - The second Box2\n * @returns The union Box2\n */\nexport function union(out: Box2, boxA: Box2, boxB: Box2): Box2 {\n out[0] = Math.min(boxA[0], boxB[0]);\n out[1] = Math.min(boxA[1], boxB[1]);\n out[2] = Math.max(boxA[2], boxB[2]);\n out[3] = Math.max(boxA[3], boxB[3]);\n return out;\n}\n\n/**\n * Calculate the center point of a bounding box\n * @param out - The output Vec2 for the center\n * @param box - The input Box2\n * @returns The center point\n */\nexport function center(out: Vec2, box: Box2): Vec2 {\n out[0] = (box[0] + box[2]) * 0.5;\n out[1] = (box[1] + box[3]) * 0.5;\n return out;\n}\n\n/**\n * Calculate the extents (half-size) of a bounding box\n * @param out - The output Vec2 for the extents\n * @param box - The input Box2\n * @returns The extents (distance from center to each edge)\n */\nexport function extents(out: Vec2, box: Box2): Vec2 {\n out[0] = (box[2] - box[0]) * 0.5;\n out[1] = (box[3] - box[1]) * 0.5;\n return out;\n}\n\n/**\n * Calculate the size (dimensions) of a bounding box\n * @param out - The output Vec2 for the size\n * @param box - The input Box2\n * @returns The size (width, height)\n */\nexport function size(out: Vec2, box: Box2): Vec2 {\n out[0] = box[2] - box[0];\n out[1] = box[3] - box[1];\n return out;\n}\n\n/**\n * Calculate the area of a bounding box\n * @param box - The input Box2\n * @returns The area (width * height)\n */\nexport function area(box: Box2): number {\n return (box[2] - box[0]) * (box[3] - box[1]);\n}\n\n/**\n * Scale a bounding box by a vector, handling non-uniform and negative scaling\n * @param out - The output Box2\n * @param box - The input Box2\n * @param scale - The scale to apply (as a Vec2)\n * @returns The scaled Box2\n */\nexport function scale(out: Box2, box: Box2, scale: Vec2): Box2 {\n const minX = box[0] * scale[0];\n const maxX = box[2] * scale[0];\n const minY = box[1] * scale[1];\n const maxY = box[3] * scale[1];\n\n // handle negative scaling by ensuring min <= max for each axis\n out[0] = Math.min(minX, maxX);\n out[2] = Math.max(minX, maxX);\n out[1] = Math.min(minY, maxY);\n out[3] = Math.max(minY, maxY);\n\n return out;\n}\n\n/**\n * Test if a point is contained within the bounding box\n * @param box - The bounding box\n * @param point - The point to test\n * @returns true if the point is inside or on the boundary of the box\n */\nexport function containsPoint(box: Box2, point: Vec2): boolean {\n return point[0] >= box[0] && point[0] <= box[2] && point[1] >= box[1] && point[1] <= box[3];\n}\n\n/**\n * Test if one Box2 completely contains another Box2\n * @param container - The potentially containing Box2\n * @param contained - The Box2 that might be contained\n * @returns true if the container Box2 completely contains the contained Box2\n */\nexport function containsBox2(container: Box2, contained: Box2): boolean {\n return (\n contained[0] >= container[0] &&\n contained[2] <= container[2] &&\n contained[1] >= container[1] &&\n contained[3] <= container[3]\n );\n}\n\n/**\n * Check whether two bounding boxes intersect\n */\nexport function intersectsBox2(boxA: Box2, boxB: Box2): boolean {\n return boxA[0] <= boxB[2] && boxA[2] >= boxB[0] && boxA[1] <= boxB[3] && boxA[3] >= boxB[1];\n}\n\n/**\n * Test intersection between an axis-aligned bounding box and a circle.\n */\nexport function intersectsCircle(box: Box2, circle: Circle): boolean {\n const { center, radius } = circle;\n const cx = center[0];\n const cy = center[1];\n // distance from the circle centre to the box along each axis (0 when inside)\n const dx = cx < box[0] ? box[0] - cx : cx > box[2] ? cx - box[2] : 0;\n const dy = cy < box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