@ac-kit/math-geometry 0.2.2 → 0.3.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 (371) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/README.md +323 -52
  3. package/dist/_brand.d.ts +14 -0
  4. package/dist/_brand.d.ts.map +1 -0
  5. package/dist/_brand.js +2 -0
  6. package/dist/_brand.js.map +1 -0
  7. package/dist/_ear-clipping.d.ts +20 -0
  8. package/dist/_ear-clipping.d.ts.map +1 -0
  9. package/dist/_ear-clipping.js +360 -0
  10. package/dist/_ear-clipping.js.map +1 -0
  11. package/dist/_ray3-intersect.d.ts +19 -0
  12. package/dist/_ray3-intersect.d.ts.map +1 -0
  13. package/dist/_ray3-intersect.js +122 -0
  14. package/dist/_ray3-intersect.js.map +1 -0
  15. package/dist/box2-array-boundary.d.ts +50 -0
  16. package/dist/box2-array-boundary.d.ts.map +1 -0
  17. package/dist/box2-array-boundary.js +97 -0
  18. package/dist/box2-array-boundary.js.map +1 -0
  19. package/dist/box2-array.d.ts +42 -0
  20. package/dist/box2-array.d.ts.map +1 -0
  21. package/dist/box2-array.js +134 -0
  22. package/dist/box2-array.js.map +1 -0
  23. package/dist/box2-componentwise.d.ts +110 -0
  24. package/dist/box2-componentwise.d.ts.map +1 -0
  25. package/dist/box2-componentwise.js +325 -0
  26. package/dist/box2-componentwise.js.map +1 -0
  27. package/dist/box2-grid-index.d.ts +67 -0
  28. package/dist/box2-grid-index.d.ts.map +1 -0
  29. package/dist/box2-grid-index.js +198 -0
  30. package/dist/box2-grid-index.js.map +1 -0
  31. package/dist/box2-record.d.ts +83 -0
  32. package/dist/box2-record.d.ts.map +1 -0
  33. package/dist/box2-record.js +124 -0
  34. package/dist/box2-record.js.map +1 -0
  35. package/dist/box2.d.ts +38 -0
  36. package/dist/box2.d.ts.map +1 -0
  37. package/dist/box2.js +97 -0
  38. package/dist/box2.js.map +1 -0
  39. package/dist/box3-array-boundary.d.ts +50 -0
  40. package/dist/box3-array-boundary.d.ts.map +1 -0
  41. package/dist/box3-array-boundary.js +107 -0
  42. package/dist/box3-array-boundary.js.map +1 -0
  43. package/dist/box3-componentwise.d.ts +110 -0
  44. package/dist/box3-componentwise.d.ts.map +1 -0
  45. package/dist/box3-componentwise.js +392 -0
  46. package/dist/box3-componentwise.js.map +1 -0
  47. package/dist/box3-record.d.ts +92 -0
  48. package/dist/box3-record.d.ts.map +1 -0
  49. package/dist/box3-record.js +147 -0
  50. package/dist/box3-record.js.map +1 -0
  51. package/dist/box3.d.ts +19 -16
  52. package/dist/box3.d.ts.map +1 -1
  53. package/dist/box3.js +73 -76
  54. package/dist/box3.js.map +1 -1
  55. package/dist/box4-array-boundary.d.ts +50 -0
  56. package/dist/box4-array-boundary.d.ts.map +1 -0
  57. package/dist/box4-array-boundary.js +117 -0
  58. package/dist/box4-array-boundary.js.map +1 -0
  59. package/dist/box4-componentwise.d.ts +110 -0
  60. package/dist/box4-componentwise.d.ts.map +1 -0
  61. package/dist/box4-componentwise.js +459 -0
  62. package/dist/box4-componentwise.js.map +1 -0
  63. package/dist/box4-record.d.ts +96 -0
  64. package/dist/box4-record.d.ts.map +1 -0
  65. package/dist/box4-record.js +167 -0
  66. package/dist/box4-record.js.map +1 -0
  67. package/dist/box4.d.ts +13 -8
  68. package/dist/box4.d.ts.map +1 -1
  69. package/dist/box4.js +27 -5
  70. package/dist/box4.js.map +1 -1
  71. package/dist/circle2-array-boundary.d.ts +51 -0
  72. package/dist/circle2-array-boundary.d.ts.map +1 -0
  73. package/dist/circle2-array-boundary.js +93 -0
  74. package/dist/circle2-array-boundary.js.map +1 -0
  75. package/dist/circle2-array.d.ts +17 -0
  76. package/dist/circle2-array.d.ts.map +1 -0
  77. package/dist/circle2-array.js +44 -0
  78. package/dist/circle2-array.js.map +1 -0
  79. package/dist/circle2-record.d.ts +81 -0
  80. package/dist/circle2-record.d.ts.map +1 -0
  81. package/dist/circle2-record.js +114 -0
  82. package/dist/circle2-record.js.map +1 -0
  83. package/dist/circle2.d.ts +27 -82
  84. package/dist/circle2.d.ts.map +1 -1
  85. package/dist/circle2.js +59 -104
  86. package/dist/circle2.js.map +1 -1
  87. package/dist/coordinates/cylindrical-record.d.ts +86 -0
  88. package/dist/coordinates/cylindrical-record.d.ts.map +1 -0
  89. package/dist/coordinates/cylindrical-record.js +114 -0
  90. package/dist/coordinates/cylindrical-record.js.map +1 -0
  91. package/dist/coordinates/horizontal-record.d.ts +86 -0
  92. package/dist/coordinates/horizontal-record.d.ts.map +1 -0
  93. package/dist/coordinates/horizontal-record.js +114 -0
  94. package/dist/coordinates/horizontal-record.js.map +1 -0
  95. package/dist/coordinates/horizontal.d.ts +48 -0
  96. package/dist/coordinates/horizontal.d.ts.map +1 -0
  97. package/dist/coordinates/horizontal.js +100 -0
  98. package/dist/coordinates/horizontal.js.map +1 -0
  99. package/dist/coordinates/index.d.ts +10 -0
  100. package/dist/coordinates/index.d.ts.map +1 -0
  101. package/dist/coordinates/index.js +10 -0
  102. package/dist/coordinates/index.js.map +1 -0
  103. package/dist/coordinates/longitude-latitude-record.d.ts +81 -0
  104. package/dist/coordinates/longitude-latitude-record.d.ts.map +1 -0
  105. package/dist/coordinates/longitude-latitude-record.js +104 -0
  106. package/dist/coordinates/longitude-latitude-record.js.map +1 -0
  107. package/dist/coordinates/longitude-latitude.d.ts +33 -0
  108. package/dist/coordinates/longitude-latitude.d.ts.map +1 -0
  109. package/dist/coordinates/longitude-latitude.js +78 -0
  110. package/dist/coordinates/longitude-latitude.js.map +1 -0
  111. package/dist/coordinates/polar-record.d.ts +77 -0
  112. package/dist/coordinates/polar-record.d.ts.map +1 -0
  113. package/dist/coordinates/polar-record.js +104 -0
  114. package/dist/coordinates/polar-record.js.map +1 -0
  115. package/dist/coordinates/polar.d.ts +28 -0
  116. package/dist/coordinates/polar.d.ts.map +1 -0
  117. package/dist/coordinates/polar.js +68 -0
  118. package/dist/coordinates/polar.js.map +1 -0
  119. package/dist/coordinates/spherical-cylindrical.d.ts +49 -0
  120. package/dist/coordinates/spherical-cylindrical.d.ts.map +1 -0
  121. package/dist/coordinates/spherical-cylindrical.js +110 -0
  122. package/dist/coordinates/spherical-cylindrical.js.map +1 -0
  123. package/dist/coordinates/spherical-record.d.ts +86 -0
  124. package/dist/coordinates/spherical-record.d.ts.map +1 -0
  125. package/dist/coordinates/spherical-record.js +114 -0
  126. package/dist/coordinates/spherical-record.js.map +1 -0
  127. package/dist/frustum3-record.d.ts +132 -0
  128. package/dist/frustum3-record.d.ts.map +1 -0
  129. package/dist/frustum3-record.js +333 -0
  130. package/dist/frustum3-record.js.map +1 -0
  131. package/dist/frustum3.d.ts +60 -0
  132. package/dist/frustum3.d.ts.map +1 -0
  133. package/dist/frustum3.js +186 -0
  134. package/dist/frustum3.js.map +1 -0
  135. package/dist/index.d.ts +36 -16
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +36 -16
  138. package/dist/index.js.map +1 -1
  139. package/dist/line2-record.d.ts +87 -0
  140. package/dist/line2-record.d.ts.map +1 -0
  141. package/dist/line2-record.js +123 -0
  142. package/dist/line2-record.js.map +1 -0
  143. package/dist/line2.d.ts +20 -33
  144. package/dist/line2.d.ts.map +1 -1
  145. package/dist/line2.js +56 -51
  146. package/dist/line2.js.map +1 -1
  147. package/dist/line3-record.d.ts +91 -0
  148. package/dist/line3-record.d.ts.map +1 -0
  149. package/dist/line3-record.js +146 -0
  150. package/dist/line3-record.js.map +1 -0
  151. package/dist/line3.d.ts +11 -24
  152. package/dist/line3.d.ts.map +1 -1
  153. package/dist/line3.js +32 -36
  154. package/dist/line3.js.map +1 -1
  155. package/dist/mesh/_generator-kit.d.ts +14 -0
  156. package/dist/mesh/_generator-kit.d.ts.map +1 -0
  157. package/dist/mesh/_generator-kit.js +39 -0
  158. package/dist/mesh/_generator-kit.js.map +1 -0
  159. package/dist/mesh/_index-kernels-u16.d.ts +43 -0
  160. package/dist/mesh/_index-kernels-u16.d.ts.map +1 -0
  161. package/dist/mesh/_index-kernels-u16.js +264 -0
  162. package/dist/mesh/_index-kernels-u16.js.map +1 -0
  163. package/dist/mesh/_index-kernels-u32.d.ts +43 -0
  164. package/dist/mesh/_index-kernels-u32.d.ts.map +1 -0
  165. package/dist/mesh/_index-kernels-u32.js +264 -0
  166. package/dist/mesh/_index-kernels-u32.js.map +1 -0
  167. package/dist/mesh/generate-box.d.ts +16 -0
  168. package/dist/mesh/generate-box.d.ts.map +1 -0
  169. package/dist/mesh/generate-box.js +79 -0
  170. package/dist/mesh/generate-box.js.map +1 -0
  171. package/dist/mesh/generate-cylinder.d.ts +25 -0
  172. package/dist/mesh/generate-cylinder.d.ts.map +1 -0
  173. package/dist/mesh/generate-cylinder.js +117 -0
  174. package/dist/mesh/generate-cylinder.js.map +1 -0
  175. package/dist/mesh/generate-heightfield.d.ts +24 -0
  176. package/dist/mesh/generate-heightfield.d.ts.map +1 -0
  177. package/dist/mesh/generate-heightfield.js +48 -0
  178. package/dist/mesh/generate-heightfield.js.map +1 -0
  179. package/dist/mesh/generate-plane.d.ts +18 -0
  180. package/dist/mesh/generate-plane.d.ts.map +1 -0
  181. package/dist/mesh/generate-plane.js +39 -0
  182. package/dist/mesh/generate-plane.js.map +1 -0
  183. package/dist/mesh/generate-sphere.d.ts +50 -0
  184. package/dist/mesh/generate-sphere.d.ts.map +1 -0
  185. package/dist/mesh/generate-sphere.js +244 -0
  186. package/dist/mesh/generate-sphere.js.map +1 -0
  187. package/dist/mesh/index.d.ts +8 -0
  188. package/dist/mesh/index.d.ts.map +1 -0
  189. package/dist/mesh/index.js +8 -0
  190. package/dist/mesh/index.js.map +1 -0
  191. package/dist/mesh/mesh3-kernels.d.ts +82 -0
  192. package/dist/mesh/mesh3-kernels.d.ts.map +1 -0
  193. package/dist/mesh/mesh3-kernels.js +180 -0
  194. package/dist/mesh/mesh3-kernels.js.map +1 -0
  195. package/dist/mesh/mesh3.d.ts +66 -0
  196. package/dist/mesh/mesh3.d.ts.map +1 -0
  197. package/dist/mesh/mesh3.js +128 -0
  198. package/dist/mesh/mesh3.js.map +1 -0
  199. package/dist/plane3-record.d.ts +88 -0
  200. package/dist/plane3-record.d.ts.map +1 -0
  201. package/dist/plane3-record.js +123 -0
  202. package/dist/plane3-record.js.map +1 -0
  203. package/dist/plane3.d.ts +42 -28
  204. package/dist/plane3.d.ts.map +1 -1
  205. package/dist/plane3.js +166 -48
  206. package/dist/plane3.js.map +1 -1
  207. package/dist/polygon2.d.ts +82 -29
  208. package/dist/polygon2.d.ts.map +1 -1
  209. package/dist/polygon2.js +236 -93
  210. package/dist/polygon2.js.map +1 -1
  211. package/dist/polygon3.d.ts +40 -21
  212. package/dist/polygon3.d.ts.map +1 -1
  213. package/dist/polygon3.js +215 -91
  214. package/dist/polygon3.js.map +1 -1
  215. package/dist/polyline2.d.ts +37 -0
  216. package/dist/polyline2.d.ts.map +1 -0
  217. package/dist/polyline2.js +146 -0
  218. package/dist/polyline2.js.map +1 -0
  219. package/dist/polyline3.d.ts +35 -0
  220. package/dist/polyline3.d.ts.map +1 -0
  221. package/dist/polyline3.js +159 -0
  222. package/dist/polyline3.js.map +1 -0
  223. package/dist/quadtree.d.ts +238 -0
  224. package/dist/quadtree.d.ts.map +1 -0
  225. package/dist/quadtree.js +1019 -0
  226. package/dist/quadtree.js.map +1 -0
  227. package/dist/ray2-record.d.ts +86 -0
  228. package/dist/ray2-record.d.ts.map +1 -0
  229. package/dist/ray2-record.js +123 -0
  230. package/dist/ray2-record.js.map +1 -0
  231. package/dist/ray2.d.ts +38 -13
  232. package/dist/ray2.d.ts.map +1 -1
  233. package/dist/ray2.js +85 -22
  234. package/dist/ray2.js.map +1 -1
  235. package/dist/ray3-array.d.ts +27 -0
  236. package/dist/ray3-array.d.ts.map +1 -0
  237. package/dist/ray3-array.js +89 -0
  238. package/dist/ray3-array.js.map +1 -0
  239. package/dist/ray3-record.d.ts +90 -0
  240. package/dist/ray3-record.d.ts.map +1 -0
  241. package/dist/ray3-record.js +146 -0
  242. package/dist/ray3-record.js.map +1 -0
  243. package/dist/ray3.d.ts +72 -25
  244. package/dist/ray3.d.ts.map +1 -1
  245. package/dist/ray3.js +233 -64
  246. package/dist/ray3.js.map +1 -1
  247. package/dist/segment2-record.d.ts +80 -0
  248. package/dist/segment2-record.d.ts.map +1 -0
  249. package/dist/segment2-record.js +122 -0
  250. package/dist/segment2-record.js.map +1 -0
  251. package/dist/segment2.d.ts +34 -19
  252. package/dist/segment2.d.ts.map +1 -1
  253. package/dist/segment2.js +88 -42
  254. package/dist/segment2.js.map +1 -1
  255. package/dist/segment3-record.d.ts +90 -0
  256. package/dist/segment3-record.d.ts.map +1 -0
  257. package/dist/segment3-record.js +146 -0
  258. package/dist/segment3-record.js.map +1 -0
  259. package/dist/segment3.d.ts +24 -12
  260. package/dist/segment3.d.ts.map +1 -1
  261. package/dist/segment3.js +67 -30
  262. package/dist/segment3.js.map +1 -1
  263. package/dist/size.d.ts +40 -0
  264. package/dist/size.d.ts.map +1 -0
  265. package/dist/size.js +72 -0
  266. package/dist/size.js.map +1 -0
  267. package/dist/sphere3-array-boundary.d.ts +51 -0
  268. package/dist/sphere3-array-boundary.d.ts.map +1 -0
  269. package/dist/sphere3-array-boundary.js +98 -0
  270. package/dist/sphere3-array-boundary.js.map +1 -0
  271. package/dist/sphere3-record.d.ts +88 -0
  272. package/dist/sphere3-record.d.ts.map +1 -0
  273. package/dist/sphere3-record.js +123 -0
  274. package/dist/sphere3-record.js.map +1 -0
  275. package/dist/sphere3.d.ts +55 -12
  276. package/dist/sphere3.d.ts.map +1 -1
  277. package/dist/sphere3.js +233 -24
  278. package/dist/sphere3.js.map +1 -1
  279. package/dist/spherical/cap.d.ts +56 -0
  280. package/dist/spherical/cap.d.ts.map +1 -0
  281. package/dist/spherical/cap.js +363 -0
  282. package/dist/spherical/cap.js.map +1 -0
  283. package/dist/spherical/great-circle.d.ts +39 -0
  284. package/dist/spherical/great-circle.d.ts.map +1 -0
  285. package/dist/spherical/great-circle.js +158 -0
  286. package/dist/spherical/great-circle.js.map +1 -0
  287. package/dist/spherical/index.d.ts +3 -0
  288. package/dist/spherical/index.d.ts.map +1 -0
  289. package/dist/spherical/index.js +3 -0
  290. package/dist/spherical/index.js.map +1 -0
  291. package/dist/triangle2-record.d.ts +91 -0
  292. package/dist/triangle2-record.d.ts.map +1 -0
  293. package/dist/triangle2-record.js +146 -0
  294. package/dist/triangle2-record.js.map +1 -0
  295. package/dist/triangle2.d.ts +29 -14
  296. package/dist/triangle2.d.ts.map +1 -1
  297. package/dist/triangle2.js +86 -22
  298. package/dist/triangle2.js.map +1 -1
  299. package/dist/triangle3-record.d.ts +97 -0
  300. package/dist/triangle3-record.d.ts.map +1 -0
  301. package/dist/triangle3-record.js +178 -0
  302. package/dist/triangle3-record.js.map +1 -0
  303. package/dist/triangle3.d.ts +41 -17
  304. package/dist/triangle3.d.ts.map +1 -1
  305. package/dist/triangle3.js +267 -38
  306. package/dist/triangle3.js.map +1 -1
  307. package/package.json +15 -8
  308. package/dist/angles.d.ts +0 -31
  309. package/dist/angles.d.ts.map +0 -1
  310. package/dist/angles.js +0 -53
  311. package/dist/angles.js.map +0 -1
  312. package/dist/coordinate-spaces.d.ts +0 -39
  313. package/dist/coordinate-spaces.d.ts.map +0 -1
  314. package/dist/coordinate-spaces.js +0 -52
  315. package/dist/coordinate-spaces.js.map +0 -1
  316. package/dist/coordinates-vec2.d.ts +0 -7
  317. package/dist/coordinates-vec2.d.ts.map +0 -1
  318. package/dist/coordinates-vec2.js +0 -35
  319. package/dist/coordinates-vec2.js.map +0 -1
  320. package/dist/coordinates-vec3.d.ts +0 -11
  321. package/dist/coordinates-vec3.d.ts.map +0 -1
  322. package/dist/coordinates-vec3.js +0 -61
  323. package/dist/coordinates-vec3.js.map +0 -1
  324. package/dist/coordinates.d.ts +0 -54
  325. package/dist/coordinates.d.ts.map +0 -1
  326. package/dist/coordinates.js +0 -2
  327. package/dist/coordinates.js.map +0 -1
  328. package/dist/euler-angles-quaternion.d.ts +0 -7
  329. package/dist/euler-angles-quaternion.d.ts.map +0 -1
  330. package/dist/euler-angles-quaternion.js +0 -100
  331. package/dist/euler-angles-quaternion.js.map +0 -1
  332. package/dist/euler-angles.d.ts +0 -33
  333. package/dist/euler-angles.d.ts.map +0 -1
  334. package/dist/euler-angles.js +0 -35
  335. package/dist/euler-angles.js.map +0 -1
  336. package/dist/geometry-vectors.d.ts +0 -11
  337. package/dist/geometry-vectors.d.ts.map +0 -1
  338. package/dist/geometry-vectors.js +0 -19
  339. package/dist/geometry-vectors.js.map +0 -1
  340. package/dist/mesh3.d.ts +0 -32
  341. package/dist/mesh3.d.ts.map +0 -1
  342. package/dist/mesh3.js +0 -142
  343. package/dist/mesh3.js.map +0 -1
  344. package/dist/point2.d.ts +0 -41
  345. package/dist/point2.d.ts.map +0 -1
  346. package/dist/point2.js +0 -92
  347. package/dist/point2.js.map +0 -1
  348. package/dist/point3.d.ts +0 -43
  349. package/dist/point3.d.ts.map +0 -1
  350. package/dist/point3.js +0 -103
  351. package/dist/point3.js.map +0 -1
  352. package/dist/point4.d.ts +0 -12
  353. package/dist/point4.d.ts.map +0 -1
  354. package/dist/point4.js +0 -28
  355. package/dist/point4.js.map +0 -1
  356. package/dist/rect2.d.ts +0 -54
  357. package/dist/rect2.d.ts.map +0 -1
  358. package/dist/rect2.js +0 -149
  359. package/dist/rect2.js.map +0 -1
  360. package/dist/size2.d.ts +0 -33
  361. package/dist/size2.d.ts.map +0 -1
  362. package/dist/size2.js +0 -81
  363. package/dist/size2.js.map +0 -1
  364. package/dist/size3.d.ts +0 -21
  365. package/dist/size3.d.ts.map +0 -1
  366. package/dist/size3.js +0 -59
  367. package/dist/size3.js.map +0 -1
  368. package/dist/size4.d.ts +0 -10
  369. package/dist/size4.d.ts.map +0 -1
  370. package/dist/size4.js +0 -16
  371. package/dist/size4.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,233 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 34e8cfa: `polyline2CumulativeLengths(out, coordinates)` and
8
+ `polyline3CumulativeLengths(out, coordinates)` write the length of a chain up
9
+ to each vertex into `out` (the first is 0, the last `polyline2Length`'s result):
10
+ what a dash pattern or a distance label along a path needs. They allocate
11
+ nothing and throw a `RangeError` for an odd or non-multiple-of-3 coordinate
12
+ count, an `out` that has not one entry per vertex, or an `out` that may share
13
+ memory with `coordinates` (a `SharedArrayBuffer` and its clones count as
14
+ shared).
15
+ - 34e8cfa: Shapes and coordinate records are packed, branded tuples of numbers made by
16
+ creators, with buffer forms and hit-tests, and points, vectors and sizes are
17
+ `@ac-kit/math-linear`'s `Vec2`, `Vec3` and `Vec4`.
18
+
19
+ - **Boxes, circles, spheres.** `Box2`, `Box3` and `Box4` (kept: an axis-aligned
20
+ box in four dimensions, the fourth axis often time) are min/max records,
21
+ `[minX, minY, maxX, maxY]`, and `Circle2` and `Sphere3` are
22
+ `[centerX, centerY, radius]` and `[centerX, centerY, centerZ, radius]`. Each
23
+ has `…Create` (the empty box, for a box), `…Of`, `…Clone`, `…Set`, `…Copy`,
24
+ exact `…Equals`, tolerant `…IsClose`, the checked `…FromArray` and
25
+ `…IsFinite`, and a `Float64Array` buffer family (`…ArrayCreate`, `…Load`,
26
+ `…Store`, `…LoadStrided`, `…StoreStrided`, `…StoreFloat32`,
27
+ `…ArrayIsFinite`). Hit-tests over packed boxes and circles:
28
+ `box2ArrayFindIndexContainingXy`, `box2ArrayFindLastIndexContainingXy` (the
29
+ topmost), `box2ArrayContainingXy`, `box2ArrayFindIndexIntersecting`,
30
+ `box2ArrayIntersecting`, `circle2ArrayFindIndexContainingXy`. New: the box
31
+ family (union, intersection, expansion, translation, clamping, distance, lerp,
32
+ parameter, letterboxing with `box2FitInside`, transformed bounds by an
33
+ affine map), `box3FromPoints` and `sphere3FromPoints` (Ritter), unions of
34
+ buffers, and `Box2GridIndex` for overlap queries (label collision, broad
35
+ phase).
36
+ - **Linear shapes.** `Segment2/3`, `Ray2/3`, `Line2/3` and `Plane3`
37
+ (`[normalX, normalY, normalZ, d]`, `n·p + d = 0`), with closest points,
38
+ distances, and intersections that return a parameter (`Infinity` for a miss):
39
+ `ray3IntersectPlane3`, `ray3IntersectSphere3`, `ray3IntersectBox3`,
40
+ `ray3IntersectTriangle3` (Möller–Trumbore, with back-face culling),
41
+ `ray2IntersectSegment2`; the crossing of two segments or lines is a `boolean`
42
+ with `NaN` in `out` on a miss. Picking: `ray3FromViewport` (a finite unit
43
+ direction in all three depth ranges, an infinite far plane included) and
44
+ `ray3FindNearestPoint`, `ray3FindNearestBox3`, `ray3FindNearestSphere3` over
45
+ buffers.
46
+ - **Frustums.** `Frustum3` is six inward planes; `frustum3FromMat4x4` reads them
47
+ from a view-projection for `"zero-to-one"`, `"negative-one-to-one"` and
48
+ `"one-to-zero"` (reversed depth), an infinite far plane allowed;
49
+ `frustum3ContainsPoint`, `frustum3IntersectsSphere3`, `frustum3IntersectsBox3`
50
+ and the culling kernels `frustum3CullSphere3Array`, `frustum3CullBox3Array`.
51
+ - **Triangles, polygons, polylines.** `Triangle2/3` tuples (areas, barycentric
52
+ coordinates, containment, closest point, front-facing); polygons and
53
+ polylines are `Float64Array`s of vertices, rings implicitly closed, holes
54
+ given by start index; `polygon2ContainsXy` with both fill rules,
55
+ `polygon2Triangulate` by ear clipping with holes (it was a fan),
56
+ `polygon3Triangulate`, areas, centroids, perimeters, `polygon2IsConvex`,
57
+ polyline distances and closest points.
58
+ - **Coordinates.** `PolarCoords`, `SphericalCoords`, `CylindricalCoords` are
59
+ tuples, converted by `polarFromVec2`, `sphericalFromVec3YUp`,
60
+ `vec3FromSphericalZUp`, `cylindricalFromVec3ZUp`, … ; new: `LongitudeLatitude`
61
+ (longitude first) with buffer forms, `mat3x3FromLocalFrame` (`"east-north-up"`,
62
+ `"north-east-down"`) and `HorizontalCoords` (azimuth clockwise from north).
63
+ - **The sphere.** `sphericalBearing`, `sphericalDestination`, `sphericalCircle`,
64
+ `sphericalArc`, `sphericalCapContains` (the angle to the centre at most the
65
+ radius, boundary included, accurate for caps of any size), and clipping to a
66
+ cap: `sphericalArcClipToCap` and `sphericalPolylineClipToCap` (room for
67
+ `9n − 6` numbers for `n` vertices), for the visible
68
+ region of an azimuthal projection.
69
+ - **Meshes.** `Mesh3` is `{ positions, indices, normals?, uvs? }`: packed
70
+ `Float64Array`s (3 numbers per vertex, `uvs` 2) and `indices` as a
71
+ `Uint16Array` up to 65 535 vertices (`indexArrayCreate` picks; `0xFFFF` stays
72
+ free as a restart index) or a `Uint32Array`. Kernels write into an `out`:
73
+ `mesh3VertexNormals` (area-weighted, unit, zero for an unused vertex),
74
+ `mesh3FaceNormals` (zero for a zero-area face), `mesh3SurfaceArea`,
75
+ `mesh3Volume` (signed), `mesh3Centroid`, `mesh3IntersectRay3` (the nearest
76
+ triangle and `[t, u, v]`, `−1` for a miss), `mesh3TriangleDepths` and
77
+ `mesh3ReorderTriangles` (back-to-front sorting of translucent triangles); each
78
+ runs a generated twin per index type, with bit-identical results. Also
79
+ `mesh3VertexCount`, `mesh3TriangleCount`, `mesh3Triangle` (`false` and `NaN`
80
+ for a selector that is not a triangle), `mesh3Equals` and
81
+ `mesh3Merge` (the index type follows the total vertex count; an index past its
82
+ own mesh is a `RangeError`). Kernels refuse an `out` that shares memory with an
83
+ input. Generators, Y up,
84
+ counter-clockwise, with normals and uvs: `mesh3Box`, `mesh3Plane`,
85
+ `mesh3Heightfield`, `mesh3Octahedron`, `mesh3IcoSphere`, `mesh3UvSphere`,
86
+ `mesh3Cylinder`; a bad size or segment count is a `RangeError`.
87
+ - Every operation takes `out` first, never throws on degenerate input and
88
+ returns `NaN` rather than a stale value; per-element operations allocate
89
+ nothing (the triangulations allocate O(n) scratch, and only the creators
90
+ allocate values), and a creator's result never has holey or integer storage.
91
+ Bulk functions throw a `RangeError` once per call for a bad length.
92
+ Degree-2 quantities (areas, centroids, barycentric determinants, a ray's
93
+ perpendicular distance) are accurate for products within [1e−150, 1e150]; no
94
+ `…Scaled` variants yet.
95
+
96
+ Migration:
97
+
98
+ - `Point2<T>`, `Point3<T>`, `Point4`, `Size2<T>`, `Size3<T>`, `Size4` and every
99
+ `point*`/`size*` function are gone: use `Vec2`, `Vec3`, `Vec4` and the `vec*`
100
+ functions of `@ac-kit/math-linear` (`{ x, y }` becomes `vec2Of(x, y)`,
101
+ `point2Distance(a, b, "manhattan")` becomes `vec2DistanceManhattan(a, b)`).
102
+ `DistanceType` is gone with them: code that chooses a distance at run time
103
+ passes `@ac-kit/core`'s `Distance<T>`. The `size2` functions that make sense
104
+ for a size (`size2AspectRatio`, `size2Area`, `size2Contains`, `size2IsZero`,
105
+ `size2ScaleToFit`, `size2ScaleToFill`, `size3ScaleToFit`, `size3Volume`) take
106
+ `Vec2`/`Vec3`, `out` first. `point2ToNdc`/`ndcToPoint2` are
107
+ `vec2ViewportToNdc`/`vec2NdcToViewport`, `point2ToUv`/`uvToPoint2` are
108
+ `box2Parameter`/`box2PointAt`, and `geometry-vectors.ts`'s converters are
109
+ gone (points are vectors).
110
+ - `Rect2` (origin and size) is `Box2`, min/max: `box2FromXywh(out, x, y, w, h)`;
111
+ `rect2Right`, `rect2Bottom` are `box[2]`, `box[3]`; `rect2Inflate` and
112
+ `rect2Inset` are `box2ExpandByScalar` with `+margin` and `−margin`;
113
+ `rect2Intersect` is `box2IntersectsBox2` and `rect2Intersection` returns an
114
+ empty box (`box2IsEmpty`) instead of `null`; `rect2FitInside(container,
115
+ contained)` is `box2FitInside(out, box, container)`; `rect2Clamp` has no
116
+ meaning on min/max records and is removed. `Box3` (origin and size) is
117
+ min/max, same verbs; `Box4` is `[minX, minY, minZ, minW, maxX, maxY, maxZ,
118
+ maxW]`, so `{ origin, size }` becomes `box4Of(o.x, o.y, o.z, o.w, o.x +
119
+ s.width, o.y + s.height, o.z + s.depth, o.w + s.duration)`.
120
+ - `Circle2`, `Sphere3`, `Line*`, `Ray*`, `Segment*`, `Triangle*`, `Plane3`,
121
+ `Polygon2`, `Polygon3` are no longer objects: they are the tuples above, and
122
+ a polygon is its `Float64Array` coordinates (`polygon2ContainsPoint(p,
123
+ point)` becomes `polygon2ContainsPoint(coordinates, point, "evenodd")`,
124
+ `polygonNBoundingBox` is `boxNFromPoints`). `circle2Intersects` and
125
+ `sphere3Intersects` are `circle2IntersectsCircle2` and
126
+ `sphere3IntersectsSphere3`; `line2Intersect` and `segment2Intersect` are
127
+ `line2IntersectLine2(out, a, b): boolean` (the point) and
128
+ `segment2IntersectSegment2(out, a, b): boolean` (the parameters);
129
+ `ray3IntersectPlane` and `ray3IntersectSphere` return a point or `null`, their
130
+ successors `ray3IntersectPlane3` and `ray3IntersectSphere3` return the
131
+ parameter `t` (`Infinity` for a miss; the point is `ray3At`). A plane
132
+ `{ normal, distance }` (`n·p − distance = 0`) is `[nx, ny, nz, d]` with `d =
133
+ −distance`, and `plane3DistanceToPoint` is `plane3SignedDistanceToPoint`.
134
+ - Direction functions no longer throw on a zero direction: a degenerate ray or
135
+ line is documented per function.
136
+ - `Mesh3` (`{ vertices: Point3[], faces: [a, b, c][] }`) is the packed
137
+ `{ positions, indices }` of `Float64Array` and `Uint16Array | Uint32Array`:
138
+ `mesh3FaceCount` and `mesh3FaceTriangle` are `mesh3TriangleCount` and
139
+ `mesh3Triangle(out, positions, indices, triangle): boolean`, `mesh3FaceNormal` is the
140
+ bulk `mesh3FaceNormals(out, positions, indices)`, `mesh3BoundingBox` is
141
+ `box3FromPoints`, and `mesh3VertexNormals(mesh)` is
142
+ `mesh3VertexNormals(out, positions, indices)` (a vertex no triangle uses gets
143
+ the zero vector, no longer `[0, 1, 0]`). `mesh3Centroid` of a mesh of zero
144
+ area is `NaN`, no longer the vertex average.
145
+ - `PolarCoords`, `SphericalCoords(Y/Z)`, `CylindricalCoords(Y/Z)` and
146
+ `PolygonalPolar…` are tuples: `vec2ToPolar`, `polarToVec2`,
147
+ `vec3ToSphericalY`, `sphericalYToVec3` and the Z and cylindrical ones become
148
+ `polarFromVec2`, `vec2FromPolar`, `sphericalFromVec3YUp`,
149
+ `vec3FromSphericalYUp`, `…ZUp`, `cylindricalFrom…`; `vec2ToPolygonalPolar` and
150
+ `polygonalPolarToVec2` are `polygonalPolarFromVec2(out, v, sides, rotation)`
151
+ and `vec2FromPolygonalPolar`. An inclination is an `atan2`, so the zero vector
152
+ gives `[0, 0, 0]` rather than `NaN`.
153
+ - The angle functions (`angleWrapDeg`, `angleNormalizeRad`, …) are no longer
154
+ re-exported: import them from `@ac-kit/math-scalar`. Euler angles and their
155
+ conversions (`eulerAnglesToQuaternion`, …) are `@ac-kit/math-linear`'s
156
+ (`quaternionFromEuler`, `eulerFromQuaternion`, twelve orders).
157
+ - Values are made by creators: an array literal no longer type-checks as a
158
+ `Box2`, and a value from `JSON.parse` goes through `box2FromArray`.
159
+ - 34e8cfa: `Quadtree` indexes 2-D points by integer id. `new Quadtree(points)` or
160
+ `assign(points)` builds it over a `Float64Array` of x, y pairs (ids 0…n−1,
161
+ reusing its storage across calls, as a force step does each tick); `add`,
162
+ `remove`, `clear` change it afterwards. `find(x, y, maxDistance?)` returns the
163
+ nearest id (lowest id on ties, −1 when none) and `forEachInBox` lists the ids
164
+ in a closed box. `visit` and `visitAfter` walk the tree in pre- and post-order,
165
+ handing the visitor each node's number and its square cell as a box the
166
+ traversal reuses (read it during the call, copy it to keep it), so the
167
+ traversal allocates nothing per node; node numbers are dense, so an aggregate such
168
+ as a Barnes–Hut centre of mass lives in a `Float64Array(nodeCount() * k)`. The
169
+ cells and visit order match d3-quadtree for the same points wherever d3's cell
170
+ edges are exact (integer edges below 2⁵³, so at every ordinary scale); beyond
171
+ that the root cell is re-rooted on exact edges instead, so growing the tree
172
+ never loses a point. Coincident points
173
+ share a leaf, listed in ascending id order. Stored coordinates (construction,
174
+ `assign`, `add`) must be finite with |x|, |y| ≤ 1e150: an odd length, a
175
+ non-finite coordinate or one beyond that range throws `RangeError` before the
176
+ tree changes (`assign` checks every point first and leaves the tree as it was).
177
+ Queries never throw: `find` returns −1 for a NaN, infinite or beyond-±1e150
178
+ coordinate (outside the supported range: no result), and `forEachInBox` visits
179
+ what lies inside the supported range (an infinite box lists every id), nothing
180
+ for a NaN or inverted box. Ids are never reissued, so storage grows with the ids
181
+ issued until `clear` or `assign`.
182
+
183
+ ### Patch Changes
184
+
185
+ - Updated dependencies [34e8cfa]
186
+ - Updated dependencies [34e8cfa]
187
+ - Updated dependencies [34e8cfa]
188
+ - Updated dependencies [34e8cfa]
189
+ - Updated dependencies [34e8cfa]
190
+ - Updated dependencies [34e8cfa]
191
+ - Updated dependencies [34e8cfa]
192
+ - Updated dependencies [34e8cfa]
193
+ - Updated dependencies [34e8cfa]
194
+ - Updated dependencies [34e8cfa]
195
+ - Updated dependencies [34e8cfa]
196
+ - Updated dependencies [34e8cfa]
197
+ - Updated dependencies [34e8cfa]
198
+ - Updated dependencies [34e8cfa]
199
+ - Updated dependencies [34e8cfa]
200
+ - Updated dependencies [34e8cfa]
201
+ - Updated dependencies [34e8cfa]
202
+ - Updated dependencies [34e8cfa]
203
+ - Updated dependencies [34e8cfa]
204
+ - Updated dependencies [34e8cfa]
205
+ - Updated dependencies [34e8cfa]
206
+ - Updated dependencies [34e8cfa]
207
+ - Updated dependencies [34e8cfa]
208
+ - Updated dependencies [34e8cfa]
209
+ - Updated dependencies [34e8cfa]
210
+ - Updated dependencies [34e8cfa]
211
+ - Updated dependencies [34e8cfa]
212
+ - Updated dependencies [34e8cfa]
213
+ - Updated dependencies [34e8cfa]
214
+ - Updated dependencies [34e8cfa]
215
+ - Updated dependencies [34e8cfa]
216
+ - @ac-kit/core@0.12.0
217
+ - @ac-kit/math-scalar@0.3.0
218
+ - @ac-kit/math-linear@0.3.0
219
+
220
+ ## 0.2.3
221
+
222
+ ### Patch Changes
223
+
224
+ - Updated dependencies [065cf8d]
225
+ - Updated dependencies [065cf8d]
226
+ - Updated dependencies [065cf8d]
227
+ - @ac-kit/core@0.11.0
228
+ - @ac-kit/math-linear@0.2.1
229
+ - @ac-kit/math-scalar@0.2.3
230
+
3
231
  ## 0.2.2
4
232
 
5
233
  ### Patch Changes
package/README.md CHANGED
@@ -1,85 +1,356 @@
1
1
  # @ac-kit/math-geometry
2
2
 
3
- Computational geometry in 2D, 3D and 4D: shapes, coordinate systems, angles, and
4
- the predicates and constructions over them.
3
+ Euclidean geometry and the geometry of the sphere: shapes, hit-tests, frustums
4
+ and picking rays, coordinate systems, great-circle arcs and clipping to a cap,
5
+ and packed triangle meshes with their generators.
5
6
 
6
7
  ## Scope
7
8
 
8
- Objects defined by a boundary or an extent — points, rectangles, circles,
9
- polygons, planes, meshes — and the conversions between the coordinate systems
10
- they are expressed in.
9
+ Objects defined by a boundary or an extent — boxes, circles, spheres, segments,
10
+ rays, lines, planes, triangles, polygons, frustums, triangle meshes — the
11
+ conversions between the coordinate systems they are expressed in, and the unit
12
+ sphere (bearings, small circles, arcs, cap clipping).
11
13
 
14
+ Points, vectors and sizes are `Vec2`, `Vec3`, `Vec4` of `@ac-kit/math-linear`.
12
15
  Curves parameterised by a scalar belong in `@ac-kit/math-curves`; discrete
13
- integer lattices belong in `@ac-kit/math-grid`.
16
+ integer lattices belong in `@ac-kit/math-grid`; the Earth's ellipsoid and map
17
+ projections are not here, the sphere is abstract.
14
18
 
15
19
  ## Contents
16
20
 
17
- | Group | Types |
18
- | ----------- | ---------------------------------------------------------------------------------------------------- |
19
- | 2D shapes | `Point2`, `Rect2`, `Circle2`, `Line2`, `Segment2`, `Ray2`, `Triangle2`, `Polygon2` |
20
- | 3D shapes | `Point3`, `Box3`, `Sphere3`, `Line3`, `Segment3`, `Ray3`, `Plane3`, `Triangle3`, `Polygon3`, `Mesh3` |
21
- | 4D | `Point4`, `Box4` |
22
- | Sizes | `Size2`, `Size3`, `Size4` — including `scaleToFit` and `scaleToFill` |
23
- | Coordinates | Polar, spherical and cylindrical systems, and the conversions to and from Cartesian |
24
- | Angles | `EulerAngles`, `EulerOrder`, wrapping, normalisation, angular distance and interpolation |
21
+ | Group | Types |
22
+ | ------------ | ---------------------------------------------------------------------------------------- |
23
+ | Boxes | `Box2`, `Box3`, `Box4` (min/max records; the fourth axis of a `Box4` is often time) |
24
+ | Round shapes | `Circle2`, `Sphere3` |
25
+ | Linear | `Segment2/3`, `Ray2/3`, `Line2/3`, `Plane3`, `Frustum3` (six inward planes) |
26
+ | Triangles | `Triangle2`, `Triangle3` |
27
+ | Chains | polygons (rings, holes) and polylines, packed in a `Float64Array` |
28
+ | Coordinates | `PolarCoords`, `SphericalCoords`, `CylindricalCoords`, `LongitudeLatitude`, `HorizontalCoords` |
29
+ | Sphere | bearing, destination, small circles, arcs, `sphericalArcClipToCap` and friends |
30
+ | Meshes | `Mesh3`, packed positions and indices, kernels and generators (`mesh3Box`, `mesh3IcoSphere`, …) |
31
+ | Structures | `Box2GridIndex`, boxes bucketed on a uniform grid for overlap queries; `Quadtree`, 2-D points indexed by id |
32
+
33
+ ## Values and buffers
34
+
35
+ A shape or coordinate record is a plain array of numbers typed as a branded
36
+ tuple, holding exactly the numbers one element of the matching buffer holds. A
37
+ box is `[minX, minY, maxX, maxY]`, a circle `[centerX, centerY, radius]`, a ray
38
+ `[originX, originY, originZ, directionX, directionY, directionZ]`, a plane
39
+ `[normalX, normalY, normalZ, d]` with `n·p + d = 0`. Boxes, circles and
40
+ spheres have buffer forms: a tight `Float64Array` of the same records.
41
+
42
+ ```ts
43
+ import {
44
+ box2ContainsXy,
45
+ box2Create,
46
+ box2FromXywh,
47
+ box2ArrayFindLastIndexContainingXy,
48
+ box2Union,
49
+ } from "@ac-kit/math-geometry";
50
+
51
+ const button = box2FromXywh(box2Create(), 10, 20, 100, 30);
52
+ const toolbar = box2Union(box2Create(), button, box2FromXywh(box2Create(), 0, 0, 50, 50));
53
+
54
+ box2ContainsXy(button, 40, 30); // true: closed, boundary included
55
+
56
+ // UI hit-testing over packed boxes: the topmost box under the pointer, or −1.
57
+ const boxes = new Float64Array([0, 0, 200, 100, 10, 20, 110, 50]);
58
+ box2ArrayFindLastIndexContainingXy(boxes, 40, 30); // 1
59
+ ```
60
+
61
+ The standard is the one of `@ac-kit/math-linear`:
62
+
63
+ - **Creators allocate; operations write into `out`.** `box2Create()`,
64
+ `box2Of(minX, …)`, `box2Clone(box)`, `box2FromArray(out, source)`; every
65
+ function that makes a value takes `out` first, writes it and returns it, and
66
+ `out` may be any of the inputs. The per-element functions allocate nothing;
67
+ the bulk kernels that need working storage (`polygon2Triangulate` and
68
+ `polygon3Triangulate` allocate O(n) scratch, documented per function) say so.
69
+ There is no object literal and no exported constant array: an array literal
70
+ does not type-check as a `Box2`.
71
+ - **`out` is required and first.** `box2Union(out, a, b)`; a scalar result is
72
+ returned, a ray query returns its parameter (`Infinity` for a miss), an index
73
+ query returns `−1`, a fallible construction returns `boolean` and writes
74
+ `NaN` into `out` when it fails.
75
+ - **Degenerate input does not throw** in an operation: an undefined result is
76
+ `NaN`, and a zero direction is documented per function. Throws are limited to
77
+ builders (`mat3x3FromLocalFrame` with unknown axes), bulk length mismatches
78
+ (`RangeError`, once per call) and invalid constructor arguments
79
+ (`Box2GridIndex`).
80
+ - **Range of the arithmetic.** Lengths use `Math.sqrt`, so they are as
81
+ accurate as the products they sum. Plain arithmetic stays accurate while
82
+ the products involved (areas, cross products, squared distances,
83
+ barycentric determinants, a ray's perpendicular distance) stay within
84
+ [1e−150, 1e150], that is, for coordinates and extents between about 1e−75
85
+ and 1e75 in the degree-2 quantities. Outside that range a result may
86
+ underflow or overflow to `0`, `Infinity` or `NaN` (a fallible construction
87
+ then returns `false`). The mesh kernels follow the same range: vertex normals,
88
+ areas, volumes and centroids are accurate for edges between 1e−150 and 1e150
89
+ long, and generators for sizes within it. There are no `…Scaled` variants
90
+ yet.
91
+ - **Buffers are `Float64Array`s.** A value never aliases a buffer: it is
92
+ copied in and out with `box2Load(out, array, index)`, `box2Store(array, index,
93
+ value)`, the `…Strided` forms for interleaved data and `…StoreFloat32` for
94
+ staging. Bulk functions (`box2FromPoints`, `frustum3CullSphere3Array`,
95
+ `ray3FindNearestPoint`, `horizontalArrayFromVec3Enu`, …) are O(n) kernels
96
+ that read the count from the length.
97
+ - **Every record has** `…Create`, `…Of`, `…Clone`, `…Set`, `…Copy`, exact
98
+ `…Equals`, tolerant `…IsClose` and the checked `…FromArray`/`…IsFinite` for
99
+ data from outside (parsed JSON, messages): `box2FromArray(out, JSON.parse(text))`
100
+ writes `NaN` for anything that is not a number, so a value never holds a
101
+ non-number.
102
+
103
+ Rules for callers who bypass the types (JavaScript, a cast, an `any` from
104
+ `JSON.parse`): never store a non-number or `undefined` in a value, no `push`, no
105
+ length change; never pass a `Float64Array` or a hand-made array where a value is
106
+ expected, even once; make a copy with `…Clone`, not `structuredClone`. Enable
107
+ the type-aware lint rule `typescript/no-unsafe-argument` so that an `any` passed
108
+ where a value is expected is reported.
25
109
 
26
110
  ## Equality and tolerance
27
111
 
28
- `*Equals` is always **exact**. It is transitive, so it is safe as a `Set` or
29
- `Map` key and as a dedupe basis, and it agrees with the matching
30
- `*CompareLexicographic` — `compare(a, b) === 0` exactly when `equals(a, b)`. The
31
- tolerant counterpart is `*IsClose`, which is deliberately a different name
32
- because it is _not_ an equality: `a ≈ b` and `b ≈ c` does not give `a ≈ c`, so
33
- it must never back an ordering or a container.
34
-
35
- Which tolerance a predicate takes depends on what it asks:
36
-
37
- - **Solid predicates** — `circle2ContainsPoint`, `circle2Intersects` — are exact
38
- and take no tolerance. The boundary is measure-zero, so an epsilon would only
39
- move it by an arbitrary amount. For deliberate slack, inflate the shape:
40
- `circle2ContainsPoint({ ...c, radius: c.radius + margin }, p)`. That is a
41
- length; an epsilon on the squared distance actually compared is not.
42
- - **Incidence predicates** — `plane3ContainsPoint`, `line2ContainsPoint` — take
43
- a **linear** tolerance, a distance in your own units. Exact would be useless:
44
- a constructed point never lands exactly on a plane.
45
- - **Degeneracy guards** — `line2Intersect`, `segment2Intersect`,
46
- `ray3IntersectPlane` — take an **angular** tolerance. It is dimensionless and
47
- compared against a quantity already scaled by the operands' magnitudes, so
48
- rescaling an input never changes the verdict.
112
+ `…Equals` is always **exact**; the tolerant counterpart is `…IsClose`, which is
113
+ not an equality (it is not transitive) and must never back an ordering or a
114
+ `Set`. Which tolerance a predicate takes depends on what it asks:
115
+
116
+ - **Solid predicates** — `circle2ContainsPoint`, `box2ContainsPoint`,
117
+ `sphere3IntersectsSphere3` — are exact and take no tolerance; boundaries
118
+ count. For slack, inflate the shape (`box2ExpandByScalar`).
119
+ - **Incidence predicates** — `plane3ContainsPoint`, `line2ContainsPoint`,
120
+ `triangle3ContainsPoint` — take a **linear** tolerance, a distance in your own
121
+ units.
122
+ - **Degeneracy guards** — `line2IntersectLine2`, `segment2IntersectSegment2`,
123
+ `ray3IntersectPlane3` — take an **angular** tolerance, dimensionless and
124
+ compared against a quantity scaled by the operands' magnitudes, so rescaling
125
+ an input never changes the verdict.
49
126
 
50
127
  Each accepts its tolerance as a final argument and otherwise falls back to
51
128
  `geometryConfig`:
52
129
 
53
130
  ```ts
54
- import { geometryConfig, plane3ContainsPoint } from "@ac-kit/math-geometry";
131
+ import { geometryConfig, plane3ContainsPoint, plane3Of } from "@ac-kit/math-geometry";
132
+ import { vec3Of } from "@ac-kit/math-linear";
55
133
 
56
134
  // Per call
57
- plane3ContainsPoint(plane, point, 1e-6);
135
+ plane3ContainsPoint(plane3Of(0, 1, 0, -2), vec3Of(9, 2.0001, 9), 1e-3);
58
136
 
59
137
  // Or globally, if you work in millimetres rather than metres
60
138
  geometryConfig.defaultLinearTolerance = 1e-6;
61
139
  ```
62
140
 
63
- The two defaults are separate because the quantities are — the same split CAD
64
- kernels make between OpenCASCADE's `Precision::Confusion()` and
65
- `Precision::Angular()`. `geometryConfig` is process-global and mutable, so two
66
- libraries sharing a process cannot disagree; pass a tolerance explicitly
67
- wherever that matters.
141
+ `geometryConfig` is process-global and mutable, so two libraries sharing a
142
+ process cannot disagree; pass a tolerance explicitly wherever that matters.
68
143
 
69
- ## Point versus vector
144
+ ## Cameras: frustums and picking
145
+
146
+ `frustum3FromMat4x4(out, viewProjection, depthRange)` extracts six normalised
147
+ inward planes (Gribb–Hartmann); `depthRange` is the projection's own
148
+ (`"zero-to-one"`, `"negative-one-to-one"`, or `"one-to-zero"` for reversed
149
+ depth), and an infinite far plane is allowed: it culls nothing. A degenerate
150
+ matrix (all zeros, or a plane that holds nowhere) gives `NaN` planes, which
151
+ nothing passes.
152
+ `ray3FromViewport` gives the picking ray through a pixel, with a finite unit
153
+ direction in all three depth ranges, infinite far included.
154
+
155
+ ```ts
156
+ import {
157
+ frustum3Create,
158
+ frustum3CullSphere3Array,
159
+ frustum3FromMat4x4,
160
+ ray3Create,
161
+ ray3FindNearestSphere3,
162
+ ray3FromViewport,
163
+ } from "@ac-kit/math-geometry";
164
+ import {
165
+ mat4x4Create,
166
+ mat4x4Invert,
167
+ mat4x4LookAt,
168
+ mat4x4Multiply,
169
+ mat4x4Perspective,
170
+ vec3Of,
171
+ viewportOf,
172
+ } from "@ac-kit/math-linear";
70
173
 
71
- `Point2` and `Vec2` have the same representation and different meaning: a point
72
- is a position, a vector is a displacement. Subtracting two points yields a
73
- vector; adding a vector to a point yields a point; adding two points is not
74
- meaningful. The distinction is carried in the type names so that call sites read
75
- correctly, even though no runtime check enforces it.
174
+ const view = mat4x4LookAt(mat4x4Create(), vec3Of(0, 2, 10), vec3Of(0, 0, 0), vec3Of(0, 1, 0));
175
+ const projection = mat4x4Perspective(mat4x4Create(), 1, 16 / 9, 0.1, Infinity, "zero-to-one");
176
+ const viewProjection = mat4x4Multiply(mat4x4Create(), projection, view);
177
+
178
+ // Cull four spheres (centre and radius each): 1 for may-be-visible, 0 for out.
179
+ const frustum = frustum3FromMat4x4(frustum3Create(), viewProjection, "zero-to-one");
180
+ const spheres = new Float64Array([0, 0, 0, 1, 0, 0, 50, 1, 100, 0, 0, 1, 0, 0, -400, 5]);
181
+ const visible = new Uint8Array(4);
182
+ frustum3CullSphere3Array(visible, frustum, spheres);
183
+
184
+ // Pick: the nearest sphere under pixel (640, 360) of a 1280 × 720 target.
185
+ const inverse = mat4x4Create();
186
+ mat4x4Invert(inverse, viewProjection);
187
+ const ray = ray3FromViewport(ray3Create(), 640, 360, inverse, viewportOf(0, 0, 1280, 720), "zero-to-one");
188
+ ray3FindNearestSphere3(ray, spheres);
189
+ ```
190
+
191
+ ## Polygons and triangulation
192
+
193
+ A polygon is a `Float64Array` of `x, y` (or `x, y, z`) pairs, each ring
194
+ implicitly closed, holes given by the vertex index where each hole ring starts
195
+ (earcut's convention). `polygon2ContainsXy` takes a fill rule (`"nonzero"` or
196
+ `"evenodd"`, the Canvas and SVG spellings) and `polygon2Triangulate` clips ears
197
+ with the holes bridged to the outer ring, writing triangle indices into a
198
+ `Uint32Array` (`3·(n + 2h − 2)` entries).
199
+
200
+ ```ts
201
+ import { polygon2Area, polygon2Triangulate } from "@ac-kit/math-geometry";
202
+
203
+ // A square with a square hole: eight vertices, one hole starting at vertex 4.
204
+ const ring = new Float64Array([0, 0, 10, 0, 10, 10, 0, 10, 4, 4, 6, 4, 6, 6, 4, 6]);
205
+ const holes = new Uint32Array([4]);
206
+ const indices = new Uint32Array(3 * (8 + 2 - 2));
207
+ const triangles = polygon2Triangulate(indices, ring, holes); // 8
208
+ ```
209
+
210
+ ## Coordinates
211
+
212
+ Records are tuples; the system (up axis, local axes) is in the function name,
213
+ not in a type. Angles are radians; azimuths and signed angles are in `(−π, π]`
214
+ (`horizontalFromVec3Enu` gives `[0, 2π)` clockwise from north, as navigators
215
+ read it).
216
+
217
+ | System | Functions |
218
+ | ------------------ | ---------------------------------------------------------------------------------------------- |
219
+ | Polar | `polarFromVec2`, `vec2FromPolar`, and the polygonal norm `polygonalPolarFromVec2` |
220
+ | Spherical, Y up | `sphericalFromVec3YUp`, `vec3FromSphericalYUp` (orbit cameras) |
221
+ | Spherical, Z up | `sphericalFromVec3ZUp`, `vec3FromSphericalZUp` (ISO 80000-2) |
222
+ | Cylindrical | `cylindricalFromVec3YUp`, `…ZUp` and their inverses |
223
+ | Longitude–latitude | `vec3FromLongitudeLatitude`, `longitudeLatitudeFromVec3` and the buffer forms (longitude first) |
224
+ | Local frames | `mat3x3FromLocalFrame(out, position, "east-north-up" \| "north-east-down")` |
225
+ | Horizontal | `horizontalFromVec3Enu`, `vec3EnuFromHorizontal`, `horizontalArrayFromVec3Enu` |
226
+
227
+ ```ts
228
+ import {
229
+ horizontalCoordsCreate,
230
+ horizontalFromVec3Enu,
231
+ longitudeLatitudeOf,
232
+ mat3x3FromLocalFrame,
233
+ } from "@ac-kit/math-geometry";
234
+ import { mat3x3Create, vec3Create, vec3Of, vec3TransformMat3x3 } from "@ac-kit/math-linear";
235
+
236
+ // A direction in a Z-up global frame (ECEF, equatorial), seen from an observer.
237
+ const observer = longitudeLatitudeOf(0.1, 0.8);
238
+ const toLocal = mat3x3FromLocalFrame(mat3x3Create(), observer, "east-north-up");
239
+ const enu = vec3TransformMat3x3(vec3Create(), vec3Of(0.3, 0.2, 0.9), toLocal);
240
+ const sky = horizontalFromVec3Enu(horizontalCoordsCreate(), enu); // [azimuth, elevation, range]
241
+ ```
242
+
243
+ ## The sphere
244
+
245
+ Geometry of the abstract unit sphere, on unit `Vec3`s with north at +Z: no Earth,
246
+ no ellipsoid. `sphericalBearing`, `sphericalDestination`, `sphericalCircle` (a
247
+ small circle, counter-clockwise seen from outside) and `sphericalArc` (a
248
+ great-circle arc, ends included). Angular distance is `vec3AngleBetween` and
249
+ interpolation `vec3Slerp`, from `@ac-kit/math-linear`.
250
+
251
+ `sphericalArcClipToCap` and `sphericalPolylineClipToCap` clip to the cap of
252
+ angular radius `ρ` around a centre, which gives an azimuthal projection a safe
253
+ domain (the hemisphere for the orthographic one, a cap below `π` that keeps the
254
+ antipode out for the stereographic one): constellation lines, graticules and the
255
+ horizon are clipped before they are projected. The crossings are computed from
256
+ the plane of the arc and the plane of the cap, not found by bisection. A point
257
+ is in the cap when its angle to the centre is at most the radius (boundary
258
+ included, so a radius of `π / 2` keeps its equator), accurate for caps of any
259
+ size; every vertex in the cap is kept, and a polyline of `n` vertices needs room
260
+ for `9n − 6` numbers (`3n − 2` vertices: two crossings per arc at most).
261
+
262
+ ```ts
263
+ import { sphericalPolylineClipToCap } from "@ac-kit/math-geometry";
264
+ import { vec3Of } from "@ac-kit/math-linear";
265
+
266
+ // Three unit vectors along the equator; keep what is within 1 rad of +X.
267
+ const line = new Float64Array([1, 0, 0, 0.5, 0.866, 0, -0.5, 0.866, 0]);
268
+ const outVertices = new Float64Array(9 * 3 - 6);
269
+ const outRuns = new Uint32Array(3 + 1);
270
+ const runs = sphericalPolylineClipToCap(outVertices, outRuns, line, vec3Of(1, 0, 0), 1);
271
+ // runs === 1; outRuns[0] … outRuns[runs] are the CSR offsets of the visible vertices
272
+ ```
273
+
274
+ ## Meshes
275
+
276
+ A mesh is `positions` (a `Float64Array`, 3 numbers per vertex) and `indices` (3
277
+ per triangle, counter-clockwise from the front), each attribute its own packed
278
+ array: `normals` with 3 per vertex, `uvs` with 2. Interleaving and narrowing to
279
+ `Float32Array` are upload decisions. `indices` is a `Uint16Array` up to 65 535
280
+ vertices (`0xFFFF` stays free as WebGL 2's restart index) and a `Uint32Array`
281
+ above; `indexArrayCreate(length, vertexCount)` picks, and every kernel runs a
282
+ generated twin for the type it is given, so a program that sticks to one type
283
+ per mesh pays no mixing cost. Both twins give bit-identical results.
284
+
285
+ The generators (`mesh3Box`, `mesh3Plane`, `mesh3Heightfield`,
286
+ `mesh3Octahedron`, `mesh3IcoSphere`, `mesh3UvSphere`, `mesh3Cylinder`) make Y-up
287
+ meshes with every attribute, and `mesh3Merge` joins several into one. The kernels
288
+ (`mesh3VertexNormals`, `mesh3FaceNormals`, `mesh3SurfaceArea`, `mesh3Volume`,
289
+ `mesh3Centroid`, `mesh3IntersectRay3`, `mesh3TriangleDepths`,
290
+ `mesh3ReorderTriangles`) write into an `out` you provide, which must not share
291
+ memory with an input (`RangeError`). They check lengths once
292
+ and no index: an index past the last vertex reads `NaN`, which the checked layer
293
+ catches before an upload. A vertex no triangle uses, and a zero-area face, get
294
+ the zero normal; the volume is signed, positive when the faces point outward.
295
+
296
+ ```ts
297
+ import { mesh3Heightfield, mesh3VertexNormals } from "@ac-kit/math-geometry";
298
+
299
+ // A terrain of 125 × 155 heights: 19 375 vertices, so 16-bit indices.
300
+ const terrain = mesh3Heightfield({
301
+ heights: new Float64Array(125 * 155),
302
+ columns: 125,
303
+ rows: 155,
304
+ width: 10,
305
+ depth: 12,
306
+ });
307
+ const normals = mesh3VertexNormals(
308
+ new Float64Array(terrain.positions.length),
309
+ terrain.positions,
310
+ terrain.indices,
311
+ );
312
+ ```
313
+
314
+ ## Overlap queries over many boxes
315
+
316
+ `Box2GridIndex` buckets boxes on a uniform grid, so a label-collision pass costs
317
+ the boxes of the cells each label covers instead of all of them. Boundaries
318
+ count as overlap (the convention of `box2IntersectsBox2`).
319
+
320
+ ```ts
321
+ import { Box2GridIndex, box2FromXywh, box2Create } from "@ac-kit/math-geometry";
322
+
323
+ const index = new Box2GridIndex(box2FromXywh(box2Create(), 0, 0, 1000, 600), 32);
324
+ const label = box2FromXywh(box2Create(), 40, 40, 90, 14);
325
+ index.tryInsert(label, 1); // true: placed
326
+ index.tryInsert(box2FromXywh(box2Create(), 100, 44, 60, 14), 2); // false: it overlaps label 1
327
+ ```
328
+
329
+ ## Nearest point and range queries
330
+
331
+ `Quadtree` indexes 2-D points by integer id over a `Float64Array` of x, y
332
+ pairs, with d3-quadtree's cells and visit order at every ordinary scale. Stored
333
+ coordinates (construction, `assign`, `add`) must be finite with |x|, |y| ≤
334
+ 1e150; larger or non-finite values throw `RangeError` before the tree changes.
335
+ Queries never throw: `find` returns −1 for a NaN, infinite or beyond-±1e150
336
+ coordinate (outside the supported range: no result), and `forEachInBox` visits
337
+ what lies inside the supported range (an infinite box lists every id), nothing
338
+ for a NaN or inverted box.
339
+
340
+ ```ts
341
+ import { Quadtree } from "@ac-kit/math-geometry";
342
+
343
+ const tree = new Quadtree(Float64Array.of(0, 0, 3, 4, 10, 10));
344
+ tree.find(2, 3); // 1: the nearest id
345
+ tree.forEachInBox(0, 0, 5, 5, (id) => {}); // ids in a closed box
346
+ ```
76
347
 
77
348
  ## Angles
78
349
 
79
- Angles are radians throughout. `DEG_TO_RAD` and `RAD_TO_DEG` from
80
- `@ac-kit/math-scalar` convert at the boundary; nothing inside the package
81
- accepts degrees, since a mixed convention is the single most common source of
82
- geometry bugs.
350
+ Angles are radians throughout; the angle functions (`angleNormalizeRad`,
351
+ `angleWrapDeg`, …) live in `@ac-kit/math-scalar`, as do `DEG_TO_RAD` and
352
+ `RAD_TO_DEG`. Nothing inside this package accepts degrees: a mixed convention is
353
+ the single most common source of geometry bugs.
83
354
 
84
355
  See the
85
356
  [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/math-geometry/)
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The brand of every value type of the math packages: a property with a string
3
+ * key that is stable across versions, so two installed copies of a package (two
4
+ * dependents pinning different minors) stay assignable to each other, which a
5
+ * per-package `unique symbol` would not allow.
6
+ *
7
+ * Declared identically and internally in each package, never imported across
8
+ * packages: the structure is the identity. The key is reserved, and the brand
9
+ * costs nothing at run time.
10
+ */
11
+ export type Brand_<Name extends string> = {
12
+ readonly "~acKitMathType": Name;
13
+ };
14
+ //# sourceMappingURL=_brand.d.ts.map