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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/LICENSE +97 -49
  2. package/README.md +16 -1
  3. package/THIRD-PARTY-NOTICES.md +18 -0
  4. package/dist/culling/constants.d.ts +3 -0
  5. package/dist/culling/constants.d.ts.map +1 -0
  6. package/dist/culling/constants.js +5 -0
  7. package/dist/culling/constants.js.map +1 -0
  8. package/dist/culling/index.cjs +2124 -0
  9. package/dist/culling/index.cjs.map +6 -0
  10. package/dist/culling/index.d.ts +31 -0
  11. package/dist/culling/index.d.ts.map +1 -0
  12. package/dist/culling/index.js +25 -0
  13. package/dist/culling/index.js.map +1 -0
  14. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
  15. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
  16. package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
  17. package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
  18. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
  19. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
  20. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
  21. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
  22. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
  23. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
  24. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
  25. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
  26. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
  27. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
  28. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
  29. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
  30. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
  31. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
  32. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +116 -0
  33. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
  34. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
  35. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
  36. package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
  37. package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
  38. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
  39. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
  40. package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
  41. package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
  42. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
  43. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
  44. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
  45. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
  46. package/dist/culling/lib/culling-volume.d.ts +46 -0
  47. package/dist/culling/lib/culling-volume.d.ts.map +1 -0
  48. package/dist/culling/lib/culling-volume.js +126 -0
  49. package/dist/culling/lib/culling-volume.js.map +1 -0
  50. package/dist/culling/lib/perspective-frustum.d.ts +153 -0
  51. package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
  52. package/dist/culling/lib/perspective-frustum.js +191 -0
  53. package/dist/culling/lib/perspective-frustum.js.map +1 -0
  54. package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
  55. package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
  56. package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
  57. package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
  58. package/dist/culling/lib/plane.d.ts +35 -0
  59. package/dist/culling/lib/plane.d.ts.map +1 -0
  60. package/dist/culling/lib/plane.js +90 -0
  61. package/dist/culling/lib/plane.js.map +1 -0
  62. package/dist/culling/lib/ray.d.ts +13 -0
  63. package/dist/culling/lib/ray.d.ts.map +1 -0
  64. package/dist/culling/lib/ray.js +30 -0
  65. package/dist/culling/lib/ray.js.map +1 -0
  66. package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
  67. package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
  68. package/dist/culling/lib/shapes/box-shape.js +69 -0
  69. package/dist/culling/lib/shapes/box-shape.js.map +1 -0
  70. package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
  71. package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
  72. package/dist/culling/lib/shapes/capsule-shape.js +151 -0
  73. package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
  74. package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
  75. package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
  76. package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
  77. package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
  78. package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
  79. package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
  80. package/dist/culling/lib/shapes/implicit-shape.js +142 -0
  81. package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
  82. package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
  83. package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
  84. package/dist/culling/lib/shapes/plane-shape.js +71 -0
  85. package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
  86. package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
  87. package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
  88. package/dist/culling/lib/shapes/sphere-shape.js +43 -0
  89. package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
  90. package/dist/culling/oriented-box-2d.d.ts +22 -0
  91. package/dist/culling/oriented-box-2d.d.ts.map +1 -0
  92. package/dist/culling/oriented-box-2d.js +86 -0
  93. package/dist/culling/oriented-box-2d.js.map +1 -0
  94. package/dist/culling/queries.d.ts +44 -0
  95. package/dist/culling/queries.d.ts.map +1 -0
  96. package/dist/culling/queries.js +259 -0
  97. package/dist/culling/queries.js.map +1 -0
  98. package/dist/curves/bezier-curves.d.ts +18 -0
  99. package/dist/curves/bezier-curves.d.ts.map +1 -0
  100. package/dist/curves/bezier-curves.js +54 -0
  101. package/dist/curves/bezier-curves.js.map +1 -0
  102. package/dist/curves/catmull-rom-curve.d.ts +15 -0
  103. package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
  104. package/dist/curves/catmull-rom-curve.js +77 -0
  105. package/dist/curves/catmull-rom-curve.js.map +1 -0
  106. package/dist/curves/curve-arc-length.d.ts +17 -0
  107. package/dist/curves/curve-arc-length.d.ts.map +1 -0
  108. package/dist/curves/curve-arc-length.js +58 -0
  109. package/dist/curves/curve-arc-length.js.map +1 -0
  110. package/dist/curves/curve.d.ts +23 -0
  111. package/dist/curves/curve.d.ts.map +1 -0
  112. package/dist/curves/curve.js +77 -0
  113. package/dist/curves/curve.js.map +1 -0
  114. package/dist/curves/hermite-curve.d.ts +9 -0
  115. package/dist/curves/hermite-curve.d.ts.map +1 -0
  116. package/dist/curves/hermite-curve.js +24 -0
  117. package/dist/curves/hermite-curve.js.map +1 -0
  118. package/dist/curves/index.d.ts +8 -0
  119. package/dist/curves/index.d.ts.map +1 -0
  120. package/dist/curves/index.js +9 -0
  121. package/dist/curves/index.js.map +1 -0
  122. package/dist/geometries/box-geometry.js +1 -1
  123. package/dist/geometries/box-geometry.js.map +1 -1
  124. package/dist/geometries/capsule-geometry.js +1 -1
  125. package/dist/geometries/capsule-geometry.js.map +1 -1
  126. package/dist/geometries/cylinder-geometry.js +1 -1
  127. package/dist/geometries/cylinder-geometry.js.map +1 -1
  128. package/dist/geometries/geometry-helpers.js +1 -1
  129. package/dist/geometries/geometry-helpers.js.map +1 -1
  130. package/dist/geometries/ico-sphere-geometry.js +1 -1
  131. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  132. package/dist/geometries/plane-geometry.js +1 -1
  133. package/dist/geometries/plane-geometry.js.map +1 -1
  134. package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
  135. package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
  136. package/dist/geometries/primitive-mesh-builder.js +74 -0
  137. package/dist/geometries/primitive-mesh-builder.js.map +1 -0
  138. package/dist/geometries/prism-geometry.d.ts +13 -0
  139. package/dist/geometries/prism-geometry.d.ts.map +1 -0
  140. package/dist/geometries/prism-geometry.js +34 -0
  141. package/dist/geometries/prism-geometry.js.map +1 -0
  142. package/dist/geometries/ring-geometry.d.ts +15 -0
  143. package/dist/geometries/ring-geometry.d.ts.map +1 -0
  144. package/dist/geometries/ring-geometry.js +64 -0
  145. package/dist/geometries/ring-geometry.js.map +1 -0
  146. package/dist/geometries/sphere-geometry.js +1 -1
  147. package/dist/geometries/sphere-geometry.js.map +1 -1
  148. package/dist/geometries/surface-of-revolution.js +1 -1
  149. package/dist/geometries/surface-of-revolution.js.map +1 -1
  150. package/dist/geometries/truncated-cone-geometry.js +1 -1
  151. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  152. package/dist/index.cjs +6105 -16
  153. package/dist/index.cjs.map +3 -3
  154. package/dist/index.d.ts +26 -0
  155. package/dist/index.d.ts.map +1 -1
  156. package/dist/index.js +15 -1
  157. package/dist/index.js.map +1 -1
  158. package/dist/lib/geometry-utils.js +1 -1
  159. package/dist/lib/geometry-utils.js.map +1 -1
  160. package/dist/lib/geometry.d.ts +1 -1
  161. package/dist/lib/geometry.d.ts.map +1 -1
  162. package/dist/lib/geometry.js +1 -1
  163. package/dist/lib/geometry.js.map +1 -1
  164. package/dist/lib/hinge-tree.d.ts +33 -0
  165. package/dist/lib/hinge-tree.d.ts.map +1 -0
  166. package/dist/lib/hinge-tree.js +144 -0
  167. package/dist/lib/hinge-tree.js.map +1 -0
  168. package/dist/parametric/lathe-geometry.d.ts +14 -0
  169. package/dist/parametric/lathe-geometry.d.ts.map +1 -0
  170. package/dist/parametric/lathe-geometry.js +48 -0
  171. package/dist/parametric/lathe-geometry.js.map +1 -0
  172. package/dist/parametric/parametric-geometry.d.ts +20 -0
  173. package/dist/parametric/parametric-geometry.d.ts.map +1 -0
  174. package/dist/parametric/parametric-geometry.js +88 -0
  175. package/dist/parametric/parametric-geometry.js.map +1 -0
  176. package/dist/parametric/torus-geometry.d.ts +19 -0
  177. package/dist/parametric/torus-geometry.d.ts.map +1 -0
  178. package/dist/parametric/torus-geometry.js +89 -0
  179. package/dist/parametric/torus-geometry.js.map +1 -0
  180. package/dist/parametric.d.ts +7 -0
  181. package/dist/parametric.d.ts.map +1 -0
  182. package/dist/parametric.js +7 -0
  183. package/dist/parametric.js.map +1 -0
  184. package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
  185. package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
  186. package/dist/polygon/clip-triangle-mesh.js +155 -0
  187. package/dist/polygon/clip-triangle-mesh.js.map +1 -0
  188. package/dist/polygon/cut-by-grid.d.ts +24 -0
  189. package/dist/polygon/cut-by-grid.d.ts.map +1 -0
  190. package/dist/polygon/cut-by-grid.js +221 -0
  191. package/dist/polygon/cut-by-grid.js.map +1 -0
  192. package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
  193. package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
  194. package/dist/polygon/cut-by-mercator-bounds.js +149 -0
  195. package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
  196. package/dist/polygon/earcut.d.ts +13 -0
  197. package/dist/polygon/earcut.d.ts.map +1 -0
  198. package/dist/polygon/earcut.js +693 -0
  199. package/dist/polygon/earcut.js.map +1 -0
  200. package/dist/polygon/index.d.ts +14 -0
  201. package/dist/polygon/index.d.ts.map +1 -0
  202. package/dist/polygon/index.js +13 -0
  203. package/dist/polygon/index.js.map +1 -0
  204. package/dist/polygon/lineclip.d.ts +31 -0
  205. package/dist/polygon/lineclip.d.ts.map +1 -0
  206. package/dist/polygon/lineclip.js +184 -0
  207. package/dist/polygon/lineclip.js.map +1 -0
  208. package/dist/polygon/polygon-utils.d.ts +103 -0
  209. package/dist/polygon/polygon-utils.d.ts.map +1 -0
  210. package/dist/polygon/polygon-utils.js +155 -0
  211. package/dist/polygon/polygon-utils.js.map +1 -0
  212. package/dist/polygon/polygon.d.ts +41 -0
  213. package/dist/polygon/polygon.d.ts.map +1 -0
  214. package/dist/polygon/polygon.js +76 -0
  215. package/dist/polygon/polygon.js.map +1 -0
  216. package/dist/polygon/subdivide-polyline.d.ts +56 -0
  217. package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
  218. package/dist/polygon/subdivide-polyline.js +141 -0
  219. package/dist/polygon/subdivide-polyline.js.map +1 -0
  220. package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
  221. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
  222. package/dist/polygon/subdivide-triangle-mesh.js +238 -0
  223. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
  224. package/dist/polygon/utils.d.ts +5 -0
  225. package/dist/polygon/utils.d.ts.map +1 -0
  226. package/dist/polygon/utils.js +38 -0
  227. package/dist/polygon/utils.js.map +1 -0
  228. package/dist/spatial-index/box-index.d.ts +86 -0
  229. package/dist/spatial-index/box-index.d.ts.map +1 -0
  230. package/dist/spatial-index/box-index.js +335 -0
  231. package/dist/spatial-index/box-index.js.map +1 -0
  232. package/dist/spatial-index/index.d.ts +7 -0
  233. package/dist/spatial-index/index.d.ts.map +1 -0
  234. package/dist/spatial-index/index.js +6 -0
  235. package/dist/spatial-index/index.js.map +1 -0
  236. package/dist/spatial-index/triangle-bvh.d.ts +74 -0
  237. package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
  238. package/dist/spatial-index/triangle-bvh.js +221 -0
  239. package/dist/spatial-index/triangle-bvh.js.map +1 -0
  240. package/dist/utils/attribute-compression.d.ts +50 -0
  241. package/dist/utils/attribute-compression.d.ts.map +1 -0
  242. package/dist/utils/attribute-compression.js +186 -0
  243. package/dist/utils/attribute-compression.js.map +1 -0
  244. package/dist/utils/attribute-iterator.d.ts +8 -0
  245. package/dist/utils/attribute-iterator.d.ts.map +1 -0
  246. package/dist/utils/attribute-iterator.js +25 -0
  247. package/dist/utils/attribute-iterator.js.map +1 -0
  248. package/dist/utils/compose-attribute-provenance.d.ts +13 -0
  249. package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
  250. package/dist/utils/compose-attribute-provenance.js +63 -0
  251. package/dist/utils/compose-attribute-provenance.js.map +1 -0
  252. package/dist/utils/compute-vertex-normals.d.ts +4 -0
  253. package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
  254. package/dist/utils/compute-vertex-normals.js +54 -0
  255. package/dist/utils/compute-vertex-normals.js.map +1 -0
  256. package/dist/utils/constants.d.ts +52 -0
  257. package/dist/utils/constants.d.ts.map +1 -0
  258. package/dist/utils/constants.js +39 -0
  259. package/dist/utils/constants.js.map +1 -0
  260. package/dist/utils/coordinates.d.ts +3 -0
  261. package/dist/utils/coordinates.d.ts.map +1 -0
  262. package/dist/utils/coordinates.js +8 -0
  263. package/dist/utils/coordinates.js.map +1 -0
  264. package/dist/utils/geometry.d.ts +20 -0
  265. package/dist/utils/geometry.d.ts.map +1 -0
  266. package/dist/utils/geometry.js +31 -0
  267. package/dist/utils/geometry.js.map +1 -0
  268. package/dist/utils/gl-type.d.ts +17 -0
  269. package/dist/utils/gl-type.d.ts.map +1 -0
  270. package/dist/utils/gl-type.js +69 -0
  271. package/dist/utils/gl-type.js.map +1 -0
  272. package/dist/utils/index.d.ts +18 -0
  273. package/dist/utils/index.d.ts.map +1 -0
  274. package/dist/utils/index.js +16 -0
  275. package/dist/utils/index.js.map +1 -0
  276. package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
  277. package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
  278. package/dist/utils/interpolate-packed-attributes.js +192 -0
  279. package/dist/utils/interpolate-packed-attributes.js.map +1 -0
  280. package/dist/utils/mesh-processing.d.ts +18 -0
  281. package/dist/utils/mesh-processing.d.ts.map +1 -0
  282. package/dist/utils/mesh-processing.js +300 -0
  283. package/dist/utils/mesh-processing.js.map +1 -0
  284. package/dist/utils/primitive-iterator.d.ts +21 -0
  285. package/dist/utils/primitive-iterator.d.ts.map +1 -0
  286. package/dist/utils/primitive-iterator.js +117 -0
  287. package/dist/utils/primitive-iterator.js.map +1 -0
  288. package/dist/utils/qualify-surface-transition.d.ts +21 -0
  289. package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
  290. package/dist/utils/qualify-surface-transition.js +140 -0
  291. package/dist/utils/qualify-surface-transition.js.map +1 -0
  292. package/dist/utils/rgb565.d.ts +5 -0
  293. package/dist/utils/rgb565.d.ts.map +1 -0
  294. package/dist/utils/rgb565.js +24 -0
  295. package/dist/utils/rgb565.js.map +1 -0
  296. package/dist/utils/typed-array-utils.d.ts +3 -0
  297. package/dist/utils/typed-array-utils.d.ts.map +1 -0
  298. package/dist/utils/typed-array-utils.js +16 -0
  299. package/dist/utils/typed-array-utils.js.map +1 -0
  300. package/package.json +12 -4
  301. package/src/culling/constants.ts +6 -0
  302. package/src/culling/index.ts +55 -0
  303. package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
  304. package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
  305. package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
  306. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
  307. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +153 -0
  308. package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
  309. package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
  310. package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
  311. package/src/culling/lib/culling-volume.ts +163 -0
  312. package/src/culling/lib/perspective-frustum.ts +288 -0
  313. package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
  314. package/src/culling/lib/plane.ts +118 -0
  315. package/src/culling/lib/ray.ts +33 -0
  316. package/src/culling/lib/shapes/box-shape.ts +78 -0
  317. package/src/culling/lib/shapes/capsule-shape.ts +232 -0
  318. package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
  319. package/src/culling/lib/shapes/implicit-shape.ts +209 -0
  320. package/src/culling/lib/shapes/plane-shape.ts +78 -0
  321. package/src/culling/lib/shapes/sphere-shape.ts +60 -0
  322. package/src/culling/oriented-box-2d.ts +165 -0
  323. package/src/culling/queries.ts +332 -0
  324. package/src/curves/bezier-curves.ts +62 -0
  325. package/src/curves/catmull-rom-curve.ts +89 -0
  326. package/src/curves/curve-arc-length.ts +70 -0
  327. package/src/curves/curve.ts +96 -0
  328. package/src/curves/hermite-curve.ts +34 -0
  329. package/src/curves/index.ts +15 -0
  330. package/src/geometries/box-geometry.ts +1 -1
  331. package/src/geometries/capsule-geometry.ts +1 -1
  332. package/src/geometries/cylinder-geometry.ts +1 -1
  333. package/src/geometries/geometry-helpers.ts +1 -1
  334. package/src/geometries/ico-sphere-geometry.ts +1 -1
  335. package/src/geometries/plane-geometry.ts +1 -1
  336. package/src/geometries/primitive-mesh-builder.ts +84 -0
  337. package/src/geometries/prism-geometry.ts +57 -0
  338. package/src/geometries/ring-geometry.ts +102 -0
  339. package/src/geometries/sphere-geometry.ts +1 -1
  340. package/src/geometries/surface-of-revolution.ts +1 -1
  341. package/src/geometries/truncated-cone-geometry.ts +1 -1
  342. package/src/index.ts +179 -1
  343. package/src/lib/geometry-utils.ts +2 -2
  344. package/src/lib/geometry.ts +2 -2
  345. package/src/lib/hinge-tree.ts +170 -0
  346. package/src/parametric/lathe-geometry.ts +70 -0
  347. package/src/parametric/parametric-geometry.ts +118 -0
  348. package/src/parametric/torus-geometry.ts +118 -0
  349. package/src/parametric.ts +9 -0
  350. package/src/polygon/clip-triangle-mesh.ts +218 -0
  351. package/src/polygon/cut-by-grid.ts +313 -0
  352. package/src/polygon/cut-by-mercator-bounds.ts +204 -0
  353. package/src/polygon/earcut.ts +859 -0
  354. package/src/polygon/index.ts +42 -0
  355. package/src/polygon/lineclip.ts +218 -0
  356. package/src/polygon/polygon-utils.ts +273 -0
  357. package/src/polygon/polygon.ts +105 -0
  358. package/src/polygon/subdivide-polyline.ts +223 -0
  359. package/src/polygon/subdivide-triangle-mesh.ts +342 -0
  360. package/src/polygon/utils.ts +50 -0
  361. package/src/spatial-index/box-index.ts +452 -0
  362. package/src/spatial-index/index.ts +20 -0
  363. package/src/spatial-index/triangle-bvh.ts +345 -0
  364. package/src/utils/attribute-compression.ts +234 -0
  365. package/src/utils/attribute-iterator.ts +28 -0
  366. package/src/utils/compose-attribute-provenance.ts +74 -0
  367. package/src/utils/compute-vertex-normals.ts +63 -0
  368. package/src/utils/constants.ts +42 -0
  369. package/src/utils/coordinates.ts +8 -0
  370. package/src/utils/geometry.ts +49 -0
  371. package/src/utils/gl-type.ts +87 -0
  372. package/src/utils/index.ts +55 -0
  373. package/src/utils/interpolate-packed-attributes.ts +284 -0
  374. package/src/utils/mesh-processing.ts +377 -0
  375. package/src/utils/primitive-iterator.ts +145 -0
  376. package/src/utils/qualify-surface-transition.ts +169 -0
  377. package/src/utils/rgb565.ts +26 -0
  378. package/src/utils/typed-array-utils.ts +16 -0
@@ -0,0 +1,859 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT AND ISC
3
+ // SPDX-FileCopyrightText: Copyright (c) 2016, Mapbox
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Adapted from Mapbox earcut. Original ISC notice retained below.
6
+
7
+ /*
8
+ Adapted from https://github.com/mapbox/earcut to allow passing in
9
+ of outline and hole areas using the `areas` parameter. As the
10
+ areas are calcuted as part of classifying the polygon rings
11
+ we can pass them in again to avoid recomputation
12
+
13
+ ISC License
14
+
15
+ Copyright (c) 2016, Mapbox
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any purpose
18
+ with or without fee is hereby granted, provided that the above copyright notice
19
+ and this permission notice appear in all copies.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
23
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
25
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
26
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27
+ THIS SOFTWARE.
28
+
29
+ */
30
+
31
+ // @ts-nocheck
32
+
33
+ /* eslint-disable */
34
+
35
+ import type {NumericArray} from '@math.gl/core';
36
+ import {DimIndex, Plane2D} from './polygon-utils';
37
+
38
+ /**
39
+ * Computes a triangulation of a polygon
40
+ * @param positions a flat array of the vertex positions that define the polygon.
41
+ * @param holeIndices an array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).
42
+ * @param dim the number of elements in each vertex. Size `2` will interpret `positions` as `[x0, y0, x1, y1, ...]` and size `3` will interpret `positions` as `[x0, y0, z0, x1, y1, z1, ...]`. Default `2`.
43
+ * @param areas areas of outer polygon and holes as computed by `getPolygonSignedArea()`. Can be optionally supplied to speed up triangulation
44
+ * @returns array of indices into the `positions` array that describes the triangulation of the polygon
45
+ * Adapted from https://github.com/mapbox/earcut
46
+ */
47
+ export function earcut(
48
+ positions: NumericArray,
49
+ holeIndices?: NumericArray,
50
+ dim: number = 2,
51
+ areas?: NumericArray,
52
+ plane: Plane2D = 'xy'
53
+ ): number[] {
54
+ // Keep nested calls from numeric array getters isolated.
55
+ const savedIndex = vertexPoolIndex;
56
+ const savedQueue = activeHoleQueue;
57
+ if (!holeQueues[callDepth]) holeQueues[callDepth] = [];
58
+ activeHoleQueue = holeQueues[callDepth];
59
+ callDepth++;
60
+ try {
61
+ return triangulate(positions, holeIndices, dim, areas, plane);
62
+ } finally {
63
+ activeHoleQueue.length = 0;
64
+ activeHoleQueue = savedQueue;
65
+ vertexPoolIndex = savedIndex;
66
+ callDepth--;
67
+ // Do not retain arbitrarily large object graphs after a one-off polygon.
68
+ if (callDepth === 0 && vertexPool.length > 65536) vertexPool.length = 0;
69
+ }
70
+ }
71
+
72
+ function triangulate(positions, holeIndices, dim, areas, plane): number[] {
73
+ const hasHoles = holeIndices && holeIndices.length;
74
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
75
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
76
+ const triangles = [];
77
+
78
+ if (!outerNode || outerNode.next === outerNode.prev) return triangles;
79
+
80
+ let invSize;
81
+ let maxX;
82
+ let maxY;
83
+ let minX;
84
+ let minY;
85
+ let x;
86
+ let y;
87
+
88
+ if (hasHoles) outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
89
+
90
+ // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
91
+ if (positions.length > 80 * dim) {
92
+ const i0 = DimIndex[plane[0]];
93
+ const i1 = DimIndex[plane[1]];
94
+ minX = maxX = positions[i0];
95
+ minY = maxY = positions[i1];
96
+
97
+ for (let i = dim; i < outerLen; i += dim) {
98
+ x = positions[i + i0];
99
+ y = positions[i + i1];
100
+ if (x < minX) minX = x;
101
+ if (y < minY) minY = y;
102
+ if (x > maxX) maxX = x;
103
+ if (y > maxY) maxY = y;
104
+ }
105
+
106
+ // minX, minY and invSize are later used to transform coords into integers for z-order calculation
107
+ invSize = Math.max(maxX - minX, maxY - minY);
108
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
109
+ }
110
+
111
+ earcutLinked(outerNode, triangles, minX, minY, invSize, 0);
112
+
113
+ return triangles;
114
+ }
115
+
116
+ // create a circular doubly linked list from polygon points in the specified winding order
117
+ function linkedList(
118
+ data: NumericArray,
119
+ start: number,
120
+ end: number,
121
+ dim: number,
122
+ clockwise: boolean,
123
+ area: number | undefined,
124
+ plane: Plane2D
125
+ ): Vertex {
126
+ if (start >= end) return null;
127
+ let i;
128
+ let last;
129
+ const i0 = DimIndex[plane[0]];
130
+ const i1 = DimIndex[plane[1]];
131
+ if (area === undefined) {
132
+ // Combine coordinate reads and area accumulation, as in loaders.gl.
133
+ let sum = 0;
134
+ let previousX = data[end - dim + i0];
135
+ let previousY = data[end - dim + i1];
136
+ for (i = start; i < end; i += dim) {
137
+ const x = data[i + i0];
138
+ const y = data[i + i1];
139
+ sum += (x - previousX) * (y + previousY);
140
+ last = insertNode(i / dim, x, y, last);
141
+ previousX = x;
142
+ previousY = y;
143
+ }
144
+ if (last && clockwise !== sum / 2 < 0) {
145
+ let node = last;
146
+ do {
147
+ const next = node.next;
148
+ node.next = node.prev;
149
+ node.prev = next;
150
+ node = next;
151
+ } while (node !== last);
152
+ // Preserve the starting vertex and triangle order of reverse insertion.
153
+ last = last.prev;
154
+ }
155
+ } else if (clockwise === area < 0) {
156
+ for (i = start; i < end; i += dim) last = insertNode(i / dim, data[i + i0], data[i + i1], last);
157
+ } else {
158
+ for (i = end - dim; i >= start; i -= dim)
159
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
160
+ }
161
+
162
+ if (last && equals(last, last.next)) {
163
+ removeNode(last);
164
+ last = last.next;
165
+ }
166
+
167
+ return last;
168
+ }
169
+
170
+ // eliminate colinear or duplicate points
171
+ function filterPoints(start, end?) {
172
+ if (!start) return start;
173
+ if (!end) end = start;
174
+
175
+ let p = start;
176
+ let again;
177
+ do {
178
+ again = false;
179
+
180
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
181
+ removeNode(p);
182
+ p = end = p.prev;
183
+ if (p === p.next) break;
184
+ again = true;
185
+ } else {
186
+ p = p.next;
187
+ }
188
+ } while (again || p !== end);
189
+
190
+ return end;
191
+ }
192
+
193
+ // main ear slicing loop which triangulates a polygon (given as a linked list)
194
+ function earcutLinked(ear, triangles, minX, minY, invSize, pass?) {
195
+ if (!ear) return;
196
+
197
+ // interlink polygon nodes in z-order
198
+ if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
199
+
200
+ let stop = ear;
201
+ let prev;
202
+ let next;
203
+
204
+ // iterate through ears, slicing them one by one
205
+ while (ear.prev !== ear.next) {
206
+ prev = ear.prev;
207
+ next = ear.next;
208
+
209
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
210
+ // cut off the triangle
211
+ triangles.push(prev.i);
212
+ triangles.push(ear.i);
213
+ triangles.push(next.i);
214
+
215
+ removeNode(ear);
216
+
217
+ // skipping the next vertex leads to less sliver triangles
218
+ ear = next.next;
219
+ stop = next.next;
220
+
221
+ continue;
222
+ }
223
+
224
+ ear = next;
225
+
226
+ // if we looped through the whole remaining polygon and can't find any more ears
227
+ if (ear === stop) {
228
+ // try filtering points and slicing again
229
+ if (!pass) {
230
+ earcutLinked(filterPoints(ear), triangles, minX, minY, invSize, 1);
231
+
232
+ // if this didn't work, try curing all small self-intersections locally
233
+ } else if (pass === 1) {
234
+ ear = cureLocalIntersections(filterPoints(ear), triangles);
235
+ earcutLinked(ear, triangles, minX, minY, invSize, 2);
236
+
237
+ // as a last resort, try splitting the remaining polygon into two
238
+ } else if (pass === 2) {
239
+ splitEarcut(ear, triangles, minX, minY, invSize);
240
+ }
241
+
242
+ break;
243
+ }
244
+ }
245
+ }
246
+
247
+ // check whether a polygon node forms a valid ear with adjacent nodes
248
+ function isEar(ear) {
249
+ const a = ear.prev;
250
+ const b = ear;
251
+ const c = ear.next;
252
+
253
+ if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
254
+
255
+ // now make sure we don't have other points inside the potential ear
256
+ const ax = a.x;
257
+ const bx = b.x;
258
+ const cx = c.x;
259
+ const ay = a.y;
260
+ const by = b.y;
261
+ const cy = c.y;
262
+
263
+ // triangle bbox; min & max are calculated like this for speed
264
+ const x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx;
265
+ const y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy;
266
+ const x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx;
267
+ const y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;
268
+
269
+ let p = c.next;
270
+ while (p !== a) {
271
+ if (
272
+ p.x >= x0 &&
273
+ p.x <= x1 &&
274
+ p.y >= y0 &&
275
+ p.y <= y1 &&
276
+ pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
277
+ area(p.prev, p, p.next) >= 0
278
+ )
279
+ return false;
280
+ p = p.next;
281
+ }
282
+
283
+ return true;
284
+ }
285
+
286
+ function isEarHashed(ear, minX, minY, invSize) {
287
+ const a = ear.prev;
288
+ const b = ear;
289
+ const c = ear.next;
290
+
291
+ if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
292
+
293
+ const ax = a.x;
294
+ const bx = b.x;
295
+ const cx = c.x;
296
+ const ay = a.y;
297
+ const by = b.y;
298
+ const cy = c.y;
299
+
300
+ // triangle bbox; min & max are calculated like this for speed
301
+ const x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx;
302
+ const y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy;
303
+ const x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx;
304
+ const y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;
305
+
306
+ // z-order range for the current triangle bbox;
307
+ const minZ = zOrder(x0, y0, minX, minY, invSize);
308
+ const maxZ = zOrder(x1, y1, minX, minY, invSize);
309
+
310
+ let p = ear.prevZ;
311
+ let n = ear.nextZ;
312
+
313
+ // look for points inside the triangle in both directions
314
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
315
+ if (
316
+ p.x >= x0 &&
317
+ p.x <= x1 &&
318
+ p.y >= y0 &&
319
+ p.y <= y1 &&
320
+ p !== a &&
321
+ p !== c &&
322
+ pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
323
+ area(p.prev, p, p.next) >= 0
324
+ )
325
+ return false;
326
+ p = p.prevZ;
327
+
328
+ if (
329
+ n.x >= x0 &&
330
+ n.x <= x1 &&
331
+ n.y >= y0 &&
332
+ n.y <= y1 &&
333
+ n !== a &&
334
+ n !== c &&
335
+ pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&
336
+ area(n.prev, n, n.next) >= 0
337
+ )
338
+ return false;
339
+ n = n.nextZ;
340
+ }
341
+
342
+ // look for remaining points in decreasing z-order
343
+ while (p && p.z >= minZ) {
344
+ if (
345
+ p.x >= x0 &&
346
+ p.x <= x1 &&
347
+ p.y >= y0 &&
348
+ p.y <= y1 &&
349
+ p !== a &&
350
+ p !== c &&
351
+ pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
352
+ area(p.prev, p, p.next) >= 0
353
+ )
354
+ return false;
355
+ p = p.prevZ;
356
+ }
357
+
358
+ // look for remaining points in increasing z-order
359
+ while (n && n.z <= maxZ) {
360
+ if (
361
+ n.x >= x0 &&
362
+ n.x <= x1 &&
363
+ n.y >= y0 &&
364
+ n.y <= y1 &&
365
+ n !== a &&
366
+ n !== c &&
367
+ pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&
368
+ area(n.prev, n, n.next) >= 0
369
+ )
370
+ return false;
371
+ n = n.nextZ;
372
+ }
373
+
374
+ return true;
375
+ }
376
+
377
+ // go through all polygon nodes and cure small local self-intersections
378
+ function cureLocalIntersections(start, triangles) {
379
+ let p = start;
380
+ do {
381
+ const a = p.prev;
382
+ const b = p.next.next;
383
+
384
+ if (
385
+ !equals(a, b) &&
386
+ intersects(a, p, p.next, b) &&
387
+ locallyInside(a, b) &&
388
+ locallyInside(b, a)
389
+ ) {
390
+ triangles.push(a.i);
391
+ triangles.push(p.i);
392
+ triangles.push(b.i);
393
+
394
+ // remove two nodes involved
395
+ removeNode(p);
396
+ removeNode(p.next);
397
+
398
+ p = start = b;
399
+ }
400
+ p = p.next;
401
+ } while (p !== start);
402
+
403
+ return filterPoints(p);
404
+ }
405
+
406
+ // try splitting polygon into two and triangulate them independently
407
+ function splitEarcut(start, triangles, minX, minY, invSize) {
408
+ // look for a valid diagonal that divides the polygon into two
409
+ let a = start;
410
+ do {
411
+ let b = a.next.next;
412
+ while (b !== a.prev) {
413
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
414
+ // split the polygon in two by the diagonal
415
+ let c = splitPolygon(a, b);
416
+
417
+ // filter colinear points around the cuts
418
+ a = filterPoints(a, a.next);
419
+ c = filterPoints(c, c.next);
420
+
421
+ // run earcut on each half
422
+ earcutLinked(a, triangles, minX, minY, invSize, 0);
423
+ earcutLinked(c, triangles, minX, minY, invSize, 0);
424
+ return;
425
+ }
426
+ b = b.next;
427
+ }
428
+ a = a.next;
429
+ } while (a !== start);
430
+ }
431
+
432
+ // link every hole into the outer loop, producing a single-ring polygon without holes
433
+ function eliminateHoles(
434
+ data: NumericArray,
435
+ holeIndices: NumericArray,
436
+ outerNode: Vertex,
437
+ dim: number,
438
+ areas: NumericArray | undefined,
439
+ plane: Plane2D
440
+ ): Vertex {
441
+ const queue = activeHoleQueue;
442
+ queue.length = 0;
443
+ let i;
444
+ let len;
445
+ let start;
446
+ let end;
447
+ let list;
448
+
449
+ for (i = 0, len = holeIndices.length; i < len; i++) {
450
+ start = holeIndices[i] * dim;
451
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
452
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
453
+ if (!list) continue;
454
+ if (list === list.next) list.steiner = true;
455
+ queue.push(getLeftmost(list));
456
+ }
457
+
458
+ queue.sort(compareX);
459
+
460
+ // process holes from left to right
461
+ for (i = 0; i < queue.length; i++) {
462
+ outerNode = eliminateHole(queue[i], outerNode);
463
+ }
464
+
465
+ return outerNode;
466
+ }
467
+
468
+ function compareX(a, b) {
469
+ return a.x - b.x;
470
+ }
471
+
472
+ // find a bridge between vertices that connects hole with an outer ring and and link it
473
+ function eliminateHole(hole, outerNode) {
474
+ const bridge = findHoleBridge(hole, outerNode);
475
+ if (!bridge) {
476
+ return outerNode;
477
+ }
478
+
479
+ const bridgeReverse = splitPolygon(bridge, hole);
480
+
481
+ // filter collinear points around the cuts
482
+ filterPoints(bridgeReverse, bridgeReverse.next);
483
+ return filterPoints(bridge, bridge.next);
484
+ }
485
+
486
+ // David Eberly's algorithm for finding a bridge between hole and outer polygon
487
+ function findHoleBridge(hole, outerNode) {
488
+ let p = outerNode;
489
+ const hx = hole.x;
490
+ const hy = hole.y;
491
+ let qx = -Infinity;
492
+ let m;
493
+
494
+ // find a segment intersected by a ray from the hole's leftmost point to the left;
495
+ // segment's endpoint with lesser x will be potential connection point
496
+ do {
497
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
498
+ const x = p.x + ((hy - p.y) * (p.next.x - p.x)) / (p.next.y - p.y);
499
+ if (x <= hx && x > qx) {
500
+ qx = x;
501
+ m = p.x < p.next.x ? p : p.next;
502
+ if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint
503
+ }
504
+ }
505
+ p = p.next;
506
+ } while (p !== outerNode);
507
+
508
+ if (!m) return null;
509
+
510
+ // look for points inside the triangle of hole point, segment intersection and endpoint;
511
+ // if there are no points found, we have a valid connection;
512
+ // otherwise choose the point of the minimum angle with the ray as connection point
513
+
514
+ const stop = m;
515
+ const mx = m.x;
516
+ const my = m.y;
517
+ let tanMin = Infinity;
518
+ let tan;
519
+
520
+ p = m;
521
+
522
+ do {
523
+ if (
524
+ hx >= p.x &&
525
+ p.x >= mx &&
526
+ hx !== p.x &&
527
+ pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)
528
+ ) {
529
+ tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
530
+
531
+ if (
532
+ locallyInside(p, hole) &&
533
+ (tan < tanMin ||
534
+ (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))
535
+ ) {
536
+ m = p;
537
+ tanMin = tan;
538
+ }
539
+ }
540
+
541
+ p = p.next;
542
+ } while (p !== stop);
543
+
544
+ return m;
545
+ }
546
+
547
+ // whether sector in vertex m contains sector in vertex p in the same coordinates
548
+ function sectorContainsSector(m, p) {
549
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
550
+ }
551
+
552
+ // interlink polygon nodes in z-order
553
+ function indexCurve(start, minX, minY, invSize) {
554
+ let p = start;
555
+ do {
556
+ if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize);
557
+ p.prevZ = p.prev;
558
+ p.nextZ = p.next;
559
+ p = p.next;
560
+ } while (p !== start);
561
+
562
+ p.prevZ.nextZ = null;
563
+ p.prevZ = null;
564
+
565
+ sortLinked(p);
566
+ }
567
+
568
+ // Simon Tatham's linked list merge sort algorithm
569
+ // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
570
+ function sortLinked(list) {
571
+ let e;
572
+ let i;
573
+ let inSize = 1;
574
+ let numMerges;
575
+ let p;
576
+ let pSize;
577
+ let q;
578
+ let qSize;
579
+ let tail;
580
+
581
+ do {
582
+ p = list;
583
+ list = null;
584
+ tail = null;
585
+ numMerges = 0;
586
+
587
+ while (p) {
588
+ numMerges++;
589
+ q = p;
590
+ pSize = 0;
591
+ for (i = 0; i < inSize; i++) {
592
+ pSize++;
593
+ q = q.nextZ;
594
+ if (!q) break;
595
+ }
596
+ qSize = inSize;
597
+
598
+ while (pSize > 0 || (qSize > 0 && q)) {
599
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
600
+ e = p;
601
+ p = p.nextZ;
602
+ pSize--;
603
+ } else {
604
+ e = q;
605
+ q = q.nextZ;
606
+ qSize--;
607
+ }
608
+
609
+ if (tail) tail.nextZ = e;
610
+ else list = e;
611
+
612
+ e.prevZ = tail;
613
+ tail = e;
614
+ }
615
+
616
+ p = q;
617
+ }
618
+
619
+ tail.nextZ = null;
620
+ inSize *= 2;
621
+ } while (numMerges > 1);
622
+
623
+ return list;
624
+ }
625
+
626
+ // z-order of a point given coords and inverse of the longer side of data bbox
627
+ function zOrder(x, y, minX, minY, invSize) {
628
+ // coords are transformed into non-negative 15-bit integer range
629
+ x = ((x - minX) * invSize) | 0;
630
+ y = ((y - minY) * invSize) | 0;
631
+
632
+ x = (x | (x << 8)) & 0x00ff00ff;
633
+ x = (x | (x << 4)) & 0x0f0f0f0f;
634
+ x = (x | (x << 2)) & 0x33333333;
635
+ x = (x | (x << 1)) & 0x55555555;
636
+
637
+ y = (y | (y << 8)) & 0x00ff00ff;
638
+ y = (y | (y << 4)) & 0x0f0f0f0f;
639
+ y = (y | (y << 2)) & 0x33333333;
640
+ y = (y | (y << 1)) & 0x55555555;
641
+
642
+ return x | (y << 1);
643
+ }
644
+
645
+ // find the leftmost node of a polygon ring
646
+ function getLeftmost(start) {
647
+ let p = start;
648
+ let leftmost = start;
649
+ do {
650
+ if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p;
651
+ p = p.next;
652
+ } while (p !== start);
653
+
654
+ return leftmost;
655
+ }
656
+
657
+ // check if a point lies within a convex triangle
658
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
659
+ return (
660
+ (cx - px) * (ay - py) >= (ax - px) * (cy - py) &&
661
+ (ax - px) * (by - py) >= (bx - px) * (ay - py) &&
662
+ (bx - px) * (cy - py) >= (cx - px) * (by - py)
663
+ );
664
+ }
665
+
666
+ // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
667
+ function isValidDiagonal(a, b) {
668
+ return (
669
+ a.next.i !== b.i &&
670
+ a.prev.i !== b.i &&
671
+ !intersectsPolygon(a, b) && // dones't intersect other edges
672
+ ((locallyInside(a, b) &&
673
+ locallyInside(b, a) &&
674
+ middleInside(a, b) && // locally visible
675
+ (area(a.prev, a, b.prev) || area(a, b.prev, b))) || // does not create opposite-facing sectors
676
+ (equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0))
677
+ ); // special zero-length case
678
+ }
679
+
680
+ // signed area of a triangle
681
+ function area(p, q, r) {
682
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
683
+ }
684
+
685
+ // check if two points are equal
686
+ function equals(p1, p2) {
687
+ return p1.x === p2.x && p1.y === p2.y;
688
+ }
689
+
690
+ // check if two segments intersect
691
+ function intersects(p1, q1, p2, q2) {
692
+ const o1 = sign(area(p1, q1, p2));
693
+ const o2 = sign(area(p1, q1, q2));
694
+ const o3 = sign(area(p2, q2, p1));
695
+ const o4 = sign(area(p2, q2, q1));
696
+
697
+ if (o1 !== o2 && o3 !== o4) return true; // general case
698
+
699
+ if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
700
+ if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
701
+ if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
702
+ if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
703
+
704
+ return false;
705
+ }
706
+
707
+ // for collinear points p, q, r, check if point q lies on segment pr
708
+ function onSegment(p, q, r) {
709
+ return (
710
+ q.x <= Math.max(p.x, r.x) &&
711
+ q.x >= Math.min(p.x, r.x) &&
712
+ q.y <= Math.max(p.y, r.y) &&
713
+ q.y >= Math.min(p.y, r.y)
714
+ );
715
+ }
716
+
717
+ function sign(num) {
718
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
719
+ }
720
+
721
+ // check if a polygon diagonal intersects any polygon segments
722
+ function intersectsPolygon(a, b) {
723
+ let p = a;
724
+ do {
725
+ if (
726
+ p.i !== a.i &&
727
+ p.next.i !== a.i &&
728
+ p.i !== b.i &&
729
+ p.next.i !== b.i &&
730
+ intersects(p, p.next, a, b)
731
+ )
732
+ return true;
733
+ p = p.next;
734
+ } while (p !== a);
735
+
736
+ return false;
737
+ }
738
+
739
+ // check if a polygon diagonal is locally inside the polygon
740
+ function locallyInside(a, b) {
741
+ return area(a.prev, a, a.next) < 0
742
+ ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0
743
+ : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
744
+ }
745
+
746
+ // check if the middle point of a polygon diagonal is inside the polygon
747
+ function middleInside(a, b) {
748
+ let p = a;
749
+ let inside = false;
750
+ const px = (a.x + b.x) / 2;
751
+ const py = (a.y + b.y) / 2;
752
+ do {
753
+ if (
754
+ p.y > py !== p.next.y > py &&
755
+ p.next.y !== p.y &&
756
+ px < ((p.next.x - p.x) * (py - p.y)) / (p.next.y - p.y) + p.x
757
+ )
758
+ inside = !inside;
759
+ p = p.next;
760
+ } while (p !== a);
761
+
762
+ return inside;
763
+ }
764
+
765
+ // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
766
+ // if one belongs to the outer ring and another to a hole, it merges it into a single ring
767
+ function splitPolygon(a, b) {
768
+ const a2 = allocateVertex(a.i, a.x, a.y);
769
+ const b2 = allocateVertex(b.i, b.x, b.y);
770
+ const an = a.next;
771
+ const bp = b.prev;
772
+
773
+ a.next = b;
774
+ b.prev = a;
775
+
776
+ a2.next = an;
777
+ an.prev = a2;
778
+
779
+ b2.next = a2;
780
+ a2.prev = b2;
781
+
782
+ bp.next = b2;
783
+ b2.prev = bp;
784
+
785
+ return b2;
786
+ }
787
+
788
+ // create a node and optionally link it with previous one (in a circular doubly linked list)
789
+ function insertNode(i, x, y, last) {
790
+ const p = allocateVertex(i, x, y);
791
+
792
+ if (!last) {
793
+ p.prev = p;
794
+ p.next = p;
795
+ } else {
796
+ p.next = last.next;
797
+ p.prev = last;
798
+ last.next.prev = p;
799
+ last.next = p;
800
+ }
801
+ return p;
802
+ }
803
+
804
+ function removeNode(p) {
805
+ p.next.prev = p.prev;
806
+ p.prev.next = p.next;
807
+
808
+ if (p.prevZ) p.prevZ.nextZ = p.nextZ;
809
+ if (p.nextZ) p.nextZ.prevZ = p.prevZ;
810
+ }
811
+
812
+ // Reuse scratch nodes and queues across calls; no input or output arrays are retained.
813
+ const vertexPool: Vertex[] = [];
814
+ let vertexPoolIndex = 0;
815
+ const holeQueues: Vertex[][] = [];
816
+ let activeHoleQueue: Vertex[] = [];
817
+ let callDepth = 0;
818
+
819
+ function allocateVertex(i: number, x: number, y: number): Vertex {
820
+ let vertex = vertexPool[vertexPoolIndex];
821
+ if (!vertex) vertexPool[vertexPoolIndex] = vertex = new Vertex(i, x, y);
822
+ vertexPoolIndex++;
823
+ vertex.i = i;
824
+ vertex.x = x;
825
+ vertex.y = y;
826
+ vertex.prev = vertex.next = vertex.prevZ = vertex.nextZ = null;
827
+ vertex.z = 0;
828
+ vertex.steiner = false;
829
+ return vertex;
830
+ }
831
+
832
+ class Vertex {
833
+ // vertex index, independent of coordinate stride
834
+ i: number;
835
+
836
+ // vertex coordinates
837
+ x: number;
838
+ y: number;
839
+
840
+ // previous and next vertex nodes in a polygon ring
841
+ prev: Vertex = null;
842
+ next: Vertex = null;
843
+
844
+ // z-order curve value
845
+ z: number = 0;
846
+
847
+ // previous and next nodes in z-order
848
+ prevZ: Vertex = null;
849
+ nextZ: Vertex = null;
850
+
851
+ // indicates whether this is a steiner point
852
+ steiner: boolean = false;
853
+
854
+ constructor(i: number, x: number, y: number) {
855
+ this.i = i;
856
+ this.x = x;
857
+ this.y = y;
858
+ }
859
+ }