@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,114 @@
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];
9
+ /**
10
+ * Creates the circle of radius 0 at the origin.
11
+ *
12
+ * Allocates; keep it out of hot loops.
13
+ */
14
+ export function circle2Create() {
15
+ const out = TEMPLATE_.slice();
16
+ out[0] = 0;
17
+ out[1] = 0;
18
+ out[2] = 0;
19
+ return out;
20
+ }
21
+ /**
22
+ * Creates the circle with the components `centerX, centerY, radius`, in storage
23
+ * order.
24
+ *
25
+ * Allocates; keep it out of hot loops.
26
+ */
27
+ export function circle2Of(centerX, centerY, radius) {
28
+ const out = TEMPLATE_.slice();
29
+ out[0] = centerX;
30
+ out[1] = centerY;
31
+ out[2] = radius;
32
+ return out;
33
+ }
34
+ /**
35
+ * Creates a copy of `a`. Like every creator it starts from a clean array.
36
+ *
37
+ * Allocates; keep it out of hot loops.
38
+ */
39
+ export function circle2Clone(a) {
40
+ const out = TEMPLATE_.slice();
41
+ out[0] = a[0];
42
+ out[1] = a[1];
43
+ out[2] = a[2];
44
+ return out;
45
+ }
46
+ /** Writes the components, in storage order, into `out`. */
47
+ export function circle2Set(out, centerX, centerY, radius) {
48
+ out[0] = centerX;
49
+ out[1] = centerY;
50
+ out[2] = radius;
51
+ return out;
52
+ }
53
+ /** Writes a copy of `a` into `out`. `out` may be `a`. */
54
+ export function circle2Copy(out, a) {
55
+ out[0] = a[0];
56
+ out[1] = a[1];
57
+ out[2] = a[2];
58
+ return out;
59
+ }
60
+ /**
61
+ * Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
62
+ * included, and an infinity equals itself. See {@link circle2IsClose} for a
63
+ * tolerant test.
64
+ */
65
+ export function circle2Equals(a, b) {
66
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
67
+ }
68
+ /**
69
+ * Component-wise approximate equality: every pair differs by at most
70
+ * `tolerance`, an absolute bound in the caller's units, and an infinity is
71
+ * close only to itself. Not transitive, so never a basis for ordering or a
72
+ * container key: use {@link circle2Equals} there.
73
+ *
74
+ * @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
75
+ */
76
+ export function circle2IsClose(a, b, tolerance = geometryConfig.defaultLinearTolerance) {
77
+ return (isCloseAbsolute(a[0], b[0], tolerance) &&
78
+ isCloseAbsolute(a[1], b[1], tolerance) &&
79
+ isCloseAbsolute(a[2], b[2], tolerance));
80
+ }
81
+ /**
82
+ * The checked way in from untyped data (JSON, messages, arrays of unknown
83
+ * origin): `source[offset … offset + 3)` copied into `out`, each element that
84
+ * is not a number written as `NaN`, an index past the end of `source` too, so
85
+ * `out` never holds a non-number. A cold path: buffers use {@link circle2Load}.
86
+ * O(1).
87
+ *
88
+ * `source` may be `out` itself: the 3 elements are read before the first write.
89
+ *
90
+ * @param out The circle to fill.
91
+ * @param source The array to read, of any length and any content.
92
+ * @param offset The index of the first component in `source`.
93
+ * @returns `out`.
94
+ */
95
+ export function circle2FromArray(out, source, offset = 0) {
96
+ const value0 = numberAtOrNaN(source, offset);
97
+ const value1 = numberAtOrNaN(source, offset + 1);
98
+ const value2 = numberAtOrNaN(source, offset + 2);
99
+ out[0] = value0;
100
+ out[1] = value1;
101
+ out[2] = value2;
102
+ return out;
103
+ }
104
+ /**
105
+ * Whether every component is a finite number: the check to run after parsing
106
+ * untrusted data or before an upload, as operations never check. A component
107
+ * that is not a number at all counts as not finite.
108
+ */
109
+ export function circle2IsFinite(value) {
110
+ return (Number.isFinite(value[0]) &&
111
+ Number.isFinite(value[1]) &&
112
+ Number.isFinite(value[2]));
113
+ }
114
+ //# sourceMappingURL=circle2-record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle2-record.js","sourceRoot":"","sources":["../src/circle2-record.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA0B9C;;;GAGG;AACH,MAAM,SAAS,GAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAa,CAAC;IACzC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACxB,OAAe,EACf,OAAe,EACf,MAAc;IAEd,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAa,CAAC;IACzC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACjB,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACjB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAChB,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,CAAkB;IAC9C,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAa,CAAC;IACzC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC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C;QACtC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CACtC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC/B,GAAY,EACZ,MAAyB,EACzB,MAAM,GAAG,CAAC;IAEV,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IACjD,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAChB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAChB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAChB,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAsB;IACrD,OAAO,CACN,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/circle2.d.ts CHANGED
@@ -1,95 +1,40 @@
1
- import { Vec2 } from "@ac-kit/math-linear";
2
- import { Point2 } from "./point2.js";
3
- export type Circle2 = {
4
- center: Point2;
5
- radius: number;
6
- };
1
+ import type { ReadonlyVec2, Vec2 } from "@ac-kit/math-linear";
2
+ import type { Box2, ReadonlyBox2 } from "./box2-record.js";
3
+ import type { Circle2, ReadonlyCircle2 } from "./circle2-record.js";
4
+ /** The area, `π r²`; `0` for a negative radius (an empty circle). */
5
+ export declare function circle2Area(circle: ReadonlyCircle2): number;
6
+ /** The circumference, `2 π r`; `0` for a negative radius. */
7
+ export declare function circle2Circumference(circle: ReadonlyCircle2): number;
7
8
  /**
8
- * Calculates the area of a 2D circle.
9
- *
10
- * @param c - Circle to calculate area for.
11
- * @returns Area of the circle.
9
+ * Whether `point` lies in the disc, boundary included: exact, `(dx² + dy²) ≤
10
+ * r²`. A negative radius contains nothing. For slack, grow the radius.
12
11
  */
13
- export declare function circle2Area(c: Circle2): number;
12
+ export declare function circle2ContainsPoint(circle: ReadonlyCircle2, point: ReadonlyVec2): boolean;
14
13
  /**
15
- * Calculates the circumference of a 2D circle.
16
- *
17
- * @param c - Circle to calculate circumference for.
18
- * @returns Circumference of the circle.
14
+ * {@link circle2ContainsPoint} with the components as arguments, for pointer
15
+ * events.
19
16
  */
20
- export declare function circle2Circumference(c: Circle2): number;
17
+ export declare function circle2ContainsXy(circle: ReadonlyCircle2, x: number, y: number): boolean;
21
18
  /**
22
- * Determines whether a point is inside or on the boundary of a 2D circle.
23
- *
24
- * Exact: the boundary is measure-zero, so a tolerance would only move it by an
25
- * arbitrary amount. For deliberate slack, inflate `c.radius` — a length, unlike
26
- * an epsilon on the squared distance compared here.
27
- *
28
- * @param c - Circle to check against.
29
- * @param p - Point to check.
30
- * @returns True if the point is inside or on the boundary of the circle, false
31
- * otherwise.
19
+ * Whether the two discs share a point, boundaries included. A negative radius
20
+ * intersects nothing.
32
21
  */
33
- export declare function circle2ContainsPoint(c: Circle2, p: Point2): boolean;
22
+ export declare function circle2IntersectsCircle2(a: ReadonlyCircle2, b: ReadonlyCircle2): boolean;
34
23
  /**
35
- * Determines whether two 2D circles are equal, considering their centers and
36
- * radii.
37
- *
38
- * @param a - First circle to compare.
39
- * @param b - Second circle to compare.
40
- * @returns True if the circles are equal, false otherwise.
24
+ * Whether the disc and the box share a point, boundaries included. An empty box
25
+ * or a negative radius intersects nothing.
41
26
  */
42
- export declare function circle2Equals(a: Circle2, b: Circle2): boolean;
27
+ export declare function circle2IntersectsBox2(circle: ReadonlyCircle2, box: ReadonlyBox2): boolean;
43
28
  /**
44
- * Determines whether two 2D circles are within `tolerance` of each other, in
45
- * centre and radius.
46
- *
47
- * Not transitive, so never a basis for ordering or for a set or map key — use
48
- * {@link circle2Equals} there.
49
- *
50
- * @param a - First circle to compare.
51
- * @param b - Second circle to compare.
52
- * @param tolerance - Distance, in the caller's own units.
53
- * @returns True if the circles are close, false otherwise.
29
+ * Writes the point of the circle at `angle` from +x into `out`:
30
+ * counter-clockwise in a y-up frame, clockwise on a y-down screen.
54
31
  */
55
- export declare function circle2IsClose(a: Circle2, b: Circle2, tolerance?: number): boolean;
32
+ export declare function circle2PointAt(out: Vec2, circle: ReadonlyCircle2, angle: number): Vec2;
33
+ /** Writes `circle` moved by `offset` into `out`. `out` may be `circle`. */
34
+ export declare function circle2Translate(out: Circle2, circle: ReadonlyCircle2, offset: ReadonlyVec2): Circle2;
56
35
  /**
57
- * The point of a 2D circle's boundary at `angle` radians, measured from the
58
- * positive x axis towards the positive y axis — counter-clockwise when y points
59
- * up, as everywhere in this package. In a y-down frame such as SVG's or a
60
- * canvas's, the same angle runs clockwise.
61
- *
62
- * Any finite angle; whole turns wrap.
63
- *
64
- * O(1) time, O(1) memory.
65
- *
66
- * @example
67
- * ```ts
68
- * circle2PointAt({ center: { x: 1, y: 2 }, radius: 3 }, 0); // { x: 4, y: 2 }
69
- * ```;
70
- *
71
- * @param c - The circle.
72
- * @param angle - Radians from the positive x axis.
73
- * @returns The point on the boundary.
74
- * @see {@link polarToVec2} for the same point relative to the centre.
36
+ * Writes the smallest box holding the circle into `out`; a negative radius
37
+ * gives an empty box.
75
38
  */
76
- export declare function circle2PointAt(c: Circle2, angle: number): Point2;
77
- /**
78
- * Determines whether two 2D circles intersect.
79
- *
80
- * Exact, for the same reason as {@link circle2ContainsPoint}.
81
- *
82
- * @param a - First circle to check for intersection.
83
- * @param b - Second circle to check for intersection.
84
- * @returns True if the circles intersect, false otherwise.
85
- */
86
- export declare function circle2Intersects(a: Circle2, b: Circle2): boolean;
87
- /**
88
- * Translates a 2D circle by a given vector.
89
- *
90
- * @param c - Circle to translate.
91
- * @param v - Vector by which to translate the circle.
92
- * @returns A new Circle2 object representing the translated circle.
93
- */
94
- export declare function circle2Translate(c: Circle2, v: Vec2): Circle2;
39
+ export declare function circle2BoundingBox(out: Box2, circle: ReadonlyCircle2): Box2;
95
40
  //# sourceMappingURL=circle2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"circle2.d.ts","sourceRoot":"","sources":["../src/circle2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAgB,MAAM,qBAAqB,CAAC;AAKzD,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AAEpD,MAAM,MAAM,OAAO,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAEvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAKnE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAM7D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC7B,CAAC,EAAE,OAAO,EACV,CAAC,EAAE,OAAO,EACV,SAAS,GAAE,MAA8C,GACvD,OAAO,CAKT;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC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e,EACvB,MAAM,EAAE,YAAY,GAClB,OAAO,CAMT;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAO3E"}
package/dist/circle2.js CHANGED
@@ -1,125 +1,80 @@
1
- import { isCloseAbsolute } from "@ac-kit/core";
2
- import { vec2LengthSq } from "@ac-kit/math-linear";
3
- import { TWO_PI } from "@ac-kit/math-scalar";
4
- import { polarToVec2 } from "./coordinates-vec2.js";
5
- import { geometryConfig } from "./globals.js";
6
- import { point2IsClose } from "./point2.js";
7
- /**
8
- * Calculates the area of a 2D circle.
9
- *
10
- * @param c - Circle to calculate area for.
11
- * @returns Area of the circle.
12
- */
13
- export function circle2Area(c) {
14
- return Math.PI * c.radius * c.radius;
1
+ /** The area, `π r²`; `0` for a negative radius (an empty circle). */
2
+ export function circle2Area(circle) {
3
+ const radius = circle[2];
4
+ return radius < 0 ? 0 : Math.PI * radius * radius;
15
5
  }
16
- /**
17
- * Calculates the circumference of a 2D circle.
18
- *
19
- * @param c - Circle to calculate circumference for.
20
- * @returns Circumference of the circle.
21
- */
22
- export function circle2Circumference(c) {
23
- return TWO_PI * c.radius;
6
+ /** The circumference, `2 π r`; `0` for a negative radius. */
7
+ export function circle2Circumference(circle) {
8
+ const radius = circle[2];
9
+ return radius < 0 ? 0 : 2 * Math.PI * radius;
24
10
  }
25
11
  /**
26
- * Determines whether a point is inside or on the boundary of a 2D circle.
27
- *
28
- * Exact: the boundary is measure-zero, so a tolerance would only move it by an
29
- * arbitrary amount. For deliberate slack, inflate `c.radius` — a length, unlike
30
- * an epsilon on the squared distance compared here.
31
- *
32
- * @param c - Circle to check against.
33
- * @param p - Point to check.
34
- * @returns True if the point is inside or on the boundary of the circle, false
35
- * otherwise.
12
+ * Whether `point` lies in the disc, boundary included: exact, `(dx² + dy²) ≤
13
+ * r²`. A negative radius contains nothing. For slack, grow the radius.
36
14
  */
37
- export function circle2ContainsPoint(c, p) {
38
- const distSq = vec2LengthSq([p.x - c.center.x, p.y - c.center.y]);
39
- const radSq = c.radius * c.radius;
40
- return distSq <= radSq;
15
+ export function circle2ContainsPoint(circle, point) {
16
+ return circle2ContainsXy(circle, point[0], point[1]);
41
17
  }
42
18
  /**
43
- * Determines whether two 2D circles are equal, considering their centers and
44
- * radii.
45
- *
46
- * @param a - First circle to compare.
47
- * @param b - Second circle to compare.
48
- * @returns True if the circles are equal, false otherwise.
19
+ * {@link circle2ContainsPoint} with the components as arguments, for pointer
20
+ * events.
49
21
  */
50
- export function circle2Equals(a, b) {
51
- return (a.center.x === b.center.x &&
52
- a.center.y === b.center.y &&
53
- a.radius === b.radius);
22
+ export function circle2ContainsXy(circle, x, y) {
23
+ const dx = x - circle[0];
24
+ const dy = y - circle[1];
25
+ const radius = circle[2];
26
+ return radius >= 0 && dx * dx + dy * dy <= radius * radius;
54
27
  }
55
28
  /**
56
- * Determines whether two 2D circles are within `tolerance` of each other, in
57
- * centre and radius.
58
- *
59
- * Not transitive, so never a basis for ordering or for a set or map key — use
60
- * {@link circle2Equals} there.
61
- *
62
- * @param a - First circle to compare.
63
- * @param b - Second circle to compare.
64
- * @param tolerance - Distance, in the caller's own units.
65
- * @returns True if the circles are close, false otherwise.
29
+ * Whether the two discs share a point, boundaries included. A negative radius
30
+ * intersects nothing.
66
31
  */
67
- export function circle2IsClose(a, b, tolerance = geometryConfig.defaultLinearTolerance) {
68
- return (point2IsClose(a.center, b.center, tolerance) &&
69
- isCloseAbsolute(a.radius, b.radius, tolerance));
32
+ export function circle2IntersectsCircle2(a, b) {
33
+ const dx = a[0] - b[0];
34
+ const dy = a[1] - b[1];
35
+ const sum = a[2] + b[2];
36
+ return a[2] >= 0 && b[2] >= 0 && dx * dx + dy * dy <= sum * sum;
70
37
  }
71
38
  /**
72
- * The point of a 2D circle's boundary at `angle` radians, measured from the
73
- * positive x axis towards the positive y axis — counter-clockwise when y points
74
- * up, as everywhere in this package. In a y-down frame such as SVG's or a
75
- * canvas's, the same angle runs clockwise.
76
- *
77
- * Any finite angle; whole turns wrap.
78
- *
79
- * O(1) time, O(1) memory.
80
- *
81
- * @example
82
- * ```ts
83
- * circle2PointAt({ center: { x: 1, y: 2 }, radius: 3 }, 0); // { x: 4, y: 2 }
84
- * ```;
85
- *
86
- * @param c - The circle.
87
- * @param angle - Radians from the positive x axis.
88
- * @returns The point on the boundary.
89
- * @see {@link polarToVec2} for the same point relative to the centre.
39
+ * Whether the disc and the box share a point, boundaries included. An empty box
40
+ * or a negative radius intersects nothing.
90
41
  */
91
- export function circle2PointAt(c, angle) {
92
- const [dx, dy] = polarToVec2({ radius: c.radius, angle });
93
- return { x: c.center.x + dx, y: c.center.y + dy };
42
+ export function circle2IntersectsBox2(circle, box) {
43
+ const dx = Math.max(box[0] - circle[0], 0, circle[0] - box[2]);
44
+ const dy = Math.max(box[1] - circle[1], 0, circle[1] - box[3]);
45
+ const radius = circle[2];
46
+ return (radius >= 0 &&
47
+ box[0] <= box[2] &&
48
+ box[1] <= box[3] &&
49
+ dx * dx + dy * dy <= radius * radius);
94
50
  }
95
51
  /**
96
- * Determines whether two 2D circles intersect.
97
- *
98
- * Exact, for the same reason as {@link circle2ContainsPoint}.
99
- *
100
- * @param a - First circle to check for intersection.
101
- * @param b - Second circle to check for intersection.
102
- * @returns True if the circles intersect, false otherwise.
52
+ * Writes the point of the circle at `angle` from +x into `out`:
53
+ * counter-clockwise in a y-up frame, clockwise on a y-down screen.
103
54
  */
104
- export function circle2Intersects(a, b) {
105
- const distSq = vec2LengthSq([
106
- b.center.x - a.center.x,
107
- b.center.y - a.center.y,
108
- ]);
109
- const radSum = a.radius + b.radius;
110
- return distSq <= radSum * radSum;
55
+ export function circle2PointAt(out, circle, angle) {
56
+ out[0] = circle[0] + circle[2] * Math.cos(angle);
57
+ out[1] = circle[1] + circle[2] * Math.sin(angle);
58
+ return out;
59
+ }
60
+ /** Writes `circle` moved by `offset` into `out`. `out` may be `circle`. */
61
+ export function circle2Translate(out, circle, offset) {
62
+ const radius = circle[2];
63
+ out[0] = circle[0] + offset[0];
64
+ out[1] = circle[1] + offset[1];
65
+ out[2] = radius;
66
+ return out;
111
67
  }
112
68
  /**
113
- * Translates a 2D circle by a given vector.
114
- *
115
- * @param c - Circle to translate.
116
- * @param v - Vector by which to translate the circle.
117
- * @returns A new Circle2 object representing the translated circle.
69
+ * Writes the smallest box holding the circle into `out`; a negative radius
70
+ * gives an empty box.
118
71
  */
119
- export function circle2Translate(c, v) {
120
- return {
121
- center: { x: c.center.x + v[0], y: c.center.y + v[1] },
122
- radius: c.radius,
123
- };
72
+ export function circle2BoundingBox(out, circle) {
73
+ const radius = circle[2];
74
+ out[0] = circle[0] - radius;
75
+ out[1] = circle[1] - radius;
76
+ out[2] = circle[0] + radius;
77
+ out[3] = circle[1] + radius;
78
+ return out;
124
79
  }
125
80
  //# sourceMappingURL=circle2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"circle2.js","sourceRoot":"","sources":["../src/circle2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAQ,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAU,aAAa,EAAE,MAAM,aAAa,CAAC;AAOpD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,CAAU;IACrC,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,CAAU;IAC9C,OAAO,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,M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AAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/B,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/B,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAChB,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAS,EAAE,MAAuB;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACzB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC5B,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC5B,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC5B,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC5B,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,86 @@
1
+ import type { Brand_ } from "../_brand.js";
2
+ /**
3
+ * Cylindrical coordinates: the distance from the axis, the azimuth around it in
4
+ * radians and the height along it. Which axis is up is in the name of the
5
+ * function that converts (`…YUp`, `…ZUp`), not in the type.
6
+ *
7
+ * A plain array of 3 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 cylindricalCoordsCreate}, {@link cylindricalCoordsOf},
12
+ * {@link cylindricalCoordsClone}, {@link cylindricalCoordsFromArray} and the
13
+ * functions that write an `out` make one; see `Vec3` in `@ac-kit/math-linear`
14
+ * for the rules that bind callers who bypass the types.
15
+ */
16
+ export type CylindricalCoords = [
17
+ radius: number,
18
+ azimuth: number,
19
+ height: number
20
+ ] & Brand_<"CylindricalCoords">;
21
+ /** A {@link CylindricalCoords} that is only read. */
22
+ export type ReadonlyCylindricalCoords = readonly [
23
+ radius: number,
24
+ azimuth: number,
25
+ height: number
26
+ ] & Brand_<"CylindricalCoords">;
27
+ /**
28
+ * Creates the cylindrical coordinates `[0, 0, 0]`, the origin.
29
+ *
30
+ * Allocates; keep it out of hot loops.
31
+ */
32
+ export declare function cylindricalCoordsCreate(): CylindricalCoords;
33
+ /**
34
+ * Creates the cylindrical coordinates with the components `radius, azimuth,
35
+ * height`, in storage order.
36
+ *
37
+ * Allocates; keep it out of hot loops.
38
+ */
39
+ export declare function cylindricalCoordsOf(radius: number, azimuth: number, height: number): CylindricalCoords;
40
+ /**
41
+ * Creates a copy of `a`. Like every creator it starts from a clean array.
42
+ *
43
+ * Allocates; keep it out of hot loops.
44
+ */
45
+ export declare function cylindricalCoordsClone(a: ReadonlyCylindricalCoords): CylindricalCoords;
46
+ /** Writes the components, in storage order, into `out`. */
47
+ export declare function cylindricalCoordsSet(out: CylindricalCoords, radius: number, azimuth: number, height: number): CylindricalCoords;
48
+ /** Writes a copy of `a` into `out`. `out` may be `a`. */
49
+ export declare function cylindricalCoordsCopy(out: CylindricalCoords, a: ReadonlyCylindricalCoords): CylindricalCoords;
50
+ /**
51
+ * Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
52
+ * included, and an infinity equals itself. See {@link cylindricalCoordsIsClose}
53
+ * for a tolerant test.
54
+ */
55
+ export declare function cylindricalCoordsEquals(a: ReadonlyCylindricalCoords, b: ReadonlyCylindricalCoords): boolean;
56
+ /**
57
+ * Component-wise approximate equality: every pair differs by at most
58
+ * `tolerance`, an absolute bound in the caller's units, and an infinity is
59
+ * close only to itself. Not transitive, so never a basis for ordering or a
60
+ * container key: use {@link cylindricalCoordsEquals} there.
61
+ *
62
+ * @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
63
+ */
64
+ export declare function cylindricalCoordsIsClose(a: ReadonlyCylindricalCoords, b: ReadonlyCylindricalCoords, tolerance?: number): boolean;
65
+ /**
66
+ * The checked way in from untyped data (JSON, messages, arrays of unknown
67
+ * origin): `source[offset … offset + 3)` copied into `out`, each element that
68
+ * is not a number written as `NaN`, an index past the end of `source` too, so
69
+ * `out` never holds a non-number. A cold path: buffers use
70
+ * {@link cylindricalCoordsLoad}. O(1).
71
+ *
72
+ * `source` may be `out` itself: the 3 elements are read before the first write.
73
+ *
74
+ * @param out The cylindrical coordinates to fill.
75
+ * @param source The array to read, of any length and any content.
76
+ * @param offset The index of the first component in `source`.
77
+ * @returns `out`.
78
+ */
79
+ export declare function cylindricalCoordsFromArray(out: CylindricalCoords, source: ArrayLike<number>, offset?: number): CylindricalCoords;
80
+ /**
81
+ * Whether every component is a finite number: the check to run after parsing
82
+ * untrusted data or before an upload, as operations never check. A component
83
+ * that is not a number at all counts as not finite.
84
+ */
85
+ export declare function cylindricalCoordsIsFinite(value: ReadonlyCylindricalCoords): boolean;
86
+ //# sourceMappingURL=cylindrical-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cylindrical-record.d.ts","sourceRoot":"","sources":["../../src/coordinates/cylindrical-record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,MAAM;CACd,GACA,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE7B,qDAAqD;AACrD,MAAM,MAAM,yBAAyB,GAAG,SAAS;IAChD,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,MAAM;CACd,GACA,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAQ7B;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,iBAAiB,CAM3D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,E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