@ac-kit/math-geometry 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/README.md +323 -52
  3. package/dist/_brand.d.ts +14 -0
  4. package/dist/_brand.d.ts.map +1 -0
  5. package/dist/_brand.js +2 -0
  6. package/dist/_brand.js.map +1 -0
  7. package/dist/_ear-clipping.d.ts +20 -0
  8. package/dist/_ear-clipping.d.ts.map +1 -0
  9. package/dist/_ear-clipping.js +360 -0
  10. package/dist/_ear-clipping.js.map +1 -0
  11. package/dist/_ray3-intersect.d.ts +19 -0
  12. package/dist/_ray3-intersect.d.ts.map +1 -0
  13. package/dist/_ray3-intersect.js +122 -0
  14. package/dist/_ray3-intersect.js.map +1 -0
  15. package/dist/box2-array-boundary.d.ts +50 -0
  16. package/dist/box2-array-boundary.d.ts.map +1 -0
  17. package/dist/box2-array-boundary.js +97 -0
  18. package/dist/box2-array-boundary.js.map +1 -0
  19. package/dist/box2-array.d.ts +42 -0
  20. package/dist/box2-array.d.ts.map +1 -0
  21. package/dist/box2-array.js +134 -0
  22. package/dist/box2-array.js.map +1 -0
  23. package/dist/box2-componentwise.d.ts +110 -0
  24. package/dist/box2-componentwise.d.ts.map +1 -0
  25. package/dist/box2-componentwise.js +325 -0
  26. package/dist/box2-componentwise.js.map +1 -0
  27. package/dist/box2-grid-index.d.ts +67 -0
  28. package/dist/box2-grid-index.d.ts.map +1 -0
  29. package/dist/box2-grid-index.js +198 -0
  30. package/dist/box2-grid-index.js.map +1 -0
  31. package/dist/box2-record.d.ts +83 -0
  32. package/dist/box2-record.d.ts.map +1 -0
  33. package/dist/box2-record.js +124 -0
  34. package/dist/box2-record.js.map +1 -0
  35. package/dist/box2.d.ts +38 -0
  36. package/dist/box2.d.ts.map +1 -0
  37. package/dist/box2.js +97 -0
  38. package/dist/box2.js.map +1 -0
  39. package/dist/box3-array-boundary.d.ts +50 -0
  40. package/dist/box3-array-boundary.d.ts.map +1 -0
  41. package/dist/box3-array-boundary.js +107 -0
  42. package/dist/box3-array-boundary.js.map +1 -0
  43. package/dist/box3-componentwise.d.ts +110 -0
  44. package/dist/box3-componentwise.d.ts.map +1 -0
  45. package/dist/box3-componentwise.js +392 -0
  46. package/dist/box3-componentwise.js.map +1 -0
  47. package/dist/box3-record.d.ts +92 -0
  48. package/dist/box3-record.d.ts.map +1 -0
  49. package/dist/box3-record.js +147 -0
  50. package/dist/box3-record.js.map +1 -0
  51. package/dist/box3.d.ts +19 -16
  52. package/dist/box3.d.ts.map +1 -1
  53. package/dist/box3.js +73 -76
  54. package/dist/box3.js.map +1 -1
  55. package/dist/box4-array-boundary.d.ts +50 -0
  56. package/dist/box4-array-boundary.d.ts.map +1 -0
  57. package/dist/box4-array-boundary.js +117 -0
  58. package/dist/box4-array-boundary.js.map +1 -0
  59. package/dist/box4-componentwise.d.ts +110 -0
  60. package/dist/box4-componentwise.d.ts.map +1 -0
  61. package/dist/box4-componentwise.js +459 -0
  62. package/dist/box4-componentwise.js.map +1 -0
  63. package/dist/box4-record.d.ts +96 -0
  64. package/dist/box4-record.d.ts.map +1 -0
  65. package/dist/box4-record.js +167 -0
  66. package/dist/box4-record.js.map +1 -0
  67. package/dist/box4.d.ts +13 -8
  68. package/dist/box4.d.ts.map +1 -1
  69. package/dist/box4.js +27 -5
  70. package/dist/box4.js.map +1 -1
  71. package/dist/circle2-array-boundary.d.ts +51 -0
  72. package/dist/circle2-array-boundary.d.ts.map +1 -0
  73. package/dist/circle2-array-boundary.js +93 -0
  74. package/dist/circle2-array-boundary.js.map +1 -0
  75. package/dist/circle2-array.d.ts +17 -0
  76. package/dist/circle2-array.d.ts.map +1 -0
  77. package/dist/circle2-array.js +44 -0
  78. package/dist/circle2-array.js.map +1 -0
  79. package/dist/circle2-record.d.ts +81 -0
  80. package/dist/circle2-record.d.ts.map +1 -0
  81. package/dist/circle2-record.js +114 -0
  82. package/dist/circle2-record.js.map +1 -0
  83. package/dist/circle2.d.ts +27 -82
  84. package/dist/circle2.d.ts.map +1 -1
  85. package/dist/circle2.js +59 -104
  86. package/dist/circle2.js.map +1 -1
  87. package/dist/coordinates/cylindrical-record.d.ts +86 -0
  88. package/dist/coordinates/cylindrical-record.d.ts.map +1 -0
  89. package/dist/coordinates/cylindrical-record.js +114 -0
  90. package/dist/coordinates/cylindrical-record.js.map +1 -0
  91. package/dist/coordinates/horizontal-record.d.ts +86 -0
  92. package/dist/coordinates/horizontal-record.d.ts.map +1 -0
  93. package/dist/coordinates/horizontal-record.js +114 -0
  94. package/dist/coordinates/horizontal-record.js.map +1 -0
  95. package/dist/coordinates/horizontal.d.ts +48 -0
  96. package/dist/coordinates/horizontal.d.ts.map +1 -0
  97. package/dist/coordinates/horizontal.js +100 -0
  98. package/dist/coordinates/horizontal.js.map +1 -0
  99. package/dist/coordinates/index.d.ts +10 -0
  100. package/dist/coordinates/index.d.ts.map +1 -0
  101. package/dist/coordinates/index.js +10 -0
  102. package/dist/coordinates/index.js.map +1 -0
  103. package/dist/coordinates/longitude-latitude-record.d.ts +81 -0
  104. package/dist/coordinates/longitude-latitude-record.d.ts.map +1 -0
  105. package/dist/coordinates/longitude-latitude-record.js +104 -0
  106. package/dist/coordinates/longitude-latitude-record.js.map +1 -0
  107. package/dist/coordinates/longitude-latitude.d.ts +33 -0
  108. package/dist/coordinates/longitude-latitude.d.ts.map +1 -0
  109. package/dist/coordinates/longitude-latitude.js +78 -0
  110. package/dist/coordinates/longitude-latitude.js.map +1 -0
  111. package/dist/coordinates/polar-record.d.ts +77 -0
  112. package/dist/coordinates/polar-record.d.ts.map +1 -0
  113. package/dist/coordinates/polar-record.js +104 -0
  114. package/dist/coordinates/polar-record.js.map +1 -0
  115. package/dist/coordinates/polar.d.ts +28 -0
  116. package/dist/coordinates/polar.d.ts.map +1 -0
  117. package/dist/coordinates/polar.js +68 -0
  118. package/dist/coordinates/polar.js.map +1 -0
  119. package/dist/coordinates/spherical-cylindrical.d.ts +49 -0
  120. package/dist/coordinates/spherical-cylindrical.d.ts.map +1 -0
  121. package/dist/coordinates/spherical-cylindrical.js +110 -0
  122. package/dist/coordinates/spherical-cylindrical.js.map +1 -0
  123. package/dist/coordinates/spherical-record.d.ts +86 -0
  124. package/dist/coordinates/spherical-record.d.ts.map +1 -0
  125. package/dist/coordinates/spherical-record.js +114 -0
  126. package/dist/coordinates/spherical-record.js.map +1 -0
  127. package/dist/frustum3-record.d.ts +132 -0
  128. package/dist/frustum3-record.d.ts.map +1 -0
  129. package/dist/frustum3-record.js +333 -0
  130. package/dist/frustum3-record.js.map +1 -0
  131. package/dist/frustum3.d.ts +60 -0
  132. package/dist/frustum3.d.ts.map +1 -0
  133. package/dist/frustum3.js +186 -0
  134. package/dist/frustum3.js.map +1 -0
  135. package/dist/index.d.ts +36 -16
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +36 -16
  138. package/dist/index.js.map +1 -1
  139. package/dist/line2-record.d.ts +87 -0
  140. package/dist/line2-record.d.ts.map +1 -0
  141. package/dist/line2-record.js +123 -0
  142. package/dist/line2-record.js.map +1 -0
  143. package/dist/line2.d.ts +20 -33
  144. package/dist/line2.d.ts.map +1 -1
  145. package/dist/line2.js +56 -51
  146. package/dist/line2.js.map +1 -1
  147. package/dist/line3-record.d.ts +91 -0
  148. package/dist/line3-record.d.ts.map +1 -0
  149. package/dist/line3-record.js +146 -0
  150. package/dist/line3-record.js.map +1 -0
  151. package/dist/line3.d.ts +11 -24
  152. package/dist/line3.d.ts.map +1 -1
  153. package/dist/line3.js +32 -36
  154. package/dist/line3.js.map +1 -1
  155. package/dist/mesh/_generator-kit.d.ts +14 -0
  156. package/dist/mesh/_generator-kit.d.ts.map +1 -0
  157. package/dist/mesh/_generator-kit.js +39 -0
  158. package/dist/mesh/_generator-kit.js.map +1 -0
  159. package/dist/mesh/_index-kernels-u16.d.ts +43 -0
  160. package/dist/mesh/_index-kernels-u16.d.ts.map +1 -0
  161. package/dist/mesh/_index-kernels-u16.js +264 -0
  162. package/dist/mesh/_index-kernels-u16.js.map +1 -0
  163. package/dist/mesh/_index-kernels-u32.d.ts +43 -0
  164. package/dist/mesh/_index-kernels-u32.d.ts.map +1 -0
  165. package/dist/mesh/_index-kernels-u32.js +264 -0
  166. package/dist/mesh/_index-kernels-u32.js.map +1 -0
  167. package/dist/mesh/generate-box.d.ts +16 -0
  168. package/dist/mesh/generate-box.d.ts.map +1 -0
  169. package/dist/mesh/generate-box.js +79 -0
  170. package/dist/mesh/generate-box.js.map +1 -0
  171. package/dist/mesh/generate-cylinder.d.ts +25 -0
  172. package/dist/mesh/generate-cylinder.d.ts.map +1 -0
  173. package/dist/mesh/generate-cylinder.js +117 -0
  174. package/dist/mesh/generate-cylinder.js.map +1 -0
  175. package/dist/mesh/generate-heightfield.d.ts +24 -0
  176. package/dist/mesh/generate-heightfield.d.ts.map +1 -0
  177. package/dist/mesh/generate-heightfield.js +48 -0
  178. package/dist/mesh/generate-heightfield.js.map +1 -0
  179. package/dist/mesh/generate-plane.d.ts +18 -0
  180. package/dist/mesh/generate-plane.d.ts.map +1 -0
  181. package/dist/mesh/generate-plane.js +39 -0
  182. package/dist/mesh/generate-plane.js.map +1 -0
  183. package/dist/mesh/generate-sphere.d.ts +50 -0
  184. package/dist/mesh/generate-sphere.d.ts.map +1 -0
  185. package/dist/mesh/generate-sphere.js +244 -0
  186. package/dist/mesh/generate-sphere.js.map +1 -0
  187. package/dist/mesh/index.d.ts +8 -0
  188. package/dist/mesh/index.d.ts.map +1 -0
  189. package/dist/mesh/index.js +8 -0
  190. package/dist/mesh/index.js.map +1 -0
  191. package/dist/mesh/mesh3-kernels.d.ts +82 -0
  192. package/dist/mesh/mesh3-kernels.d.ts.map +1 -0
  193. package/dist/mesh/mesh3-kernels.js +180 -0
  194. package/dist/mesh/mesh3-kernels.js.map +1 -0
  195. package/dist/mesh/mesh3.d.ts +66 -0
  196. package/dist/mesh/mesh3.d.ts.map +1 -0
  197. package/dist/mesh/mesh3.js +128 -0
  198. package/dist/mesh/mesh3.js.map +1 -0
  199. package/dist/plane3-record.d.ts +88 -0
  200. package/dist/plane3-record.d.ts.map +1 -0
  201. package/dist/plane3-record.js +123 -0
  202. package/dist/plane3-record.js.map +1 -0
  203. package/dist/plane3.d.ts +42 -28
  204. package/dist/plane3.d.ts.map +1 -1
  205. package/dist/plane3.js +166 -48
  206. package/dist/plane3.js.map +1 -1
  207. package/dist/polygon2.d.ts +82 -29
  208. package/dist/polygon2.d.ts.map +1 -1
  209. package/dist/polygon2.js +236 -93
  210. package/dist/polygon2.js.map +1 -1
  211. package/dist/polygon3.d.ts +40 -21
  212. package/dist/polygon3.d.ts.map +1 -1
  213. package/dist/polygon3.js +215 -91
  214. package/dist/polygon3.js.map +1 -1
  215. package/dist/polyline2.d.ts +37 -0
  216. package/dist/polyline2.d.ts.map +1 -0
  217. package/dist/polyline2.js +146 -0
  218. package/dist/polyline2.js.map +1 -0
  219. package/dist/polyline3.d.ts +35 -0
  220. package/dist/polyline3.d.ts.map +1 -0
  221. package/dist/polyline3.js +159 -0
  222. package/dist/polyline3.js.map +1 -0
  223. package/dist/quadtree.d.ts +238 -0
  224. package/dist/quadtree.d.ts.map +1 -0
  225. package/dist/quadtree.js +1019 -0
  226. package/dist/quadtree.js.map +1 -0
  227. package/dist/ray2-record.d.ts +86 -0
  228. package/dist/ray2-record.d.ts.map +1 -0
  229. package/dist/ray2-record.js +123 -0
  230. package/dist/ray2-record.js.map +1 -0
  231. package/dist/ray2.d.ts +38 -13
  232. package/dist/ray2.d.ts.map +1 -1
  233. package/dist/ray2.js +85 -22
  234. package/dist/ray2.js.map +1 -1
  235. package/dist/ray3-array.d.ts +27 -0
  236. package/dist/ray3-array.d.ts.map +1 -0
  237. package/dist/ray3-array.js +89 -0
  238. package/dist/ray3-array.js.map +1 -0
  239. package/dist/ray3-record.d.ts +90 -0
  240. package/dist/ray3-record.d.ts.map +1 -0
  241. package/dist/ray3-record.js +146 -0
  242. package/dist/ray3-record.js.map +1 -0
  243. package/dist/ray3.d.ts +72 -25
  244. package/dist/ray3.d.ts.map +1 -1
  245. package/dist/ray3.js +233 -64
  246. package/dist/ray3.js.map +1 -1
  247. package/dist/segment2-record.d.ts +80 -0
  248. package/dist/segment2-record.d.ts.map +1 -0
  249. package/dist/segment2-record.js +122 -0
  250. package/dist/segment2-record.js.map +1 -0
  251. package/dist/segment2.d.ts +34 -19
  252. package/dist/segment2.d.ts.map +1 -1
  253. package/dist/segment2.js +88 -42
  254. package/dist/segment2.js.map +1 -1
  255. package/dist/segment3-record.d.ts +90 -0
  256. package/dist/segment3-record.d.ts.map +1 -0
  257. package/dist/segment3-record.js +146 -0
  258. package/dist/segment3-record.js.map +1 -0
  259. package/dist/segment3.d.ts +24 -12
  260. package/dist/segment3.d.ts.map +1 -1
  261. package/dist/segment3.js +67 -30
  262. package/dist/segment3.js.map +1 -1
  263. package/dist/size.d.ts +40 -0
  264. package/dist/size.d.ts.map +1 -0
  265. package/dist/size.js +72 -0
  266. package/dist/size.js.map +1 -0
  267. package/dist/sphere3-array-boundary.d.ts +51 -0
  268. package/dist/sphere3-array-boundary.d.ts.map +1 -0
  269. package/dist/sphere3-array-boundary.js +98 -0
  270. package/dist/sphere3-array-boundary.js.map +1 -0
  271. package/dist/sphere3-record.d.ts +88 -0
  272. package/dist/sphere3-record.d.ts.map +1 -0
  273. package/dist/sphere3-record.js +123 -0
  274. package/dist/sphere3-record.js.map +1 -0
  275. package/dist/sphere3.d.ts +55 -12
  276. package/dist/sphere3.d.ts.map +1 -1
  277. package/dist/sphere3.js +233 -24
  278. package/dist/sphere3.js.map +1 -1
  279. package/dist/spherical/cap.d.ts +56 -0
  280. package/dist/spherical/cap.d.ts.map +1 -0
  281. package/dist/spherical/cap.js +363 -0
  282. package/dist/spherical/cap.js.map +1 -0
  283. package/dist/spherical/great-circle.d.ts +39 -0
  284. package/dist/spherical/great-circle.d.ts.map +1 -0
  285. package/dist/spherical/great-circle.js +158 -0
  286. package/dist/spherical/great-circle.js.map +1 -0
  287. package/dist/spherical/index.d.ts +3 -0
  288. package/dist/spherical/index.d.ts.map +1 -0
  289. package/dist/spherical/index.js +3 -0
  290. package/dist/spherical/index.js.map +1 -0
  291. package/dist/triangle2-record.d.ts +91 -0
  292. package/dist/triangle2-record.d.ts.map +1 -0
  293. package/dist/triangle2-record.js +146 -0
  294. package/dist/triangle2-record.js.map +1 -0
  295. package/dist/triangle2.d.ts +29 -14
  296. package/dist/triangle2.d.ts.map +1 -1
  297. package/dist/triangle2.js +86 -22
  298. package/dist/triangle2.js.map +1 -1
  299. package/dist/triangle3-record.d.ts +97 -0
  300. package/dist/triangle3-record.d.ts.map +1 -0
  301. package/dist/triangle3-record.js +178 -0
  302. package/dist/triangle3-record.js.map +1 -0
  303. package/dist/triangle3.d.ts +41 -17
  304. package/dist/triangle3.d.ts.map +1 -1
  305. package/dist/triangle3.js +267 -38
  306. package/dist/triangle3.js.map +1 -1
  307. package/package.json +15 -8
  308. package/dist/angles.d.ts +0 -31
  309. package/dist/angles.d.ts.map +0 -1
  310. package/dist/angles.js +0 -53
  311. package/dist/angles.js.map +0 -1
  312. package/dist/coordinate-spaces.d.ts +0 -39
  313. package/dist/coordinate-spaces.d.ts.map +0 -1
  314. package/dist/coordinate-spaces.js +0 -52
  315. package/dist/coordinate-spaces.js.map +0 -1
  316. package/dist/coordinates-vec2.d.ts +0 -7
  317. package/dist/coordinates-vec2.d.ts.map +0 -1
  318. package/dist/coordinates-vec2.js +0 -35
  319. package/dist/coordinates-vec2.js.map +0 -1
  320. package/dist/coordinates-vec3.d.ts +0 -11
  321. package/dist/coordinates-vec3.d.ts.map +0 -1
  322. package/dist/coordinates-vec3.js +0 -61
  323. package/dist/coordinates-vec3.js.map +0 -1
  324. package/dist/coordinates.d.ts +0 -54
  325. package/dist/coordinates.d.ts.map +0 -1
  326. package/dist/coordinates.js +0 -2
  327. package/dist/coordinates.js.map +0 -1
  328. package/dist/euler-angles-quaternion.d.ts +0 -7
  329. package/dist/euler-angles-quaternion.d.ts.map +0 -1
  330. package/dist/euler-angles-quaternion.js +0 -100
  331. package/dist/euler-angles-quaternion.js.map +0 -1
  332. package/dist/euler-angles.d.ts +0 -33
  333. package/dist/euler-angles.d.ts.map +0 -1
  334. package/dist/euler-angles.js +0 -35
  335. package/dist/euler-angles.js.map +0 -1
  336. package/dist/geometry-vectors.d.ts +0 -11
  337. package/dist/geometry-vectors.d.ts.map +0 -1
  338. package/dist/geometry-vectors.js +0 -19
  339. package/dist/geometry-vectors.js.map +0 -1
  340. package/dist/mesh3.d.ts +0 -32
  341. package/dist/mesh3.d.ts.map +0 -1
  342. package/dist/mesh3.js +0 -142
  343. package/dist/mesh3.js.map +0 -1
  344. package/dist/point2.d.ts +0 -41
  345. package/dist/point2.d.ts.map +0 -1
  346. package/dist/point2.js +0 -92
  347. package/dist/point2.js.map +0 -1
  348. package/dist/point3.d.ts +0 -43
  349. package/dist/point3.d.ts.map +0 -1
  350. package/dist/point3.js +0 -103
  351. package/dist/point3.js.map +0 -1
  352. package/dist/point4.d.ts +0 -12
  353. package/dist/point4.d.ts.map +0 -1
  354. package/dist/point4.js +0 -28
  355. package/dist/point4.js.map +0 -1
  356. package/dist/rect2.d.ts +0 -54
  357. package/dist/rect2.d.ts.map +0 -1
  358. package/dist/rect2.js +0 -149
  359. package/dist/rect2.js.map +0 -1
  360. package/dist/size2.d.ts +0 -33
  361. package/dist/size2.d.ts.map +0 -1
  362. package/dist/size2.js +0 -81
  363. package/dist/size2.js.map +0 -1
  364. package/dist/size3.d.ts +0 -21
  365. package/dist/size3.d.ts.map +0 -1
  366. package/dist/size3.js +0 -59
  367. package/dist/size3.js.map +0 -1
  368. package/dist/size4.d.ts +0 -10
  369. package/dist/size4.d.ts.map +0 -1
  370. package/dist/size4.js +0 -16
  371. package/dist/size4.js.map +0 -1
@@ -0,0 +1,128 @@
1
+ import { assertInteger, isIterableEqual } from "@ac-kit/core";
2
+ /** The largest vertex count a `Uint16Array` index holds. */
3
+ const MAX_VERTEX_COUNT_U16_ = 0xffff;
4
+ const MAX_VERTEX_COUNT_U32_ = 4294967296;
5
+ /**
6
+ * Creates a zero-filled index buffer of `length` indices, a `Uint16Array` when
7
+ * `vertexCount` is at most 65 535 and a `Uint32Array` otherwise. Allocates.
8
+ *
9
+ * @throws {RangeError} When `length` is not a non-negative safe integer, or
10
+ * `vertexCount` is not an integer in `[0, 2³²]` (an index would not fit).
11
+ */
12
+ export function indexArrayCreate(length, vertexCount) {
13
+ assertInteger(length, "indexArrayCreate: length", 0);
14
+ assertInteger(vertexCount, "indexArrayCreate: vertexCount", 0, MAX_VERTEX_COUNT_U32_);
15
+ return vertexCount <= MAX_VERTEX_COUNT_U16_
16
+ ? new Uint16Array(length)
17
+ : new Uint32Array(length);
18
+ }
19
+ /** The number of vertices of `positions`, `positions.length / 3`. O(1). */
20
+ export function mesh3VertexCount(positions) {
21
+ return positions.length / 3;
22
+ }
23
+ /** The number of triangles of `indices`, `indices.length / 3`. O(1). */
24
+ export function mesh3TriangleCount(indices) {
25
+ return indices.length / 3;
26
+ }
27
+ /**
28
+ * Writes triangle number `triangle` of the mesh into `out`, its three vertices
29
+ * copied, and returns `true`. A `triangle` that is not an integer in range, or
30
+ * a vertex index past the last whole vertex record (`index·3 + 2 <
31
+ * positions.length` fails), makes `out` all `NaN` and returns `false`. O(1).
32
+ */
33
+ export function mesh3Triangle(out, positions, indices, triangle) {
34
+ const corner = triangle * 3;
35
+ // Whole vertex records only: seven numbers hold two vertices, not three.
36
+ const vertexCount = Math.floor(positions.length / 3);
37
+ // The `!` is for the compiler: past the end `+undefined` is `NaN`, which
38
+ // fails the range test below.
39
+ const firstVertex = +indices[corner];
40
+ const secondVertex = +indices[corner + 1];
41
+ const thirdVertex = +indices[corner + 2];
42
+ if (!(Number.isInteger(triangle) &&
43
+ firstVertex < vertexCount &&
44
+ secondVertex < vertexCount &&
45
+ thirdVertex < vertexCount)) {
46
+ out.fill(Number.NaN);
47
+ return false;
48
+ }
49
+ const a = firstVertex * 3;
50
+ const b = secondVertex * 3;
51
+ const c = thirdVertex * 3;
52
+ out[0] = positions[a];
53
+ out[1] = positions[a + 1];
54
+ out[2] = positions[a + 2];
55
+ out[3] = positions[b];
56
+ out[4] = positions[b + 1];
57
+ out[5] = positions[b + 2];
58
+ out[6] = positions[c];
59
+ out[7] = positions[c + 1];
60
+ out[8] = positions[c + 2];
61
+ return true;
62
+ }
63
+ function attributeEquals_(a, b) {
64
+ return a === undefined || b === undefined ? a === b : isIterableEqual(a, b);
65
+ }
66
+ /**
67
+ * Whether two meshes have the same positions, indices, normals and uvs, number
68
+ * for number (`-0` equals `0`, `NaN` equals nothing), with the same attributes
69
+ * present. The index type does not matter: a `Uint16Array` and a `Uint32Array`
70
+ * of the same values are equal. O(size).
71
+ */
72
+ export function mesh3Equals(a, b) {
73
+ return (attributeEquals_(a.positions, b.positions) &&
74
+ isIterableEqual(a.indices, b.indices) &&
75
+ attributeEquals_(a.normals, b.normals) &&
76
+ attributeEquals_(a.uvs, b.uvs));
77
+ }
78
+ /**
79
+ * One mesh from several, in order: the attributes are concatenated and each
80
+ * mesh's indices are offset by the vertices before it. The index type is chosen
81
+ * by the total vertex count ({@link indexArrayCreate}), so merging
82
+ * `Uint16Array` meshes can give a `Uint32Array` one. Nothing is shared with the
83
+ * inputs. No meshes, or only empty ones, give an empty mesh. O(total).
84
+ *
85
+ * @throws {RangeError} When a mesh has a position count that is not a multiple
86
+ * of 3, an index count that is not a multiple of 3, or normals or uvs that do
87
+ * not match its vertex count, or an index past its own mesh's last vertex; or
88
+ * the total exceeds 2³² vertices.
89
+ */
90
+ export function mesh3Merge(meshes) {
91
+ let vertexCount = 0;
92
+ let indexCount = 0;
93
+ for (const mesh of meshes) {
94
+ const count = mesh.positions.length / 3;
95
+ if (!Number.isInteger(count) ||
96
+ mesh.indices.length % 3 !== 0 ||
97
+ mesh.normals.length !== mesh.positions.length ||
98
+ mesh.uvs.length !== count * 2) {
99
+ throw new RangeError(`mesh3Merge: a mesh has ${mesh.positions.length} position numbers, ${mesh.normals.length} normal numbers, ${mesh.uvs.length} uv numbers and ${mesh.indices.length} indices, which do not describe a whole number of vertices and triangles.`);
100
+ }
101
+ vertexCount += count;
102
+ indexCount += mesh.indices.length;
103
+ }
104
+ const indices = indexArrayCreate(indexCount, vertexCount);
105
+ const positions = new Float64Array(vertexCount * 3);
106
+ const normals = new Float64Array(vertexCount * 3);
107
+ const uvs = new Float64Array(vertexCount * 2);
108
+ let vertexOffset = 0;
109
+ let indexOffset = 0;
110
+ for (const mesh of meshes) {
111
+ positions.set(mesh.positions, vertexOffset * 3);
112
+ normals.set(mesh.normals, vertexOffset * 3);
113
+ uvs.set(mesh.uvs, vertexOffset * 2);
114
+ const source = mesh.indices;
115
+ const meshVertexCount = mesh.positions.length / 3;
116
+ for (let index = 0; index < source.length; index++) {
117
+ const vertex = source[index];
118
+ if (!(vertex < meshVertexCount)) {
119
+ throw new RangeError(`mesh3Merge: index ${index} of a mesh is ${vertex}, past its last vertex (${meshVertexCount - 1}).`);
120
+ }
121
+ indices[indexOffset + index] = vertex + vertexOffset;
122
+ }
123
+ vertexOffset += meshVertexCount;
124
+ indexOffset += source.length;
125
+ }
126
+ return { positions, indices, normals, uvs };
127
+ }
128
+ //# sourceMappingURL=mesh3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mesh3.js","sourceRoot":"","sources":["../../src/mesh/mesh3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAgC9D,4DAA4D;AAC5D,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,MAAM,qBAAqB,GAAG,UAAa,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAAc,EACd,WAAmB;IAEnB,aAAa,CAAC,MAAM,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;IACrD,aAAa,CACZ,WAAW,EACX,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AC,CAAC;IAC9C,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC3B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;QAC5C,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACpD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAE,CAAC;YAC9B,IAAI,CAAC,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,UAAU,CACnB,qBAAqB,KAAK,iBAAiB,MAAM,2BAA2B,eAAe,GAAG,CAAC,IAAI,CACnG,CAAC;YACH,CAAC;YACD,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,GAAG,MAAM,GAAG,YAAY,CAAC;QACtD,CAAC;QACD,YAAY,IAAI,eAAe,CAAC;QAChC,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type { Brand_ } from "./_brand.js";
2
+ /**
3
+ * A plane `n·p + d = 0`: the normal `[normalX, normalY, normalZ]` pointing to
4
+ * the positive side, then `d` (three.js's `constant`). The normal is a unit
5
+ * vector when the functions that need one say so.
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 plane3Create}, {@link plane3Of}, {@link plane3Clone},
12
+ * {@link plane3FromArray} and the functions that write an `out` make one; see
13
+ * `Vec3` in `@ac-kit/math-linear` for the rules that bind callers who bypass
14
+ * the types.
15
+ */
16
+ export type Plane3 = [
17
+ normalX: number,
18
+ normalY: number,
19
+ normalZ: number,
20
+ d: number
21
+ ] & Brand_<"Plane3">;
22
+ /** A {@link Plane3} that is only read. */
23
+ export type ReadonlyPlane3 = readonly [
24
+ normalX: number,
25
+ normalY: number,
26
+ normalZ: number,
27
+ d: number
28
+ ] & Brand_<"Plane3">;
29
+ /**
30
+ * Creates the all-zero plane (a zero normal).
31
+ *
32
+ * Allocates; keep it out of hot loops.
33
+ */
34
+ export declare function plane3Create(): Plane3;
35
+ /**
36
+ * Creates the plane with the components `normalX, normalY, normalZ, d`, in
37
+ * storage order.
38
+ *
39
+ * Allocates; keep it out of hot loops.
40
+ */
41
+ export declare function plane3Of(normalX: number, normalY: number, normalZ: number, d: number): Plane3;
42
+ /**
43
+ * Creates a copy of `a`. Like every creator it starts from a clean array.
44
+ *
45
+ * Allocates; keep it out of hot loops.
46
+ */
47
+ export declare function plane3Clone(a: ReadonlyPlane3): Plane3;
48
+ /** Writes the components, in storage order, into `out`. */
49
+ export declare function plane3Set(out: Plane3, normalX: number, normalY: number, normalZ: number, d: number): Plane3;
50
+ /** Writes a copy of `a` into `out`. `out` may be `a`. */
51
+ export declare function plane3Copy(out: Plane3, a: ReadonlyPlane3): Plane3;
52
+ /**
53
+ * Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
54
+ * included, and an infinity equals itself. See {@link plane3IsClose} for a
55
+ * tolerant test.
56
+ */
57
+ export declare function plane3Equals(a: ReadonlyPlane3, b: ReadonlyPlane3): boolean;
58
+ /**
59
+ * Component-wise approximate equality: every pair differs by at most
60
+ * `tolerance`, an absolute bound in the caller's units, and an infinity is
61
+ * close only to itself. Not transitive, so never a basis for ordering or a
62
+ * container key: use {@link plane3Equals} there.
63
+ *
64
+ * @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
65
+ */
66
+ export declare function plane3IsClose(a: ReadonlyPlane3, b: ReadonlyPlane3, tolerance?: number): boolean;
67
+ /**
68
+ * The checked way in from untyped data (JSON, messages, arrays of unknown
69
+ * origin): `source[offset … offset + 4)` copied into `out`, each element that
70
+ * is not a number written as `NaN`, an index past the end of `source` too, so
71
+ * `out` never holds a non-number. A cold path: buffers use {@link plane3Load}.
72
+ * O(1).
73
+ *
74
+ * `source` may be `out` itself: the 4 elements are read before the first write.
75
+ *
76
+ * @param out The plane to fill.
77
+ * @param source The array to read, of any length and any content.
78
+ * @param offset The index of the first component in `source`.
79
+ * @returns `out`.
80
+ */
81
+ export declare function plane3FromArray(out: Plane3, source: ArrayLike<number>, offset?: number): Plane3;
82
+ /**
83
+ * Whether every component is a finite number: the check to run after parsing
84
+ * untrusted data or before an upload, as operations never check. A component
85
+ * that is not a number at all counts as not finite.
86
+ */
87
+ export declare function plane3IsFinite(value: ReadonlyPlane3): boolean;
88
+ //# sourceMappingURL=plane3-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plane3-record.d.ts","sourceRoot":"","sources":["../src/plane3-record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,MAAM,GAAG;IACpB,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,CAAC,EAAE,MAAM;CACT,GACA,MAAM,CAAC,QAAQ,CAAC,CAAC;AAElB,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG,SAAS;IACrC,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,CAAC,EAAE,MAAM;CACT,GACA,MAAM,CAAC,QAAQ,CAAC,CAAC;AAQlB;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAOrC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,CAAC,EAAE,MAAM,GACP,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAOrD;AAED,2DAA2D;AAC3D,wBAAgB,SAAS,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,CAAC,EAAE,MAAM,GACP,MAAM,CAMR;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,GAAG,MAAM,CAMjE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,CAE1E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC5B,CAAC,EAAE,cAAc,EACjB,CAAC,EAAE,cAAc,EACjB,SAAS,GAAE,MAA8C,GACvD,OAAO,CAOT;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,MAAM,SAAI,GACR,MAAM,CAUR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAO7D"}
@@ -0,0 +1,123 @@
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 all-zero plane (a zero normal).
11
+ *
12
+ * Allocates; keep it out of hot loops.
13
+ */
14
+ export function plane3Create() {
15
+ const out = TEMPLATE_.slice();
16
+ out[0] = 0;
17
+ out[1] = 0;
18
+ out[2] = 0;
19
+ out[3] = 0;
20
+ return out;
21
+ }
22
+ /**
23
+ * Creates the plane with the components `normalX, normalY, normalZ, d`, in
24
+ * storage order.
25
+ *
26
+ * Allocates; keep it out of hot loops.
27
+ */
28
+ export function plane3Of(normalX, normalY, normalZ, d) {
29
+ const out = TEMPLATE_.slice();
30
+ out[0] = normalX;
31
+ out[1] = normalY;
32
+ out[2] = normalZ;
33
+ out[3] = d;
34
+ return out;
35
+ }
36
+ /**
37
+ * Creates a copy of `a`. Like every creator it starts from a clean array.
38
+ *
39
+ * Allocates; keep it out of hot loops.
40
+ */
41
+ export function plane3Clone(a) {
42
+ const out = TEMPLATE_.slice();
43
+ out[0] = a[0];
44
+ out[1] = a[1];
45
+ out[2] = a[2];
46
+ out[3] = a[3];
47
+ return out;
48
+ }
49
+ /** Writes the components, in storage order, into `out`. */
50
+ export function plane3Set(out, normalX, normalY, normalZ, d) {
51
+ out[0] = normalX;
52
+ out[1] = normalY;
53
+ out[2] = normalZ;
54
+ out[3] = d;
55
+ return out;
56
+ }
57
+ /** Writes a copy of `a` into `out`. `out` may be `a`. */
58
+ export function plane3Copy(out, a) {
59
+ out[0] = a[0];
60
+ out[1] = a[1];
61
+ out[2] = a[2];
62
+ out[3] = a[3];
63
+ return out;
64
+ }
65
+ /**
66
+ * Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
67
+ * included, and an infinity equals itself. See {@link plane3IsClose} for a
68
+ * tolerant test.
69
+ */
70
+ export function plane3Equals(a, b) {
71
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
72
+ }
73
+ /**
74
+ * Component-wise approximate equality: every pair differs by at most
75
+ * `tolerance`, an absolute bound in the caller's units, and an infinity is
76
+ * close only to itself. Not transitive, so never a basis for ordering or a
77
+ * container key: use {@link plane3Equals} there.
78
+ *
79
+ * @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
80
+ */
81
+ export function plane3IsClose(a, b, tolerance = geometryConfig.defaultLinearTolerance) {
82
+ return (isCloseAbsolute(a[0], b[0], tolerance) &&
83
+ isCloseAbsolute(a[1], b[1], tolerance) &&
84
+ isCloseAbsolute(a[2], b[2], tolerance) &&
85
+ isCloseAbsolute(a[3], b[3], tolerance));
86
+ }
87
+ /**
88
+ * The checked way in from untyped data (JSON, messages, arrays of unknown
89
+ * origin): `source[offset … offset + 4)` copied into `out`, each element that
90
+ * is not a number written as `NaN`, an index past the end of `source` too, so
91
+ * `out` never holds a non-number. A cold path: buffers use {@link plane3Load}.
92
+ * O(1).
93
+ *
94
+ * `source` may be `out` itself: the 4 elements are read before the first write.
95
+ *
96
+ * @param out The plane to fill.
97
+ * @param source The array to read, of any length and any content.
98
+ * @param offset The index of the first component in `source`.
99
+ * @returns `out`.
100
+ */
101
+ export function plane3FromArray(out, source, offset = 0) {
102
+ const value0 = numberAtOrNaN(source, offset);
103
+ const value1 = numberAtOrNaN(source, offset + 1);
104
+ const value2 = numberAtOrNaN(source, offset + 2);
105
+ const value3 = numberAtOrNaN(source, offset + 3);
106
+ out[0] = value0;
107
+ out[1] = value1;
108
+ out[2] = value2;
109
+ out[3] = value3;
110
+ return out;
111
+ }
112
+ /**
113
+ * Whether every component is a finite number: the check to run after parsing
114
+ * untrusted data or before an upload, as operations never check. A component
115
+ * that is not a number at all counts as not finite.
116
+ */
117
+ export function plane3IsFinite(value) {
118
+ return (Number.isFinite(value[0]) &&
119
+ Number.isFinite(value[1]) &&
120
+ Number.isFinite(value[2]) &&
121
+ Number.isFinite(value[3]));
122
+ }
123
+ //# sourceMappingURL=plane3-record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plane3-record.js","sourceRoot":"","sources":["../src/plane3-record.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAiC9C;;;GAGG;AACH,MAAM,SAAS,GAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC3B,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAY,CAAC;IACxC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,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,QAAQ,CACvB,OAAe,EACf,OAAe,EACf,OAAe,EACf,CAAS;IAET,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAY,CAAC;IACxC,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACjB,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACjB,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACjB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAiB;IAC5C,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAY,CAAC;IACxC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACd,GAAG,CAAC,CAAC,CAA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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/plane3.d.ts CHANGED
@@ -1,38 +1,52 @@
1
- import { Vec3 } from "@ac-kit/math-linear";
2
- export type Plane3 = {
3
- /** Unit normal vector pointing away from the plane's surface. */
4
- normal: Vec3;
5
- /** Signed distance from the origin to the plane along the normal. */
6
- distance: number;
7
- };
1
+ import type { ReadonlyAffine3, ReadonlyVec3, Vec3 } from "@ac-kit/math-linear";
2
+ import type { Plane3, ReadonlyPlane3 } from "./plane3-record.js";
8
3
  /**
9
- * Returns the signed distance from the plane to `p`. Positive if `p` is on the
10
- * normal side.
4
+ * Writes the plane through `point` with the given `normal` into `out`. The
5
+ * normal is copied as it is, not normalised: `d` is `−normal · point`.
11
6
  */
12
- export declare function plane3DistanceToPoint(plane: Plane3, p: Vec3): number;
7
+ export declare function plane3FromNormalAndPoint(out: Plane3, normal: ReadonlyVec3, point: ReadonlyVec3): Plane3;
13
8
  /**
14
- * Whether `p` lies on `plane`, within `tolerance` of it.
15
- *
16
- * Tolerant by necessity: a plane has zero volume, so no constructed point ever
17
- * lands on one exactly. `tolerance` is a distance in the caller's own units,
18
- * which is the only form defined here — the signed distance is compared against
19
- * zero, where a relative or ULP bound degenerates to exact equality.
9
+ * Writes the plane through three points into `out`, with a unit normal given by
10
+ * the right-hand rule: counter-clockwise `a, b, c` seen from the positive side.
11
+ * Collinear points give a zero normal and `d = 0`. The normal is normalised by
12
+ * its largest component first, right at any magnitude.
13
+ */
14
+ export declare function plane3FromPoints(out: Plane3, a: ReadonlyVec3, b: ReadonlyVec3, c: ReadonlyVec3): Plane3;
15
+ /**
16
+ * `n · p + d`: the distance from the plane, positive on the side the normal
17
+ * points to, when the normal is a unit vector (see {@link plane3Normalize}).
20
18
  */
21
- export declare function plane3ContainsPoint(plane: Plane3, p: Vec3, tolerance?: number): boolean;
19
+ export declare function plane3SignedDistanceToPoint(plane: ReadonlyPlane3, point: ReadonlyVec3): number;
22
20
  /**
23
- * Exact equality of normal and distance.
21
+ * Whether `point` lies on the plane, within `tolerance` of it; the normal must
22
+ * be a unit vector.
24
23
  *
25
- * Compares the representation, not the geometry: a plane and its flip describe
26
- * the same surface but are not equal.
24
+ * @param tolerance A distance in the caller's units; defaults to
25
+ * `geometryConfig.defaultLinearTolerance`.
26
+ */
27
+ export declare function plane3ContainsPoint(plane: ReadonlyPlane3, point: ReadonlyVec3, tolerance?: number): boolean;
28
+ /**
29
+ * Writes the point of the plane nearest to `point` into `out`. Any non-zero
30
+ * normal works, unit or not; a zero normal gives `NaN`. `out` may be `point`.
31
+ */
32
+ export declare function plane3ProjectPoint(out: Vec3, plane: ReadonlyPlane3, point: ReadonlyVec3): Vec3;
33
+ /**
34
+ * Writes the plane with the opposite orientation (same points, negated normal
35
+ * and `d`) into `out`. `out` may be `plane`.
36
+ */
37
+ export declare function plane3Flip(out: Plane3, plane: ReadonlyPlane3): Plane3;
38
+ /**
39
+ * Writes the plane with a unit normal (the four numbers divided by the normal's
40
+ * length) into `out`. A zero normal gives non-finite components. `out` may be
41
+ * `plane`.
27
42
  */
28
- export declare function plane3Equals(a: Plane3, b: Plane3): boolean;
29
- /** Returns a new plane with the normal and distance sign flipped. */
30
- export declare function plane3Flip(plane: Plane3): Plane3;
43
+ export declare function plane3Normalize(out: Plane3, plane: ReadonlyPlane3): Plane3;
31
44
  /**
32
- * Normalizes the plane so that `normal` is a unit vector. If `normal` is
33
- * already a unit vector, this is a no-op.
45
+ * Writes the plane moved by `transform` into `out`, through the inverse
46
+ * transpose of its linear part, so a non-uniform scale tilts the normal
47
+ * correctly. The normal is no longer a unit vector after a scale. Returns
48
+ * `false`, with `out` holding `NaN`, when the transform is singular (or the
49
+ * result is not finite). `out` may be `plane`.
34
50
  */
35
- export declare function plane3Normalize(plane: Plane3): Plane3;
36
- /** Projects `p` onto the plane (closest point on the plane to `p`). */
37
- export declare function plane3ProjectPoint(plane: Plane3, p: Vec3): Vec3;
51
+ export declare function plane3TransformAffine3(out: Plane3, plane: ReadonlyPlane3, transform: ReadonlyAffine3): boolean;
38
52
  //# sourceMappingURL=plane3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plane3.d.ts","sourceRoot":"","sources":["../src/plane3.ts"],"names":[],"mappings":"AACA,OAAO,EACN,IAAI,EAMJ,MAAM,qBAAqB,CAAC;AAI7B,MAAM,MAAM,MAAM,GAAG;IACpB,iEAAiE;IACjE,MAAM,EAAE,IAAI,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,EACb,CAAC,EAAE,IAAI,EACP,SAAS,GAAE,MAA8C,GACvD,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAO1D;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKhD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASrD;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAG/D"}
1
+ {"version":3,"file":"plane3.d.ts","sourceRoot":"","sources":["../src/plane3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,qBAAqB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