@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.2

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 (378) hide show
  1. package/LICENSE +97 -49
  2. package/README.md +16 -1
  3. package/THIRD-PARTY-NOTICES.md +18 -0
  4. package/dist/culling/constants.d.ts +3 -0
  5. package/dist/culling/constants.d.ts.map +1 -0
  6. package/dist/culling/constants.js +5 -0
  7. package/dist/culling/constants.js.map +1 -0
  8. package/dist/culling/index.cjs +2124 -0
  9. package/dist/culling/index.cjs.map +6 -0
  10. package/dist/culling/index.d.ts +31 -0
  11. package/dist/culling/index.d.ts.map +1 -0
  12. package/dist/culling/index.js +25 -0
  13. package/dist/culling/index.js.map +1 -0
  14. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
  15. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
  16. package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
  17. package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
  18. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
  19. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
  20. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
  21. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
  22. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
  23. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
  24. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
  25. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
  26. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
  27. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
  28. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
  29. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
  30. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
  31. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
  32. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +116 -0
  33. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
  34. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
  35. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
  36. package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
  37. package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
  38. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
  39. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
  40. package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
  41. package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
  42. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
  43. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
  44. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
  45. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
  46. package/dist/culling/lib/culling-volume.d.ts +46 -0
  47. package/dist/culling/lib/culling-volume.d.ts.map +1 -0
  48. package/dist/culling/lib/culling-volume.js +126 -0
  49. package/dist/culling/lib/culling-volume.js.map +1 -0
  50. package/dist/culling/lib/perspective-frustum.d.ts +153 -0
  51. package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
  52. package/dist/culling/lib/perspective-frustum.js +191 -0
  53. package/dist/culling/lib/perspective-frustum.js.map +1 -0
  54. package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
  55. package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
  56. package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
  57. package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
  58. package/dist/culling/lib/plane.d.ts +35 -0
  59. package/dist/culling/lib/plane.d.ts.map +1 -0
  60. package/dist/culling/lib/plane.js +90 -0
  61. package/dist/culling/lib/plane.js.map +1 -0
  62. package/dist/culling/lib/ray.d.ts +13 -0
  63. package/dist/culling/lib/ray.d.ts.map +1 -0
  64. package/dist/culling/lib/ray.js +30 -0
  65. package/dist/culling/lib/ray.js.map +1 -0
  66. package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
  67. package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
  68. package/dist/culling/lib/shapes/box-shape.js +69 -0
  69. package/dist/culling/lib/shapes/box-shape.js.map +1 -0
  70. package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
  71. package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
  72. package/dist/culling/lib/shapes/capsule-shape.js +151 -0
  73. package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
  74. package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
  75. package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
  76. package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
  77. package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
  78. package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
  79. package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
  80. package/dist/culling/lib/shapes/implicit-shape.js +142 -0
  81. package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
  82. package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
  83. package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
  84. package/dist/culling/lib/shapes/plane-shape.js +71 -0
  85. package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
  86. package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
  87. package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
  88. package/dist/culling/lib/shapes/sphere-shape.js +43 -0
  89. package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
  90. package/dist/culling/oriented-box-2d.d.ts +22 -0
  91. package/dist/culling/oriented-box-2d.d.ts.map +1 -0
  92. package/dist/culling/oriented-box-2d.js +86 -0
  93. package/dist/culling/oriented-box-2d.js.map +1 -0
  94. package/dist/culling/queries.d.ts +44 -0
  95. package/dist/culling/queries.d.ts.map +1 -0
  96. package/dist/culling/queries.js +259 -0
  97. package/dist/culling/queries.js.map +1 -0
  98. package/dist/curves/bezier-curves.d.ts +18 -0
  99. package/dist/curves/bezier-curves.d.ts.map +1 -0
  100. package/dist/curves/bezier-curves.js +54 -0
  101. package/dist/curves/bezier-curves.js.map +1 -0
  102. package/dist/curves/catmull-rom-curve.d.ts +15 -0
  103. package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
  104. package/dist/curves/catmull-rom-curve.js +77 -0
  105. package/dist/curves/catmull-rom-curve.js.map +1 -0
  106. package/dist/curves/curve-arc-length.d.ts +17 -0
  107. package/dist/curves/curve-arc-length.d.ts.map +1 -0
  108. package/dist/curves/curve-arc-length.js +58 -0
  109. package/dist/curves/curve-arc-length.js.map +1 -0
  110. package/dist/curves/curve.d.ts +23 -0
  111. package/dist/curves/curve.d.ts.map +1 -0
  112. package/dist/curves/curve.js +77 -0
  113. package/dist/curves/curve.js.map +1 -0
  114. package/dist/curves/hermite-curve.d.ts +9 -0
  115. package/dist/curves/hermite-curve.d.ts.map +1 -0
  116. package/dist/curves/hermite-curve.js +24 -0
  117. package/dist/curves/hermite-curve.js.map +1 -0
  118. package/dist/curves/index.d.ts +8 -0
  119. package/dist/curves/index.d.ts.map +1 -0
  120. package/dist/curves/index.js +9 -0
  121. package/dist/curves/index.js.map +1 -0
  122. package/dist/geometries/box-geometry.js +1 -1
  123. package/dist/geometries/box-geometry.js.map +1 -1
  124. package/dist/geometries/capsule-geometry.js +1 -1
  125. package/dist/geometries/capsule-geometry.js.map +1 -1
  126. package/dist/geometries/cylinder-geometry.js +1 -1
  127. package/dist/geometries/cylinder-geometry.js.map +1 -1
  128. package/dist/geometries/geometry-helpers.js +1 -1
  129. package/dist/geometries/geometry-helpers.js.map +1 -1
  130. package/dist/geometries/ico-sphere-geometry.js +1 -1
  131. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  132. package/dist/geometries/plane-geometry.js +1 -1
  133. package/dist/geometries/plane-geometry.js.map +1 -1
  134. package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
  135. package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
  136. package/dist/geometries/primitive-mesh-builder.js +74 -0
  137. package/dist/geometries/primitive-mesh-builder.js.map +1 -0
  138. package/dist/geometries/prism-geometry.d.ts +13 -0
  139. package/dist/geometries/prism-geometry.d.ts.map +1 -0
  140. package/dist/geometries/prism-geometry.js +34 -0
  141. package/dist/geometries/prism-geometry.js.map +1 -0
  142. package/dist/geometries/ring-geometry.d.ts +15 -0
  143. package/dist/geometries/ring-geometry.d.ts.map +1 -0
  144. package/dist/geometries/ring-geometry.js +64 -0
  145. package/dist/geometries/ring-geometry.js.map +1 -0
  146. package/dist/geometries/sphere-geometry.js +1 -1
  147. package/dist/geometries/sphere-geometry.js.map +1 -1
  148. package/dist/geometries/surface-of-revolution.js +1 -1
  149. package/dist/geometries/surface-of-revolution.js.map +1 -1
  150. package/dist/geometries/truncated-cone-geometry.js +1 -1
  151. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  152. package/dist/index.cjs +6105 -16
  153. package/dist/index.cjs.map +3 -3
  154. package/dist/index.d.ts +26 -0
  155. package/dist/index.d.ts.map +1 -1
  156. package/dist/index.js +15 -1
  157. package/dist/index.js.map +1 -1
  158. package/dist/lib/geometry-utils.js +1 -1
  159. package/dist/lib/geometry-utils.js.map +1 -1
  160. package/dist/lib/geometry.d.ts +1 -1
  161. package/dist/lib/geometry.d.ts.map +1 -1
  162. package/dist/lib/geometry.js +1 -1
  163. package/dist/lib/geometry.js.map +1 -1
  164. package/dist/lib/hinge-tree.d.ts +33 -0
  165. package/dist/lib/hinge-tree.d.ts.map +1 -0
  166. package/dist/lib/hinge-tree.js +144 -0
  167. package/dist/lib/hinge-tree.js.map +1 -0
  168. package/dist/parametric/lathe-geometry.d.ts +14 -0
  169. package/dist/parametric/lathe-geometry.d.ts.map +1 -0
  170. package/dist/parametric/lathe-geometry.js +48 -0
  171. package/dist/parametric/lathe-geometry.js.map +1 -0
  172. package/dist/parametric/parametric-geometry.d.ts +20 -0
  173. package/dist/parametric/parametric-geometry.d.ts.map +1 -0
  174. package/dist/parametric/parametric-geometry.js +88 -0
  175. package/dist/parametric/parametric-geometry.js.map +1 -0
  176. package/dist/parametric/torus-geometry.d.ts +19 -0
  177. package/dist/parametric/torus-geometry.d.ts.map +1 -0
  178. package/dist/parametric/torus-geometry.js +89 -0
  179. package/dist/parametric/torus-geometry.js.map +1 -0
  180. package/dist/parametric.d.ts +7 -0
  181. package/dist/parametric.d.ts.map +1 -0
  182. package/dist/parametric.js +7 -0
  183. package/dist/parametric.js.map +1 -0
  184. package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
  185. package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
  186. package/dist/polygon/clip-triangle-mesh.js +155 -0
  187. package/dist/polygon/clip-triangle-mesh.js.map +1 -0
  188. package/dist/polygon/cut-by-grid.d.ts +24 -0
  189. package/dist/polygon/cut-by-grid.d.ts.map +1 -0
  190. package/dist/polygon/cut-by-grid.js +221 -0
  191. package/dist/polygon/cut-by-grid.js.map +1 -0
  192. package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
  193. package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
  194. package/dist/polygon/cut-by-mercator-bounds.js +149 -0
  195. package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
  196. package/dist/polygon/earcut.d.ts +13 -0
  197. package/dist/polygon/earcut.d.ts.map +1 -0
  198. package/dist/polygon/earcut.js +693 -0
  199. package/dist/polygon/earcut.js.map +1 -0
  200. package/dist/polygon/index.d.ts +14 -0
  201. package/dist/polygon/index.d.ts.map +1 -0
  202. package/dist/polygon/index.js +13 -0
  203. package/dist/polygon/index.js.map +1 -0
  204. package/dist/polygon/lineclip.d.ts +31 -0
  205. package/dist/polygon/lineclip.d.ts.map +1 -0
  206. package/dist/polygon/lineclip.js +184 -0
  207. package/dist/polygon/lineclip.js.map +1 -0
  208. package/dist/polygon/polygon-utils.d.ts +103 -0
  209. package/dist/polygon/polygon-utils.d.ts.map +1 -0
  210. package/dist/polygon/polygon-utils.js +155 -0
  211. package/dist/polygon/polygon-utils.js.map +1 -0
  212. package/dist/polygon/polygon.d.ts +41 -0
  213. package/dist/polygon/polygon.d.ts.map +1 -0
  214. package/dist/polygon/polygon.js +76 -0
  215. package/dist/polygon/polygon.js.map +1 -0
  216. package/dist/polygon/subdivide-polyline.d.ts +56 -0
  217. package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
  218. package/dist/polygon/subdivide-polyline.js +141 -0
  219. package/dist/polygon/subdivide-polyline.js.map +1 -0
  220. package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
  221. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
  222. package/dist/polygon/subdivide-triangle-mesh.js +238 -0
  223. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
  224. package/dist/polygon/utils.d.ts +5 -0
  225. package/dist/polygon/utils.d.ts.map +1 -0
  226. package/dist/polygon/utils.js +38 -0
  227. package/dist/polygon/utils.js.map +1 -0
  228. package/dist/spatial-index/box-index.d.ts +86 -0
  229. package/dist/spatial-index/box-index.d.ts.map +1 -0
  230. package/dist/spatial-index/box-index.js +335 -0
  231. package/dist/spatial-index/box-index.js.map +1 -0
  232. package/dist/spatial-index/index.d.ts +7 -0
  233. package/dist/spatial-index/index.d.ts.map +1 -0
  234. package/dist/spatial-index/index.js +6 -0
  235. package/dist/spatial-index/index.js.map +1 -0
  236. package/dist/spatial-index/triangle-bvh.d.ts +74 -0
  237. package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
  238. package/dist/spatial-index/triangle-bvh.js +221 -0
  239. package/dist/spatial-index/triangle-bvh.js.map +1 -0
  240. package/dist/utils/attribute-compression.d.ts +50 -0
  241. package/dist/utils/attribute-compression.d.ts.map +1 -0
  242. package/dist/utils/attribute-compression.js +186 -0
  243. package/dist/utils/attribute-compression.js.map +1 -0
  244. package/dist/utils/attribute-iterator.d.ts +8 -0
  245. package/dist/utils/attribute-iterator.d.ts.map +1 -0
  246. package/dist/utils/attribute-iterator.js +25 -0
  247. package/dist/utils/attribute-iterator.js.map +1 -0
  248. package/dist/utils/compose-attribute-provenance.d.ts +13 -0
  249. package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
  250. package/dist/utils/compose-attribute-provenance.js +63 -0
  251. package/dist/utils/compose-attribute-provenance.js.map +1 -0
  252. package/dist/utils/compute-vertex-normals.d.ts +4 -0
  253. package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
  254. package/dist/utils/compute-vertex-normals.js +54 -0
  255. package/dist/utils/compute-vertex-normals.js.map +1 -0
  256. package/dist/utils/constants.d.ts +52 -0
  257. package/dist/utils/constants.d.ts.map +1 -0
  258. package/dist/utils/constants.js +39 -0
  259. package/dist/utils/constants.js.map +1 -0
  260. package/dist/utils/coordinates.d.ts +3 -0
  261. package/dist/utils/coordinates.d.ts.map +1 -0
  262. package/dist/utils/coordinates.js +8 -0
  263. package/dist/utils/coordinates.js.map +1 -0
  264. package/dist/utils/geometry.d.ts +20 -0
  265. package/dist/utils/geometry.d.ts.map +1 -0
  266. package/dist/utils/geometry.js +31 -0
  267. package/dist/utils/geometry.js.map +1 -0
  268. package/dist/utils/gl-type.d.ts +17 -0
  269. package/dist/utils/gl-type.d.ts.map +1 -0
  270. package/dist/utils/gl-type.js +69 -0
  271. package/dist/utils/gl-type.js.map +1 -0
  272. package/dist/utils/index.d.ts +18 -0
  273. package/dist/utils/index.d.ts.map +1 -0
  274. package/dist/utils/index.js +16 -0
  275. package/dist/utils/index.js.map +1 -0
  276. package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
  277. package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
  278. package/dist/utils/interpolate-packed-attributes.js +192 -0
  279. package/dist/utils/interpolate-packed-attributes.js.map +1 -0
  280. package/dist/utils/mesh-processing.d.ts +18 -0
  281. package/dist/utils/mesh-processing.d.ts.map +1 -0
  282. package/dist/utils/mesh-processing.js +300 -0
  283. package/dist/utils/mesh-processing.js.map +1 -0
  284. package/dist/utils/primitive-iterator.d.ts +21 -0
  285. package/dist/utils/primitive-iterator.d.ts.map +1 -0
  286. package/dist/utils/primitive-iterator.js +117 -0
  287. package/dist/utils/primitive-iterator.js.map +1 -0
  288. package/dist/utils/qualify-surface-transition.d.ts +21 -0
  289. package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
  290. package/dist/utils/qualify-surface-transition.js +140 -0
  291. package/dist/utils/qualify-surface-transition.js.map +1 -0
  292. package/dist/utils/rgb565.d.ts +5 -0
  293. package/dist/utils/rgb565.d.ts.map +1 -0
  294. package/dist/utils/rgb565.js +24 -0
  295. package/dist/utils/rgb565.js.map +1 -0
  296. package/dist/utils/typed-array-utils.d.ts +3 -0
  297. package/dist/utils/typed-array-utils.d.ts.map +1 -0
  298. package/dist/utils/typed-array-utils.js +16 -0
  299. package/dist/utils/typed-array-utils.js.map +1 -0
  300. package/package.json +12 -4
  301. package/src/culling/constants.ts +6 -0
  302. package/src/culling/index.ts +55 -0
  303. package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
  304. package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
  305. package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
  306. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
  307. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +153 -0
  308. package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
  309. package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
  310. package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
  311. package/src/culling/lib/culling-volume.ts +163 -0
  312. package/src/culling/lib/perspective-frustum.ts +288 -0
  313. package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
  314. package/src/culling/lib/plane.ts +118 -0
  315. package/src/culling/lib/ray.ts +33 -0
  316. package/src/culling/lib/shapes/box-shape.ts +78 -0
  317. package/src/culling/lib/shapes/capsule-shape.ts +232 -0
  318. package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
  319. package/src/culling/lib/shapes/implicit-shape.ts +209 -0
  320. package/src/culling/lib/shapes/plane-shape.ts +78 -0
  321. package/src/culling/lib/shapes/sphere-shape.ts +60 -0
  322. package/src/culling/oriented-box-2d.ts +165 -0
  323. package/src/culling/queries.ts +332 -0
  324. package/src/curves/bezier-curves.ts +62 -0
  325. package/src/curves/catmull-rom-curve.ts +89 -0
  326. package/src/curves/curve-arc-length.ts +70 -0
  327. package/src/curves/curve.ts +96 -0
  328. package/src/curves/hermite-curve.ts +34 -0
  329. package/src/curves/index.ts +15 -0
  330. package/src/geometries/box-geometry.ts +1 -1
  331. package/src/geometries/capsule-geometry.ts +1 -1
  332. package/src/geometries/cylinder-geometry.ts +1 -1
  333. package/src/geometries/geometry-helpers.ts +1 -1
  334. package/src/geometries/ico-sphere-geometry.ts +1 -1
  335. package/src/geometries/plane-geometry.ts +1 -1
  336. package/src/geometries/primitive-mesh-builder.ts +84 -0
  337. package/src/geometries/prism-geometry.ts +57 -0
  338. package/src/geometries/ring-geometry.ts +102 -0
  339. package/src/geometries/sphere-geometry.ts +1 -1
  340. package/src/geometries/surface-of-revolution.ts +1 -1
  341. package/src/geometries/truncated-cone-geometry.ts +1 -1
  342. package/src/index.ts +179 -1
  343. package/src/lib/geometry-utils.ts +2 -2
  344. package/src/lib/geometry.ts +2 -2
  345. package/src/lib/hinge-tree.ts +170 -0
  346. package/src/parametric/lathe-geometry.ts +70 -0
  347. package/src/parametric/parametric-geometry.ts +118 -0
  348. package/src/parametric/torus-geometry.ts +118 -0
  349. package/src/parametric.ts +9 -0
  350. package/src/polygon/clip-triangle-mesh.ts +218 -0
  351. package/src/polygon/cut-by-grid.ts +313 -0
  352. package/src/polygon/cut-by-mercator-bounds.ts +204 -0
  353. package/src/polygon/earcut.ts +859 -0
  354. package/src/polygon/index.ts +42 -0
  355. package/src/polygon/lineclip.ts +218 -0
  356. package/src/polygon/polygon-utils.ts +273 -0
  357. package/src/polygon/polygon.ts +105 -0
  358. package/src/polygon/subdivide-polyline.ts +223 -0
  359. package/src/polygon/subdivide-triangle-mesh.ts +342 -0
  360. package/src/polygon/utils.ts +50 -0
  361. package/src/spatial-index/box-index.ts +452 -0
  362. package/src/spatial-index/index.ts +20 -0
  363. package/src/spatial-index/triangle-bvh.ts +345 -0
  364. package/src/utils/attribute-compression.ts +234 -0
  365. package/src/utils/attribute-iterator.ts +28 -0
  366. package/src/utils/compose-attribute-provenance.ts +74 -0
  367. package/src/utils/compute-vertex-normals.ts +63 -0
  368. package/src/utils/constants.ts +42 -0
  369. package/src/utils/coordinates.ts +8 -0
  370. package/src/utils/geometry.ts +49 -0
  371. package/src/utils/gl-type.ts +87 -0
  372. package/src/utils/index.ts +55 -0
  373. package/src/utils/interpolate-packed-attributes.ts +284 -0
  374. package/src/utils/mesh-processing.ts +377 -0
  375. package/src/utils/primitive-iterator.ts +145 -0
  376. package/src/utils/qualify-surface-transition.ts +169 -0
  377. package/src/utils/rgb565.ts +26 -0
  378. package/src/utils/typed-array-utils.ts +16 -0
@@ -0,0 +1,209 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Matrix4, Vector3} from '@math.gl/core';
6
+ import type {CullingResult} from '../../constants';
7
+ import {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';
8
+ import {BoundingSphere} from '../bounding-volumes/bounding-sphere';
9
+ import type {BoundingVolume} from '../bounding-volumes/bounding-volume';
10
+ import type {Plane} from '../plane';
11
+ import type {Ray} from '../ray';
12
+
13
+ export type RayIntersection = {
14
+ distance: number;
15
+ point: Vector3;
16
+ normal: Vector3;
17
+ entering: boolean;
18
+ };
19
+
20
+ export interface ImplicitShape extends BoundingVolume {
21
+ readonly type: 'box' | 'capsule' | 'cylinder' | 'plane' | 'sphere';
22
+ readonly matrix: Matrix4;
23
+ clone(): ImplicitShape;
24
+ equals(shape: ImplicitShape): boolean;
25
+ containsPoint(point: readonly number[]): boolean;
26
+ intersectRay(ray: Ray): RayIntersection | undefined;
27
+ getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined;
28
+ getBoundingSphere(): BoundingSphere | undefined;
29
+ }
30
+
31
+ export type LocalRayIntersection = {distance: number; normal: readonly number[]};
32
+
33
+ /** Shared affine transform, support mapping and query implementation for finite convex shapes. */
34
+ export abstract class ImplicitShapeBase implements ImplicitShape {
35
+ abstract readonly type: ImplicitShape['type'];
36
+ readonly matrix: Matrix4;
37
+ protected inverseMatrix: Matrix4;
38
+
39
+ constructor(matrix?: readonly number[]) {
40
+ this.matrix = new Matrix4();
41
+ if (matrix) this.matrix.copy(matrix);
42
+ validateAffineMatrix(this.matrix);
43
+ this.inverseMatrix = this.matrix.clone().invert();
44
+ }
45
+
46
+ abstract clone(): ImplicitShapeBase;
47
+ abstract containsLocalPoint(point: readonly number[]): boolean;
48
+ abstract distanceToLocalPoint(point: readonly number[]): number;
49
+ abstract supportLocal(direction: readonly number[]): readonly number[];
50
+ abstract intersectLocalRay(
51
+ origin: readonly number[],
52
+ direction: readonly number[]
53
+ ): LocalRayIntersection | undefined;
54
+
55
+ equals(shape: ImplicitShape): boolean {
56
+ if (this.type !== shape.type) return false;
57
+ for (let i = 0; i < 16; i++) if (this.matrix[i] !== shape.matrix[i]) return false;
58
+ return true;
59
+ }
60
+
61
+ transform(transform: readonly number[]): this {
62
+ const next = new Matrix4().copy(transform);
63
+ validateAffineMatrix(next);
64
+ this.matrix.multiplyLeft(next);
65
+ validateAffineMatrix(this.matrix);
66
+ this.inverseMatrix.copy(this.matrix).invert();
67
+ return this;
68
+ }
69
+
70
+ containsPoint(point: readonly number[]): boolean {
71
+ return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point) as readonly number[]);
72
+ }
73
+
74
+ distanceSquaredTo(point: readonly number[]): number {
75
+ const distance = this.distanceTo(point);
76
+ return distance * distance;
77
+ }
78
+
79
+ /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
80
+ distanceTo(point: readonly number[]): number {
81
+ const localPoint = this.inverseMatrix.transformAsPoint(point);
82
+ const localDistance = this.distanceToLocalPoint(localPoint as readonly number[]);
83
+ const scales = this.matrix.getScale();
84
+ return localDistance * Math.min(scales[0], scales[1], scales[2]);
85
+ }
86
+
87
+ intersectPlane(plane: Plane): CullingResult {
88
+ const maximum = this.getSupportPoint(plane.normal);
89
+ const minimum = this.getSupportPoint([-plane.normal[0], -plane.normal[1], -plane.normal[2]]);
90
+ const maxDistance = plane.getPointDistance(maximum);
91
+ const minDistance = plane.getPointDistance(minimum);
92
+ if (minDistance > 0) return 'inside';
93
+ if (maxDistance < 0) return 'outside';
94
+ return 'intersecting';
95
+ }
96
+
97
+ intersectRay(ray: Ray): RayIntersection | undefined {
98
+ const localOrigin = this.inverseMatrix.transformAsPoint(ray.origin);
99
+ const localDirection = this.inverseMatrix.transformAsVector(ray.direction);
100
+ const hit = this.intersectLocalRay(
101
+ localOrigin as readonly number[],
102
+ localDirection as readonly number[]
103
+ );
104
+ if (!hit || hit.distance < 0) return undefined;
105
+ const point = new Vector3(ray.direction).scale(hit.distance).add(ray.origin);
106
+ const inverse = this.inverseMatrix;
107
+ const normal = new Vector3(
108
+ inverse[0] * hit.normal[0] + inverse[1] * hit.normal[1] + inverse[2] * hit.normal[2],
109
+ inverse[4] * hit.normal[0] + inverse[5] * hit.normal[1] + inverse[6] * hit.normal[2],
110
+ inverse[8] * hit.normal[0] + inverse[9] * hit.normal[1] + inverse[10] * hit.normal[2]
111
+ ).normalize();
112
+ return {distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0};
113
+ }
114
+
115
+ getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined {
116
+ const minimum = new Vector3();
117
+ const maximum = new Vector3();
118
+ for (let axis = 0; axis < 3; axis++) {
119
+ const direction = [0, 0, 0];
120
+ direction[axis] = 1;
121
+ maximum[axis] = this.getSupportPoint(direction)[axis];
122
+ direction[axis] = -1;
123
+ minimum[axis] = this.getSupportPoint(direction)[axis];
124
+ }
125
+ return new AxisAlignedBoundingBox(minimum, maximum);
126
+ }
127
+
128
+ getBoundingSphere(): BoundingSphere | undefined {
129
+ const box = this.getAxisAlignedBoundingBox();
130
+ if (!box) return undefined;
131
+ return new BoundingSphere().fromCornerPoints(box.minimum, box.maximum);
132
+ }
133
+
134
+ protected getSupportPoint(worldDirection: readonly number[]): Vector3 {
135
+ const matrix = this.matrix;
136
+ const localDirection = [
137
+ matrix[0] * worldDirection[0] + matrix[1] * worldDirection[1] + matrix[2] * worldDirection[2],
138
+ matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
139
+ matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
140
+ ];
141
+ return new Vector3(this.supportLocal(localDirection)).transform(this.matrix);
142
+ }
143
+ }
144
+
145
+ export function validateAffineMatrix(matrix: readonly number[]): void {
146
+ if (matrix.length !== 16 || matrix.some(value => !Number.isFinite(value))) {
147
+ throw new Error('Shape matrix must contain 16 finite values');
148
+ }
149
+ if (
150
+ Math.abs(matrix[3]) > 1e-12 ||
151
+ Math.abs(matrix[7]) > 1e-12 ||
152
+ Math.abs(matrix[11]) > 1e-12 ||
153
+ Math.abs(matrix[15] - 1) > 1e-12
154
+ ) {
155
+ throw new Error('Shape matrix must be affine');
156
+ }
157
+ if (Math.abs(new Matrix4().copy(matrix).determinant()) < 1e-15)
158
+ throw new Error('Shape matrix must be invertible');
159
+ }
160
+
161
+ export function solveQuadratic(a: number, b: number, c: number): number[] {
162
+ if (Math.abs(a) < 1e-15) return Math.abs(b) < 1e-15 ? [] : [-c / b];
163
+ const discriminant = b * b - 4 * a * c;
164
+ if (discriminant < 0) return [];
165
+ const root = Math.sqrt(Math.max(0, discriminant));
166
+ return [(-b - root) / (2 * a), (-b + root) / (2 * a)].sort((left, right) => left - right);
167
+ }
168
+
169
+ export function closestDistanceToSegment2D(
170
+ px: number,
171
+ py: number,
172
+ ax: number,
173
+ ay: number,
174
+ bx: number,
175
+ by: number
176
+ ): number {
177
+ const dx = bx - ax;
178
+ const dy = by - ay;
179
+ const denominator = dx * dx + dy * dy;
180
+ const t = denominator
181
+ ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator))
182
+ : 0;
183
+ return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
184
+ }
185
+
186
+ /** Distance in the radial/Y half-plane to a spherical profile arc selected by normal Y range. */
187
+ export function closestDistanceToCircleArc2D(
188
+ px: number,
189
+ py: number,
190
+ centerY: number,
191
+ radius: number,
192
+ minimumNormalY: number,
193
+ maximumNormalY: number
194
+ ): number {
195
+ if (radius === 0) return Math.hypot(px, py - centerY);
196
+ const dx = px;
197
+ const dy = py - centerY;
198
+ const length = Math.hypot(dx, dy);
199
+ const normalY = length ? dy / length : 0;
200
+ if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
201
+ return Math.abs(length - radius);
202
+ }
203
+ const minimumRadius = radius * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
204
+ const maximumRadius = radius * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
205
+ return Math.min(
206
+ Math.hypot(px - minimumRadius, py - (centerY + radius * minimumNormalY)),
207
+ Math.hypot(px - maximumRadius, py - (centerY + radius * maximumNormalY))
208
+ );
209
+ }
@@ -0,0 +1,78 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Vector3} from '@math.gl/core';
6
+ import type {CullingResult} from '../../constants';
7
+ import {ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection} from './implicit-shape';
8
+ import type {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';
9
+ import type {BoundingSphere} from '../bounding-volumes/bounding-sphere';
10
+ import type {Plane} from '../plane';
11
+
12
+ export type PlaneShapeProps = {sizeX?: number; sizeZ?: number; matrix?: readonly number[]};
13
+
14
+ /** Analytic glTF plane. The surface faces +Y and the negative-Y half-space is inside. */
15
+ export class PlaneShape extends ImplicitShapeBase {
16
+ readonly type = 'plane' as const;
17
+ readonly sizeX?: number;
18
+ readonly sizeZ?: number;
19
+ constructor(props: PlaneShapeProps = {}) {
20
+ super(props.matrix);
21
+ this.sizeX = props.sizeX;
22
+ this.sizeZ = props.sizeZ;
23
+ if (this.sizeX !== undefined && (!Number.isFinite(this.sizeX) || this.sizeX <= 0))
24
+ throw new Error('Plane sizeX must be greater than zero');
25
+ if (this.sizeZ !== undefined && (!Number.isFinite(this.sizeZ) || this.sizeZ <= 0))
26
+ throw new Error('Plane sizeZ must be greater than zero');
27
+ }
28
+ clone(): PlaneShape {
29
+ return new PlaneShape({sizeX: this.sizeX, sizeZ: this.sizeZ, matrix: this.matrix});
30
+ }
31
+ override equals(shape: ImplicitShape): boolean {
32
+ return (
33
+ shape instanceof PlaneShape &&
34
+ super.equals(shape) &&
35
+ this.sizeX === shape.sizeX &&
36
+ this.sizeZ === shape.sizeZ
37
+ );
38
+ }
39
+ containsLocalPoint(point: readonly number[]): boolean {
40
+ return point[1] <= 1e-12;
41
+ }
42
+ distanceToLocalPoint(point: readonly number[]): number {
43
+ return Math.max(0, point[1]);
44
+ }
45
+ supportLocal(): readonly number[] {
46
+ throw new Error('An unbounded plane half-space has no finite support point');
47
+ }
48
+ intersectLocalRay(
49
+ origin: readonly number[],
50
+ direction: readonly number[]
51
+ ): LocalRayIntersection | undefined {
52
+ if (Math.abs(direction[1]) < 1e-15) return undefined;
53
+ const distance = -origin[1] / direction[1];
54
+ if (distance < 0) return undefined;
55
+ const x = origin[0] + distance * direction[0];
56
+ const z = origin[2] + distance * direction[2];
57
+ if (this.sizeX !== undefined && Math.abs(x) > this.sizeX / 2 + 1e-12) return undefined;
58
+ if (this.sizeZ !== undefined && Math.abs(z) > this.sizeZ / 2 + 1e-12) return undefined;
59
+ return {distance, normal: [0, 1, 0]};
60
+ }
61
+ override intersectPlane(plane: Plane): CullingResult {
62
+ const boundaryPoint = new Vector3(0, 0, 0).transform(this.matrix);
63
+ const inverse = this.inverseMatrix;
64
+ const boundaryNormal = new Vector3(inverse[1], inverse[5], inverse[9]).normalize();
65
+ const alignment = boundaryNormal.dot(plane.normal);
66
+ if (Math.abs(Math.abs(alignment) - 1) > 1e-10) return 'intersecting';
67
+ const boundaryDistance = plane.getPointDistance(boundaryPoint);
68
+ if (alignment < 0 && boundaryDistance > 0) return 'inside';
69
+ if (alignment > 0 && boundaryDistance < 0) return 'outside';
70
+ return 'intersecting';
71
+ }
72
+ override getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined {
73
+ return undefined;
74
+ }
75
+ override getBoundingSphere(): BoundingSphere | undefined {
76
+ return undefined;
77
+ }
78
+ }
@@ -0,0 +1,60 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ ImplicitShapeBase,
7
+ solveQuadratic,
8
+ type ImplicitShape,
9
+ type LocalRayIntersection
10
+ } from './implicit-shape';
11
+
12
+ const EPSILON = 1e-6;
13
+
14
+ export type SphereShapeProps = {radius?: number; matrix?: readonly number[]};
15
+
16
+ /** Analytic glTF sphere shape. */
17
+ export class SphereShape extends ImplicitShapeBase {
18
+ readonly type = 'sphere' as const;
19
+ readonly radius: number;
20
+ constructor(props: SphereShapeProps = {}) {
21
+ super(props.matrix);
22
+ this.radius = props.radius ?? 0.5;
23
+ if (!Number.isFinite(this.radius) || this.radius <= 0)
24
+ throw new Error('Sphere radius must be greater than zero');
25
+ }
26
+ clone(): SphereShape {
27
+ return new SphereShape({radius: this.radius, matrix: this.matrix});
28
+ }
29
+ override equals(shape: ImplicitShape): boolean {
30
+ return shape instanceof SphereShape && super.equals(shape) && this.radius === shape.radius;
31
+ }
32
+ containsLocalPoint(point: readonly number[]): boolean {
33
+ return Math.hypot(...point) <= this.radius + EPSILON;
34
+ }
35
+ distanceToLocalPoint(point: readonly number[]): number {
36
+ return Math.max(0, Math.hypot(...point) - this.radius);
37
+ }
38
+ supportLocal(direction: readonly number[]): readonly number[] {
39
+ const length = Math.hypot(...direction);
40
+ return length ? direction.map(value => (value / length) * this.radius) : [this.radius, 0, 0];
41
+ }
42
+ intersectLocalRay(
43
+ origin: readonly number[],
44
+ direction: readonly number[]
45
+ ): LocalRayIntersection | undefined {
46
+ const roots = solveQuadratic(
47
+ dot(direction, direction),
48
+ 2 * dot(origin, direction),
49
+ dot(origin, origin) - this.radius * this.radius
50
+ );
51
+ const distance = roots.find(value => value >= 0);
52
+ if (distance === undefined) return undefined;
53
+ const point = origin.map((value, i) => value + distance * direction[i]);
54
+ return {distance, normal: point.map(value => value / this.radius)};
55
+ }
56
+ }
57
+
58
+ function dot(a: readonly number[], b: readonly number[]): number {
59
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
60
+ }
@@ -0,0 +1,165 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** A rectangle in a shared two-dimensional Euclidean coordinate space. */
6
+ export type OrientedBox2D = {
7
+ /** Two finite center coordinates; arrays, typed arrays and core vectors are accepted. */
8
+ readonly center: Readonly<ArrayLike<number>>;
9
+ /** Nonnegative half-width and half-height, in the center's coordinate units. */
10
+ readonly halfSize: Readonly<ArrayLike<number>>;
11
+ /** Nonzero finite width-axis direction. Its magnitude does not change the size. */
12
+ readonly direction: Readonly<ArrayLike<number>>;
13
+ };
14
+
15
+ /** Test closed rectangles using their four separating axes, without allocating query objects.
16
+ * Directions are normalized locally; the height axis is the perpendicular of the width axis.
17
+ * Points and line segments (zero half-sizes) are supported. Inputs are never modified.
18
+ * Subtracting centers before projection avoids projecting large translated corner coordinates.
19
+ * @param first First rectangle in the shared coordinate space.
20
+ * @param second Second rectangle in the shared coordinate space.
21
+ * @param epsilon Nonnegative finite separation allowance in coordinate units; default zero.
22
+ * Touching edges/vertices intersect. A gap no larger than epsilon on every tested axis also
23
+ * intersects; this is a SAT allowance, not a Euclidean-distance query.
24
+ * @throws RangeError For invalid vectors, sizes, directions or epsilon.
25
+ */
26
+ export function intersectOrientedBoxes2D(
27
+ first: OrientedBox2D,
28
+ second: OrientedBox2D,
29
+ epsilon = 0
30
+ ): boolean {
31
+ validateBox(first);
32
+ validateBox(second);
33
+ if (!Number.isFinite(epsilon) || epsilon < 0) {
34
+ throw new RangeError('Box separation allowance must be finite and nonnegative');
35
+ }
36
+
37
+ // Scale before normalizing so both huge and subnormal directions remain usable.
38
+ const firstDirectionScale = Math.max(Math.abs(first.direction[0]), Math.abs(first.direction[1]));
39
+ const secondDirectionScale = Math.max(
40
+ Math.abs(second.direction[0]),
41
+ Math.abs(second.direction[1])
42
+ );
43
+ const firstWidthX = first.direction[0] / firstDirectionScale;
44
+ const firstWidthY = first.direction[1] / firstDirectionScale;
45
+ const secondWidthX = second.direction[0] / secondDirectionScale;
46
+ const secondWidthY = second.direction[1] / secondDirectionScale;
47
+ const firstLength = Math.hypot(firstWidthX, firstWidthY);
48
+ const secondLength = Math.hypot(secondWidthX, secondWidthY);
49
+ const firstX = firstWidthX / firstLength;
50
+ const firstY = firstWidthY / firstLength;
51
+ const secondX = secondWidthX / secondLength;
52
+ const secondY = secondWidthY / secondLength;
53
+
54
+ // Clamp unit-axis dot products against rounding slightly above one.
55
+ const cosine = Math.min(1, Math.abs(firstX * secondX + firstY * secondY));
56
+ const sine = Math.min(1, Math.abs(firstX * secondY - firstY * secondX));
57
+ return (
58
+ overlapsOnAxis(
59
+ first,
60
+ second,
61
+ firstX,
62
+ firstY,
63
+ first.halfSize[0],
64
+ second.halfSize[0] * cosine,
65
+ second.halfSize[1] * sine,
66
+ epsilon
67
+ ) &&
68
+ overlapsOnAxis(
69
+ first,
70
+ second,
71
+ -firstY,
72
+ firstX,
73
+ first.halfSize[1],
74
+ second.halfSize[0] * sine,
75
+ second.halfSize[1] * cosine,
76
+ epsilon
77
+ ) &&
78
+ overlapsOnAxis(
79
+ first,
80
+ second,
81
+ secondX,
82
+ secondY,
83
+ second.halfSize[0],
84
+ first.halfSize[0] * cosine,
85
+ first.halfSize[1] * sine,
86
+ epsilon
87
+ ) &&
88
+ overlapsOnAxis(
89
+ first,
90
+ second,
91
+ -secondY,
92
+ secondX,
93
+ second.halfSize[1],
94
+ first.halfSize[0] * sine,
95
+ first.halfSize[1] * cosine,
96
+ epsilon
97
+ )
98
+ );
99
+ }
100
+
101
+ /** Scale each projection independently so an irrelevant huge extent cannot erase a small gap. */
102
+ function overlapsOnAxis(
103
+ first: OrientedBox2D,
104
+ second: OrientedBox2D,
105
+ axisX: number,
106
+ axisY: number,
107
+ ownRadius: number,
108
+ otherWidthRadius: number,
109
+ otherHeightRadius: number,
110
+ epsilon: number
111
+ ): boolean {
112
+ const displacementX = second.center[0] - first.center[0];
113
+ const displacementY = second.center[1] - first.center[1];
114
+ // Keep a representable center difference before multiplying. If subtraction overflows,
115
+ // project the finite centers first; a zero axis component then stays exactly zero.
116
+ const projectionX = Number.isFinite(displacementX)
117
+ ? displacementX * axisX
118
+ : second.center[0] * axisX - first.center[0] * axisX;
119
+ const projectionY = Number.isFinite(displacementY)
120
+ ? displacementY * axisY
121
+ : second.center[1] * axisY - first.center[1] * axisY;
122
+ const scale =
123
+ Math.max(
124
+ ownRadius,
125
+ otherWidthRadius,
126
+ otherHeightRadius,
127
+ epsilon,
128
+ Number.isFinite(projectionX)
129
+ ? Math.abs(projectionX)
130
+ : Math.max(Math.abs(first.center[0] * axisX), Math.abs(second.center[0] * axisX)),
131
+ Number.isFinite(projectionY)
132
+ ? Math.abs(projectionY)
133
+ : Math.max(Math.abs(first.center[1] * axisY), Math.abs(second.center[1] * axisY))
134
+ ) || 1;
135
+ const normalizedX = Number.isFinite(projectionX)
136
+ ? projectionX / scale
137
+ : (second.center[0] * axisX) / scale - (first.center[0] * axisX) / scale;
138
+ const normalizedY = Number.isFinite(projectionY)
139
+ ? projectionY / scale
140
+ : (second.center[1] * axisY) / scale - (first.center[1] * axisY) / scale;
141
+ return (
142
+ Math.abs(normalizedX + normalizedY) <=
143
+ ownRadius / scale + otherWidthRadius / scale + otherHeightRadius / scale + epsilon / scale
144
+ );
145
+ }
146
+
147
+ /** Validate structural boxes before entering the scalar query kernel. */
148
+ function validateBox(box: OrientedBox2D): void {
149
+ validateVector(box.center);
150
+ validateVector(box.halfSize);
151
+ validateVector(box.direction);
152
+ if (box.halfSize[0] < 0 || box.halfSize[1] < 0) {
153
+ throw new RangeError('Box half-sizes must be nonnegative');
154
+ }
155
+ if (box.direction[0] === 0 && box.direction[1] === 0) {
156
+ throw new RangeError('Box direction must be nonzero');
157
+ }
158
+ }
159
+
160
+ /** Require exactly two finite components, without copying the vector. */
161
+ function validateVector(vector: Readonly<ArrayLike<number>>): void {
162
+ if (vector.length !== 2 || !Number.isFinite(vector[0]) || !Number.isFinite(vector[1])) {
163
+ throw new RangeError('Box vectors must have exactly two finite components');
164
+ }
165
+ }