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

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 (457) hide show
  1. package/LICENSE +97 -49
  2. package/README.md +77 -1
  3. package/THIRD-PARTY-NOTICES.md +18 -0
  4. package/dist/color/color-lut-types.d.ts +16 -0
  5. package/dist/color/color-lut-types.d.ts.map +1 -0
  6. package/dist/color/color-lut-types.js +5 -0
  7. package/dist/color/color-lut-types.js.map +1 -0
  8. package/dist/color/index.cjs +132 -0
  9. package/dist/color/index.cjs.map +6 -0
  10. package/dist/color/index.d.ts +4 -0
  11. package/dist/color/index.d.ts.map +1 -0
  12. package/dist/color/index.js +5 -0
  13. package/dist/color/index.js.map +1 -0
  14. package/dist/color/sample-lut.d.ts +13 -0
  15. package/dist/color/sample-lut.d.ts.map +1 -0
  16. package/dist/color/sample-lut.js +132 -0
  17. package/dist/color/sample-lut.js.map +1 -0
  18. package/dist/culling/bounds.d.ts +20 -0
  19. package/dist/culling/bounds.d.ts.map +1 -0
  20. package/dist/culling/bounds.js +121 -0
  21. package/dist/culling/bounds.js.map +1 -0
  22. package/dist/culling/constants.d.ts +3 -0
  23. package/dist/culling/constants.d.ts.map +1 -0
  24. package/dist/culling/constants.js +5 -0
  25. package/dist/culling/constants.js.map +1 -0
  26. package/dist/culling/frustum-planes.d.ts +5 -0
  27. package/dist/culling/frustum-planes.d.ts.map +1 -0
  28. package/dist/culling/frustum-planes.js +37 -0
  29. package/dist/culling/frustum-planes.js.map +1 -0
  30. package/dist/culling/geometric-queries.d.ts +34 -0
  31. package/dist/culling/geometric-queries.d.ts.map +1 -0
  32. package/dist/culling/geometric-queries.js +208 -0
  33. package/dist/culling/geometric-queries.js.map +1 -0
  34. package/dist/culling/index.cjs +2560 -0
  35. package/dist/culling/index.cjs.map +6 -0
  36. package/dist/culling/index.d.ts +37 -0
  37. package/dist/culling/index.d.ts.map +1 -0
  38. package/dist/culling/index.js +29 -0
  39. package/dist/culling/index.js.map +1 -0
  40. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
  41. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
  42. package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
  43. package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
  44. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
  45. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
  46. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
  47. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
  48. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
  49. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
  50. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
  51. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
  52. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
  53. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
  54. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
  55. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
  56. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
  57. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
  58. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +133 -0
  59. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
  60. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
  61. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
  62. package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
  63. package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
  64. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
  65. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
  66. package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
  67. package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
  68. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
  69. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
  70. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
  71. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
  72. package/dist/culling/lib/culling-volume.d.ts +49 -0
  73. package/dist/culling/lib/culling-volume.d.ts.map +1 -0
  74. package/dist/culling/lib/culling-volume.js +133 -0
  75. package/dist/culling/lib/culling-volume.js.map +1 -0
  76. package/dist/culling/lib/perspective-frustum.d.ts +153 -0
  77. package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
  78. package/dist/culling/lib/perspective-frustum.js +191 -0
  79. package/dist/culling/lib/perspective-frustum.js.map +1 -0
  80. package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
  81. package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
  82. package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
  83. package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
  84. package/dist/culling/lib/plane.d.ts +35 -0
  85. package/dist/culling/lib/plane.d.ts.map +1 -0
  86. package/dist/culling/lib/plane.js +90 -0
  87. package/dist/culling/lib/plane.js.map +1 -0
  88. package/dist/culling/lib/ray.d.ts +18 -0
  89. package/dist/culling/lib/ray.d.ts.map +1 -0
  90. package/dist/culling/lib/ray.js +51 -0
  91. package/dist/culling/lib/ray.js.map +1 -0
  92. package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
  93. package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
  94. package/dist/culling/lib/shapes/box-shape.js +69 -0
  95. package/dist/culling/lib/shapes/box-shape.js.map +1 -0
  96. package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
  97. package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
  98. package/dist/culling/lib/shapes/capsule-shape.js +151 -0
  99. package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
  100. package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
  101. package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
  102. package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
  103. package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
  104. package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
  105. package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
  106. package/dist/culling/lib/shapes/implicit-shape.js +142 -0
  107. package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
  108. package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
  109. package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
  110. package/dist/culling/lib/shapes/plane-shape.js +71 -0
  111. package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
  112. package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
  113. package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
  114. package/dist/culling/lib/shapes/sphere-shape.js +43 -0
  115. package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
  116. package/dist/culling/oriented-box-2d.d.ts +22 -0
  117. package/dist/culling/oriented-box-2d.d.ts.map +1 -0
  118. package/dist/culling/oriented-box-2d.js +86 -0
  119. package/dist/culling/oriented-box-2d.js.map +1 -0
  120. package/dist/culling/queries.d.ts +44 -0
  121. package/dist/culling/queries.d.ts.map +1 -0
  122. package/dist/culling/queries.js +259 -0
  123. package/dist/culling/queries.js.map +1 -0
  124. package/dist/culling/screen-ray.d.ts +22 -0
  125. package/dist/culling/screen-ray.d.ts.map +1 -0
  126. package/dist/culling/screen-ray.js +55 -0
  127. package/dist/culling/screen-ray.js.map +1 -0
  128. package/dist/curves/adaptive-sampling.d.ts +16 -0
  129. package/dist/curves/adaptive-sampling.d.ts.map +1 -0
  130. package/dist/curves/adaptive-sampling.js +59 -0
  131. package/dist/curves/adaptive-sampling.js.map +1 -0
  132. package/dist/curves/bezier-curves.d.ts +18 -0
  133. package/dist/curves/bezier-curves.d.ts.map +1 -0
  134. package/dist/curves/bezier-curves.js +54 -0
  135. package/dist/curves/bezier-curves.js.map +1 -0
  136. package/dist/curves/catmull-rom-curve.d.ts +15 -0
  137. package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
  138. package/dist/curves/catmull-rom-curve.js +77 -0
  139. package/dist/curves/catmull-rom-curve.js.map +1 -0
  140. package/dist/curves/curve-arc-length.d.ts +17 -0
  141. package/dist/curves/curve-arc-length.d.ts.map +1 -0
  142. package/dist/curves/curve-arc-length.js +58 -0
  143. package/dist/curves/curve-arc-length.js.map +1 -0
  144. package/dist/curves/curve.d.ts +23 -0
  145. package/dist/curves/curve.d.ts.map +1 -0
  146. package/dist/curves/curve.js +77 -0
  147. package/dist/curves/curve.js.map +1 -0
  148. package/dist/curves/hermite-curve.d.ts +9 -0
  149. package/dist/curves/hermite-curve.d.ts.map +1 -0
  150. package/dist/curves/hermite-curve.js +24 -0
  151. package/dist/curves/hermite-curve.js.map +1 -0
  152. package/dist/curves/index.d.ts +12 -0
  153. package/dist/curves/index.d.ts.map +1 -0
  154. package/dist/curves/index.js +11 -0
  155. package/dist/curves/index.js.map +1 -0
  156. package/dist/curves/parallel-transport.d.ts +12 -0
  157. package/dist/curves/parallel-transport.d.ts.map +1 -0
  158. package/dist/curves/parallel-transport.js +83 -0
  159. package/dist/curves/parallel-transport.js.map +1 -0
  160. package/dist/geometries/box-geometry.js +1 -1
  161. package/dist/geometries/box-geometry.js.map +1 -1
  162. package/dist/geometries/capsule-geometry.js +1 -1
  163. package/dist/geometries/capsule-geometry.js.map +1 -1
  164. package/dist/geometries/cylinder-geometry.js +1 -1
  165. package/dist/geometries/cylinder-geometry.js.map +1 -1
  166. package/dist/geometries/geometry-helpers.js +1 -1
  167. package/dist/geometries/geometry-helpers.js.map +1 -1
  168. package/dist/geometries/ico-sphere-geometry.js +1 -1
  169. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  170. package/dist/geometries/plane-geometry.js +1 -1
  171. package/dist/geometries/plane-geometry.js.map +1 -1
  172. package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
  173. package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
  174. package/dist/geometries/primitive-mesh-builder.js +74 -0
  175. package/dist/geometries/primitive-mesh-builder.js.map +1 -0
  176. package/dist/geometries/prism-geometry.d.ts +13 -0
  177. package/dist/geometries/prism-geometry.d.ts.map +1 -0
  178. package/dist/geometries/prism-geometry.js +34 -0
  179. package/dist/geometries/prism-geometry.js.map +1 -0
  180. package/dist/geometries/ring-geometry.d.ts +15 -0
  181. package/dist/geometries/ring-geometry.d.ts.map +1 -0
  182. package/dist/geometries/ring-geometry.js +64 -0
  183. package/dist/geometries/ring-geometry.js.map +1 -0
  184. package/dist/geometries/sphere-geometry.js +1 -1
  185. package/dist/geometries/sphere-geometry.js.map +1 -1
  186. package/dist/geometries/surface-of-revolution.js +1 -1
  187. package/dist/geometries/surface-of-revolution.js.map +1 -1
  188. package/dist/geometries/truncated-cone-geometry.js +1 -1
  189. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  190. package/dist/index.cjs +6993 -37
  191. package/dist/index.cjs.map +3 -3
  192. package/dist/index.d.ts +35 -0
  193. package/dist/index.d.ts.map +1 -1
  194. package/dist/index.js +20 -1
  195. package/dist/index.js.map +1 -1
  196. package/dist/lib/geometry-utils.js +1 -1
  197. package/dist/lib/geometry-utils.js.map +1 -1
  198. package/dist/lib/geometry.d.ts +1 -1
  199. package/dist/lib/geometry.d.ts.map +1 -1
  200. package/dist/lib/geometry.js +1 -1
  201. package/dist/lib/geometry.js.map +1 -1
  202. package/dist/lib/hinge-tree.d.ts +33 -0
  203. package/dist/lib/hinge-tree.d.ts.map +1 -0
  204. package/dist/lib/hinge-tree.js +144 -0
  205. package/dist/lib/hinge-tree.js.map +1 -0
  206. package/dist/lighting/index.cjs +175 -0
  207. package/dist/lighting/index.cjs.map +6 -0
  208. package/dist/lighting/index.d.ts +4 -0
  209. package/dist/lighting/index.d.ts.map +1 -0
  210. package/dist/lighting/index.js +5 -0
  211. package/dist/lighting/index.js.map +1 -0
  212. package/dist/lighting/lighting-types.d.ts +16 -0
  213. package/dist/lighting/lighting-types.d.ts.map +1 -0
  214. package/dist/lighting/lighting-types.js +5 -0
  215. package/dist/lighting/lighting-types.js.map +1 -0
  216. package/dist/lighting/photometry.d.ts +36 -0
  217. package/dist/lighting/photometry.d.ts.map +1 -0
  218. package/dist/lighting/photometry.js +181 -0
  219. package/dist/lighting/photometry.js.map +1 -0
  220. package/dist/parametric/lathe-geometry.d.ts +14 -0
  221. package/dist/parametric/lathe-geometry.d.ts.map +1 -0
  222. package/dist/parametric/lathe-geometry.js +48 -0
  223. package/dist/parametric/lathe-geometry.js.map +1 -0
  224. package/dist/parametric/parametric-geometry.d.ts +20 -0
  225. package/dist/parametric/parametric-geometry.d.ts.map +1 -0
  226. package/dist/parametric/parametric-geometry.js +88 -0
  227. package/dist/parametric/parametric-geometry.js.map +1 -0
  228. package/dist/parametric/torus-geometry.d.ts +19 -0
  229. package/dist/parametric/torus-geometry.d.ts.map +1 -0
  230. package/dist/parametric/torus-geometry.js +89 -0
  231. package/dist/parametric/torus-geometry.js.map +1 -0
  232. package/dist/parametric.d.ts +7 -0
  233. package/dist/parametric.d.ts.map +1 -0
  234. package/dist/parametric.js +7 -0
  235. package/dist/parametric.js.map +1 -0
  236. package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
  237. package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
  238. package/dist/polygon/clip-triangle-mesh.js +155 -0
  239. package/dist/polygon/clip-triangle-mesh.js.map +1 -0
  240. package/dist/polygon/cut-by-grid.d.ts +24 -0
  241. package/dist/polygon/cut-by-grid.d.ts.map +1 -0
  242. package/dist/polygon/cut-by-grid.js +221 -0
  243. package/dist/polygon/cut-by-grid.js.map +1 -0
  244. package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
  245. package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
  246. package/dist/polygon/cut-by-mercator-bounds.js +149 -0
  247. package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
  248. package/dist/polygon/earcut.d.ts +13 -0
  249. package/dist/polygon/earcut.d.ts.map +1 -0
  250. package/dist/polygon/earcut.js +693 -0
  251. package/dist/polygon/earcut.js.map +1 -0
  252. package/dist/polygon/index.d.ts +16 -0
  253. package/dist/polygon/index.d.ts.map +1 -0
  254. package/dist/polygon/index.js +14 -0
  255. package/dist/polygon/index.js.map +1 -0
  256. package/dist/polygon/lineclip.d.ts +31 -0
  257. package/dist/polygon/lineclip.d.ts.map +1 -0
  258. package/dist/polygon/lineclip.js +184 -0
  259. package/dist/polygon/lineclip.js.map +1 -0
  260. package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
  261. package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
  262. package/dist/polygon/pole-of-inaccessibility.js +285 -0
  263. package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
  264. package/dist/polygon/polygon-utils.d.ts +103 -0
  265. package/dist/polygon/polygon-utils.d.ts.map +1 -0
  266. package/dist/polygon/polygon-utils.js +155 -0
  267. package/dist/polygon/polygon-utils.js.map +1 -0
  268. package/dist/polygon/polygon.d.ts +41 -0
  269. package/dist/polygon/polygon.d.ts.map +1 -0
  270. package/dist/polygon/polygon.js +76 -0
  271. package/dist/polygon/polygon.js.map +1 -0
  272. package/dist/polygon/subdivide-polyline.d.ts +56 -0
  273. package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
  274. package/dist/polygon/subdivide-polyline.js +141 -0
  275. package/dist/polygon/subdivide-polyline.js.map +1 -0
  276. package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
  277. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
  278. package/dist/polygon/subdivide-triangle-mesh.js +238 -0
  279. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
  280. package/dist/polygon/utils.d.ts +5 -0
  281. package/dist/polygon/utils.d.ts.map +1 -0
  282. package/dist/polygon/utils.js +38 -0
  283. package/dist/polygon/utils.js.map +1 -0
  284. package/dist/spatial-index/box-index.d.ts +86 -0
  285. package/dist/spatial-index/box-index.d.ts.map +1 -0
  286. package/dist/spatial-index/box-index.js +335 -0
  287. package/dist/spatial-index/box-index.js.map +1 -0
  288. package/dist/spatial-index/index.d.ts +7 -0
  289. package/dist/spatial-index/index.d.ts.map +1 -0
  290. package/dist/spatial-index/index.js +6 -0
  291. package/dist/spatial-index/index.js.map +1 -0
  292. package/dist/spatial-index/triangle-bvh.d.ts +74 -0
  293. package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
  294. package/dist/spatial-index/triangle-bvh.js +221 -0
  295. package/dist/spatial-index/triangle-bvh.js.map +1 -0
  296. package/dist/utils/attribute-compression.d.ts +50 -0
  297. package/dist/utils/attribute-compression.d.ts.map +1 -0
  298. package/dist/utils/attribute-compression.js +186 -0
  299. package/dist/utils/attribute-compression.js.map +1 -0
  300. package/dist/utils/attribute-iterator.d.ts +8 -0
  301. package/dist/utils/attribute-iterator.d.ts.map +1 -0
  302. package/dist/utils/attribute-iterator.js +25 -0
  303. package/dist/utils/attribute-iterator.js.map +1 -0
  304. package/dist/utils/compose-attribute-provenance.d.ts +13 -0
  305. package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
  306. package/dist/utils/compose-attribute-provenance.js +63 -0
  307. package/dist/utils/compose-attribute-provenance.js.map +1 -0
  308. package/dist/utils/compute-vertex-normals.d.ts +4 -0
  309. package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
  310. package/dist/utils/compute-vertex-normals.js +54 -0
  311. package/dist/utils/compute-vertex-normals.js.map +1 -0
  312. package/dist/utils/constants.d.ts +52 -0
  313. package/dist/utils/constants.d.ts.map +1 -0
  314. package/dist/utils/constants.js +39 -0
  315. package/dist/utils/constants.js.map +1 -0
  316. package/dist/utils/coordinates.d.ts +3 -0
  317. package/dist/utils/coordinates.d.ts.map +1 -0
  318. package/dist/utils/coordinates.js +8 -0
  319. package/dist/utils/coordinates.js.map +1 -0
  320. package/dist/utils/geometry.d.ts +20 -0
  321. package/dist/utils/geometry.d.ts.map +1 -0
  322. package/dist/utils/geometry.js +31 -0
  323. package/dist/utils/geometry.js.map +1 -0
  324. package/dist/utils/gl-type.d.ts +17 -0
  325. package/dist/utils/gl-type.d.ts.map +1 -0
  326. package/dist/utils/gl-type.js +69 -0
  327. package/dist/utils/gl-type.js.map +1 -0
  328. package/dist/utils/index.d.ts +18 -0
  329. package/dist/utils/index.d.ts.map +1 -0
  330. package/dist/utils/index.js +16 -0
  331. package/dist/utils/index.js.map +1 -0
  332. package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
  333. package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
  334. package/dist/utils/interpolate-packed-attributes.js +192 -0
  335. package/dist/utils/interpolate-packed-attributes.js.map +1 -0
  336. package/dist/utils/mesh-processing.d.ts +18 -0
  337. package/dist/utils/mesh-processing.d.ts.map +1 -0
  338. package/dist/utils/mesh-processing.js +300 -0
  339. package/dist/utils/mesh-processing.js.map +1 -0
  340. package/dist/utils/primitive-iterator.d.ts +21 -0
  341. package/dist/utils/primitive-iterator.d.ts.map +1 -0
  342. package/dist/utils/primitive-iterator.js +117 -0
  343. package/dist/utils/primitive-iterator.js.map +1 -0
  344. package/dist/utils/project-bounds.d.ts +44 -0
  345. package/dist/utils/project-bounds.d.ts.map +1 -0
  346. package/dist/utils/project-bounds.js +93 -0
  347. package/dist/utils/project-bounds.js.map +1 -0
  348. package/dist/utils/project-texture-coordinates.d.ts +19 -0
  349. package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
  350. package/dist/utils/project-texture-coordinates.js +49 -0
  351. package/dist/utils/project-texture-coordinates.js.map +1 -0
  352. package/dist/utils/qualify-surface-transition.d.ts +21 -0
  353. package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
  354. package/dist/utils/qualify-surface-transition.js +140 -0
  355. package/dist/utils/qualify-surface-transition.js.map +1 -0
  356. package/dist/utils/rgb565.d.ts +5 -0
  357. package/dist/utils/rgb565.d.ts.map +1 -0
  358. package/dist/utils/rgb565.js +24 -0
  359. package/dist/utils/rgb565.js.map +1 -0
  360. package/dist/utils/typed-array-utils.d.ts +3 -0
  361. package/dist/utils/typed-array-utils.d.ts.map +1 -0
  362. package/dist/utils/typed-array-utils.js +16 -0
  363. package/dist/utils/typed-array-utils.js.map +1 -0
  364. package/package.json +24 -4
  365. package/src/color/color-lut-types.ts +19 -0
  366. package/src/color/index.ts +6 -0
  367. package/src/color/sample-lut.ts +175 -0
  368. package/src/culling/bounds.ts +152 -0
  369. package/src/culling/constants.ts +6 -0
  370. package/src/culling/frustum-planes.ts +41 -0
  371. package/src/culling/geometric-queries.ts +299 -0
  372. package/src/culling/index.ts +93 -0
  373. package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
  374. package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
  375. package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
  376. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
  377. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +171 -0
  378. package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
  379. package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
  380. package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
  381. package/src/culling/lib/culling-volume.ts +171 -0
  382. package/src/culling/lib/perspective-frustum.ts +288 -0
  383. package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
  384. package/src/culling/lib/plane.ts +118 -0
  385. package/src/culling/lib/ray.ts +54 -0
  386. package/src/culling/lib/shapes/box-shape.ts +78 -0
  387. package/src/culling/lib/shapes/capsule-shape.ts +232 -0
  388. package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
  389. package/src/culling/lib/shapes/implicit-shape.ts +209 -0
  390. package/src/culling/lib/shapes/plane-shape.ts +78 -0
  391. package/src/culling/lib/shapes/sphere-shape.ts +60 -0
  392. package/src/culling/oriented-box-2d.ts +165 -0
  393. package/src/culling/queries.ts +332 -0
  394. package/src/culling/screen-ray.ts +75 -0
  395. package/src/curves/adaptive-sampling.ts +85 -0
  396. package/src/curves/bezier-curves.ts +62 -0
  397. package/src/curves/catmull-rom-curve.ts +89 -0
  398. package/src/curves/curve-arc-length.ts +70 -0
  399. package/src/curves/curve.ts +96 -0
  400. package/src/curves/hermite-curve.ts +34 -0
  401. package/src/curves/index.ts +19 -0
  402. package/src/curves/parallel-transport.ts +104 -0
  403. package/src/geometries/box-geometry.ts +1 -1
  404. package/src/geometries/capsule-geometry.ts +1 -1
  405. package/src/geometries/cylinder-geometry.ts +1 -1
  406. package/src/geometries/geometry-helpers.ts +1 -1
  407. package/src/geometries/ico-sphere-geometry.ts +1 -1
  408. package/src/geometries/plane-geometry.ts +1 -1
  409. package/src/geometries/primitive-mesh-builder.ts +84 -0
  410. package/src/geometries/prism-geometry.ts +57 -0
  411. package/src/geometries/ring-geometry.ts +102 -0
  412. package/src/geometries/sphere-geometry.ts +1 -1
  413. package/src/geometries/surface-of-revolution.ts +1 -1
  414. package/src/geometries/truncated-cone-geometry.ts +1 -1
  415. package/src/index.ts +226 -1
  416. package/src/lib/geometry-utils.ts +2 -2
  417. package/src/lib/geometry.ts +2 -2
  418. package/src/lib/hinge-tree.ts +170 -0
  419. package/src/lighting/index.ts +10 -0
  420. package/src/lighting/lighting-types.ts +20 -0
  421. package/src/lighting/photometry.ts +264 -0
  422. package/src/parametric/lathe-geometry.ts +70 -0
  423. package/src/parametric/parametric-geometry.ts +118 -0
  424. package/src/parametric/torus-geometry.ts +118 -0
  425. package/src/parametric.ts +9 -0
  426. package/src/polygon/clip-triangle-mesh.ts +218 -0
  427. package/src/polygon/cut-by-grid.ts +313 -0
  428. package/src/polygon/cut-by-mercator-bounds.ts +204 -0
  429. package/src/polygon/earcut.ts +859 -0
  430. package/src/polygon/index.ts +48 -0
  431. package/src/polygon/lineclip.ts +218 -0
  432. package/src/polygon/pole-of-inaccessibility.ts +330 -0
  433. package/src/polygon/polygon-utils.ts +273 -0
  434. package/src/polygon/polygon.ts +105 -0
  435. package/src/polygon/subdivide-polyline.ts +223 -0
  436. package/src/polygon/subdivide-triangle-mesh.ts +342 -0
  437. package/src/polygon/utils.ts +50 -0
  438. package/src/spatial-index/box-index.ts +452 -0
  439. package/src/spatial-index/index.ts +20 -0
  440. package/src/spatial-index/triangle-bvh.ts +345 -0
  441. package/src/utils/attribute-compression.ts +234 -0
  442. package/src/utils/attribute-iterator.ts +28 -0
  443. package/src/utils/compose-attribute-provenance.ts +74 -0
  444. package/src/utils/compute-vertex-normals.ts +63 -0
  445. package/src/utils/constants.ts +42 -0
  446. package/src/utils/coordinates.ts +8 -0
  447. package/src/utils/geometry.ts +49 -0
  448. package/src/utils/gl-type.ts +87 -0
  449. package/src/utils/index.ts +55 -0
  450. package/src/utils/interpolate-packed-attributes.ts +284 -0
  451. package/src/utils/mesh-processing.ts +377 -0
  452. package/src/utils/primitive-iterator.ts +145 -0
  453. package/src/utils/project-bounds.ts +154 -0
  454. package/src/utils/project-texture-coordinates.ts +67 -0
  455. package/src/utils/qualify-surface-transition.ts +169 -0
  456. package/src/utils/rgb565.ts +26 -0
  457. package/src/utils/typed-array-utils.ts +16 -0
@@ -0,0 +1,377 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Matrix4} from '@math.gl/core';
6
+ import type {TypedArray, TypedArrayConstructor} from '@math.gl/core';
7
+ import {GL} from './constants';
8
+ import {getAttributeValues, type Geometry, type GeometryAttribute} from './geometry';
9
+
10
+ type MeshData = {
11
+ attributes: Record<string, {value: TypedArray; size: number}>;
12
+ position: string;
13
+ count: number;
14
+ indices: Uint32Array;
15
+ };
16
+
17
+ /** Fresh, indexed triangle-list geometry. No input buffers are changed. */
18
+ export function transformGeometry(
19
+ geometry: Geometry,
20
+ matrix: Readonly<ArrayLike<number>>
21
+ ): Geometry {
22
+ const mesh = readMesh(geometry);
23
+ if (
24
+ matrix.length !== 16 ||
25
+ Array.from(matrix).some(v => !Number.isFinite(v)) ||
26
+ matrix[3] !== 0 ||
27
+ matrix[7] !== 0 ||
28
+ matrix[11] !== 0 ||
29
+ matrix[15] !== 1
30
+ ) {
31
+ throw new RangeError('Transform must be a finite affine column-major matrix');
32
+ }
33
+ const transform = new Matrix4(Array.from(matrix));
34
+ // Factor out independent column scales before testing orientation/invertibility.
35
+ // A raw determinant can underflow or overflow for finite invertible matrices.
36
+ const columns = [0, 4, 8].map(offset => Array.from(matrix).slice(offset, offset + 3));
37
+ const scales = columns.map(column => Math.max(...column.map(Math.abs)));
38
+ const basis = columns.map((column, i) => column.map(v => (scales[i] ? v / scales[i] : 0)));
39
+ const cofactors = [
40
+ cross(basis[1], basis[2]),
41
+ cross(basis[2], basis[0]),
42
+ cross(basis[0], basis[1])
43
+ ];
44
+ const determinant = basis[0].reduce((sum, v, i) => sum + v * cofactors[0][i], 0);
45
+ const attributes = copyAttributes(mesh.attributes);
46
+ const normalName = attributes['NORMAL'] ? 'NORMAL' : attributes['normals'] ? 'normals' : null;
47
+ const tangentName = attributes['TANGENT'] ? 'TANGENT' : null;
48
+ if ((normalName || tangentName) && (!Number.isFinite(determinant) || determinant === 0))
49
+ throw new RangeError('Normals and tangents require an invertible transform');
50
+ const positions = new Float64Array(mesh.count * 3);
51
+ const source = mesh.attributes[mesh.position].value;
52
+ for (let i = 0; i < mesh.count; i++) {
53
+ const point = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
54
+ positions.set(point, i * 3);
55
+ }
56
+ attributes[mesh.position] = {size: 3, value: positions};
57
+ if (normalName) {
58
+ const input = mesh.attributes[normalName];
59
+ if (input.size !== 3) throw new RangeError('Normals must have size 3');
60
+ const output = new Float64Array(mesh.count * 3);
61
+ for (let i = 0; i < mesh.count; i++) {
62
+ const value = normalizedLinearCombination(
63
+ cofactors,
64
+ Array.from(input.value.slice(i * 3, i * 3 + 3)),
65
+ scales.map(v => -Math.log(v))
66
+ );
67
+ output.set(
68
+ value.map(v => (determinant < 0 ? -v : v)),
69
+ i * 3
70
+ );
71
+ }
72
+ attributes[normalName] = {size: 3, value: output};
73
+ }
74
+ if (tangentName) {
75
+ const input = mesh.attributes[tangentName];
76
+ if (input.size !== 4) throw new RangeError('Tangents must have size 4');
77
+ const output = new Float64Array(mesh.count * 4);
78
+ for (let i = 0; i < mesh.count; i++) {
79
+ const value = normalizedLinearCombination(
80
+ basis,
81
+ Array.from(input.value.slice(i * 4, i * 4 + 3)),
82
+ scales.map(Math.log)
83
+ );
84
+ if (normalName) {
85
+ const n = attributes[normalName].value.slice(i * 3, i * 3 + 3);
86
+ const projection = value[0] * n[0] + value[1] * n[1] + value[2] * n[2];
87
+ for (let axis = 0; axis < 3; axis++) value[axis] -= projection * n[axis];
88
+ }
89
+ const length = Math.hypot(...value);
90
+ output.set(
91
+ value.map(v => (length ? v / length : 0)),
92
+ i * 4
93
+ );
94
+ output[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
95
+ }
96
+ attributes[tangentName] = {size: 4, value: output};
97
+ }
98
+ const indices = mesh.indices.slice();
99
+ if (determinant < 0)
100
+ for (let i = 0; i < indices.length; i += 3)
101
+ [indices[i + 1], indices[i + 2]] = [indices[i + 2], indices[i + 1]];
102
+ return {mode: GL.TRIANGLES, attributes, indices};
103
+ }
104
+
105
+ /** Concatenates compatible triangle meshes and offsets vertex indices. */
106
+ export function mergeGeometries(geometries: readonly Geometry[]): Geometry {
107
+ if (!geometries.length) throw new RangeError('At least one geometry is required');
108
+ const meshes = geometries.map(readMesh),
109
+ first = meshes[0],
110
+ names = Object.keys(first.attributes).sort();
111
+ let count = 0,
112
+ indexCount = 0;
113
+ for (const mesh of meshes) {
114
+ if (
115
+ mesh.position !== first.position ||
116
+ Object.keys(mesh.attributes).length !== names.length ||
117
+ names.some(name => !Object.prototype.hasOwnProperty.call(mesh.attributes, name))
118
+ )
119
+ throw new RangeError('Attribute names must match');
120
+ for (const name of names) {
121
+ if (
122
+ mesh.attributes[name].size !== first.attributes[name].size ||
123
+ mesh.attributes[name].value.constructor !== first.attributes[name].value.constructor
124
+ ) {
125
+ throw new RangeError('Attribute sizes and storage types must match');
126
+ }
127
+ }
128
+ count += mesh.count;
129
+ indexCount += mesh.indices.length;
130
+ }
131
+ if (count > 0xffffffff) throw new RangeError('Geometry exceeds 32-bit indexing');
132
+ const attributes: Record<string, GeometryAttribute> = {};
133
+ for (const name of names) {
134
+ const attribute = first.attributes[name],
135
+ Constructor = attribute.value.constructor as TypedArrayConstructor;
136
+ const value = new Constructor(count * attribute.size);
137
+ let offset = 0;
138
+ for (const mesh of meshes) {
139
+ value.set(mesh.attributes[name].value, offset);
140
+ offset += mesh.attributes[name].value.length;
141
+ }
142
+ attributes[name] = {size: attribute.size, value};
143
+ }
144
+ const indices = new Uint32Array(indexCount);
145
+ let vertexOffset = 0,
146
+ indexOffset = 0;
147
+ for (const mesh of meshes) {
148
+ for (const index of mesh.indices) indices[indexOffset++] = index + vertexOffset;
149
+ vertexOffset += mesh.count;
150
+ }
151
+ return {mode: GL.TRIANGLES, attributes, indices};
152
+ }
153
+
154
+ export type WeldGeometryOptions = {
155
+ /** Position quantization step; zero means exact matching. */ positionGridSize?: number;
156
+ };
157
+ export type WeldGeometryResult = {
158
+ geometry: Geometry;
159
+ vertexMap: Uint32Array;
160
+ removedVertices: number;
161
+ };
162
+
163
+ /** Welds full attribute tuples, preserving UV seams and hard normal edges. */
164
+ export function weldGeometry(
165
+ geometry: Geometry,
166
+ options: WeldGeometryOptions = {}
167
+ ): WeldGeometryResult {
168
+ const mesh = readMesh(geometry),
169
+ grid = options.positionGridSize ?? 0;
170
+ if (!Number.isFinite(grid) || grid < 0)
171
+ throw new RangeError('positionGridSize must be finite and nonnegative');
172
+ const names = Object.keys(mesh.attributes).sort(),
173
+ keys = new Map<string, number>(),
174
+ rows: number[] = [],
175
+ vertexMap = new Uint32Array(mesh.count);
176
+ for (let i = 0; i < mesh.count; i++) {
177
+ const tuple: number[] = [];
178
+ for (const name of names) {
179
+ const attribute = mesh.attributes[name];
180
+ for (let component = 0; component < attribute.size; component++) {
181
+ const value = attribute.value[i * attribute.size + component];
182
+ const quantized = name === mesh.position && grid ? Math.round(value / grid) : value;
183
+ if (!Number.isFinite(quantized)) throw new RangeError('Position quantization overflow');
184
+ tuple.push(quantized);
185
+ }
186
+ }
187
+ const key = tuple.join(',');
188
+ let row = keys.get(key);
189
+ if (row === undefined) {
190
+ row = rows.length;
191
+ keys.set(key, row);
192
+ rows.push(i);
193
+ }
194
+ vertexMap[i] = row;
195
+ }
196
+ const attributes: Record<string, GeometryAttribute> = {};
197
+ for (const name of names) {
198
+ const attribute = mesh.attributes[name],
199
+ Constructor = attribute.value.constructor as TypedArrayConstructor;
200
+ const value = new Constructor(rows.length * attribute.size);
201
+ rows.forEach((row, i) =>
202
+ value.set(
203
+ attribute.value.subarray(row * attribute.size, (row + 1) * attribute.size),
204
+ i * attribute.size
205
+ )
206
+ );
207
+ attributes[name] = {size: attribute.size, value};
208
+ }
209
+ return {
210
+ geometry: {
211
+ mode: GL.TRIANGLES,
212
+ attributes,
213
+ indices: Uint32Array.from(mesh.indices, index => vertexMap[index])
214
+ },
215
+ vertexMap,
216
+ removedVertices: mesh.count - rows.length
217
+ };
218
+ }
219
+
220
+ /** Returns triangle numbers with area <= areaEpsilon, in original draw order. */
221
+ export function getDegenerateTriangles(geometry: Geometry, areaEpsilon = 0): Uint32Array {
222
+ if (!Number.isFinite(areaEpsilon) || areaEpsilon < 0)
223
+ throw new RangeError('Area epsilon must be finite and nonnegative');
224
+ const mesh = readMesh(geometry),
225
+ positions = mesh.attributes[mesh.position].value,
226
+ result: number[] = [];
227
+ for (let i = 0; i < mesh.indices.length; i += 3) {
228
+ const [a, b, c] = Array.from(mesh.indices.subarray(i, i + 3), index => index * 3);
229
+ const ab = [
230
+ positions[b] - positions[a],
231
+ positions[b + 1] - positions[a + 1],
232
+ positions[b + 2] - positions[a + 2]
233
+ ];
234
+ const ac = [
235
+ positions[c] - positions[a],
236
+ positions[c + 1] - positions[a + 1],
237
+ positions[c + 2] - positions[a + 2]
238
+ ];
239
+ // Keep the common path in floating point, but use exact dyadic arithmetic
240
+ // when normalization loses a component or cannot distinguish collinearity.
241
+ const scaleAB = Math.max(...ab.map(Math.abs));
242
+ const scaleAC = Math.max(...ac.map(Math.abs));
243
+ const normalizedAB = ab.map(v => (scaleAB ? v / scaleAB : 0));
244
+ const normalizedAC = ac.map(v => (scaleAC ? v / scaleAC : 0));
245
+ const crossLength = Math.hypot(...cross(normalizedAB, normalizedAC));
246
+ const lostComponent = [ab, ac].some((edge, i) =>
247
+ edge.some((v, axis) => v !== 0 && (i ? normalizedAC : normalizedAB)[axis] === 0)
248
+ );
249
+ if (!Number.isFinite(crossLength) || crossLength === 0 || lostComponent) {
250
+ if (exactAreaAtMost(positions, a, b, c, areaEpsilon)) result.push(i / 3);
251
+ } else {
252
+ const logArea = Math.log(crossLength) + Math.log(scaleAB) + Math.log(scaleAC) - Math.log(2);
253
+ if (areaEpsilon > 0 && logArea <= Math.log(areaEpsilon)) result.push(i / 3);
254
+ }
255
+ }
256
+ return Uint32Array.from(result);
257
+ }
258
+
259
+ function readMesh(geometry: Geometry): MeshData {
260
+ if (geometry.mode !== GL.TRIANGLES)
261
+ throw new RangeError('Packed triangle-list geometry is required');
262
+ const position = geometry.attributes['POSITION']
263
+ ? 'POSITION'
264
+ : geometry.attributes['positions']
265
+ ? 'positions'
266
+ : null;
267
+ if (!position) throw new RangeError('POSITION or positions is required');
268
+ const attributes: MeshData['attributes'] = {};
269
+ let count: number;
270
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
271
+ const value = getAttributeValues(attribute),
272
+ size = attribute.size ?? (name === position ? 3 : undefined);
273
+ if (!Number.isSafeInteger(size) || size < 1 || value.length % size)
274
+ throw new RangeError('Attributes need explicit packed sizes');
275
+ const length = value.length / size;
276
+ if (name === position) {
277
+ if (size !== 3) throw new RangeError('Positions must have size 3');
278
+ count = length;
279
+ }
280
+ for (const component of value)
281
+ if (!Number.isFinite(component)) throw new RangeError('Attributes must be finite');
282
+ attributes[name] = {value, size};
283
+ }
284
+ for (const attribute of Object.values(attributes))
285
+ if (attribute.value.length / attribute.size !== count)
286
+ throw new RangeError('Attribute vertex counts must match');
287
+ if (count > 0xffffffff) throw new RangeError('Geometry exceeds 32-bit indexing');
288
+ const input = geometry.indices
289
+ ? getAttributeValues(geometry.indices)
290
+ : Uint32Array.from({length: count}, (_, i) => i);
291
+ if (input.length % 3) throw new RangeError('Indices must form triangles');
292
+ for (const index of input)
293
+ if (!Number.isSafeInteger(index) || index < 0 || index >= count)
294
+ throw new RangeError('Vertex index is out of bounds');
295
+ return {attributes, position, count, indices: Uint32Array.from(input)};
296
+ }
297
+ function copyAttributes(attributes: MeshData['attributes']): Record<string, GeometryAttribute> {
298
+ return Object.fromEntries(
299
+ Object.entries(attributes).map(([name, attribute]) => [
300
+ name,
301
+ {size: attribute.size, value: attribute.value.slice()}
302
+ ])
303
+ );
304
+ }
305
+
306
+ function cross(a: number[], b: number[]): number[] {
307
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
308
+ }
309
+
310
+ /** Direction-only multiplication, avoiding overflow in scale-weighted components. */
311
+ function normalizedLinearCombination(
312
+ columns: number[][],
313
+ vector: number[],
314
+ logScales: number[]
315
+ ): number[] {
316
+ const logs = vector.map((v, i) => (v ? Math.log(Math.abs(v)) + logScales[i] : -Infinity));
317
+ const largest = Math.max(...logs);
318
+ if (largest === -Infinity) return [0, 0, 0];
319
+ const weights = logs.map((v, i) => Math.sign(vector[i]) * Math.exp(v - largest));
320
+ const result = [0, 1, 2].map(axis =>
321
+ columns.reduce((sum, column, i) => sum + column[axis] * weights[i], 0)
322
+ );
323
+ const length = Math.hypot(...result);
324
+ return result.map(v => (length ? v / length : 0));
325
+ }
326
+
327
+ // Every finite binary64 value is an integer times a power of two. The fallback
328
+ // compares squared cross lengths to 4*epsilon² without floating-point products.
329
+ type Dyadic = {n: bigint; exponent: number};
330
+ function exactAreaAtMost(
331
+ positions: TypedArray,
332
+ a: number,
333
+ b: number,
334
+ c: number,
335
+ epsilon: number
336
+ ): boolean {
337
+ const edge = (end: number) =>
338
+ [0, 1, 2].map(axis =>
339
+ subtractDyadic(toDyadic(positions[end + axis]), toDyadic(positions[a + axis]))
340
+ );
341
+ const ab = edge(b),
342
+ ac = edge(c);
343
+ const components = [0, 1, 2].map(axis => {
344
+ const j = (axis + 1) % 3,
345
+ k = (axis + 2) % 3;
346
+ return subtractDyadic(multiplyDyadic(ab[j], ac[k]), multiplyDyadic(ab[k], ac[j]));
347
+ });
348
+ if (epsilon === 0) return components.every(v => v.n === 0n);
349
+ const squared = components.map(v => multiplyDyadic(v, v));
350
+ const sum = squared.reduce((total, v) => subtractDyadic(total, {...v, n: -v.n}), {
351
+ n: 0n,
352
+ exponent: 0
353
+ });
354
+ const threshold = multiplyDyadic(toDyadic(epsilon), toDyadic(epsilon));
355
+ threshold.exponent += 2;
356
+ return subtractDyadic(sum, threshold).n <= 0n;
357
+ }
358
+ function toDyadic(value: number): Dyadic {
359
+ const bits = new DataView(new ArrayBuffer(8));
360
+ bits.setFloat64(0, value);
361
+ const high = bits.getUint32(0),
362
+ low = bits.getUint32(4);
363
+ const exponentBits = (high >>> 20) & 0x7ff;
364
+ const fraction = (BigInt(high & 0xfffff) << 32n) | BigInt(low);
365
+ const n = exponentBits ? (1n << 52n) | fraction : fraction;
366
+ return {n: high >>> 31 ? -n : n, exponent: exponentBits ? exponentBits - 1075 : -1074};
367
+ }
368
+ function subtractDyadic(a: Dyadic, b: Dyadic): Dyadic {
369
+ const exponent = Math.min(a.exponent, b.exponent);
370
+ return {
371
+ n: (a.n << BigInt(a.exponent - exponent)) - (b.n << BigInt(b.exponent - exponent)),
372
+ exponent
373
+ };
374
+ }
375
+ function multiplyDyadic(a: Dyadic, b: Dyadic): Dyadic {
376
+ return {n: a.n * b.n, exponent: a.exponent + b.exponent};
377
+ }
@@ -0,0 +1,145 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {TypedArray} from '@math.gl/core';
6
+ import {GL} from './constants';
7
+ import type {Geometry} from './geometry';
8
+ import {getAttributeValues, getPositionAttribute, isGeometry} from './geometry';
9
+
10
+ /** One dereferenced point, line, or triangle primitive. */
11
+ export type Primitive = {
12
+ attributes: object;
13
+ type: number;
14
+ i1: number;
15
+ i2?: number;
16
+ i3?: number;
17
+ primitiveIndex: number;
18
+ };
19
+
20
+ /**
21
+ * Iterates through a geometry's primitives and dereferences optional indices.
22
+ *
23
+ * The legacy argument form `(indices, attributes, mode, start, end)` is also supported.
24
+ */
25
+ export function* makePrimitiveIterator(
26
+ geometryOrIndices?: Geometry | TypedArray | {value?: TypedArray; values?: TypedArray},
27
+ attributes: object = {},
28
+ mode?: number,
29
+ start = 0,
30
+ end?: number
31
+ ): Iterable<Primitive> {
32
+ let indices: TypedArray | undefined;
33
+ if (isGeometry(geometryOrIndices)) {
34
+ const geometry = geometryOrIndices;
35
+ indices = geometry.indices ? getAttributeValues(geometry.indices) : undefined;
36
+ attributes = geometry.attributes;
37
+ mode = geometry.mode;
38
+ if (end === undefined) {
39
+ const position = getPositionAttribute(geometry);
40
+ end = indices?.length ?? getAttributeValues(position).length / (position.size || 3);
41
+ }
42
+ } else if (geometryOrIndices) {
43
+ indices = getAttributeValues(geometryOrIndices);
44
+ }
45
+
46
+ if (mode === undefined) {
47
+ throw new Error('Primitive mode is required');
48
+ }
49
+ end ??= indices?.length ?? start;
50
+
51
+ const dereference = (index: number): number => Number(indices ? indices[index] : index);
52
+ let primitiveIndex = 0;
53
+
54
+ switch (mode) {
55
+ case GL.POINTS:
56
+ for (let index = start; index < end; index++) {
57
+ yield {
58
+ attributes,
59
+ type: GL.POINTS,
60
+ i1: dereference(index),
61
+ primitiveIndex: primitiveIndex++
62
+ };
63
+ }
64
+ return;
65
+
66
+ case GL.LINES:
67
+ for (let index = start; index + 1 < end; index += 2) {
68
+ yield {
69
+ attributes,
70
+ type: GL.LINES,
71
+ i1: dereference(index),
72
+ i2: dereference(index + 1),
73
+ primitiveIndex: primitiveIndex++
74
+ };
75
+ }
76
+ return;
77
+
78
+ case GL.LINE_STRIP:
79
+ for (let index = start; index + 1 < end; index++) {
80
+ yield {
81
+ attributes,
82
+ type: GL.LINES,
83
+ i1: dereference(index),
84
+ i2: dereference(index + 1),
85
+ primitiveIndex: primitiveIndex++
86
+ };
87
+ }
88
+ return;
89
+
90
+ case GL.LINE_LOOP:
91
+ for (let index = start; index < end; index++) {
92
+ yield {
93
+ attributes,
94
+ type: GL.LINES,
95
+ i1: dereference(index),
96
+ i2: dereference(index + 1 < end ? index + 1 : start),
97
+ primitiveIndex: primitiveIndex++
98
+ };
99
+ }
100
+ return;
101
+
102
+ case GL.TRIANGLES:
103
+ for (let index = start; index + 2 < end; index += 3) {
104
+ yield {
105
+ attributes,
106
+ type: GL.TRIANGLES,
107
+ i1: dereference(index),
108
+ i2: dereference(index + 1),
109
+ i3: dereference(index + 2),
110
+ primitiveIndex: primitiveIndex++
111
+ };
112
+ }
113
+ return;
114
+
115
+ case GL.TRIANGLE_STRIP:
116
+ for (let index = start; index + 2 < end; index++) {
117
+ const odd = (index - start) % 2 === 1;
118
+ yield {
119
+ attributes,
120
+ type: GL.TRIANGLES,
121
+ i1: dereference(odd ? index + 1 : index),
122
+ i2: dereference(odd ? index : index + 1),
123
+ i3: dereference(index + 2),
124
+ primitiveIndex: primitiveIndex++
125
+ };
126
+ }
127
+ return;
128
+
129
+ case GL.TRIANGLE_FAN:
130
+ for (let index = start + 1; index + 1 < end; index++) {
131
+ yield {
132
+ attributes,
133
+ type: GL.TRIANGLES,
134
+ i1: dereference(start),
135
+ i2: dereference(index),
136
+ i3: dereference(index + 1),
137
+ primitiveIndex: primitiveIndex++
138
+ };
139
+ }
140
+ return;
141
+
142
+ default:
143
+ throw new Error(`Unknown primitive mode ${mode}`);
144
+ }
145
+ }
@@ -0,0 +1,154 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** A finite, continuous source box with ordered minimum and maximum coordinates. */
6
+ export type ProjectionSourceBounds = readonly [ArrayLike<number>, ArrayLike<number>];
7
+
8
+ /** Controls bounded sampling of a prepared synchronous coordinate transform. */
9
+ export type ProjectBoundsOptions = {
10
+ /** Receives a fresh source array. Null/nonfinite output rejects the whole result.
11
+ * Exceptions propagate unchanged; no projection engine is imported by this helper.
12
+ */
13
+ transform: (position: readonly number[]) => ArrayLike<number> | null;
14
+ /** Output dimension, 2 or 3. Defaults to the source dimension. */
15
+ targetSize?: 2 | 3;
16
+ /** Equal subdivisions on each nonzero source axis. Positive integer; default 8. */
17
+ subdivisions?: number;
18
+ /** Maximum transform calls. Positive safe integer; default 262144. */
19
+ maxSamples?: number;
20
+ /** Optional caller-qualified global Lipschitz constant for EACH output component,
21
+ * measured against Euclidean source distance over the ENTIRE source box.
22
+ * Requires a finite continuous transform throughout the box, not merely at samples.
23
+ * This contract cannot be inferred or verified from point samples.
24
+ */
25
+ lipschitz?: readonly number[];
26
+ };
27
+
28
+ /** Detached bounds plus an explicit qualification; invalid results never expose partial bounds. */
29
+ export type ProjectedBoundsResult =
30
+ | {
31
+ /** 'sampled' is for approximate fitting only; 'conservative' requires the supplied contract. */
32
+ status: 'sampled' | 'conservative';
33
+ /** Output minimum and maximum vectors; safe for culling only in conservative mode. */
34
+ bounds: [number[], number[]];
35
+ /** Number of transform calls. */
36
+ sampleCount: number;
37
+ }
38
+ | {
39
+ /** A null/nonfinite transform sample or unrepresentable enclosure was encountered. */
40
+ status: 'invalid';
41
+ /** No partial result is safe to use. */
42
+ bounds: null;
43
+ /** Number of transform calls, including an invalid sample if applicable. */
44
+ sampleCount: number;
45
+ };
46
+
47
+ /** Projects a lattice covering corners, edges, faces and the interior of a 2D/3D box.
48
+ * Sampling alone cannot establish an enclosure for a nonlinear transform. When qualified
49
+ * global Lipschitz constants are supplied, inflate by the lattice covering radius instead
50
+ * of claiming corner/sample extrema are conservative. Split seams and domains beforehand.
51
+ */
52
+ export function projectBounds(
53
+ sourceBounds: ProjectionSourceBounds,
54
+ options: ProjectBoundsOptions
55
+ ): ProjectedBoundsResult {
56
+ const [minimum, maximum] = sourceBounds;
57
+ const size = minimum.length;
58
+ const {transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz} = options;
59
+ if (
60
+ (size !== 2 && size !== 3) ||
61
+ maximum.length !== size ||
62
+ (targetSize !== 2 && targetSize !== 3)
63
+ ) {
64
+ throw new RangeError('Bounds and target dimension must be 2 or 3');
65
+ }
66
+ if (
67
+ !Number.isSafeInteger(subdivisions) ||
68
+ subdivisions < 1 ||
69
+ !Number.isSafeInteger(maxSamples) ||
70
+ maxSamples < 1
71
+ ) {
72
+ throw new RangeError('Subdivision and sample budgets must be positive safe integers');
73
+ }
74
+ if (
75
+ lipschitz &&
76
+ (lipschitz.length !== targetSize ||
77
+ !Array.from(lipschitz).every(value => Number.isFinite(value) && value >= 0))
78
+ ) {
79
+ throw new RangeError('Lipschitz constants must be finite, nonnegative and match target size');
80
+ }
81
+ const widths: number[] = [];
82
+ const counts: number[] = [];
83
+ let count = 1;
84
+ for (let axis = 0; axis < size; axis++) {
85
+ const width = maximum[axis] - minimum[axis];
86
+ if (
87
+ !Number.isFinite(minimum[axis]) ||
88
+ !Number.isFinite(maximum[axis]) ||
89
+ !Number.isFinite(width) ||
90
+ width < 0
91
+ ) {
92
+ throw new RangeError('Source bounds must have finite ordered coordinates and extents');
93
+ }
94
+ widths.push(width);
95
+ counts.push(width === 0 ? 1 : subdivisions + 1);
96
+ count *= counts[axis];
97
+ if (!Number.isSafeInteger(count) || count > maxSamples) {
98
+ throw new RangeError('Projected bounds exceed the sample budget');
99
+ }
100
+ }
101
+ const lower = new Array<number>(targetSize).fill(Infinity);
102
+ const upper = new Array<number>(targetSize).fill(-Infinity);
103
+ for (let index = 0; index < count; index++) {
104
+ let remaining = index;
105
+ const source: number[] = [];
106
+ for (let axis = 0; axis < size; axis++) {
107
+ const step = remaining % counts[axis];
108
+ remaining = Math.floor(remaining / counts[axis]);
109
+ source.push(
110
+ step === 0
111
+ ? minimum[axis]
112
+ : step === subdivisions
113
+ ? maximum[axis]
114
+ : minimum[axis] + widths[axis] * (step / subdivisions)
115
+ );
116
+ }
117
+ const projected = transform(source);
118
+ if (!projected || projected.length < targetSize) {
119
+ return {status: 'invalid', bounds: null, sampleCount: index + 1};
120
+ }
121
+ for (let axis = 0; axis < targetSize; axis++) {
122
+ if (!Number.isFinite(projected[axis]))
123
+ return {status: 'invalid', bounds: null, sampleCount: index + 1};
124
+ lower[axis] = Math.min(lower[axis], projected[axis]);
125
+ upper[axis] = Math.max(upper[axis], projected[axis]);
126
+ }
127
+ }
128
+ if (lipschitz) {
129
+ const radius = Math.hypot(
130
+ ...widths.map(
131
+ (width, axis) =>
132
+ width / subdivisions / 2 +
133
+ 4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))
134
+ )
135
+ );
136
+ for (let axis = 0; axis < targetSize; axis++) {
137
+ const displacement = lipschitz[axis] * radius;
138
+ const roundoff =
139
+ 8 *
140
+ Number.EPSILON *
141
+ Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
142
+ lower[axis] -= displacement + roundoff;
143
+ upper[axis] += displacement + roundoff;
144
+ if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
145
+ return {status: 'invalid', bounds: null, sampleCount: count};
146
+ }
147
+ }
148
+ }
149
+ return {
150
+ status: lipschitz ? 'conservative' : 'sampled',
151
+ bounds: [lower, upper],
152
+ sampleCount: count
153
+ };
154
+ }