@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
@@ -0,0 +1,67 @@
1
+ import type { ReadonlyBox2 } from "./box2-record.js";
2
+ /**
3
+ * Boxes bucketed on a uniform grid, for overlap queries over many small boxes:
4
+ * label collision, broad-phase tests. Each box is registered in the cells it
5
+ * covers, so a query visits only the boxes of the cells it covers instead of
6
+ * all of them; the grid is fixed by the bounds and the cell size, and a box
7
+ * partly or wholly outside the bounds is registered in the edge cells (the
8
+ * answers stay exact, only slower there).
9
+ *
10
+ * Overlap is that of `box2IntersectsBox2`: boundaries count, so boxes that
11
+ * touch overlap; inflate or deflate a box by a small margin for the other
12
+ * convention. An empty box, or one with a `NaN` bound, overlaps nothing and is
13
+ * not stored.
14
+ *
15
+ * A cell size near the typical box size is best. The typed arrays grow by
16
+ * doubling and are reused by {@link Box2GridIndex.clear}, so a per-frame rebuild
17
+ * allocates nothing once warm.
18
+ */
19
+ export declare class Box2GridIndex {
20
+ private readonly minX_;
21
+ private readonly minY_;
22
+ private readonly inverseCellSize_;
23
+ private readonly columns_;
24
+ private readonly rows_;
25
+ private readonly heads_;
26
+ private entryNext_;
27
+ private entryBox_;
28
+ private entryCount_;
29
+ private boxes_;
30
+ private ids_;
31
+ private boxCount_;
32
+ /**
33
+ * @param bounds The area the grid covers.
34
+ * @param cellSize The side of a cell, in the boxes' units.
35
+ * @throws {RangeError} For an empty or non-finite `bounds`, a `cellSize` that
36
+ * is not positive and finite or whose inverse overflows (below about
37
+ * 5.6e−309), or more than 2²⁴ cells.
38
+ */
39
+ constructor(bounds: ReadonlyBox2, cellSize: number);
40
+ /** The number of boxes stored. */
41
+ get size(): number;
42
+ /** Whether `box` overlaps a stored box. O(boxes in the cells `box` covers). */
43
+ intersects(box: ReadonlyBox2): boolean;
44
+ /**
45
+ * The id of a stored box that overlaps `box` (the first one met, not
46
+ * necessarily the earliest inserted), or `undefined`. O(boxes in the cells
47
+ * `box` covers).
48
+ */
49
+ findIntersectingId(box: ReadonlyBox2): number | undefined;
50
+ /** Stores `box` under `id`, whether or not it overlaps. O(cells `box` covers). */
51
+ insert(box: ReadonlyBox2, id: number): void;
52
+ /**
53
+ * Stores `box` under `id` unless it overlaps a stored box.
54
+ *
55
+ * @returns Whether it was stored. An empty box overlaps nothing, so it counts
56
+ * as stored (`true`) though nothing is kept.
57
+ */
58
+ tryInsert(box: ReadonlyBox2, id: number): boolean;
59
+ /** Forgets every box, keeping the grid and the memory. O(cells). */
60
+ clear(): void;
61
+ private cellColumn_;
62
+ private cellRow_;
63
+ private addEntry_;
64
+ /** The index of a stored box that overlaps `box`, `−1` for none. */
65
+ private findIndex_;
66
+ }
67
+ //# sourceMappingURL=box2-grid-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box2-grid-index.d.ts","sourceRoot":"","sources":["../src/box2-grid-index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKrD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IACpC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,SAAS,CAAK;IAEtB;;;;;;OAMG;IACH,YAAY,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAuCjD;IAED,kCAAkC;IAClC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,+EAA+E;IAC/E,UAAU,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAErC;IAED;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAGxD;IAED,kFAAkF;IAClF,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CA+B1C;IAED;;;;;OAKG;IACH,SAAS,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAMhD;IAED,oEAAoE;IACpE,KAAK,IAAI,IAAI,CAIZ;IAED,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,SAAS;IAejB,oEAAoE;IACpE,OAAO,CAAC,UAAU;CAgClB"}
@@ -0,0 +1,198 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ /** The most cells a grid may have, so a tiny cell size cannot exhaust memory. */
3
+ const MAX_CELLS_ = 1 << 24;
4
+ /**
5
+ * Boxes bucketed on a uniform grid, for overlap queries over many small boxes:
6
+ * label collision, broad-phase tests. Each box is registered in the cells it
7
+ * covers, so a query visits only the boxes of the cells it covers instead of
8
+ * all of them; the grid is fixed by the bounds and the cell size, and a box
9
+ * partly or wholly outside the bounds is registered in the edge cells (the
10
+ * answers stay exact, only slower there).
11
+ *
12
+ * Overlap is that of `box2IntersectsBox2`: boundaries count, so boxes that
13
+ * touch overlap; inflate or deflate a box by a small margin for the other
14
+ * convention. An empty box, or one with a `NaN` bound, overlaps nothing and is
15
+ * not stored.
16
+ *
17
+ * A cell size near the typical box size is best. The typed arrays grow by
18
+ * doubling and are reused by {@link Box2GridIndex.clear}, so a per-frame rebuild
19
+ * allocates nothing once warm.
20
+ */
21
+ export class Box2GridIndex {
22
+ minX_;
23
+ minY_;
24
+ inverseCellSize_;
25
+ columns_;
26
+ rows_;
27
+ heads_;
28
+ entryNext_ = new Int32Array(64);
29
+ entryBox_ = new Uint32Array(64);
30
+ entryCount_ = 0;
31
+ boxes_ = new Float64Array(64 * 4);
32
+ ids_ = new Float64Array(64);
33
+ boxCount_ = 0;
34
+ /**
35
+ * @param bounds The area the grid covers.
36
+ * @param cellSize The side of a cell, in the boxes' units.
37
+ * @throws {RangeError} For an empty or non-finite `bounds`, a `cellSize` that
38
+ * is not positive and finite or whose inverse overflows (below about
39
+ * 5.6e−309), or more than 2²⁴ cells.
40
+ */
41
+ constructor(bounds, cellSize) {
42
+ const minX = bounds[0];
43
+ const minY = bounds[1];
44
+ const maxX = bounds[2];
45
+ const maxY = bounds[3];
46
+ if (!Number.isFinite(minX) ||
47
+ !Number.isFinite(minY) ||
48
+ !Number.isFinite(maxX) ||
49
+ !Number.isFinite(maxY) ||
50
+ minX > maxX ||
51
+ minY > maxY) {
52
+ throw new RangeError("Box2GridIndex: bounds must be a finite, non-empty box.");
53
+ }
54
+ if (!(cellSize > 0) ||
55
+ !Number.isFinite(cellSize) ||
56
+ !Number.isFinite(1 / cellSize)) {
57
+ throw new RangeError(`Box2GridIndex: cellSize must be positive and finite, with a finite inverse, got ${describeValue(cellSize)}.`);
58
+ }
59
+ const columns = Math.max(1, Math.ceil((maxX - minX) / cellSize));
60
+ const rows = Math.max(1, Math.ceil((maxY - minY) / cellSize));
61
+ if (columns * rows > MAX_CELLS_) {
62
+ throw new RangeError(`Box2GridIndex: ${columns} × ${rows} cells exceed ${MAX_CELLS_}; use a larger cellSize.`);
63
+ }
64
+ this.minX_ = minX;
65
+ this.minY_ = minY;
66
+ this.inverseCellSize_ = 1 / cellSize;
67
+ this.columns_ = columns;
68
+ this.rows_ = rows;
69
+ this.heads_ = new Int32Array(columns * rows).fill(-1);
70
+ }
71
+ /** The number of boxes stored. */
72
+ get size() {
73
+ return this.boxCount_;
74
+ }
75
+ /** Whether `box` overlaps a stored box. O(boxes in the cells `box` covers). */
76
+ intersects(box) {
77
+ return this.findIndex_(box) >= 0;
78
+ }
79
+ /**
80
+ * The id of a stored box that overlaps `box` (the first one met, not
81
+ * necessarily the earliest inserted), or `undefined`. O(boxes in the cells
82
+ * `box` covers).
83
+ */
84
+ findIntersectingId(box) {
85
+ const index = this.findIndex_(box);
86
+ return index < 0 ? undefined : this.ids_[index];
87
+ }
88
+ /** Stores `box` under `id`, whether or not it overlaps. O(cells `box` covers). */
89
+ insert(box, id) {
90
+ const minX = box[0];
91
+ const minY = box[1];
92
+ const maxX = box[2];
93
+ const maxY = box[3];
94
+ if (!(minX <= maxX && minY <= maxY)) {
95
+ return;
96
+ }
97
+ const boxIndex = this.boxCount_++;
98
+ if (boxIndex * 4 + 4 > this.boxes_.length) {
99
+ const grownBoxes = new Float64Array(this.boxes_.length * 2);
100
+ grownBoxes.set(this.boxes_);
101
+ this.boxes_ = grownBoxes;
102
+ const grownIds = new Float64Array(this.ids_.length * 2);
103
+ grownIds.set(this.ids_);
104
+ this.ids_ = grownIds;
105
+ }
106
+ this.boxes_[4 * boxIndex] = minX;
107
+ this.boxes_[4 * boxIndex + 1] = minY;
108
+ this.boxes_[4 * boxIndex + 2] = maxX;
109
+ this.boxes_[4 * boxIndex + 3] = maxY;
110
+ this.ids_[boxIndex] = id;
111
+ const firstColumn = this.cellColumn_(minX);
112
+ const lastColumn = this.cellColumn_(maxX);
113
+ const firstRow = this.cellRow_(minY);
114
+ const lastRow = this.cellRow_(maxY);
115
+ for (let row = firstRow; row <= lastRow; row++) {
116
+ for (let column = firstColumn; column <= lastColumn; column++) {
117
+ this.addEntry_(row * this.columns_ + column, boxIndex);
118
+ }
119
+ }
120
+ }
121
+ /**
122
+ * Stores `box` under `id` unless it overlaps a stored box.
123
+ *
124
+ * @returns Whether it was stored. An empty box overlaps nothing, so it counts
125
+ * as stored (`true`) though nothing is kept.
126
+ */
127
+ tryInsert(box, id) {
128
+ if (this.findIndex_(box) >= 0) {
129
+ return false;
130
+ }
131
+ this.insert(box, id);
132
+ return true;
133
+ }
134
+ /** Forgets every box, keeping the grid and the memory. O(cells). */
135
+ clear() {
136
+ this.heads_.fill(-1);
137
+ this.entryCount_ = 0;
138
+ this.boxCount_ = 0;
139
+ }
140
+ cellColumn_(x) {
141
+ const column = Math.floor((x - this.minX_) * this.inverseCellSize_);
142
+ return column < 0
143
+ ? 0
144
+ : column >= this.columns_
145
+ ? this.columns_ - 1
146
+ : column;
147
+ }
148
+ cellRow_(y) {
149
+ const row = Math.floor((y - this.minY_) * this.inverseCellSize_);
150
+ return row < 0 ? 0 : row >= this.rows_ ? this.rows_ - 1 : row;
151
+ }
152
+ addEntry_(cell, boxIndex) {
153
+ const entry = this.entryCount_++;
154
+ if (entry >= this.entryNext_.length) {
155
+ const grownNext = new Int32Array(this.entryNext_.length * 2);
156
+ grownNext.set(this.entryNext_);
157
+ this.entryNext_ = grownNext;
158
+ const grownBox = new Uint32Array(this.entryBox_.length * 2);
159
+ grownBox.set(this.entryBox_);
160
+ this.entryBox_ = grownBox;
161
+ }
162
+ this.entryNext_[entry] = this.heads_[cell];
163
+ this.entryBox_[entry] = boxIndex;
164
+ this.heads_[cell] = entry;
165
+ }
166
+ /** The index of a stored box that overlaps `box`, `−1` for none. */
167
+ findIndex_(box) {
168
+ const minX = box[0];
169
+ const minY = box[1];
170
+ const maxX = box[2];
171
+ const maxY = box[3];
172
+ if (!(minX <= maxX && minY <= maxY) || this.boxCount_ === 0) {
173
+ return -1;
174
+ }
175
+ const firstColumn = this.cellColumn_(minX);
176
+ const lastColumn = this.cellColumn_(maxX);
177
+ const firstRow = this.cellRow_(minY);
178
+ const lastRow = this.cellRow_(maxY);
179
+ const boxes = this.boxes_;
180
+ for (let row = firstRow; row <= lastRow; row++) {
181
+ for (let column = firstColumn; column <= lastColumn; column++) {
182
+ let entry = this.heads_[row * this.columns_ + column];
183
+ while (entry >= 0) {
184
+ const index = this.entryBox_[entry];
185
+ if (boxes[4 * index] <= maxX &&
186
+ minX <= boxes[4 * index + 2] &&
187
+ boxes[4 * index + 1] <= maxY &&
188
+ minY <= boxes[4 * index + 3]) {
189
+ return index;
190
+ }
191
+ entry = this.entryNext_[entry];
192
+ }
193
+ }
194
+ }
195
+ return -1;
196
+ }
197
+ }
198
+ //# sourceMappingURL=box2-grid-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box2-grid-index.js","sourceRoot":"","sources":["../src/box2-grid-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,iFAAiF;AACjF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,CAAC;AAE3B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,aAAa;IACR,KAAK,CAAS;IACd,KAAK,CAAS;IACd,gBAAgB,CAAS;IACzB,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,MAAM,CAAa;IAC5B,UAAU,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAChC,SAAS,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IAChC,WAAW,GAAG,CAAC,CAAC;IAChB,MAAM,GAAG,IAAI,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAClC,IAAI,GAAG,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC;IAC5B,SAAS,GAAG,CAAC,CAAC;IAEtB;;;;;;OAMG;IACH,YAAY,MAAoB,EAAE,QAAgB;QACjD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,IACC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;YACtB,CAAC,MAA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,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,KAAK,IAAI,GAAG,GAAG,QAAQ,EAAE,GAAG,IAAI,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC;YAChD,KAAK,IAAI,MAAM,GAAG,WAAW,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;gBAC/D,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAE,CAAC;gBACvD,OAAO,KAAK,IAAI,CAAC,EAAE,CAAC;oBACnB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAE,CAAC;oBACrC,IACC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAE,IAAI,IAAI;wBACzB,IAAI,IAAI,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE;wBAC7B,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE,IAAI,IAAI;wBAC7B,IAAI,IAAI,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAE,EAC5B,CAAC;wBACF,OAAO,KAAK,CAAC;oBACd,CAAC;oBACD,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAE,CAAC;gBACjC,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;IACX,CAAC;CACD"}
@@ -0,0 +1,83 @@
1
+ import type { Brand_ } from "./_brand.js";
2
+ /**
3
+ * An axis-aligned box in 2 dimensions, stored as its minimum corner then its
4
+ * maximum corner (min/max, so a left-top-right-bottom rectangle on a y-down
5
+ * screen). A box with a minimum above its maximum on some axis is empty.
6
+ *
7
+ * A plain array of 4 binary64 numbers carrying a type-level brand, holding
8
+ * exactly the numbers one element of the matching bulk buffer holds, in the
9
+ * same order.
10
+ *
11
+ * Only {@link box2Create}, {@link box2Of}, {@link box2Clone}, {@link box2FromArray}
12
+ * and the functions that write an `out` make one; see `Vec3` in
13
+ * `@ac-kit/math-linear` for the rules that bind callers who bypass the types.
14
+ */
15
+ export type Box2 = [minX: number, minY: number, maxX: number, maxY: number] & Brand_<"Box2">;
16
+ /** A {@link Box2} that is only read. */
17
+ export type ReadonlyBox2 = readonly [
18
+ minX: number,
19
+ minY: number,
20
+ maxX: number,
21
+ maxY: number
22
+ ] & Brand_<"Box2">;
23
+ /**
24
+ * Creates the empty box (`+∞` minima, `−∞` maxima): nothing intersects it, and
25
+ * its union with a box is that box.
26
+ *
27
+ * Allocates; keep it out of hot loops.
28
+ */
29
+ export declare function box2Create(): Box2;
30
+ /**
31
+ * Creates the box with the components `minX, minY, maxX, maxY`, in storage
32
+ * order.
33
+ *
34
+ * Allocates; keep it out of hot loops.
35
+ */
36
+ export declare function box2Of(minX: number, minY: number, maxX: number, maxY: number): Box2;
37
+ /**
38
+ * Creates a copy of `a`. Like every creator it starts from a clean array.
39
+ *
40
+ * Allocates; keep it out of hot loops.
41
+ */
42
+ export declare function box2Clone(a: ReadonlyBox2): Box2;
43
+ /** Writes the components, in storage order, into `out`. */
44
+ export declare function box2Set(out: Box2, minX: number, minY: number, maxX: number, maxY: number): Box2;
45
+ /** Writes a copy of `a` into `out`. `out` may be `a`. */
46
+ export declare function box2Copy(out: Box2, a: ReadonlyBox2): Box2;
47
+ /**
48
+ * Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
49
+ * included, and an infinity equals itself. See {@link box2IsClose} for a
50
+ * tolerant test.
51
+ */
52
+ export declare function box2Equals(a: ReadonlyBox2, b: ReadonlyBox2): boolean;
53
+ /**
54
+ * Component-wise approximate equality: every pair differs by at most
55
+ * `tolerance`, an absolute bound in the caller's units, and an infinity is
56
+ * close only to itself. Not transitive, so never a basis for ordering or a
57
+ * container key: use {@link box2Equals} there.
58
+ *
59
+ * @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
60
+ */
61
+ export declare function box2IsClose(a: ReadonlyBox2, b: ReadonlyBox2, tolerance?: number): boolean;
62
+ /**
63
+ * The checked way in from untyped data (JSON, messages, arrays of unknown
64
+ * origin): `source[offset … offset + 4)` copied into `out`, each element that
65
+ * is not a number written as `NaN`, an index past the end of `source` too, so
66
+ * `out` never holds a non-number. A cold path: buffers use {@link box2Load}.
67
+ * O(1).
68
+ *
69
+ * `source` may be `out` itself: the 4 elements are read before the first write.
70
+ *
71
+ * @param out The box to fill.
72
+ * @param source The array to read, of any length and any content.
73
+ * @param offset The index of the first component in `source`.
74
+ * @returns `out`.
75
+ */
76
+ export declare function box2FromArray(out: Box2, source: ArrayLike<number>, offset?: number): Box2;
77
+ /**
78
+ * Whether every component is a finite number: the check to run after parsing
79
+ * untrusted data or before an upload, as operations never check. A component
80
+ * that is not a number at all counts as not finite.
81
+ */
82
+ export declare function box2IsFinite(value: ReadonlyBox2): boolean;
83
+ //# sourceMappingURL=box2-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box2-record.d.ts","sourceRoot":"","sources":["../src/box2-record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,GAC1E,MAAM,CAAC,MAAM,CAAC,CAAC;AAEhB,wCAAwC;AACxC,MAAM,MAAM,YAAY,GAAG,SAAS;IACnC,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;CACZ,GACA,MAAM,CAAC,MAAM,CAAC,CAAC;AAQhB;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAOjC;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,GAAG,IAAI,CAO/C;AAED,2DAA2D;AAC3D,wBAAgB,OAAO,CACtB,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,IAAI,CAMN;AAED,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,YAAY,GAAG,IAAI,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,OAAO,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,YAAY,EACf,CAAC,EAAE,YAAY,EACf,SAAS,GAAE,MAA8C,GACvD,OAAO,CAOT;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,IAAI,EACT,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,MAAM,SAAI,GACR,IAAI,CAUN;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAOzD"}
@@ -0,0 +1,124 @@
1
+ // Generated from scripts/templates/record.liquid by scripts/generate-records.ts. Do not edit.
2
+ import { isCloseAbsolute, numberAtOrNaN } from "@ac-kit/core";
3
+ import { geometryConfig } from "./globals.js";
4
+ /**
5
+ * Every creator copies this array, which holds non-integer doubles and is never
6
+ * exposed: nothing a caller does can change the element kind it copies.
7
+ */
8
+ const TEMPLATE_ = [0.5, 0.5, 0.5, 0.5];
9
+ /**
10
+ * Creates the empty box (`+∞` minima, `−∞` maxima): nothing intersects it, and
11
+ * its union with a box is that box.
12
+ *
13
+ * Allocates; keep it out of hot loops.
14
+ */
15
+ export function box2Create() {
16
+ const out = TEMPLATE_.slice();
17
+ out[0] = Number.POSITIVE_INFINITY;
18
+ out[1] = Number.POSITIVE_INFINITY;
19
+ out[2] = Number.NEGATIVE_INFINITY;
20
+ out[3] = Number.NEGATIVE_INFINITY;
21
+ return out;
22
+ }
23
+ /**
24
+ * Creates the box with the components `minX, minY, maxX, maxY`, in storage
25
+ * order.
26
+ *
27
+ * Allocates; keep it out of hot loops.
28
+ */
29
+ export function box2Of(minX, minY, maxX, maxY) {
30
+ const out = TEMPLATE_.slice();
31
+ out[0] = minX;
32
+ out[1] = minY;
33
+ out[2] = maxX;
34
+ out[3] = maxY;
35
+ return out;
36
+ }
37
+ /**
38
+ * Creates a copy of `a`. Like every creator it starts from a clean array.
39
+ *
40
+ * Allocates; keep it out of hot loops.
41
+ */
42
+ export function box2Clone(a) {
43
+ const out = TEMPLATE_.slice();
44
+ out[0] = a[0];
45
+ out[1] = a[1];
46
+ out[2] = a[2];
47
+ out[3] = a[3];
48
+ return out;
49
+ }
50
+ /** Writes the components, in storage order, into `out`. */
51
+ export function box2Set(out, minX, minY, maxX, maxY) {
52
+ out[0] = minX;
53
+ out[1] = minY;
54
+ out[2] = maxX;
55
+ out[3] = maxY;
56
+ return out;
57
+ }
58
+ /** Writes a copy of `a` into `out`. `out` may be `a`. */
59
+ export function box2Copy(out, a) {
60
+ out[0] = a[0];
61
+ out[1] = a[1];
62
+ out[2] = a[2];
63
+ out[3] = a[3];
64
+ return out;
65
+ }
66
+ /**
67
+ * Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
68
+ * included, and an infinity equals itself. See {@link box2IsClose} for a
69
+ * tolerant test.
70
+ */
71
+ export function box2Equals(a, b) {
72
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
73
+ }
74
+ /**
75
+ * Component-wise approximate equality: every pair differs by at most
76
+ * `tolerance`, an absolute bound in the caller's units, and an infinity is
77
+ * close only to itself. Not transitive, so never a basis for ordering or a
78
+ * container key: use {@link box2Equals} there.
79
+ *
80
+ * @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
81
+ */
82
+ export function box2IsClose(a, b, tolerance = geometryConfig.defaultLinearTolerance) {
83
+ return (isCloseAbsolute(a[0], b[0], tolerance) &&
84
+ isCloseAbsolute(a[1], b[1], tolerance) &&
85
+ isCloseAbsolute(a[2], b[2], tolerance) &&
86
+ isCloseAbsolute(a[3], b[3], tolerance));
87
+ }
88
+ /**
89
+ * The checked way in from untyped data (JSON, messages, arrays of unknown
90
+ * origin): `source[offset … offset + 4)` copied into `out`, each element that
91
+ * is not a number written as `NaN`, an index past the end of `source` too, so
92
+ * `out` never holds a non-number. A cold path: buffers use {@link box2Load}.
93
+ * O(1).
94
+ *
95
+ * `source` may be `out` itself: the 4 elements are read before the first write.
96
+ *
97
+ * @param out The box to fill.
98
+ * @param source The array to read, of any length and any content.
99
+ * @param offset The index of the first component in `source`.
100
+ * @returns `out`.
101
+ */
102
+ export function box2FromArray(out, source, offset = 0) {
103
+ const value0 = numberAtOrNaN(source, offset);
104
+ const value1 = numberAtOrNaN(source, offset + 1);
105
+ const value2 = numberAtOrNaN(source, offset + 2);
106
+ const value3 = numberAtOrNaN(source, offset + 3);
107
+ out[0] = value0;
108
+ out[1] = value1;
109
+ out[2] = value2;
110
+ out[3] = value3;
111
+ return out;
112
+ }
113
+ /**
114
+ * Whether every component is a finite number: the check to run after parsing
115
+ * untrusted data or before an upload, as operations never check. A component
116
+ * that is not a number at all counts as not finite.
117
+ */
118
+ export function box2IsFinite(value) {
119
+ return (Number.isFinite(value[0]) &&
120
+ Number.isFinite(value[1]) &&
121
+ Number.isFinite(value[2]) &&
122
+ Number.isFinite(value[3]));
123
+ }
124
+ //# s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AQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACzB,CAAC;AACH,CAAC"}
package/dist/box2.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { ReadonlyAffine2 } from "@ac-kit/math-linear";
2
+ import type { Box2, ReadonlyBox2 } from "./box2-record.js";
3
+ /**
4
+ * Writes the box with its top-left corner at `[x, y]` and the size `width ×
5
+ * height` into `out`: the way in from a `DOMRect`, a Canvas rectangle or any
6
+ * origin-and-size record. A negative size gives an empty box.
7
+ */
8
+ export declare function box2FromXywh(out: Box2, x: number, y: number, width: number, height: number): Box2;
9
+ /**
10
+ * {@link box2ContainsPoint} with the components as arguments, for pointer
11
+ * events: whether `(x, y)` lies in the box, boundary included.
12
+ */
13
+ export declare function box2ContainsXy(box: ReadonlyBox2, x: number, y: number): boolean;
14
+ /** The extent on x, `maxX − minX`; negative for an empty box. */
15
+ export declare function box2Width(box: ReadonlyBox2): number;
16
+ /** The extent on y, `maxY − minY`; negative for an empty box. */
17
+ export declare function box2Height(box: ReadonlyBox2): number;
18
+ /** The area, `0` for an empty box. */
19
+ export declare function box2Area(box: ReadonlyBox2): number;
20
+ /**
21
+ * The width divided by the height: `Infinity` for a flat box of positive width,
22
+ * `NaN` for a point.
23
+ */
24
+ export declare function box2AspectRatio(box: ReadonlyBox2): number;
25
+ /**
26
+ * Writes into `out` the largest box with the aspect ratio of `box` that fits in
27
+ * `container`, centred in it (letterboxing). A box of zero or non-finite aspect
28
+ * ratio gives non-finite bounds. `out` may be `box` or `container`.
29
+ */
30
+ export declare function box2FitInside(out: Box2, box: ReadonlyBox2, container: ReadonlyBox2): Box2;
31
+ /**
32
+ * Writes the bounds of the box moved by `transform` into `out`: exact for the
33
+ * translations, scales and quarter turns, the enclosing box for any other
34
+ * rotation or shear (Arvo's method). An empty box gives an empty box. `out` may
35
+ * be `box`.
36
+ */
37
+ export declare function box2TransformAffine2(out: Box2, box: ReadonlyBox2, transform: ReadonlyAffine2): Box2;
38
+ //# sourceMappingURL=box2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box2.d.ts","sourceRoot":"","sources":["../src/box2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,IAAI,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,IAAI,CAMN;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,YAAY,EACjB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACP,OAAO,CAET;AAED,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEnD;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEpD;AAED,sCAAsC;AACtC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAIlD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,YAAY,GACrB,IAAI,CAiBN;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,eAAe,GACxB,IAAI,CAyBN"}
package/dist/box2.js ADDED
@@ -0,0 +1,97 @@
1
+ import { box2Empty } from "./box2-componentwise.js";
2
+ /**
3
+ * Writes the box with its top-left corner at `[x, y]` and the size `width ×
4
+ * height` into `out`: the way in from a `DOMRect`, a Canvas rectangle or any
5
+ * origin-and-size record. A negative size gives an empty box.
6
+ */
7
+ export function box2FromXywh(out, x, y, width, height) {
8
+ out[0] = x;
9
+ out[1] = y;
10
+ out[2] = x + width;
11
+ out[3] = y + height;
12
+ return out;
13
+ }
14
+ /**
15
+ * {@link box2ContainsPoint} with the components as arguments, for pointer
16
+ * events: whether `(x, y)` lies in the box, boundary included.
17
+ */
18
+ export function box2ContainsXy(box, x, y) {
19
+ return x >= box[0] && x <= box[2] && y >= box[1] && y <= box[3];
20
+ }
21
+ /** The extent on x, `maxX − minX`; negative for an empty box. */
22
+ export function box2Width(box) {
23
+ return box[2] - box[0];
24
+ }
25
+ /** The extent on y, `maxY − minY`; negative for an empty box. */
26
+ export function box2Height(box) {
27
+ return box[3] - box[1];
28
+ }
29
+ /** The area, `0` for an empty box. */
30
+ export function box2Area(box) {
31
+ const width = box[2] - box[0];
32
+ const height = box[3] - box[1];
33
+ return width < 0 || height < 0 ? 0 : width * height;
34
+ }
35
+ /**
36
+ * The width divided by the height: `Infinity` for a flat box of positive width,
37
+ * `NaN` for a point.
38
+ */
39
+ export function box2AspectRatio(box) {
40
+ return (box[2] - box[0]) / (box[3] - box[1]);
41
+ }
42
+ /**
43
+ * Writes into `out` the largest box with the aspect ratio of `box` that fits in
44
+ * `container`, centred in it (letterboxing). A box of zero or non-finite aspect
45
+ * ratio gives non-finite bounds. `out` may be `box` or `container`.
46
+ */
47
+ export function box2FitInside(out, box, container) {
48
+ const aspect = (box[2] - box[0]) / (box[3] - box[1]);
49
+ const containerWidth = container[2] - container[0];
50
+ const containerHeight = container[3] - container[1];
51
+ const centerX = (container[0] + container[2]) / 2;
52
+ const centerY = (container[1] + container[3]) / 2;
53
+ let width = containerWidth;
54
+ let height = containerWidth / aspect;
55
+ if (height > containerHeight) {
56
+ height = containerHeight;
57
+ width = containerHeight * aspect;
58
+ }
59
+ out[0] = centerX - width / 2;
60
+ out[1] = centerY - height / 2;
61
+ out[2] = centerX + width / 2;
62
+ out[3] = centerY + height / 2;
63
+ return out;
64
+ }
65
+ /**
66
+ * Writes the bounds of the box moved by `transform` into `out`: exact for the
67
+ * translations, scales and quarter turns, the enclosing box for any other
68
+ * rotation or shear (Arvo's method). An empty box gives an empty box. `out` may
69
+ * be `box`.
70
+ */
71
+ export function box2TransformAffine2(out, box, transform) {
72
+ const minX = box[0];
73
+ const minY = box[1];
74
+ const maxX = box[2];
75
+ const maxY = box[3];
76
+ if (minX > maxX || minY > maxY) {
77
+ return box2Empty(out);
78
+ }
79
+ const a = transform[0];
80
+ const b = transform[1];
81
+ const c = transform[2];
82
+ const d = transform[3];
83
+ const aMin = a * minX;
84
+ const aMax = a * maxX;
85
+ const bMin = b * minX;
86
+ const bMax = b * maxX;
87
+ const cMin = c * minY;
88
+ const cMax = c * maxY;
89
+ const dMin = d * minY;
90
+ const dMax = d * maxY;
91
+ out[0] = transform[4] + Math.min(aMin, aMax) + Math.min(cMin, cMax);
92
+ out[1] = transform[5] + Math.min(bMin, bMax) + Math.min(dMin, dMax);
93
+ out[2] = transform[4] + Math.max(aMin, aMax) + Math.max(cMin, cMax);
94
+ out[3] = transform[5] + Math.max(bMin, bMax) + Math.max(dMin, dMax);
95
+ return out;
96
+ }
97
+ //# sourceMappingURL=box2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box2.js","sourceRoot":"","sources":["../src/box2.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC3B,GAAS,EACT,CAAS,EACT,CAAS,EACT,KAAa,EACb,MAAc;IAEd,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,C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