@math.gl/geometry 5.0.0-alpha.8 → 5.0.0-beta.1

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 (368) 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 +5867 -16
  153. package/dist/index.cjs.map +3 -3
  154. package/dist/index.d.ts +23 -0
  155. package/dist/index.d.ts.map +1 -1
  156. package/dist/index.js +13 -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 +627 -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 +68 -0
  221. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
  222. package/dist/polygon/subdivide-triangle-mesh.js +228 -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/compute-vertex-normals.d.ts +4 -0
  249. package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
  250. package/dist/utils/compute-vertex-normals.js +54 -0
  251. package/dist/utils/compute-vertex-normals.js.map +1 -0
  252. package/dist/utils/constants.d.ts +52 -0
  253. package/dist/utils/constants.d.ts.map +1 -0
  254. package/dist/utils/constants.js +39 -0
  255. package/dist/utils/constants.js.map +1 -0
  256. package/dist/utils/coordinates.d.ts +3 -0
  257. package/dist/utils/coordinates.d.ts.map +1 -0
  258. package/dist/utils/coordinates.js +8 -0
  259. package/dist/utils/coordinates.js.map +1 -0
  260. package/dist/utils/geometry.d.ts +20 -0
  261. package/dist/utils/geometry.d.ts.map +1 -0
  262. package/dist/utils/geometry.js +31 -0
  263. package/dist/utils/geometry.js.map +1 -0
  264. package/dist/utils/gl-type.d.ts +17 -0
  265. package/dist/utils/gl-type.d.ts.map +1 -0
  266. package/dist/utils/gl-type.js +69 -0
  267. package/dist/utils/gl-type.js.map +1 -0
  268. package/dist/utils/index.d.ts +18 -0
  269. package/dist/utils/index.d.ts.map +1 -0
  270. package/dist/utils/index.js +16 -0
  271. package/dist/utils/index.js.map +1 -0
  272. package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
  273. package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
  274. package/dist/utils/interpolate-packed-attributes.js +192 -0
  275. package/dist/utils/interpolate-packed-attributes.js.map +1 -0
  276. package/dist/utils/mesh-processing.d.ts +18 -0
  277. package/dist/utils/mesh-processing.d.ts.map +1 -0
  278. package/dist/utils/mesh-processing.js +300 -0
  279. package/dist/utils/mesh-processing.js.map +1 -0
  280. package/dist/utils/primitive-iterator.d.ts +21 -0
  281. package/dist/utils/primitive-iterator.d.ts.map +1 -0
  282. package/dist/utils/primitive-iterator.js +117 -0
  283. package/dist/utils/primitive-iterator.js.map +1 -0
  284. package/dist/utils/rgb565.d.ts +5 -0
  285. package/dist/utils/rgb565.d.ts.map +1 -0
  286. package/dist/utils/rgb565.js +24 -0
  287. package/dist/utils/rgb565.js.map +1 -0
  288. package/dist/utils/typed-array-utils.d.ts +3 -0
  289. package/dist/utils/typed-array-utils.d.ts.map +1 -0
  290. package/dist/utils/typed-array-utils.js +16 -0
  291. package/dist/utils/typed-array-utils.js.map +1 -0
  292. package/package.json +12 -4
  293. package/src/culling/constants.ts +6 -0
  294. package/src/culling/index.ts +55 -0
  295. package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
  296. package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
  297. package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
  298. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
  299. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +153 -0
  300. package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
  301. package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
  302. package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
  303. package/src/culling/lib/culling-volume.ts +163 -0
  304. package/src/culling/lib/perspective-frustum.ts +288 -0
  305. package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
  306. package/src/culling/lib/plane.ts +118 -0
  307. package/src/culling/lib/ray.ts +33 -0
  308. package/src/culling/lib/shapes/box-shape.ts +78 -0
  309. package/src/culling/lib/shapes/capsule-shape.ts +232 -0
  310. package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
  311. package/src/culling/lib/shapes/implicit-shape.ts +209 -0
  312. package/src/culling/lib/shapes/plane-shape.ts +78 -0
  313. package/src/culling/lib/shapes/sphere-shape.ts +60 -0
  314. package/src/culling/oriented-box-2d.ts +165 -0
  315. package/src/culling/queries.ts +332 -0
  316. package/src/curves/bezier-curves.ts +62 -0
  317. package/src/curves/catmull-rom-curve.ts +89 -0
  318. package/src/curves/curve-arc-length.ts +70 -0
  319. package/src/curves/curve.ts +96 -0
  320. package/src/curves/hermite-curve.ts +34 -0
  321. package/src/curves/index.ts +15 -0
  322. package/src/geometries/box-geometry.ts +1 -1
  323. package/src/geometries/capsule-geometry.ts +1 -1
  324. package/src/geometries/cylinder-geometry.ts +1 -1
  325. package/src/geometries/geometry-helpers.ts +1 -1
  326. package/src/geometries/ico-sphere-geometry.ts +1 -1
  327. package/src/geometries/plane-geometry.ts +1 -1
  328. package/src/geometries/primitive-mesh-builder.ts +84 -0
  329. package/src/geometries/prism-geometry.ts +57 -0
  330. package/src/geometries/ring-geometry.ts +102 -0
  331. package/src/geometries/sphere-geometry.ts +1 -1
  332. package/src/geometries/surface-of-revolution.ts +1 -1
  333. package/src/geometries/truncated-cone-geometry.ts +1 -1
  334. package/src/index.ts +175 -1
  335. package/src/lib/geometry-utils.ts +2 -2
  336. package/src/lib/geometry.ts +2 -2
  337. package/src/lib/hinge-tree.ts +170 -0
  338. package/src/parametric/lathe-geometry.ts +70 -0
  339. package/src/parametric/parametric-geometry.ts +118 -0
  340. package/src/parametric/torus-geometry.ts +118 -0
  341. package/src/parametric.ts +9 -0
  342. package/src/polygon/clip-triangle-mesh.ts +218 -0
  343. package/src/polygon/cut-by-grid.ts +313 -0
  344. package/src/polygon/cut-by-mercator-bounds.ts +204 -0
  345. package/src/polygon/earcut.ts +798 -0
  346. package/src/polygon/index.ts +42 -0
  347. package/src/polygon/lineclip.ts +218 -0
  348. package/src/polygon/polygon-utils.ts +273 -0
  349. package/src/polygon/polygon.ts +105 -0
  350. package/src/polygon/subdivide-polyline.ts +223 -0
  351. package/src/polygon/subdivide-triangle-mesh.ts +322 -0
  352. package/src/polygon/utils.ts +50 -0
  353. package/src/spatial-index/box-index.ts +452 -0
  354. package/src/spatial-index/index.ts +20 -0
  355. package/src/spatial-index/triangle-bvh.ts +345 -0
  356. package/src/utils/attribute-compression.ts +234 -0
  357. package/src/utils/attribute-iterator.ts +28 -0
  358. package/src/utils/compute-vertex-normals.ts +63 -0
  359. package/src/utils/constants.ts +42 -0
  360. package/src/utils/coordinates.ts +8 -0
  361. package/src/utils/geometry.ts +49 -0
  362. package/src/utils/gl-type.ts +87 -0
  363. package/src/utils/index.ts +55 -0
  364. package/src/utils/interpolate-packed-attributes.ts +284 -0
  365. package/src/utils/mesh-processing.ts +377 -0
  366. package/src/utils/primitive-iterator.ts +145 -0
  367. package/src/utils/rgb565.ts +26 -0
  368. package/src/utils/typed-array-utils.ts +16 -0
@@ -0,0 +1,452 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ intersectRayBounds,
7
+ normalizeQueryDirection,
8
+ validateQueryDistance,
9
+ validateQueryPoint,
10
+ type QueryPoint
11
+ } from '../culling/queries';
12
+
13
+ export type BoxIndexOptions = {
14
+ /** Flat [minX, minY, (minZ), maxX, maxY, (maxZ)] records, copied at construction. */
15
+ bounds: ArrayLike<number>;
16
+ dimension: 2 | 3;
17
+ leafSize?: number;
18
+ };
19
+ export type NearestIndexResult = {index: number; distance: number};
20
+ /** A work unit visits one BVH node or one leaf item, including its optional refinement. */
21
+ export type IndexQueryBudget = {maxWork?: number};
22
+ /** Incomplete results are provisional: null/empty does not establish absence. */
23
+ export type IndexQueryResult<T> = {result: T; complete: boolean; work: number};
24
+ export type SearchIndexOptions = IndexQueryBudget & {
25
+ filter?: (index: number) => boolean;
26
+ /** Maximum accepted rows retained; one further match establishes truncation. */
27
+ maxResults?: number;
28
+ };
29
+ export type NearestIndexOptions = {
30
+ maxDistance?: number;
31
+ filter?: (index: number) => boolean;
32
+ /** Exact geometry distance, at least its box distance apart from roundoff. Values are never clamped; null excludes it. */
33
+ distanceToItem?: (index: number) => number | null;
34
+ };
35
+
36
+ /** Constraints for the nearest accepted ray hit against indexed boxes or caller-owned geometry. */
37
+ export type RayIndexOptions = {
38
+ /** Inclusive Euclidean distance limit; defaults to Infinity. */
39
+ maxDistance?: number;
40
+ /** Exclude an original row before exact refinement. */
41
+ filter?: (index: number) => boolean;
42
+ /**
43
+ * Exact Euclidean hit distance, or null to reject the row.
44
+ * Must be at least its indexed-box entry distance, apart from floating-point roundoff;
45
+ * geometry must stay inside that box. Refined distances are never rounded or clamped.
46
+ * The second argument is the current accepted distance limit, initially maxDistance.
47
+ * Traversal order is unspecified; this is not an all-intersections callback.
48
+ */
49
+ intersectItem?: (index: number, maxDistance: number) => number | null;
50
+ };
51
+
52
+ /** Static median-split BVH. Results refer to original input rows, not tree order. */
53
+ export class BoxIndex {
54
+ readonly dimension: 2 | 3;
55
+ readonly size: number;
56
+ private readonly bounds: Float64Array;
57
+ private readonly nodeBounds: Float64Array;
58
+ private readonly children: Int32Array;
59
+ private readonly starts: Uint32Array;
60
+ private readonly counts: Uint32Array;
61
+ private readonly order: Uint32Array;
62
+
63
+ constructor(options: BoxIndexOptions) {
64
+ const {dimension, bounds, leafSize = 8} = options;
65
+ if (dimension !== 2 && dimension !== 3) throw new RangeError('Index dimension must be 2 or 3');
66
+ if (!Number.isSafeInteger(leafSize) || leafSize < 1)
67
+ throw new RangeError('leafSize must be positive');
68
+ if (bounds.length % (dimension * 2)) throw new RangeError('Incomplete bounds record');
69
+ this.dimension = dimension;
70
+ this.bounds = Float64Array.from(bounds);
71
+ this.size = bounds.length / (dimension * 2);
72
+ if (this.size > 0x7fffffff) throw new RangeError('Index exceeds 32-bit capacity');
73
+ const stride = dimension * 2;
74
+ for (let i = 0; i < this.size; i++)
75
+ this.validateBounds(
76
+ this.bounds.subarray(i * stride, i * stride + dimension),
77
+ this.bounds.subarray(i * stride + dimension, (i + 1) * stride)
78
+ );
79
+ const records: {bounds: number[]; left: number; right: number; start: number; count: number}[] =
80
+ [];
81
+ const ids = Array.from({length: this.size}, (_, i) => i);
82
+ const build = (start: number, end: number): number => {
83
+ const node = records.length;
84
+ const bound = [
85
+ ...new Array(dimension).fill(Infinity),
86
+ ...new Array(dimension).fill(-Infinity)
87
+ ];
88
+ for (let i = start; i < end; i++)
89
+ for (let axis = 0; axis < dimension; axis++) {
90
+ bound[axis] = Math.min(bound[axis], this.bounds[ids[i] * stride + axis]);
91
+ bound[axis + dimension] = Math.max(
92
+ bound[axis + dimension],
93
+ this.bounds[ids[i] * stride + axis + dimension]
94
+ );
95
+ }
96
+ const record = {bounds: bound, left: -1, right: -1, start, count: end - start};
97
+ records.push(record);
98
+ if (end - start > leafSize) {
99
+ let axis = 0;
100
+ for (let i = 1; i < dimension; i++) {
101
+ if (bound[i + dimension] - bound[i] > bound[axis + dimension] - bound[axis]) axis = i;
102
+ }
103
+ const center = (i: number): number =>
104
+ this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension] / 2;
105
+ const sorted = ids.slice(start, end).sort((a, b) => center(a) - center(b) || a - b);
106
+ for (let i = 0; i < sorted.length; i++) ids[start + i] = sorted[i];
107
+ const middle = Math.floor((start + end) / 2);
108
+ record.left = build(start, middle);
109
+ record.right = build(middle, end);
110
+ record.count = 0;
111
+ }
112
+ return node;
113
+ };
114
+ if (this.size) build(0, this.size);
115
+ this.nodeBounds = new Float64Array(records.length * stride);
116
+ this.children = new Int32Array(records.length * 2);
117
+ this.starts = new Uint32Array(records.length);
118
+ this.counts = new Uint32Array(records.length);
119
+ records.forEach((record, i) => {
120
+ this.nodeBounds.set(record.bounds, i * stride);
121
+ this.children.set([record.left, record.right], i * 2);
122
+ this.starts[i] = record.start;
123
+ this.counts[i] = record.count;
124
+ });
125
+ this.order = Uint32Array.from(ids);
126
+ }
127
+
128
+ /** Closed-box overlap, including boundary contact. Sorted by original row index. */
129
+ search(minimum: QueryPoint, maximum: QueryPoint): number[] {
130
+ return this.searchQuery(minimum, maximum).result;
131
+ }
132
+
133
+ /** Bounded closed-box overlap. Results are sorted even when incomplete. */
134
+ searchQuery(
135
+ minimum: QueryPoint,
136
+ maximum: QueryPoint,
137
+ options: SearchIndexOptions = {}
138
+ ): IndexQueryResult<number[]> {
139
+ this.validateBounds(minimum, maximum);
140
+ const budget = new QueryBudget(options.maxWork);
141
+ const maxResults = validateLimit(options.maxResults);
142
+ const result: number[] = [];
143
+ const overlaps = (bounds: Float64Array, index: number): boolean => {
144
+ const start = index * this.dimension * 2;
145
+ for (let i = 0; i < this.dimension; i++) {
146
+ if (bounds[start + i] > maximum[i] || bounds[start + i + this.dimension] < minimum[i])
147
+ return false;
148
+ }
149
+ return true;
150
+ };
151
+ const stack = this.size ? [0] : [];
152
+ let complete = true;
153
+ search: while (stack.length) {
154
+ if (!budget.consume()) {
155
+ complete = false;
156
+ break;
157
+ }
158
+ const node = stack.pop();
159
+ if (!overlaps(this.nodeBounds, node)) continue;
160
+ if (this.counts[node]) {
161
+ for (let i = this.starts[node]; i < this.starts[node] + this.counts[node]; i++) {
162
+ if (!budget.consume()) {
163
+ complete = false;
164
+ break search;
165
+ }
166
+ const index = this.order[i];
167
+ if (overlaps(this.bounds, index) && (!options.filter || options.filter(index))) {
168
+ if (result.length === maxResults) {
169
+ complete = false;
170
+ break search;
171
+ }
172
+ result.push(index);
173
+ }
174
+ }
175
+ } else stack.push(this.children[node * 2], this.children[node * 2 + 1]);
176
+ }
177
+ return {result: result.sort((a, b) => a - b), complete, work: budget.work};
178
+ }
179
+
180
+ /** Branch-and-bound nearest box, optionally refined against actual geometry. */
181
+ nearest(point: QueryPoint, options: NearestIndexOptions = {}): NearestIndexResult | null {
182
+ return this.nearestQuery(point, {...options, maxWork: Infinity}).result;
183
+ }
184
+
185
+ nearestQuery(
186
+ point: QueryPoint,
187
+ options: NearestIndexOptions & IndexQueryBudget = {}
188
+ ): IndexQueryResult<NearestIndexResult | null> {
189
+ return this.nearestBoxQuery(point, point, options);
190
+ }
191
+
192
+ /** Nearest indexed box to a filled query box, optionally refined to enclosed geometry. */
193
+ nearestBoxQuery(
194
+ minimum: QueryPoint,
195
+ maximum: QueryPoint,
196
+ options: NearestIndexOptions & IndexQueryBudget = {}
197
+ ): IndexQueryResult<NearestIndexResult | null> {
198
+ this.validateBounds(minimum, maximum);
199
+ const budget = new QueryBudget(options.maxWork);
200
+ let best = options.maxDistance ?? Infinity;
201
+ validateQueryDistance(best);
202
+ let result: NearestIndexResult | null = null;
203
+ const distance = (bounds: Float64Array, index: number): number => {
204
+ const start = index * this.dimension * 2;
205
+ let x = 0,
206
+ y = 0,
207
+ z = 0;
208
+ x = Math.max(bounds[start] - maximum[0], 0, minimum[0] - bounds[start + this.dimension]);
209
+ y = Math.max(
210
+ bounds[start + 1] - maximum[1],
211
+ 0,
212
+ minimum[1] - bounds[start + this.dimension + 1]
213
+ );
214
+ if (this.dimension === 3)
215
+ z = Math.max(bounds[start + 2] - maximum[2], 0, minimum[2] - bounds[start + 5]);
216
+ return Math.hypot(x, y, z);
217
+ };
218
+ const stack = this.size ? [0] : [];
219
+ let complete = true;
220
+ search: while (stack.length) {
221
+ if (!budget.consume()) {
222
+ complete = false;
223
+ break;
224
+ }
225
+ const node = stack.pop();
226
+ const nodeDistance = distance(this.nodeBounds, node);
227
+ if (nodeDistance > best + getDistanceTolerance(nodeDistance, best)) continue;
228
+ if (this.counts[node]) {
229
+ for (let i = this.starts[node]; i < this.starts[node] + this.counts[node]; i++) {
230
+ if (!budget.consume()) {
231
+ complete = false;
232
+ break search;
233
+ }
234
+ const index = this.order[i];
235
+ const lower = distance(this.bounds, index);
236
+ if (
237
+ lower > best + getDistanceTolerance(lower, best) ||
238
+ (options.filter && !options.filter(index))
239
+ )
240
+ continue;
241
+ const exact = options.distanceToItem ? options.distanceToItem(index) : lower;
242
+ if (exact === null) continue;
243
+ validateQueryDistance(exact);
244
+ if (
245
+ exact < lower &&
246
+ (!Number.isFinite(lower) || lower - exact > getDistanceTolerance(lower, exact))
247
+ )
248
+ throw new RangeError('Refinement distance cannot be below box distance');
249
+ if (
250
+ Number.isFinite(exact) &&
251
+ exact <= best &&
252
+ (!result || exact < best || index < result.index)
253
+ ) {
254
+ best = exact;
255
+ result = {index, distance: exact};
256
+ }
257
+ }
258
+ } else {
259
+ const a = this.children[node * 2],
260
+ b = this.children[node * 2 + 1];
261
+ if (distance(this.nodeBounds, a) < distance(this.nodeBounds, b)) stack.push(b, a);
262
+ else stack.push(a, b);
263
+ }
264
+ }
265
+ return {result, complete, work: budget.work};
266
+ }
267
+
268
+ /**
269
+ * Nearest accepted box/geometry hit without materializing and sorting all ray candidates.
270
+ * Rejected refinements do not clip the ray. Equal distances select the lowest original row.
271
+ */
272
+ intersectRay(
273
+ origin: QueryPoint,
274
+ direction: QueryPoint,
275
+ options: RayIndexOptions = {}
276
+ ): NearestIndexResult | null {
277
+ return this.intersectRayQuery(origin, direction, {...options, maxWork: Infinity}).result;
278
+ }
279
+
280
+ intersectRayQuery(
281
+ origin: QueryPoint,
282
+ direction: QueryPoint,
283
+ options: RayIndexOptions & IndexQueryBudget = {}
284
+ ): IndexQueryResult<NearestIndexResult | null> {
285
+ validateQueryPoint(origin, this.dimension);
286
+ const budget = new QueryBudget(options.maxWork);
287
+ const unit = normalizeQueryDirection(direction, this.dimension);
288
+ let best = options.maxDistance ?? Infinity;
289
+ validateQueryDistance(best);
290
+ let result: NearestIndexResult | null = null;
291
+ const getEntry = (bounds: Float64Array, index: number): number | null => {
292
+ const offset = index * this.dimension * 2;
293
+ return intersectRayBounds(
294
+ origin,
295
+ unit,
296
+ bounds.subarray(offset, offset + this.dimension),
297
+ bounds.subarray(offset + this.dimension, offset + this.dimension * 2),
298
+ best + getDistanceTolerance(best, best)
299
+ );
300
+ };
301
+ // Defer the root bounds test until its visit, including for a zero work budget.
302
+ const stack = this.size ? [{index: 0, distance: 0}] : [];
303
+ let complete = true;
304
+ search: while (stack.length) {
305
+ if (!budget.consume()) {
306
+ complete = false;
307
+ break;
308
+ }
309
+ const candidate = stack.pop();
310
+ if (!candidate || candidate.distance > best + getDistanceTolerance(candidate.distance, best))
311
+ continue;
312
+ const node = candidate.index;
313
+ if (node === 0 && getEntry(this.nodeBounds, node) === null) continue;
314
+ if (this.counts[node]) {
315
+ for (
316
+ let offset = this.starts[node];
317
+ offset < this.starts[node] + this.counts[node];
318
+ offset++
319
+ ) {
320
+ if (!budget.consume()) {
321
+ complete = false;
322
+ break search;
323
+ }
324
+ const index = this.order[offset];
325
+ const lower = getEntry(this.bounds, index);
326
+ if (lower === null || (options.filter && !options.filter(index))) continue;
327
+ const exact = options.intersectItem ? options.intersectItem(index, best) : lower;
328
+ if (exact === null) continue;
329
+ validateQueryDistance(exact);
330
+ if (
331
+ exact < lower &&
332
+ (!Number.isFinite(lower) || lower - exact > getDistanceTolerance(lower, exact))
333
+ )
334
+ throw new RangeError('Refinement distance cannot be below box entry');
335
+ if (
336
+ Number.isFinite(exact) &&
337
+ exact <= best &&
338
+ (!result || exact < best || index < result.index)
339
+ ) {
340
+ best = exact;
341
+ result = {index, distance: exact};
342
+ }
343
+ }
344
+ } else {
345
+ const first = this.children[node * 2],
346
+ second = this.children[node * 2 + 1];
347
+ const firstDistance = getEntry(this.nodeBounds, first),
348
+ secondDistance = getEntry(this.nodeBounds, second);
349
+ if (firstDistance !== null && secondDistance !== null) {
350
+ if (firstDistance <= secondDistance)
351
+ stack.push(
352
+ {index: second, distance: secondDistance},
353
+ {index: first, distance: firstDistance}
354
+ );
355
+ else
356
+ stack.push(
357
+ {index: first, distance: firstDistance},
358
+ {index: second, distance: secondDistance}
359
+ );
360
+ } else if (firstDistance !== null) stack.push({index: first, distance: firstDistance});
361
+ else if (secondDistance !== null) stack.push({index: second, distance: secondDistance});
362
+ }
363
+ }
364
+ return {result, complete, work: budget.work};
365
+ }
366
+
367
+ /** Broad-phase ray candidates, sorted by entry distance then original row index. */
368
+ searchRay(
369
+ origin: QueryPoint,
370
+ direction: QueryPoint,
371
+ maxDistance = Infinity
372
+ ): NearestIndexResult[] {
373
+ validateQueryPoint(origin, this.dimension);
374
+ const unit = normalizeQueryDirection(direction, this.dimension);
375
+ validateQueryDistance(maxDistance);
376
+ const entry = (bounds: Float64Array, index: number): number | null => {
377
+ const start = index * this.dimension * 2;
378
+ return intersectRayBounds(
379
+ origin,
380
+ unit,
381
+ bounds.subarray(start, start + this.dimension),
382
+ bounds.subarray(start + this.dimension, start + this.dimension * 2),
383
+ maxDistance
384
+ );
385
+ };
386
+ const result: NearestIndexResult[] = [];
387
+ const stack = this.size ? [0] : [];
388
+ while (stack.length) {
389
+ const node = stack.pop();
390
+ if (entry(this.nodeBounds, node) === null) continue;
391
+ if (this.counts[node]) {
392
+ for (let i = this.starts[node]; i < this.starts[node] + this.counts[node]; i++) {
393
+ const index = this.order[i],
394
+ distance = entry(this.bounds, index);
395
+ if (distance !== null) result.push({index, distance});
396
+ }
397
+ } else stack.push(this.children[node * 2], this.children[node * 2 + 1]);
398
+ }
399
+ return result.sort((a, b) => a.distance - b.distance || a.index - b.index);
400
+ }
401
+
402
+ private validateBounds(minimum: QueryPoint, maximum: QueryPoint): void {
403
+ validateQueryPoint(minimum, this.dimension);
404
+ validateQueryPoint(maximum, this.dimension);
405
+ for (let i = 0; i < this.dimension; i++) {
406
+ if (minimum[i] > maximum[i]) throw new RangeError('Bounds must be ordered');
407
+ }
408
+ }
409
+ }
410
+
411
+ /** Relative, unit-independent allowance for independently rounded slab and geometry kernels. */
412
+ function getDistanceTolerance(first: number, second: number): number {
413
+ return (
414
+ 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(first), Math.abs(second)))
415
+ );
416
+ }
417
+
418
+ function validateLimit(value = Infinity): number {
419
+ if (value !== Infinity && (!Number.isSafeInteger(value) || value < 0))
420
+ throw new RangeError('Query limits must be nonnegative safe integers or Infinity');
421
+ return value;
422
+ }
423
+
424
+ class QueryBudget {
425
+ work = 0;
426
+ private readonly maximum: number;
427
+ constructor(maximum?: number) {
428
+ this.maximum = validateLimit(maximum);
429
+ }
430
+ consume(): boolean {
431
+ if (this.work === this.maximum) return false;
432
+ this.work++;
433
+ return true;
434
+ }
435
+ }
436
+
437
+ /** Points are zero-volume boxes: nearest gives exact Euclidean point distance. */
438
+ export class PointIndex extends BoxIndex {
439
+ constructor(options: {positions: ArrayLike<number>; dimension: 2 | 3; leafSize?: number}) {
440
+ const {positions, dimension, leafSize} = options;
441
+ if ((dimension !== 2 && dimension !== 3) || positions.length % dimension) {
442
+ throw new RangeError('Invalid point layout');
443
+ }
444
+ const bounds = new Float64Array(positions.length * 2);
445
+ for (let i = 0; i < positions.length / dimension; i++)
446
+ for (let axis = 0; axis < dimension; axis++) {
447
+ bounds[i * dimension * 2 + axis] = bounds[i * dimension * 2 + axis + dimension] =
448
+ positions[i * dimension + axis];
449
+ }
450
+ super({bounds, dimension, leafSize});
451
+ }
452
+ }
@@ -0,0 +1,20 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export {BoxIndex, PointIndex} from './box-index';
6
+ export type {
7
+ BoxIndexOptions,
8
+ NearestIndexOptions,
9
+ NearestIndexResult,
10
+ RayIndexOptions
11
+ } from './box-index';
12
+ export type {IndexQueryBudget, IndexQueryResult, SearchIndexOptions} from './box-index';
13
+ export {TriangleBVH} from './triangle-bvh';
14
+ export type {
15
+ TriangleBVHOptions,
16
+ TriangleQueryResult,
17
+ TriangleRayResult,
18
+ TriangleRayOptions
19
+ } from './triangle-bvh';
20
+ export type {TriangleNearestOptions, TriangleSegmentResult} from './triangle-bvh';