@ac-kit/math-geometry 0.2.3 → 0.4.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 (379) hide show
  1. package/CHANGELOG.md +321 -0
  2. package/README.md +363 -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/_polygon3-cross.d.ts +23 -0
  12. package/dist/_polygon3-cross.d.ts.map +1 -0
  13. package/dist/_polygon3-cross.js +418 -0
  14. package/dist/_polygon3-cross.js.map +1 -0
  15. package/dist/_ray3-intersect.d.ts +19 -0
  16. package/dist/_ray3-intersect.d.ts.map +1 -0
  17. package/dist/_ray3-intersect.js +122 -0
  18. package/dist/_ray3-intersect.js.map +1 -0
  19. package/dist/_triangle3-cross.d.ts +66 -0
  20. package/dist/_triangle3-cross.d.ts.map +1 -0
  21. package/dist/_triangle3-cross.js +396 -0
  22. package/dist/_triangle3-cross.js.map +1 -0
  23. package/dist/box2-array-boundary.d.ts +50 -0
  24. package/dist/box2-array-boundary.d.ts.map +1 -0
  25. package/dist/box2-array-boundary.js +97 -0
  26. package/dist/box2-array-boundary.js.map +1 -0
  27. package/dist/box2-array.d.ts +42 -0
  28. package/dist/box2-array.d.ts.map +1 -0
  29. package/dist/box2-array.js +134 -0
  30. package/dist/box2-array.js.map +1 -0
  31. package/dist/box2-componentwise.d.ts +110 -0
  32. package/dist/box2-componentwise.d.ts.map +1 -0
  33. package/dist/box2-componentwise.js +325 -0
  34. package/dist/box2-componentwise.js.map +1 -0
  35. package/dist/box2-grid-index.d.ts +67 -0
  36. package/dist/box2-grid-index.d.ts.map +1 -0
  37. package/dist/box2-grid-index.js +198 -0
  38. package/dist/box2-grid-index.js.map +1 -0
  39. package/dist/box2-record.d.ts +83 -0
  40. package/dist/box2-record.d.ts.map +1 -0
  41. package/dist/box2-record.js +124 -0
  42. package/dist/box2-record.js.map +1 -0
  43. package/dist/box2.d.ts +38 -0
  44. package/dist/box2.d.ts.map +1 -0
  45. package/dist/box2.js +97 -0
  46. package/dist/box2.js.map +1 -0
  47. package/dist/box3-array-boundary.d.ts +50 -0
  48. package/dist/box3-array-boundary.d.ts.map +1 -0
  49. package/dist/box3-array-boundary.js +107 -0
  50. package/dist/box3-array-boundary.js.map +1 -0
  51. package/dist/box3-componentwise.d.ts +110 -0
  52. package/dist/box3-componentwise.d.ts.map +1 -0
  53. package/dist/box3-componentwise.js +392 -0
  54. package/dist/box3-componentwise.js.map +1 -0
  55. package/dist/box3-record.d.ts +92 -0
  56. package/dist/box3-record.d.ts.map +1 -0
  57. package/dist/box3-record.js +147 -0
  58. package/dist/box3-record.js.map +1 -0
  59. package/dist/box3.d.ts +19 -16
  60. package/dist/box3.d.ts.map +1 -1
  61. package/dist/box3.js +73 -76
  62. package/dist/box3.js.map +1 -1
  63. package/dist/box4-array-boundary.d.ts +50 -0
  64. package/dist/box4-array-boundary.d.ts.map +1 -0
  65. package/dist/box4-array-boundary.js +117 -0
  66. package/dist/box4-array-boundary.js.map +1 -0
  67. package/dist/box4-componentwise.d.ts +110 -0
  68. package/dist/box4-componentwise.d.ts.map +1 -0
  69. package/dist/box4-componentwise.js +459 -0
  70. package/dist/box4-componentwise.js.map +1 -0
  71. package/dist/box4-record.d.ts +96 -0
  72. package/dist/box4-record.d.ts.map +1 -0
  73. package/dist/box4-record.js +167 -0
  74. package/dist/box4-record.js.map +1 -0
  75. package/dist/box4.d.ts +13 -8
  76. package/dist/box4.d.ts.map +1 -1
  77. package/dist/box4.js +27 -5
  78. package/dist/box4.js.map +1 -1
  79. package/dist/circle2-array-boundary.d.ts +51 -0
  80. package/dist/circle2-array-boundary.d.ts.map +1 -0
  81. package/dist/circle2-array-boundary.js +93 -0
  82. package/dist/circle2-array-boundary.js.map +1 -0
  83. package/dist/circle2-array.d.ts +17 -0
  84. package/dist/circle2-array.d.ts.map +1 -0
  85. package/dist/circle2-array.js +44 -0
  86. package/dist/circle2-array.js.map +1 -0
  87. package/dist/circle2-record.d.ts +81 -0
  88. package/dist/circle2-record.d.ts.map +1 -0
  89. package/dist/circle2-record.js +114 -0
  90. package/dist/circle2-record.js.map +1 -0
  91. package/dist/circle2.d.ts +27 -82
  92. package/dist/circle2.d.ts.map +1 -1
  93. package/dist/circle2.js +59 -104
  94. package/dist/circle2.js.map +1 -1
  95. package/dist/coordinates/cylindrical-record.d.ts +86 -0
  96. package/dist/coordinates/cylindrical-record.d.ts.map +1 -0
  97. package/dist/coordinates/cylindrical-record.js +114 -0
  98. package/dist/coordinates/cylindrical-record.js.map +1 -0
  99. package/dist/coordinates/horizontal-record.d.ts +86 -0
  100. package/dist/coordinates/horizontal-record.d.ts.map +1 -0
  101. package/dist/coordinates/horizontal-record.js +114 -0
  102. package/dist/coordinates/horizontal-record.js.map +1 -0
  103. package/dist/coordinates/horizontal.d.ts +48 -0
  104. package/dist/coordinates/horizontal.d.ts.map +1 -0
  105. package/dist/coordinates/horizontal.js +100 -0
  106. package/dist/coordinates/horizontal.js.map +1 -0
  107. package/dist/coordinates/index.d.ts +10 -0
  108. package/dist/coordinates/index.d.ts.map +1 -0
  109. package/dist/coordinates/index.js +10 -0
  110. package/dist/coordinates/index.js.map +1 -0
  111. package/dist/coordinates/longitude-latitude-record.d.ts +81 -0
  112. package/dist/coordinates/longitude-latitude-record.d.ts.map +1 -0
  113. package/dist/coordinates/longitude-latitude-record.js +104 -0
  114. package/dist/coordinates/longitude-latitude-record.js.map +1 -0
  115. package/dist/coordinates/longitude-latitude.d.ts +33 -0
  116. package/dist/coordinates/longitude-latitude.d.ts.map +1 -0
  117. package/dist/coordinates/longitude-latitude.js +78 -0
  118. package/dist/coordinates/longitude-latitude.js.map +1 -0
  119. package/dist/coordinates/polar-record.d.ts +77 -0
  120. package/dist/coordinates/polar-record.d.ts.map +1 -0
  121. package/dist/coordinates/polar-record.js +104 -0
  122. package/dist/coordinates/polar-record.js.map +1 -0
  123. package/dist/coordinates/polar.d.ts +28 -0
  124. package/dist/coordinates/polar.d.ts.map +1 -0
  125. package/dist/coordinates/polar.js +68 -0
  126. package/dist/coordinates/polar.js.map +1 -0
  127. package/dist/coordinates/spherical-cylindrical.d.ts +49 -0
  128. package/dist/coordinates/spherical-cylindrical.d.ts.map +1 -0
  129. package/dist/coordinates/spherical-cylindrical.js +110 -0
  130. package/dist/coordinates/spherical-cylindrical.js.map +1 -0
  131. package/dist/coordinates/spherical-record.d.ts +86 -0
  132. package/dist/coordinates/spherical-record.d.ts.map +1 -0
  133. package/dist/coordinates/spherical-record.js +114 -0
  134. package/dist/coordinates/spherical-record.js.map +1 -0
  135. package/dist/frustum3-record.d.ts +132 -0
  136. package/dist/frustum3-record.d.ts.map +1 -0
  137. package/dist/frustum3-record.js +333 -0
  138. package/dist/frustum3-record.js.map +1 -0
  139. package/dist/frustum3.d.ts +60 -0
  140. package/dist/frustum3.d.ts.map +1 -0
  141. package/dist/frustum3.js +186 -0
  142. package/dist/frustum3.js.map +1 -0
  143. package/dist/index.d.ts +36 -16
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +36 -16
  146. package/dist/index.js.map +1 -1
  147. package/dist/line2-record.d.ts +87 -0
  148. package/dist/line2-record.d.ts.map +1 -0
  149. package/dist/line2-record.js +123 -0
  150. package/dist/line2-record.js.map +1 -0
  151. package/dist/line2.d.ts +24 -33
  152. package/dist/line2.d.ts.map +1 -1
  153. package/dist/line2.js +78 -52
  154. package/dist/line2.js.map +1 -1
  155. package/dist/line3-record.d.ts +91 -0
  156. package/dist/line3-record.d.ts.map +1 -0
  157. package/dist/line3-record.js +146 -0
  158. package/dist/line3-record.js.map +1 -0
  159. package/dist/line3.d.ts +11 -24
  160. package/dist/line3.d.ts.map +1 -1
  161. package/dist/line3.js +32 -36
  162. package/dist/line3.js.map +1 -1
  163. package/dist/mesh/_generator-kit.d.ts +14 -0
  164. package/dist/mesh/_generator-kit.d.ts.map +1 -0
  165. package/dist/mesh/_generator-kit.js +39 -0
  166. package/dist/mesh/_generator-kit.js.map +1 -0
  167. package/dist/mesh/_index-kernels-u16.d.ts +85 -0
  168. package/dist/mesh/_index-kernels-u16.d.ts.map +1 -0
  169. package/dist/mesh/_index-kernels-u16.js +1045 -0
  170. package/dist/mesh/_index-kernels-u16.js.map +1 -0
  171. package/dist/mesh/_index-kernels-u32.d.ts +85 -0
  172. package/dist/mesh/_index-kernels-u32.d.ts.map +1 -0
  173. package/dist/mesh/_index-kernels-u32.js +1045 -0
  174. package/dist/mesh/_index-kernels-u32.js.map +1 -0
  175. package/dist/mesh/generate-box.d.ts +16 -0
  176. package/dist/mesh/generate-box.d.ts.map +1 -0
  177. package/dist/mesh/generate-box.js +79 -0
  178. package/dist/mesh/generate-box.js.map +1 -0
  179. package/dist/mesh/generate-cylinder.d.ts +25 -0
  180. package/dist/mesh/generate-cylinder.d.ts.map +1 -0
  181. package/dist/mesh/generate-cylinder.js +117 -0
  182. package/dist/mesh/generate-cylinder.js.map +1 -0
  183. package/dist/mesh/generate-heightfield.d.ts +24 -0
  184. package/dist/mesh/generate-heightfield.d.ts.map +1 -0
  185. package/dist/mesh/generate-heightfield.js +48 -0
  186. package/dist/mesh/generate-heightfield.js.map +1 -0
  187. package/dist/mesh/generate-plane.d.ts +18 -0
  188. package/dist/mesh/generate-plane.d.ts.map +1 -0
  189. package/dist/mesh/generate-plane.js +39 -0
  190. package/dist/mesh/generate-plane.js.map +1 -0
  191. package/dist/mesh/generate-sphere.d.ts +50 -0
  192. package/dist/mesh/generate-sphere.d.ts.map +1 -0
  193. package/dist/mesh/generate-sphere.js +244 -0
  194. package/dist/mesh/generate-sphere.js.map +1 -0
  195. package/dist/mesh/index.d.ts +8 -0
  196. package/dist/mesh/index.d.ts.map +1 -0
  197. package/dist/mesh/index.js +8 -0
  198. package/dist/mesh/index.js.map +1 -0
  199. package/dist/mesh/mesh3-kernels.d.ts +122 -0
  200. package/dist/mesh/mesh3-kernels.d.ts.map +1 -0
  201. package/dist/mesh/mesh3-kernels.js +220 -0
  202. package/dist/mesh/mesh3-kernels.js.map +1 -0
  203. package/dist/mesh/mesh3.d.ts +66 -0
  204. package/dist/mesh/mesh3.d.ts.map +1 -0
  205. package/dist/mesh/mesh3.js +128 -0
  206. package/dist/mesh/mesh3.js.map +1 -0
  207. package/dist/plane3-record.d.ts +88 -0
  208. package/dist/plane3-record.d.ts.map +1 -0
  209. package/dist/plane3-record.js +123 -0
  210. package/dist/plane3-record.js.map +1 -0
  211. package/dist/plane3.d.ts +43 -28
  212. package/dist/plane3.d.ts.map +1 -1
  213. package/dist/plane3.js +149 -48
  214. package/dist/plane3.js.map +1 -1
  215. package/dist/polygon2.d.ts +132 -29
  216. package/dist/polygon2.d.ts.map +1 -1
  217. package/dist/polygon2.js +529 -96
  218. package/dist/polygon2.js.map +1 -1
  219. package/dist/polygon3.d.ts +56 -21
  220. package/dist/polygon3.d.ts.map +1 -1
  221. package/dist/polygon3.js +239 -91
  222. package/dist/polygon3.js.map +1 -1
  223. package/dist/polyline2.d.ts +37 -0
  224. package/dist/polyline2.d.ts.map +1 -0
  225. package/dist/polyline2.js +146 -0
  226. package/dist/polyline2.js.map +1 -0
  227. package/dist/polyline3.d.ts +35 -0
  228. package/dist/polyline3.d.ts.map +1 -0
  229. package/dist/polyline3.js +159 -0
  230. package/dist/polyline3.js.map +1 -0
  231. package/dist/quadtree.d.ts +255 -0
  232. package/dist/quadtree.d.ts.map +1 -0
  233. package/dist/quadtree.js +1096 -0
  234. package/dist/quadtree.js.map +1 -0
  235. package/dist/ray2-record.d.ts +86 -0
  236. package/dist/ray2-record.d.ts.map +1 -0
  237. package/dist/ray2-record.js +123 -0
  238. package/dist/ray2-record.js.map +1 -0
  239. package/dist/ray2.d.ts +38 -13
  240. package/dist/ray2.d.ts.map +1 -1
  241. package/dist/ray2.js +85 -22
  242. package/dist/ray2.js.map +1 -1
  243. package/dist/ray3-array.d.ts +27 -0
  244. package/dist/ray3-array.d.ts.map +1 -0
  245. package/dist/ray3-array.js +89 -0
  246. package/dist/ray3-array.js.map +1 -0
  247. package/dist/ray3-record.d.ts +90 -0
  248. package/dist/ray3-record.d.ts.map +1 -0
  249. package/dist/ray3-record.js +146 -0
  250. package/dist/ray3-record.js.map +1 -0
  251. package/dist/ray3.d.ts +72 -25
  252. package/dist/ray3.d.ts.map +1 -1
  253. package/dist/ray3.js +233 -64
  254. package/dist/ray3.js.map +1 -1
  255. package/dist/segment2-record.d.ts +80 -0
  256. package/dist/segment2-record.d.ts.map +1 -0
  257. package/dist/segment2-record.js +122 -0
  258. package/dist/segment2-record.js.map +1 -0
  259. package/dist/segment2.d.ts +39 -19
  260. package/dist/segment2.d.ts.map +1 -1
  261. package/dist/segment2.js +104 -42
  262. package/dist/segment2.js.map +1 -1
  263. package/dist/segment3-record.d.ts +90 -0
  264. package/dist/segment3-record.d.ts.map +1 -0
  265. package/dist/segment3-record.js +146 -0
  266. package/dist/segment3-record.js.map +1 -0
  267. package/dist/segment3.d.ts +24 -12
  268. package/dist/segment3.d.ts.map +1 -1
  269. package/dist/segment3.js +67 -30
  270. package/dist/segment3.js.map +1 -1
  271. package/dist/size.d.ts +40 -0
  272. package/dist/size.d.ts.map +1 -0
  273. package/dist/size.js +72 -0
  274. package/dist/size.js.map +1 -0
  275. package/dist/sphere3-array-boundary.d.ts +51 -0
  276. package/dist/sphere3-array-boundary.d.ts.map +1 -0
  277. package/dist/sphere3-array-boundary.js +98 -0
  278. package/dist/sphere3-array-boundary.js.map +1 -0
  279. package/dist/sphere3-record.d.ts +88 -0
  280. package/dist/sphere3-record.d.ts.map +1 -0
  281. package/dist/sphere3-record.js +123 -0
  282. package/dist/sphere3-record.js.map +1 -0
  283. package/dist/sphere3.d.ts +55 -12
  284. package/dist/sphere3.d.ts.map +1 -1
  285. package/dist/sphere3.js +233 -24
  286. package/dist/sphere3.js.map +1 -1
  287. package/dist/spherical/cap.d.ts +56 -0
  288. package/dist/spherical/cap.d.ts.map +1 -0
  289. package/dist/spherical/cap.js +363 -0
  290. package/dist/spherical/cap.js.map +1 -0
  291. package/dist/spherical/great-circle.d.ts +39 -0
  292. package/dist/spherical/great-circle.d.ts.map +1 -0
  293. package/dist/spherical/great-circle.js +158 -0
  294. package/dist/spherical/great-circle.js.map +1 -0
  295. package/dist/spherical/index.d.ts +3 -0
  296. package/dist/spherical/index.d.ts.map +1 -0
  297. package/dist/spherical/index.js +3 -0
  298. package/dist/spherical/index.js.map +1 -0
  299. package/dist/triangle2-record.d.ts +91 -0
  300. package/dist/triangle2-record.d.ts.map +1 -0
  301. package/dist/triangle2-record.js +146 -0
  302. package/dist/triangle2-record.js.map +1 -0
  303. package/dist/triangle2.d.ts +29 -14
  304. package/dist/triangle2.d.ts.map +1 -1
  305. package/dist/triangle2.js +86 -22
  306. package/dist/triangle2.js.map +1 -1
  307. package/dist/triangle3-record.d.ts +97 -0
  308. package/dist/triangle3-record.d.ts.map +1 -0
  309. package/dist/triangle3-record.js +178 -0
  310. package/dist/triangle3-record.js.map +1 -0
  311. package/dist/triangle3.d.ts +60 -17
  312. package/dist/triangle3.d.ts.map +1 -1
  313. package/dist/triangle3.js +287 -38
  314. package/dist/triangle3.js.map +1 -1
  315. package/package.json +15 -8
  316. package/dist/angles.d.ts +0 -31
  317. package/dist/angles.d.ts.map +0 -1
  318. package/dist/angles.js +0 -53
  319. package/dist/angles.js.map +0 -1
  320. package/dist/coordinate-spaces.d.ts +0 -39
  321. package/dist/coordinate-spaces.d.ts.map +0 -1
  322. package/dist/coordinate-spaces.js +0 -52
  323. package/dist/coordinate-spaces.js.map +0 -1
  324. package/dist/coordinates-vec2.d.ts +0 -7
  325. package/dist/coordinates-vec2.d.ts.map +0 -1
  326. package/dist/coordinates-vec2.js +0 -35
  327. package/dist/coordinates-vec2.js.map +0 -1
  328. package/dist/coordinates-vec3.d.ts +0 -11
  329. package/dist/coordinates-vec3.d.ts.map +0 -1
  330. package/dist/coordinates-vec3.js +0 -61
  331. package/dist/coordinates-vec3.js.map +0 -1
  332. package/dist/coordinates.d.ts +0 -54
  333. package/dist/coordinates.d.ts.map +0 -1
  334. package/dist/coordinates.js +0 -2
  335. package/dist/coordinates.js.map +0 -1
  336. package/dist/euler-angles-quaternion.d.ts +0 -7
  337. package/dist/euler-angles-quaternion.d.ts.map +0 -1
  338. package/dist/euler-angles-quaternion.js +0 -100
  339. package/dist/euler-angles-quaternion.js.map +0 -1
  340. package/dist/euler-angles.d.ts +0 -33
  341. package/dist/euler-angles.d.ts.map +0 -1
  342. package/dist/euler-angles.js +0 -35
  343. package/dist/euler-angles.js.map +0 -1
  344. package/dist/geometry-vectors.d.ts +0 -11
  345. package/dist/geometry-vectors.d.ts.map +0 -1
  346. package/dist/geometry-vectors.js +0 -19
  347. package/dist/geometry-vectors.js.map +0 -1
  348. package/dist/mesh3.d.ts +0 -32
  349. package/dist/mesh3.d.ts.map +0 -1
  350. package/dist/mesh3.js +0 -142
  351. package/dist/mesh3.js.map +0 -1
  352. package/dist/point2.d.ts +0 -41
  353. package/dist/point2.d.ts.map +0 -1
  354. package/dist/point2.js +0 -92
  355. package/dist/point2.js.map +0 -1
  356. package/dist/point3.d.ts +0 -43
  357. package/dist/point3.d.ts.map +0 -1
  358. package/dist/point3.js +0 -103
  359. package/dist/point3.js.map +0 -1
  360. package/dist/point4.d.ts +0 -12
  361. package/dist/point4.d.ts.map +0 -1
  362. package/dist/point4.js +0 -28
  363. package/dist/point4.js.map +0 -1
  364. package/dist/rect2.d.ts +0 -54
  365. package/dist/rect2.d.ts.map +0 -1
  366. package/dist/rect2.js +0 -149
  367. package/dist/rect2.js.map +0 -1
  368. package/dist/size2.d.ts +0 -33
  369. package/dist/size2.d.ts.map +0 -1
  370. package/dist/size2.js +0 -81
  371. package/dist/size2.js.map +0 -1
  372. package/dist/size3.d.ts +0 -21
  373. package/dist/size3.d.ts.map +0 -1
  374. package/dist/size3.js +0 -59
  375. package/dist/size3.js.map +0 -1
  376. package/dist/size4.d.ts +0 -10
  377. package/dist/size4.d.ts.map +0 -1
  378. package/dist/size4.js +0 -16
  379. package/dist/size4.js.map +0 -1
package/README.md CHANGED
@@ -1,85 +1,396 @@
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.
143
+
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";
173
+
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
+ `polygon2SignedArea` and `polygon2Area` take an optional vertex count, for a
201
+ polygon held at the start of a longer working buffer, and
202
+ `polygon2ClipHalfPlane` cuts the first `n` vertices of one buffer to a
203
+ half-plane `(normalX, normalY, limit)` read from a third (Sutherland–Hodgman;
204
+ at most `n + 1` vertices for a convex polygon, `⌊3n/2⌋` for a concave one,
205
+ whose pieces stay joined by zero-width bridges of no area). No double crosses
206
+ the clip's call, so clipping twice and measuring, as area-coverage
207
+ antialiasing does per pixel, allocates nothing; the clip refuses an `out` that
208
+ shares memory with its input, since it cannot work in place.
209
+
210
+ ```ts
211
+ import { polygon2Area, polygon2ClipHalfPlane } from "@ac-kit/math-geometry";
212
+
213
+ // The area of a pixel square left of x = 0.3 and below y = 0.2.
214
+ const pixel = new Float64Array([0, 0, 1, 0, 1, 1, 0, 1]);
215
+ const planes = new Float64Array([1, 0, 0.3, 0, 1, 0.2]);
216
+ const half = new Float64Array(12);
217
+ const quarter = new Float64Array(16);
218
+ const halfCount = polygon2ClipHalfPlane(half, pixel, 4, planes, 0);
219
+ const count = polygon2ClipHalfPlane(quarter, half, halfCount, planes, 3);
220
+ polygon2Area(quarter, count); // ≈ 0.06
221
+ ```
222
+
223
+ ```ts
224
+ import { polygon2Area, polygon2Triangulate } from "@ac-kit/math-geometry";
225
+
226
+ // A square with a square hole: eight vertices, one hole starting at vertex 4.
227
+ const ring = new Float64Array([0, 0, 10, 0, 10, 10, 0, 10, 4, 4, 6, 4, 6, 6, 4, 6]);
228
+ const holes = new Uint32Array([4]);
229
+ const indices = new Uint32Array(3 * (8 + 2 - 2));
230
+ const triangles = polygon2Triangulate(indices, ring, holes); // 8
231
+ ```
232
+
233
+ ## Coordinates
234
+
235
+ Records are tuples; the system (up axis, local axes) is in the function name,
236
+ not in a type. Angles are radians; azimuths and signed angles are in `(−π, π]`
237
+ (`horizontalFromVec3Enu` gives `[0, 2π)` clockwise from north, as navigators
238
+ read it).
239
+
240
+ | System | Functions |
241
+ | ------------------ | ---------------------------------------------------------------------------------------------- |
242
+ | Polar | `polarFromVec2`, `vec2FromPolar`, and the polygonal norm `polygonalPolarFromVec2` |
243
+ | Spherical, Y up | `sphericalFromVec3YUp`, `vec3FromSphericalYUp` (orbit cameras) |
244
+ | Spherical, Z up | `sphericalFromVec3ZUp`, `vec3FromSphericalZUp` (ISO 80000-2) |
245
+ | Cylindrical | `cylindricalFromVec3YUp`, `…ZUp` and their inverses |
246
+ | Longitude–latitude | `vec3FromLongitudeLatitude`, `longitudeLatitudeFromVec3` and the buffer forms (longitude first) |
247
+ | Local frames | `mat3x3FromLocalFrame(out, position, "east-north-up" \| "north-east-down")` |
248
+ | Horizontal | `horizontalFromVec3Enu`, `vec3EnuFromHorizontal`, `horizontalArrayFromVec3Enu` |
249
+
250
+ ```ts
251
+ import {
252
+ horizontalCoordsCreate,
253
+ horizontalFromVec3Enu,
254
+ longitudeLatitudeOf,
255
+ mat3x3FromLocalFrame,
256
+ } from "@ac-kit/math-geometry";
257
+ import { mat3x3Create, vec3Create, vec3Of, vec3TransformMat3x3 } from "@ac-kit/math-linear";
258
+
259
+ // A direction in a Z-up global frame (ECEF, equatorial), seen from an observer.
260
+ const observer = longitudeLatitudeOf(0.1, 0.8);
261
+ const toLocal = mat3x3FromLocalFrame(mat3x3Create(), observer, "east-north-up");
262
+ const enu = vec3TransformMat3x3(vec3Create(), vec3Of(0.3, 0.2, 0.9), toLocal);
263
+ const sky = horizontalFromVec3Enu(horizontalCoordsCreate(), enu); // [azimuth, elevation, range]
264
+ ```
265
+
266
+ ## The sphere
267
+
268
+ Geometry of the abstract unit sphere, on unit `Vec3`s with north at +Z: no Earth,
269
+ no ellipsoid. `sphericalBearing`, `sphericalDestination`, `sphericalCircle` (a
270
+ small circle, counter-clockwise seen from outside) and `sphericalArc` (a
271
+ great-circle arc, ends included). Angular distance is `vec3AngleBetween` and
272
+ interpolation `vec3Slerp`, from `@ac-kit/math-linear`.
273
+
274
+ `sphericalArcClipToCap` and `sphericalPolylineClipToCap` clip to the cap of
275
+ angular radius `ρ` around a centre, which gives an azimuthal projection a safe
276
+ domain (the hemisphere for the orthographic one, a cap below `π` that keeps the
277
+ antipode out for the stereographic one): constellation lines, graticules and the
278
+ horizon are clipped before they are projected. The crossings are computed from
279
+ the plane of the arc and the plane of the cap, not found by bisection. A point
280
+ is in the cap when its angle to the centre is at most the radius (boundary
281
+ included, so a radius of `π / 2` keeps its equator), accurate for caps of any
282
+ size; every vertex in the cap is kept, and a polyline of `n` vertices needs room
283
+ for `9n − 6` numbers (`3n − 2` vertices: two crossings per arc at most).
284
+
285
+ ```ts
286
+ import { sphericalPolylineClipToCap } from "@ac-kit/math-geometry";
287
+ import { vec3Of } from "@ac-kit/math-linear";
288
+
289
+ // Three unit vectors along the equator; keep what is within 1 rad of +X.
290
+ const line = new Float64Array([1, 0, 0, 0.5, 0.866, 0, -0.5, 0.866, 0]);
291
+ const outVertices = new Float64Array(9 * 3 - 6);
292
+ const outRuns = new Uint32Array(3 + 1);
293
+ const runs = sphericalPolylineClipToCap(outVertices, outRuns, line, vec3Of(1, 0, 0), 1);
294
+ // runs === 1; outRuns[0] … outRuns[runs] are the CSR offsets of the visible vertices
295
+ ```
296
+
297
+ ## Meshes
298
+
299
+ A mesh is `positions` (a `Float64Array`, 3 numbers per vertex) and `indices` (3
300
+ per triangle, counter-clockwise from the front), each attribute its own packed
301
+ array: `normals` with 3 per vertex, `uvs` with 2. Interleaving and narrowing to
302
+ `Float32Array` are upload decisions. `indices` is a `Uint16Array` up to 65 535
303
+ vertices (`0xFFFF` stays free as WebGL 2's restart index) and a `Uint32Array`
304
+ above; `indexArrayCreate(length, vertexCount)` picks, and every kernel runs a
305
+ generated twin for the type it is given, so a program that sticks to one type
306
+ per mesh pays no mixing cost. Both twins give bit-identical results.
68
307
 
69
- ## Point versus vector
308
+ The generators (`mesh3Box`, `mesh3Plane`, `mesh3Heightfield`,
309
+ `mesh3Octahedron`, `mesh3IcoSphere`, `mesh3UvSphere`, `mesh3Cylinder`) make Y-up
310
+ meshes with every attribute, and `mesh3Merge` joins several into one. The kernels
311
+ (`mesh3VertexNormals`, `mesh3FaceNormals`, `mesh3SurfaceArea`, `mesh3Volume`,
312
+ `mesh3Centroid`, `mesh3IntersectRay3`, `mesh3TriangleDepths`,
313
+ `mesh3ReorderTriangles`) write into an `out` you provide, which must not share
314
+ memory with an input (`RangeError`). They check lengths once
315
+ and no index: an index past the last vertex reads `NaN`, which the checked layer
316
+ catches before an upload. A vertex no triangle uses, and a degenerate face (an
317
+ exactly zero cross product: collinear or repeated corners), get the zero
318
+ normal; every other face gets a unit normal with the exact cross product's
319
+ direction, within 2^−48 per component (normwise, about 3.4 · 2^−53 at worst
320
+ in testing): a component smaller than that beside the largest may round to a
321
+ zero of either sign, an exactly zero one is +0. That holds however long, thin,
322
+ small or far out the face is. A vertex normal is the direction of the exact sum
323
+ of its faces' cross products, within 2^−48 per component (normwise), the zero
324
+ vector where that sum is zero: each sum carries a running error bound, and a
325
+ vertex it does not settle (faces that cancel, however large beside the ones
326
+ left) is summed again exactly. `polygon3Normal` gives a polygon's normal with
327
+ the same guarantee as a face's, from the exact Newell vector. The volume is
328
+ signed, positive when the faces point outward.
329
+ The area, volume and centroid scale each axis by its own power of two and sum
330
+ exactly, so they give the same result in every face order and never overflow
331
+ on the way, for a mesh however thin, wide or small and anywhere up to
332
+ ±`Number.MAX_VALUE`.
70
333
 
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.
334
+ ```ts
335
+ import { mesh3Heightfield, mesh3VertexNormals } from "@ac-kit/math-geometry";
336
+
337
+ // A terrain of 125 × 155 heights: 19 375 vertices, so 16-bit indices.
338
+ const terrain = mesh3Heightfield({
339
+ heights: new Float64Array(125 * 155),
340
+ columns: 125,
341
+ rows: 155,
342
+ width: 10,
343
+ depth: 12,
344
+ });
345
+ const normals = mesh3VertexNormals(
346
+ new Float64Array(terrain.positions.length),
347
+ terrain.positions,
348
+ terrain.indices,
349
+ );
350
+ ```
351
+
352
+ ## Overlap queries over many boxes
353
+
354
+ `Box2GridIndex` buckets boxes on a uniform grid, so a label-collision pass costs
355
+ the boxes of the cells each label covers instead of all of them. Boundaries
356
+ count as overlap (the convention of `box2IntersectsBox2`).
357
+
358
+ ```ts
359
+ import { Box2GridIndex, box2FromXywh, box2Create } from "@ac-kit/math-geometry";
360
+
361
+ const index = new Box2GridIndex(box2FromXywh(box2Create(), 0, 0, 1000, 600), 32);
362
+ const label = box2FromXywh(box2Create(), 40, 40, 90, 14);
363
+ index.tryInsert(label, 1); // true: placed
364
+ index.tryInsert(box2FromXywh(box2Create(), 100, 44, 60, 14), 2); // false: it overlaps label 1
365
+ ```
366
+
367
+ ## Nearest point and range queries
368
+
369
+ `Quadtree` indexes 2-D points by integer id over a `Float64Array` of x, y
370
+ pairs, with d3-quadtree's cells and visit order at every ordinary scale. Its
371
+ storage is typed columns reused across calls, so once warmed up `assign`,
372
+ `visit`, `visitAfter`, `find` and `forEachInBox` allocate nothing. Stored
373
+ coordinates (construction, `assign`, `add`) must be finite with |x|, |y| ≤
374
+ 1e150; larger or non-finite values throw `RangeError` before the tree changes.
375
+ Queries never throw: `find` returns −1 for a NaN, infinite or beyond-±1e150
376
+ coordinate (outside the supported range: no result), and `forEachInBox` visits
377
+ what lies inside the supported range (an infinite box lists every id), nothing
378
+ for a NaN or inverted box.
379
+
380
+ ```ts
381
+ import { Quadtree } from "@ac-kit/math-geometry";
382
+
383
+ const tree = new Quadtree(Float64Array.of(0, 0, 3, 4, 10, 10));
384
+ tree.find(2, 3); // 1: the nearest id
385
+ tree.forEachInBox(0, 0, 5, 5, (id) => {}); // ids in a closed box
386
+ ```
76
387
 
77
388
  ## Angles
78
389
 
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.
390
+ Angles are radians throughout; the angle functions (`angleNormalizeRad`,
391
+ `angleWrapDeg`, …) live in `@ac-kit/math-scalar`, as do `DEG_TO_RAD` and
392
+ `RAD_TO_DEG`. Nothing inside this package accepts degrees: a mixed convention is
393
+ the single most common source of geometry bugs.
83
394
 
84
395
  See the
85
396
  [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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_brand.d.ts","sourceRoot":"","sources":["../src/_brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,MAAM,CAAC,IAAI,SAAS,MAAM,IAAI;IACzC,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC;CAChC,CAAC"}
package/dist/_brand.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=_brand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_brand.js","sourceRoot":"","sources":["../src/_brand.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Ear clipping of a polygon with holes, over packed 2D coordinates: the
3
+ * implementation behind `polygon2Triangulate` and `polygon3Triangulate`.
4
+ *
5
+ * The outer ring is made counter-clockwise (y up) and every hole clockwise;
6
+ * holes are then bridged to the outer ring from their rightmost vertex, in
7
+ * decreasing order of that vertex's x (Eberly), which gives one weakly simple
8
+ * ring held in a doubly linked list over typed arrays; ears are clipped from
9
+ * it. Triangles come out counter-clockwise. Degenerate input (collinear runs,
10
+ * duplicate points, touching rings) never loops: a pass that finds no ear
11
+ * removes degenerate nodes, and then clips a convex vertex, one covering no
12
+ * other vertex if there is one.
13
+ */
14
+ /**
15
+ * Writes the triangles of the polygon (indices into `coordinates`' vertices,
16
+ * three per triangle, counter-clockwise in a y-up frame) into `out` and returns
17
+ * how many. `holeStarts` was validated by the caller.
18
+ */
19
+ export declare function earClip_(out: Uint32Array, coordinates: Float64Array, holeStarts: Uint32Array | undefined): number;
20
+ //# sourceMappingURL=_ear-clipping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ear-clipping.d.ts","sourceRoot":"","sources":["../src/_ear-clipping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAkUH;;;;GAIG;AACH,wBAAgB,QAAQ,CACvB,GAAG,EAAE,WAAW,EAChB,WAAW,EAAE,YAAY,EACzB,UAAU,EAAE,WAAW,GAAG,SAAS,GACjC,MAAM,CA0GR"}