@math.gl/geospatial 5.0.0-rc.2 → 5.0.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 (356) hide show
  1. package/README.md +6 -6
  2. package/dist/coordinates.cjs +2523 -0
  3. package/dist/coordinates.cjs.map +6 -0
  4. package/dist/coordinates.d.ts +4 -0
  5. package/dist/coordinates.d.ts.map +1 -1
  6. package/dist/coordinates.js +2 -0
  7. package/dist/coordinates.js.map +1 -1
  8. package/dist/entries/ellipsoid.cjs +1209 -0
  9. package/dist/entries/ellipsoid.cjs.map +6 -0
  10. package/dist/entries/ellipsoid.d.ts +3 -19
  11. package/dist/entries/ellipsoid.d.ts.map +1 -1
  12. package/dist/entries/ellipsoid.js +1 -9
  13. package/dist/entries/ellipsoid.js.map +1 -1
  14. package/dist/expressions.cjs +726 -0
  15. package/dist/expressions.cjs.map +6 -0
  16. package/dist/geodesics.cjs +3195 -0
  17. package/dist/geodesics.cjs.map +6 -0
  18. package/dist/geodesics.d.ts +18 -0
  19. package/dist/geodesics.d.ts.map +1 -0
  20. package/dist/geodesics.js +13 -0
  21. package/dist/geodesics.js.map +1 -0
  22. package/dist/geographic-atlas/sampling.d.ts +1 -1
  23. package/dist/geographic-atlas/sampling.d.ts.map +1 -1
  24. package/dist/geographic-atlas/sampling.js +1 -1
  25. package/dist/geographic-atlas/sampling.js.map +1 -1
  26. package/dist/geographic-cuts.cjs +4160 -0
  27. package/dist/geographic-cuts.cjs.map +6 -0
  28. package/dist/geographic-cuts.d.ts +2 -0
  29. package/dist/geographic-cuts.d.ts.map +1 -1
  30. package/dist/geographic-cuts.js +1 -0
  31. package/dist/geographic-cuts.js.map +1 -1
  32. package/dist/geographic-seams/subdivide-cut.d.ts +1 -1
  33. package/dist/geographic-seams/subdivide-cut.d.ts.map +1 -1
  34. package/dist/geographic-seams/subdivide-cut.js +1 -1
  35. package/dist/geographic-seams/subdivide-cut.js.map +1 -1
  36. package/dist/geographic-seams/types.shared.cjs +32 -0
  37. package/dist/geographic-seams/types.shared.cjs.map +6 -0
  38. package/dist/globe.cjs +4223 -0
  39. package/dist/globe.cjs.map +6 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +2 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/line-simplification.d.ts +7 -0
  45. package/dist/line-simplification.d.ts.map +1 -1
  46. package/dist/line-simplification.js +4 -13
  47. package/dist/line-simplification.js.map +1 -1
  48. package/dist/linear-referencing.d.ts +13 -1
  49. package/dist/linear-referencing.d.ts.map +1 -1
  50. package/dist/linear-referencing.js +29 -9
  51. package/dist/linear-referencing.js.map +1 -1
  52. package/dist/maps/map-transition.shared.cjs +364 -0
  53. package/dist/maps/map-transition.shared.cjs.map +6 -0
  54. package/dist/maps/myriahedral/unfold.d.ts +1 -1
  55. package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
  56. package/dist/maps/myriahedral/unfold.js +1 -1
  57. package/dist/maps/myriahedral/unfold.js.map +1 -1
  58. package/dist/maps/presets.cjs +2 -2
  59. package/dist/maps/presets.cjs.map +2 -2
  60. package/dist/maps/transitions.cjs +3 -342
  61. package/dist/maps/transitions.cjs.map +3 -3
  62. package/dist/maps.cjs +15 -319
  63. package/dist/maps.cjs.map +3 -3
  64. package/dist/measure-referencing.d.ts +16 -0
  65. package/dist/measure-referencing.d.ts.map +1 -0
  66. package/dist/measure-referencing.js +143 -0
  67. package/dist/measure-referencing.js.map +1 -0
  68. package/dist/polygon-simplification.d.ts +6 -0
  69. package/dist/polygon-simplification.d.ts.map +1 -0
  70. package/dist/polygon-simplification.js +141 -0
  71. package/dist/polygon-simplification.js.map +1 -0
  72. package/dist/projection/experimental/core.cjs +63 -1317
  73. package/dist/projection/experimental/core.cjs.map +3 -3
  74. package/dist/projection/experimental/core.d.ts +1 -1
  75. package/dist/projection/experimental/core.d.ts.map +1 -1
  76. package/dist/projection/experimental/crs/projjson.cjs +26 -45
  77. package/dist/projection/experimental/crs/projjson.cjs.map +3 -3
  78. package/dist/projection/experimental/crs/types.shared.cjs +44 -0
  79. package/dist/projection/experimental/crs/types.shared.cjs.map +6 -0
  80. package/dist/projection/experimental/crs/wkt.cjs +36 -52
  81. package/dist/projection/experimental/crs/wkt.cjs.map +3 -3
  82. package/dist/projection/experimental/entries/projections/ob_tran.cjs +9 -23
  83. package/dist/projection/experimental/entries/projections/ob_tran.cjs.map +3 -3
  84. package/dist/projection/experimental/lazy-projections/aea.cjs +1 -1
  85. package/dist/projection/experimental/lazy-projections/aea.js +1 -1
  86. package/dist/projection/experimental/lazy-projections/aeqd.cjs +1 -1
  87. package/dist/projection/experimental/lazy-projections/aeqd.js +1 -1
  88. package/dist/projection/experimental/lazy-projections/bonne.cjs +1 -1
  89. package/dist/projection/experimental/lazy-projections/bonne.js +1 -1
  90. package/dist/projection/experimental/lazy-projections/cass.cjs +1 -1
  91. package/dist/projection/experimental/lazy-projections/cass.js +1 -1
  92. package/dist/projection/experimental/lazy-projections/cea.cjs +1 -1
  93. package/dist/projection/experimental/lazy-projections/cea.js +1 -1
  94. package/dist/projection/experimental/lazy-projections/eck6.cjs +1 -1
  95. package/dist/projection/experimental/lazy-projections/eck6.js +1 -1
  96. package/dist/projection/experimental/lazy-projections/eqc.cjs +1 -1
  97. package/dist/projection/experimental/lazy-projections/eqc.js +1 -1
  98. package/dist/projection/experimental/lazy-projections/eqdc.cjs +1 -1
  99. package/dist/projection/experimental/lazy-projections/eqdc.js +1 -1
  100. package/dist/projection/experimental/lazy-projections/eqearth.cjs +1 -1
  101. package/dist/projection/experimental/lazy-projections/eqearth.js +1 -1
  102. package/dist/projection/experimental/lazy-projections/equi.cjs +1 -1
  103. package/dist/projection/experimental/lazy-projections/equi.js +1 -1
  104. package/dist/projection/experimental/lazy-projections/etmerc.cjs +1 -1
  105. package/dist/projection/experimental/lazy-projections/etmerc.js +1 -1
  106. package/dist/projection/experimental/lazy-projections/geocent.cjs +1 -1
  107. package/dist/projection/experimental/lazy-projections/geocent.js +1 -1
  108. package/dist/projection/experimental/lazy-projections/geos.cjs +1 -1
  109. package/dist/projection/experimental/lazy-projections/geos.js +1 -1
  110. package/dist/projection/experimental/lazy-projections/gnom.cjs +1 -1
  111. package/dist/projection/experimental/lazy-projections/gnom.js +1 -1
  112. package/dist/projection/experimental/lazy-projections/gstmerc.cjs +1 -1
  113. package/dist/projection/experimental/lazy-projections/gstmerc.js +1 -1
  114. package/dist/projection/experimental/lazy-projections/index.cjs +60 -903
  115. package/dist/projection/experimental/lazy-projections/index.cjs.map +3 -3
  116. package/dist/projection/experimental/lazy-projections/krovak.cjs +1 -1
  117. package/dist/projection/experimental/lazy-projections/krovak.js +1 -1
  118. package/dist/projection/experimental/lazy-projections/laea.cjs +1 -1
  119. package/dist/projection/experimental/lazy-projections/laea.js +1 -1
  120. package/dist/projection/experimental/lazy-projections/lcc.cjs +1 -1
  121. package/dist/projection/experimental/lazy-projections/lcc.js +1 -1
  122. package/dist/projection/experimental/lazy-projections/merc.cjs +1 -1
  123. package/dist/projection/experimental/lazy-projections/merc.js +1 -1
  124. package/dist/projection/experimental/lazy-projections/mill.cjs +1 -1
  125. package/dist/projection/experimental/lazy-projections/mill.js +1 -1
  126. package/dist/projection/experimental/lazy-projections/moll.cjs +1 -1
  127. package/dist/projection/experimental/lazy-projections/moll.js +1 -1
  128. package/dist/projection/experimental/lazy-projections/nzmg.cjs +1 -1
  129. package/dist/projection/experimental/lazy-projections/nzmg.js +1 -1
  130. package/dist/projection/experimental/lazy-projections/ob_tran.cjs +1 -1
  131. package/dist/projection/experimental/lazy-projections/ob_tran.js +1 -1
  132. package/dist/projection/experimental/lazy-projections/omerc.cjs +1 -1
  133. package/dist/projection/experimental/lazy-projections/omerc.js +1 -1
  134. package/dist/projection/experimental/lazy-projections/ortho.cjs +1 -1
  135. package/dist/projection/experimental/lazy-projections/ortho.js +1 -1
  136. package/dist/projection/experimental/lazy-projections/poly.cjs +1 -1
  137. package/dist/projection/experimental/lazy-projections/poly.js +1 -1
  138. package/dist/projection/experimental/lazy-projections/qsc.cjs +1 -1
  139. package/dist/projection/experimental/lazy-projections/qsc.js +1 -1
  140. package/dist/projection/experimental/lazy-projections/robin.cjs +1 -1
  141. package/dist/projection/experimental/lazy-projections/robin.js +1 -1
  142. package/dist/projection/experimental/lazy-projections/sinu.cjs +1 -1
  143. package/dist/projection/experimental/lazy-projections/sinu.js +1 -1
  144. package/dist/projection/experimental/lazy-projections/somerc.cjs +1 -1
  145. package/dist/projection/experimental/lazy-projections/somerc.js +1 -1
  146. package/dist/projection/experimental/lazy-projections/stere.cjs +1 -1
  147. package/dist/projection/experimental/lazy-projections/stere.js +1 -1
  148. package/dist/projection/experimental/lazy-projections/sterea.cjs +1 -1
  149. package/dist/projection/experimental/lazy-projections/sterea.js +1 -1
  150. package/dist/projection/experimental/lazy-projections/tmerc.cjs +1 -1
  151. package/dist/projection/experimental/lazy-projections/tmerc.js +1 -1
  152. package/dist/projection/experimental/lazy-projections/tpers.cjs +1 -1
  153. package/dist/projection/experimental/lazy-projections/tpers.js +1 -1
  154. package/dist/projection/experimental/lazy-projections/utm.cjs +1 -1
  155. package/dist/projection/experimental/lazy-projections/utm.js +1 -1
  156. package/dist/projection/experimental/lazy-projections/vandg.cjs +1 -1
  157. package/dist/projection/experimental/lazy-projections/vandg.js +1 -1
  158. package/dist/projection/experimental/projection-engine.shared.cjs +1184 -0
  159. package/dist/projection/experimental/projection-engine.shared.cjs.map +6 -0
  160. package/dist/projection/experimental/typescript-projection.shared.cjs +1703 -0
  161. package/dist/projection/experimental/typescript-projection.shared.cjs.map +6 -0
  162. package/dist/projection/index.cjs +622 -1535
  163. package/dist/projection/index.cjs.map +3 -3
  164. package/dist/projection/pipeline.cjs +44 -58
  165. package/dist/projection/pipeline.cjs.map +3 -3
  166. package/dist/projection/transform-analysis.cjs +20 -936
  167. package/dist/projection/transform-analysis.cjs.map +3 -3
  168. package/dist/spatial-box-clipping.d.ts +9 -0
  169. package/dist/spatial-box-clipping.d.ts.map +1 -0
  170. package/dist/spatial-box-clipping.js +123 -0
  171. package/dist/spatial-box-clipping.js.map +1 -0
  172. package/dist/spatial-dwithin.d.ts +19 -0
  173. package/dist/spatial-dwithin.d.ts.map +1 -0
  174. package/dist/spatial-dwithin.js +107 -0
  175. package/dist/spatial-dwithin.js.map +1 -0
  176. package/dist/spatial-hulls.d.ts +6 -0
  177. package/dist/spatial-hulls.d.ts.map +1 -0
  178. package/dist/spatial-hulls.js +176 -0
  179. package/dist/spatial-hulls.js.map +1 -0
  180. package/dist/spatial-line-intersection-result.d.ts +4 -0
  181. package/dist/spatial-line-intersection-result.d.ts.map +1 -0
  182. package/dist/spatial-line-intersection-result.js +79 -0
  183. package/dist/spatial-line-intersection-result.js.map +1 -0
  184. package/dist/spatial-line-polygon-intersection.d.ts +4 -0
  185. package/dist/spatial-line-polygon-intersection.d.ts.map +1 -0
  186. package/dist/spatial-line-polygon-intersection.js +130 -0
  187. package/dist/spatial-line-polygon-intersection.js.map +1 -0
  188. package/dist/spatial-planar-intersects.d.ts +11 -0
  189. package/dist/spatial-planar-intersects.d.ts.map +1 -1
  190. package/dist/spatial-planar-intersects.js +20 -12
  191. package/dist/spatial-planar-intersects.js.map +1 -1
  192. package/dist/spatial-planar.d.ts +9 -0
  193. package/dist/spatial-planar.d.ts.map +1 -1
  194. package/dist/spatial-planar.js +13 -1
  195. package/dist/spatial-planar.js.map +1 -1
  196. package/dist/spatial-polygon-overlay.d.ts +5 -0
  197. package/dist/spatial-polygon-overlay.d.ts.map +1 -0
  198. package/dist/spatial-polygon-overlay.js +23 -0
  199. package/dist/spatial-polygon-overlay.js.map +1 -0
  200. package/dist/spatial-sql.d.ts +13 -2
  201. package/dist/spatial-sql.d.ts.map +1 -1
  202. package/dist/spatial-sql.js +30 -12
  203. package/dist/spatial-sql.js.map +1 -1
  204. package/dist/spatial-subdivision.d.ts +9 -0
  205. package/dist/spatial-subdivision.d.ts.map +1 -0
  206. package/dist/spatial-subdivision.js +61 -0
  207. package/dist/spatial-subdivision.js.map +1 -0
  208. package/dist/spatial-touches.d.ts +13 -0
  209. package/dist/spatial-touches.d.ts.map +1 -0
  210. package/dist/spatial-touches.js +192 -0
  211. package/dist/spatial-touches.js.map +1 -0
  212. package/dist/st-functions.cjs +2411 -112
  213. package/dist/st-functions.cjs.map +3 -3
  214. package/dist/st-functions.d.ts +67 -2
  215. package/dist/st-functions.d.ts.map +1 -1
  216. package/dist/st-functions.js +195 -12
  217. package/dist/st-functions.js.map +1 -1
  218. package/dist/st-geodesic-functions.d.ts +33 -0
  219. package/dist/st-geodesic-functions.d.ts.map +1 -0
  220. package/dist/st-geodesic-functions.js +84 -0
  221. package/dist/st-geodesic-functions.js.map +1 -0
  222. package/dist/st-hull-functions.cjs +386 -0
  223. package/dist/st-hull-functions.cjs.map +6 -0
  224. package/dist/st-hull-functions.d.ts +17 -0
  225. package/dist/st-hull-functions.d.ts.map +1 -0
  226. package/dist/st-hull-functions.js +14 -0
  227. package/dist/st-hull-functions.js.map +1 -0
  228. package/dist/st-overlay-functions.cjs +621 -0
  229. package/dist/st-overlay-functions.cjs.map +6 -0
  230. package/dist/st-overlay-functions.d.ts +36 -0
  231. package/dist/st-overlay-functions.d.ts.map +1 -0
  232. package/dist/st-overlay-functions.js +183 -0
  233. package/dist/st-overlay-functions.js.map +1 -0
  234. package/dist/st-viewport-functions.cjs +481 -0
  235. package/dist/st-viewport-functions.cjs.map +6 -0
  236. package/dist/st-viewport-functions.d.ts +13 -0
  237. package/dist/st-viewport-functions.d.ts.map +1 -0
  238. package/dist/st-viewport-functions.js +81 -0
  239. package/dist/st-viewport-functions.js.map +1 -0
  240. package/dist/subdivide-geodesic-polyline.d.ts +1 -1
  241. package/dist/subdivide-geodesic-polyline.d.ts.map +1 -1
  242. package/dist/subdivide-geodesic-polyline.js +1 -1
  243. package/dist/subdivide-geodesic-polyline.js.map +1 -1
  244. package/dist/subdivide-globe-mesh.d.ts +1 -1
  245. package/dist/subdivide-globe-mesh.d.ts.map +1 -1
  246. package/dist/subdivide-globe-mesh.js +1 -1
  247. package/dist/subdivide-globe-mesh.js.map +1 -1
  248. package/dist/subdivide-rhumb-polyline.d.ts +1 -1
  249. package/dist/subdivide-rhumb-polyline.d.ts.map +1 -1
  250. package/dist/subdivide-rhumb-polyline.js +1 -1
  251. package/dist/subdivide-rhumb-polyline.js.map +1 -1
  252. package/dist/tasks/index.cjs +808 -2993
  253. package/dist/tasks/index.cjs.map +3 -3
  254. package/dist/terrain/geometry.d.ts +1 -1
  255. package/dist/terrain/geometry.d.ts.map +1 -1
  256. package/dist/terrain/geometry.js +1 -1
  257. package/dist/terrain/geometry.js.map +1 -1
  258. package/dist/terrain/index.cjs +95 -22
  259. package/dist/terrain/index.cjs.map +3 -3
  260. package/dist/terrain/index.d.ts +1 -0
  261. package/dist/terrain/index.d.ts.map +1 -1
  262. package/dist/terrain/index.js +1 -0
  263. package/dist/terrain/index.js.map +1 -1
  264. package/dist/terrain/regional-watersheds.d.ts +44 -0
  265. package/dist/terrain/regional-watersheds.d.ts.map +1 -0
  266. package/dist/terrain/regional-watersheds.js +108 -0
  267. package/dist/terrain/regional-watersheds.js.map +1 -0
  268. package/dist/terrain/tile-cutout-update.d.ts.map +1 -1
  269. package/dist/terrain/tile-cutout-update.js +28 -22
  270. package/dist/terrain/tile-cutout-update.js.map +1 -1
  271. package/dist/tiles.cjs +354 -0
  272. package/dist/tiles.cjs.map +6 -0
  273. package/dist/turf-functions.cjs +16 -9
  274. package/dist/turf-functions.cjs.map +1 -1
  275. package/package.json +154 -117
  276. package/src/coordinates.ts +5 -0
  277. package/src/entries/ellipsoid.ts +7 -32
  278. package/src/geodesics.ts +40 -0
  279. package/src/geographic-atlas/sampling.ts +1 -1
  280. package/src/geographic-cuts.ts +21 -0
  281. package/src/geographic-seams/subdivide-cut.ts +1 -1
  282. package/src/index.ts +2 -0
  283. package/src/line-simplification.ts +4 -16
  284. package/src/linear-referencing.ts +44 -16
  285. package/src/maps/myriahedral/unfold.ts +1 -1
  286. package/src/measure-referencing.ts +165 -0
  287. package/src/polygon-simplification.ts +185 -0
  288. package/src/projection/experimental/core.ts +1 -1
  289. package/src/projection/experimental/lazy-projections/aea.ts +1 -1
  290. package/src/projection/experimental/lazy-projections/aeqd.ts +1 -1
  291. package/src/projection/experimental/lazy-projections/bonne.ts +1 -1
  292. package/src/projection/experimental/lazy-projections/cass.ts +1 -1
  293. package/src/projection/experimental/lazy-projections/cea.ts +1 -1
  294. package/src/projection/experimental/lazy-projections/eck6.ts +1 -1
  295. package/src/projection/experimental/lazy-projections/eqc.ts +1 -1
  296. package/src/projection/experimental/lazy-projections/eqdc.ts +1 -1
  297. package/src/projection/experimental/lazy-projections/eqearth.ts +1 -1
  298. package/src/projection/experimental/lazy-projections/equi.ts +1 -1
  299. package/src/projection/experimental/lazy-projections/etmerc.ts +1 -1
  300. package/src/projection/experimental/lazy-projections/geocent.ts +1 -1
  301. package/src/projection/experimental/lazy-projections/geos.ts +1 -1
  302. package/src/projection/experimental/lazy-projections/gnom.ts +1 -1
  303. package/src/projection/experimental/lazy-projections/gstmerc.ts +1 -1
  304. package/src/projection/experimental/lazy-projections/krovak.ts +1 -1
  305. package/src/projection/experimental/lazy-projections/laea.ts +1 -1
  306. package/src/projection/experimental/lazy-projections/lcc.ts +1 -1
  307. package/src/projection/experimental/lazy-projections/merc.ts +1 -1
  308. package/src/projection/experimental/lazy-projections/mill.ts +1 -1
  309. package/src/projection/experimental/lazy-projections/moll.ts +1 -1
  310. package/src/projection/experimental/lazy-projections/nzmg.ts +1 -1
  311. package/src/projection/experimental/lazy-projections/ob_tran.ts +1 -1
  312. package/src/projection/experimental/lazy-projections/omerc.ts +1 -1
  313. package/src/projection/experimental/lazy-projections/ortho.ts +1 -1
  314. package/src/projection/experimental/lazy-projections/poly.ts +1 -1
  315. package/src/projection/experimental/lazy-projections/qsc.ts +1 -1
  316. package/src/projection/experimental/lazy-projections/robin.ts +1 -1
  317. package/src/projection/experimental/lazy-projections/sinu.ts +1 -1
  318. package/src/projection/experimental/lazy-projections/somerc.ts +1 -1
  319. package/src/projection/experimental/lazy-projections/stere.ts +1 -1
  320. package/src/projection/experimental/lazy-projections/sterea.ts +1 -1
  321. package/src/projection/experimental/lazy-projections/tmerc.ts +1 -1
  322. package/src/projection/experimental/lazy-projections/tpers.ts +1 -1
  323. package/src/projection/experimental/lazy-projections/utm.ts +1 -1
  324. package/src/projection/experimental/lazy-projections/vandg.ts +1 -1
  325. package/src/spatial-box-clipping.ts +140 -0
  326. package/src/spatial-dwithin.ts +135 -0
  327. package/src/spatial-hulls.ts +203 -0
  328. package/src/spatial-line-intersection-result.ts +93 -0
  329. package/src/spatial-line-polygon-intersection.ts +147 -0
  330. package/src/spatial-planar-intersects.ts +21 -15
  331. package/src/spatial-planar.ts +20 -1
  332. package/src/spatial-polygon-overlay.ts +30 -0
  333. package/src/spatial-sql.ts +47 -12
  334. package/src/spatial-subdivision.ts +75 -0
  335. package/src/spatial-touches.ts +218 -0
  336. package/src/st-functions.ts +283 -15
  337. package/src/st-geodesic-functions.ts +121 -0
  338. package/src/st-hull-functions.ts +25 -0
  339. package/src/st-overlay-functions.ts +244 -0
  340. package/src/st-viewport-functions.ts +98 -0
  341. package/src/subdivide-geodesic-polyline.ts +2 -2
  342. package/src/subdivide-globe-mesh.ts +2 -2
  343. package/src/subdivide-rhumb-polyline.ts +2 -2
  344. package/src/terrain/geometry.ts +1 -1
  345. package/src/terrain/index.ts +7 -0
  346. package/src/terrain/regional-watersheds.ts +153 -0
  347. package/src/terrain/tile-cutout-update.ts +32 -26
  348. package/dist/index.cjs +0 -18674
  349. package/dist/index.cjs.map +0 -6
  350. package/dist/turf-expressions.cjs +0 -1997
  351. package/dist/turf-expressions.cjs.map +0 -6
  352. package/dist/turf-expressions.d.ts +0 -3
  353. package/dist/turf-expressions.d.ts.map +0 -1
  354. package/dist/turf-expressions.js +0 -7
  355. package/dist/turf-expressions.js.map +0 -1
  356. package/src/turf-expressions.ts +0 -7
@@ -8,5 +8,5 @@ export const lazyAzimuthalEquidistant: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'aeqd', aliases: ['Azimuthal_Equidistant']},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/aeqd')).azimuthalEquidistant
11
+ (await import('@math.gl/geospatial/projection-projections-aeqd')).azimuthalEquidistant
12
12
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyBonne: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'bonne', aliases: ['Bonne (Werner lat_1=90)']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/bonne');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-bonne');
11
11
  return projectionModule.bonne;
12
12
  }
13
13
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyCassiniSoldner: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'cass', aliases: ['Cassini', 'Cassini_Soldner']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/cass');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-cass');
11
11
  return projectionModule.cassiniSoldner;
12
12
  }
13
13
  );
@@ -8,5 +8,5 @@ export const lazyCylindricalEqualArea: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'cea', aliases: []},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/cea')).cylindricalEqualArea
11
+ (await import('@math.gl/geospatial/projection-projections-cea')).cylindricalEqualArea
12
12
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyEckertVI: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'eck6', aliases: ['Eckert_VI']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/eck6');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-eck6');
11
11
  return projectionModule.eckertVI;
12
12
  }
13
13
  );
@@ -11,5 +11,5 @@ export const lazyEquidistantCylindrical: ProjectionDescriptor =
11
11
  aliases: ['Equirectangular', 'Equidistant_Cylindrical', 'Equidistant_Cylindrical_Spherical']
12
12
  },
13
13
  async () =>
14
- (await import('@math.gl/geospatial/projection/projections/eqc')).equidistantCylindrical
14
+ (await import('@math.gl/geospatial/projection-projections-eqc')).equidistantCylindrical
15
15
  );
@@ -8,7 +8,7 @@ export const lazyEquidistantConic: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'eqdc', aliases: ['Equidistant_Conic']},
10
10
  async () => {
11
- const projectionModule = await import('@math.gl/geospatial/projection/projections/eqdc');
11
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-eqdc');
12
12
  return projectionModule.equidistantConic;
13
13
  }
14
14
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyEqualEarth: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'eqearth', aliases: ['Equal Earth', 'Equal_Earth']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/eqearth');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-eqearth');
11
11
  return projectionModule.equalEarth;
12
12
  }
13
13
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyEquirectangular: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'equi', aliases: []},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/equi');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-equi');
11
11
  return projectionModule.equirectangular;
12
12
  }
13
13
  );
@@ -8,5 +8,5 @@ export const lazyExtendedTransverseMercator: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'etmerc', aliases: ['Extended_Transverse_Mercator', 'Extended Transverse Mercator']},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/etmerc')).extendedTransverseMercator
11
+ (await import('@math.gl/geospatial/projection-projections-etmerc')).extendedTransverseMercator
12
12
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyGeocentric: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'geocent', aliases: ['Geocentric', 'geocentric', 'Geocent']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/geocent');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-geocent');
11
11
  return projectionModule.geocentric;
12
12
  }
13
13
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyGeostationary: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'geos', aliases: ['Geostationary Satellite View', 'Geostationary_Satellite']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/geos');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-geos');
11
11
  return projectionModule.geostationary;
12
12
  }
13
13
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyGnomonic: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'gnom', aliases: []},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/gnom');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-gnom');
11
11
  return projectionModule.gnomonic;
12
12
  }
13
13
  );
@@ -8,6 +8,6 @@ export const lazyGaussSchreiberTransverseMercator: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'gstmerc', aliases: ['gstmerg']},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/gstmerc'))
11
+ (await import('@math.gl/geospatial/projection-projections-gstmerc'))
12
12
  .gaussSchreiberTransverseMercator
13
13
  );
@@ -15,7 +15,7 @@ export const lazyKrovak: ProjectionDescriptor = /* @__PURE__ */ createProjection
15
15
  ]
16
16
  },
17
17
  async () => {
18
- const projectionModule = await import('@math.gl/geospatial/projection/projections/krovak');
18
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-krovak');
19
19
  return projectionModule.krovak;
20
20
  }
21
21
  );
@@ -8,5 +8,5 @@ export const lazyLambertAzimuthalEqualArea: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'laea', aliases: ['Lambert Azimuthal Equal Area', 'Lambert_Azimuthal_Equal_Area']},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/laea')).lambertAzimuthalEqualArea
11
+ (await import('@math.gl/geospatial/projection-projections-laea')).lambertAzimuthalEqualArea
12
12
  );
@@ -18,5 +18,5 @@ export const lazyLambertConformalConic: ProjectionDescriptor =
18
18
  ]
19
19
  },
20
20
  async () =>
21
- (await import('@math.gl/geospatial/projection/projections/lcc')).lambertConformalConic
21
+ (await import('@math.gl/geospatial/projection-projections-lcc')).lambertConformalConic
22
22
  );
@@ -16,7 +16,7 @@ export const lazyMercator: ProjectionDescriptor = /* @__PURE__ */ createProjecti
16
16
  ]
17
17
  },
18
18
  async () => {
19
- const projectionModule = await import('@math.gl/geospatial/projection/projections/merc');
19
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-merc');
20
20
  return projectionModule.mercator;
21
21
  }
22
22
  );
@@ -8,7 +8,7 @@ export const lazyMillerCylindrical: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'mill', aliases: ['Miller_Cylindrical']},
10
10
  async () => {
11
- const projectionModule = await import('@math.gl/geospatial/projection/projections/mill');
11
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-mill');
12
12
  return projectionModule.millerCylindrical;
13
13
  }
14
14
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyMollweide: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'moll', aliases: ['Mollweide']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/moll');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-moll');
11
11
  return projectionModule.mollweide;
12
12
  }
13
13
  );
@@ -8,7 +8,7 @@ export const lazyNewZealandMapGrid: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'nzmg', aliases: ['New_Zealand_Map_Grid']},
10
10
  async () => {
11
- const projectionModule = await import('@math.gl/geospatial/projection/projections/nzmg');
11
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-nzmg');
12
12
  return projectionModule.newZealandMapGrid;
13
13
  }
14
14
  );
@@ -16,7 +16,7 @@ export function lazyObliqueTransformation(
16
16
  },
17
17
  async () => {
18
18
  const [{obliqueTransformation}, child] = await Promise.all([
19
- import('@math.gl/geospatial/projection/projections/ob_tran'),
19
+ import('@math.gl/geospatial/projection-projections-ob_tran'),
20
20
  typeof wrapped === 'string' || 'create' in wrapped ? wrapped : wrapped.preload()
21
21
  ]);
22
22
  return obliqueTransformation(child);
@@ -19,7 +19,7 @@ export const lazyObliqueMercator: ProjectionDescriptor = /* @__PURE__ */ createP
19
19
  ]
20
20
  },
21
21
  async () => {
22
- const projectionModule = await import('@math.gl/geospatial/projection/projections/omerc');
22
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-omerc');
23
23
  return projectionModule.obliqueMercator;
24
24
  }
25
25
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyOrthographic: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'ortho', aliases: []},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/ortho');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-ortho');
11
11
  return projectionModule.orthographic;
12
12
  }
13
13
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyPolyconic: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'poly', aliases: ['Polyconic', 'American_Polyconic']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/poly');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-poly');
11
11
  return projectionModule.polyconic;
12
12
  }
13
13
  );
@@ -11,6 +11,6 @@ export const lazyQuadrilateralizedSphericalCube: ProjectionDescriptor =
11
11
  aliases: ['Quadrilateralized Spherical Cube', 'Quadrilateralized_Spherical_Cube']
12
12
  },
13
13
  async () =>
14
- (await import('@math.gl/geospatial/projection/projections/qsc'))
14
+ (await import('@math.gl/geospatial/projection-projections-qsc'))
15
15
  .quadrilateralizedSphericalCube
16
16
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyRobinson: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'robin', aliases: ['Robinson']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/robin');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-robin');
11
11
  return projectionModule.robinson;
12
12
  }
13
13
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazySinusoidal: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'sinu', aliases: ['Sinusoidal']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/sinu');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-sinu');
11
11
  return projectionModule.sinusoidal;
12
12
  }
13
13
  );
@@ -8,5 +8,5 @@ export const lazySwissObliqueMercator: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'somerc', aliases: []},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/somerc')).swissObliqueMercator
11
+ (await import('@math.gl/geospatial/projection-projections-somerc')).swissObliqueMercator
12
12
  );
@@ -15,7 +15,7 @@ export const lazyStereographic: ProjectionDescriptor = /* @__PURE__ */ createPro
15
15
  ]
16
16
  },
17
17
  async () => {
18
- const projectionModule = await import('@math.gl/geospatial/projection/projections/stere');
18
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-stere');
19
19
  return projectionModule.stereographic;
20
20
  }
21
21
  );
@@ -16,5 +16,5 @@ export const lazyObliqueStereographic: ProjectionDescriptor =
16
16
  ]
17
17
  },
18
18
  async () =>
19
- (await import('@math.gl/geospatial/projection/projections/sterea')).obliqueStereographic
19
+ (await import('@math.gl/geospatial/projection-projections-sterea')).obliqueStereographic
20
20
  );
@@ -18,5 +18,5 @@ export const lazyTransverseMercator: ProjectionDescriptor =
18
18
  ]
19
19
  },
20
20
  async () =>
21
- (await import('@math.gl/geospatial/projection/projections/tmerc')).transverseMercator
21
+ (await import('@math.gl/geospatial/projection-projections-tmerc')).transverseMercator
22
22
  );
@@ -8,7 +8,7 @@ export const lazyTiltedPerspective: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'tpers', aliases: ['Tilted_Perspective']},
10
10
  async () => {
11
- const projectionModule = await import('@math.gl/geospatial/projection/projections/tpers');
11
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-tpers');
12
12
  return projectionModule.tiltedPerspective;
13
13
  }
14
14
  );
@@ -8,5 +8,5 @@ export const lazyUniversalTransverseMercator: ProjectionDescriptor =
8
8
  /* @__PURE__ */ createProjectionDescriptor(
9
9
  {name: 'utm', aliases: ['Universal Transverse Mercator System']},
10
10
  async () =>
11
- (await import('@math.gl/geospatial/projection/projections/utm')).universalTransverseMercator
11
+ (await import('@math.gl/geospatial/projection-projections-utm')).universalTransverseMercator
12
12
  );
@@ -7,7 +7,7 @@ import type {ProjectionDescriptor} from '../projection-descriptor';
7
7
  export const lazyVanDerGrinten: ProjectionDescriptor = /* @__PURE__ */ createProjectionDescriptor(
8
8
  {name: 'vandg', aliases: ['Van_der_Grinten_I', 'VanDerGrinten', 'Van_der_Grinten']},
9
9
  async () => {
10
- const projectionModule = await import('@math.gl/geospatial/projection/projections/vandg');
10
+ const projectionModule = await import('@math.gl/geospatial/projection-projections-vandg');
11
11
  return projectionModule.vanDerGrinten;
12
12
  }
13
13
  );
@@ -0,0 +1,140 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {WellKnownGeometry} from '@math.gl/core/arrow';
6
+ import {clipPolyline} from '@math.gl/geometry/polygon';
7
+ import polygonClipping from 'polygon-clipping';
8
+ import {vertexCount} from './geometry-inspection';
9
+ import {planarBounds} from './spatial-planar';
10
+
11
+ /** Axis-aligned rectangle in planar XY coordinates. */
12
+ export type Box = [number, number, number, number];
13
+
14
+ /** Tests whether a point lies in the interior of the clipping rectangle. */
15
+ function containsPoint(point: readonly number[], [minX, minY, maxX, maxY]: Box): boolean {
16
+ const [x, y] = point;
17
+ return x! > minX && x! < maxX && y! > minY && y! < maxY;
18
+ }
19
+
20
+ /** Clips a path without joining fragments across an excursion outside the rectangle. */
21
+ function clipPath(path: readonly (readonly number[])[], box: Box): number[][][] {
22
+ if (path.some(point => !Number.isFinite(point[0]) || !Number.isFinite(point[1]))) {
23
+ throw new Error('ST_ClipByBox2D requires finite line coordinates');
24
+ }
25
+ if (path.every(point => containsPoint(point, box))) return [path.map(point => [...point])];
26
+ const [minX, minY, maxX, maxY] = box;
27
+ const paths: number[][][] = [];
28
+ for (const part of clipPolyline(
29
+ path.flatMap(point => [point[0]!, point[1]!]),
30
+ box
31
+ )) {
32
+ let vertices: number[][] = [];
33
+ for (let i = 2; i < part.length; i += 2) {
34
+ const ax = part[i - 2]!;
35
+ const ay = part[i - 1]!;
36
+ const bx = part[i]!;
37
+ const by = part[i + 1]!;
38
+ if (ax === bx && ay === by) continue;
39
+ const boundary =
40
+ (ax === bx && (ax === minX || ax === maxX)) || (ay === by && (ay === minY || ay === maxY));
41
+ if (boundary) {
42
+ if (vertices.length) paths.push(vertices);
43
+ vertices = [];
44
+ continue;
45
+ }
46
+ if (!vertices.length) vertices.push([ax, ay]);
47
+ vertices.push([bx, by]);
48
+ }
49
+ if (vertices.length) paths.push(vertices);
50
+ }
51
+ return paths;
52
+ }
53
+
54
+ /** Clips polygon shells and holes together so disconnected pieces retain their topology. */
55
+ export function clipPolygons(
56
+ polygons: readonly (readonly (readonly (readonly number[])[])[])[],
57
+ [minX, minY, maxX, maxY]: Box
58
+ ): polygonClipping.MultiPolygon {
59
+ const subject: polygonClipping.MultiPolygon = polygons
60
+ .filter(polygon => polygon[0]?.length)
61
+ .map(rings => rings.filter(ring => ring.length).map(ring => ring.map(([x, y]) => [x!, y!])));
62
+ if (!subject.length) return [];
63
+ const rectangle: polygonClipping.Polygon = [
64
+ [
65
+ [minX, minY],
66
+ [maxX, minY],
67
+ [maxX, maxY],
68
+ [minX, maxY],
69
+ [minX, minY]
70
+ ]
71
+ ];
72
+ return polygonClipping.intersection(subject, rectangle);
73
+ }
74
+
75
+ /** Individual geometry types emitted by rectangle clipping. */
76
+ type ClipPart = Extract<WellKnownGeometry, {type: 'Point' | 'LineString' | 'Polygon'}>;
77
+
78
+ /** Clips a geometry to atomic parts so the result can be recombined by geometry type. */
79
+ function clipParts(geometry: WellKnownGeometry, box: Box): ClipPart[] {
80
+ switch (geometry.type) {
81
+ case 'Point':
82
+ return containsPoint(geometry.coordinates, box) ? [geometry] : [];
83
+ case 'MultiPoint':
84
+ return geometry.coordinates.flatMap(coordinates =>
85
+ containsPoint(coordinates, box) ? [{type: 'Point', coordinates}] : []
86
+ );
87
+ case 'LineString':
88
+ return geometry.coordinates.length
89
+ ? clipPath(geometry.coordinates, box).map(coordinates => ({
90
+ type: 'LineString',
91
+ coordinates
92
+ }))
93
+ : [];
94
+ case 'MultiLineString':
95
+ return geometry.coordinates.flatMap(path =>
96
+ path.length
97
+ ? clipPath(path, box).map(coordinates => ({type: 'LineString', coordinates}))
98
+ : []
99
+ );
100
+ case 'Polygon':
101
+ case 'MultiPolygon': {
102
+ const polygons = geometry.type === 'Polygon' ? [geometry.coordinates] : geometry.coordinates;
103
+ return clipPolygons(polygons, box).map(coordinates => ({type: 'Polygon', coordinates}));
104
+ }
105
+ case 'GeometryCollection':
106
+ return geometry.geometries.flatMap(child => clipParts(child, box));
107
+ }
108
+ }
109
+
110
+ /** Returns a single geometry, a homogeneous multipart, or a mixed collection. */
111
+ function combineParts(parts: ClipPart[]): WellKnownGeometry {
112
+ if (parts.length === 1) return parts[0]!;
113
+ if (parts.length) {
114
+ if (parts.every(part => part.type === 'Point')) {
115
+ return {type: 'MultiPoint', coordinates: parts.map(part => part.coordinates)};
116
+ }
117
+ if (parts.every(part => part.type === 'LineString')) {
118
+ return {type: 'MultiLineString', coordinates: parts.map(part => part.coordinates)};
119
+ }
120
+ if (parts.every(part => part.type === 'Polygon')) {
121
+ return {type: 'MultiPolygon', coordinates: parts.map(part => part.coordinates)};
122
+ }
123
+ }
124
+ return {type: 'GeometryCollection', geometries: parts};
125
+ }
126
+
127
+ /** Derives the rectangle from a bounds geometry and clips a planar feature. */
128
+ export function clipGeometryByBox(
129
+ geometry: WellKnownGeometry,
130
+ boundsGeometry: WellKnownGeometry
131
+ ): WellKnownGeometry | null {
132
+ const bounds = planarBounds(boundsGeometry);
133
+ if (!bounds) return null;
134
+ if (!bounds.every(Number.isFinite)) throw new Error('ST_ClipByBox2D requires finite bounds');
135
+ if (!vertexCount(geometry)) return geometry;
136
+ if (bounds[0] === bounds[2] || bounds[1] === bounds[3]) {
137
+ throw new Error('ST_ClipByBox2D requires a rectangle with positive width and height');
138
+ }
139
+ return combineParts(clipParts(geometry, bounds as Box));
140
+ }
@@ -0,0 +1,135 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {WellKnownGeometry} from '@math.gl/core/arrow';
6
+ import {BoxIndex} from '@math.gl/geometry/spatial-index';
7
+ import {distanceToPlanarSegment, planarBounds} from './spatial-planar';
8
+ import {planarIntersects, segmentsMeet} from './spatial-planar-intersects';
9
+
10
+ /** One planar coordinate. */
11
+ type Position = readonly number[];
12
+ /** One polyline component. */
13
+ type Path = readonly Position[];
14
+ /** A segment and its two-dimensional bounds. */
15
+ type Segment = {
16
+ /** First endpoint. */
17
+ a: Position;
18
+ /** Second endpoint. */
19
+ b: Position;
20
+ /** Minimum X and Y followed by maximum X and Y. */
21
+ bounds: readonly [number, number, number, number];
22
+ };
23
+ /** 2D geometries with linear components. */
24
+ type Linear = Extract<WellKnownGeometry, {type: 'LineString' | 'MultiLineString'}>;
25
+ /** 2D geometries with polygonal components. */
26
+ type Areal = Extract<WellKnownGeometry, {type: 'Polygon' | 'MultiPolygon'}>;
27
+ /** A single point geometry. */
28
+ type Point = Extract<WellKnownGeometry, {type: 'Point'}>;
29
+
30
+ /** Candidate-pair cutoff above which a spatial index can avoid a full scan. */
31
+ const directPairLimit = 1024;
32
+
33
+ /** Tests a point against the filled area, hole boundaries, and exterior boundaries. */
34
+ export function pointWithinPolygonDistance(point: Point, polygon: Areal, radius: number): boolean {
35
+ const [x, y] = point.coordinates;
36
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return false;
37
+ const bounds = planarBounds(polygon);
38
+ if (!bounds || !boxesWithin([x!, y!, x!, y!], bounds, radius)) return false;
39
+ if (planarIntersects(point, polygon)) return true;
40
+ if (radius === 0) return false;
41
+ const areas = polygon.type === 'Polygon' ? [polygon.coordinates] : polygon.coordinates;
42
+ for (const area of areas) {
43
+ for (const ring of area) {
44
+ for (let i = 0; i < ring.length; i++) {
45
+ const a = ring[i === 0 ? ring.length - 1 : i - 1]!;
46
+ const b = ring[i]!;
47
+ if (distanceToPlanarSegment(point.coordinates, a, b) <= radius) return true;
48
+ }
49
+ }
50
+ }
51
+ return false;
52
+ }
53
+
54
+ /** Keeps multiline components separate, including degenerate point-like segments. */
55
+ function lineSegments(geometry: Linear): Segment[] {
56
+ const paths: readonly Path[] =
57
+ geometry.type === 'LineString' ? [geometry.coordinates] : geometry.coordinates;
58
+ const segments: Segment[] = [];
59
+ for (const path of paths) {
60
+ if (path.some(point => !Number.isFinite(point[0]) || !Number.isFinite(point[1])))
61
+ throw new Error('ST_DWithin requires finite line coordinates');
62
+ if (!path.length) continue;
63
+ for (let i = 0; i < Math.max(1, path.length - 1); i++) {
64
+ const a = path[i]!;
65
+ const b = path[i + 1] ?? a;
66
+ segments.push({
67
+ a,
68
+ b,
69
+ bounds: [
70
+ Math.min(a[0]!, b[0]!),
71
+ Math.min(a[1]!, b[1]!),
72
+ Math.max(a[0]!, b[0]!),
73
+ Math.max(a[1]!, b[1]!)
74
+ ]
75
+ });
76
+ }
77
+ }
78
+ return segments;
79
+ }
80
+
81
+ /** Uses the largest axis gap as a conservative lower bound on Euclidean distance. */
82
+ function boxesWithin(a: readonly number[], b: readonly number[], radius: number): boolean {
83
+ return Math.max(a[0]! - b[2]!, b[0]! - a[2]!, a[1]! - b[3]!, b[1]! - a[3]!) <= radius;
84
+ }
85
+
86
+ /** Intersecting segments have zero gap; otherwise a closest pair includes an endpoint. */
87
+ function segmentsWithin(left: Segment, right: Segment, radius: number): boolean {
88
+ if (!boxesWithin(left.bounds, right.bounds, radius)) return false;
89
+ const {a, b} = left;
90
+ const {a: c, b: d} = right;
91
+ return (
92
+ segmentsMeet(a, b, c, d) ||
93
+ (radius > 0 &&
94
+ (distanceToPlanarSegment(a, c, d) <= radius ||
95
+ distanceToPlanarSegment(b, c, d) <= radius ||
96
+ distanceToPlanarSegment(c, a, b) <= radius ||
97
+ distanceToPlanarSegment(d, a, b) <= radius))
98
+ );
99
+ }
100
+
101
+ /** Builds finite search bounds with enough padding to round outward. */
102
+ function expandBound(value: number, radius: number, direction: -1 | 1): number {
103
+ const padding = Math.max(Math.abs(value), radius) * Number.EPSILON;
104
+ return Math.max(
105
+ -Number.MAX_VALUE,
106
+ Math.min(Number.MAX_VALUE, value + direction * (radius + padding))
107
+ );
108
+ }
109
+
110
+ /** Tests line pairs by exact segment refinement after rejecting distant bounds. */
111
+ export function linesWithinDistance(left: Linear, right: Linear, radius: number): boolean {
112
+ const leftBounds = planarBounds(left);
113
+ const rightBounds = planarBounds(right);
114
+ if (!leftBounds || !rightBounds || !boxesWithin(leftBounds, rightBounds, radius)) return false;
115
+ const a = lineSegments(left);
116
+ const b = lineSegments(right);
117
+ if (!a.length || !b.length) return false;
118
+ if (radius === Infinity) return true;
119
+ if (a.length * b.length <= directPairLimit || Math.min(a.length, b.length) < 8) {
120
+ return a.some(segment => b.some(candidate => segmentsWithin(segment, candidate, radius)));
121
+ }
122
+
123
+ const [indexed, queries] = a.length <= b.length ? [a, b] : [b, a];
124
+ const index = new BoxIndex({dimension: 2, bounds: indexed.flatMap(segment => segment.bounds)});
125
+ for (const segment of queries) {
126
+ const [x0, y0, x1, y1] = segment.bounds;
127
+ const {result} = index.searchQuery(
128
+ [expandBound(x0, radius, -1), expandBound(y0, radius, -1)],
129
+ [expandBound(x1, radius, 1), expandBound(y1, radius, 1)],
130
+ {filter: candidate => segmentsWithin(segment, indexed[candidate]!, radius), maxResults: 1}
131
+ );
132
+ if (result.length) return true;
133
+ }
134
+ return false;
135
+ }