wallhammer-web 0.0.0-stage → 0.4.0

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 (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,297 @@
1
+ // Least-cost ways over a sphere grid: the cheapest chain of neighbour steps between two nodes, the regions of many
2
+ // sources (which source reaches each node most cheaply), and the cheapest step between every two regions that touch.
3
+ // The caller gives the cost of a step and decides what a way stands for.
4
+ //
5
+ // One shared core: a binary heap ordered by (cost, source index, node index), neighbours in the order of
6
+ // `gridNeighbours` (over the edges and corners of the cube), a predecessor replaced only by a strictly lower cost. No
7
+ // estimate of the rest of the way, so the result is exact for any cost. Arithmetic only: the same input gives the same
8
+ // nodes in every runtime.
9
+ import { gridNeighbours } from './grid.js';
10
+ /** A binary min-heap of (cost, source, node) triples with lazy deletion. */
11
+ class Heap {
12
+ cost = new Float64Array(1024);
13
+ src = new Int32Array(1024);
14
+ node = new Int32Array(1024);
15
+ size = 0;
16
+ clear() {
17
+ this.size = 0;
18
+ }
19
+ less(i, j) {
20
+ const a = this.cost[i];
21
+ const b = this.cost[j];
22
+ if (a !== b)
23
+ return a < b;
24
+ const s = this.src[i] - this.src[j];
25
+ if (s !== 0)
26
+ return s < 0;
27
+ return this.node[i] < this.node[j];
28
+ }
29
+ swap(i, j) {
30
+ const c = this.cost[i];
31
+ this.cost[i] = this.cost[j];
32
+ this.cost[j] = c;
33
+ const s = this.src[i];
34
+ this.src[i] = this.src[j];
35
+ this.src[j] = s;
36
+ const n = this.node[i];
37
+ this.node[i] = this.node[j];
38
+ this.node[j] = n;
39
+ }
40
+ push(cost, src, node) {
41
+ if (this.size === this.cost.length) {
42
+ const grow = this.size * 2;
43
+ const c = new Float64Array(grow);
44
+ c.set(this.cost);
45
+ this.cost = c;
46
+ const s = new Int32Array(grow);
47
+ s.set(this.src);
48
+ this.src = s;
49
+ const n = new Int32Array(grow);
50
+ n.set(this.node);
51
+ this.node = n;
52
+ }
53
+ let i = this.size++;
54
+ this.cost[i] = cost;
55
+ this.src[i] = src;
56
+ this.node[i] = node;
57
+ while (i > 0) {
58
+ const p = (i - 1) >> 1;
59
+ if (!this.less(i, p))
60
+ break;
61
+ this.swap(i, p);
62
+ i = p;
63
+ }
64
+ }
65
+ /** Removes the least triple; read it from index `size` afterwards (cost, src, node). */
66
+ pop() {
67
+ const last = --this.size;
68
+ this.swap(0, last);
69
+ let i = 0;
70
+ for (;;) {
71
+ const l = 2 * i + 1;
72
+ if (l >= last)
73
+ break;
74
+ const r = l + 1;
75
+ const m = r < last && this.less(r, l) ? r : l;
76
+ if (!this.less(m, i))
77
+ break;
78
+ this.swap(i, m);
79
+ i = m;
80
+ }
81
+ }
82
+ }
83
+ /** Scratch arrays for `routeGrid` on grid `g` (about 20 bytes per node). */
84
+ export function routeScratch(g) {
85
+ return makeScratch(g);
86
+ }
87
+ function makeScratch(g) {
88
+ return { count: g.count, mark: new Uint32Array(g.count), cost: new Float64Array(g.count), prev: new Int32Array(g.count), stamp: 0, heap: new Heap() };
89
+ }
90
+ function checkCost(c, a, b) {
91
+ if (!(c > 0))
92
+ throw new Error(`route: the step ${a} → ${b} costs ${c} (must be > 0 or Infinity)`);
93
+ }
94
+ const nb = new Int32Array(8);
95
+ /**
96
+ * Nodes from `from` to `to` inclusive along the least total cost; null if `to` is unreachable or not settled within
97
+ * `maxNodes` settled nodes. `from === to` gives `[from]`.
98
+ */
99
+ export function routeGrid(g, o) {
100
+ const { from, to, cost } = o;
101
+ if (!(from >= 0 && from < g.count && to >= 0 && to < g.count))
102
+ throw new Error(`routeGrid: node ${from} or ${to} is not on the grid`);
103
+ if (from === to)
104
+ return Uint32Array.of(from);
105
+ const s = o.scratch ?? makeScratch(g);
106
+ if (s.count !== g.count)
107
+ throw new Error(`routeGrid: the scratch is of a grid of ${s.count} nodes, not ${g.count}`);
108
+ // A new stamp; when the marks would overflow, clear them once.
109
+ if (s.stamp >= 0x7ffffffe) {
110
+ s.mark.fill(0);
111
+ s.stamp = 0;
112
+ }
113
+ const stamp = ++s.stamp;
114
+ const open = 2 * stamp;
115
+ const done = open + 1;
116
+ const { mark, prev } = s;
117
+ const best = s.cost;
118
+ const heap = s.heap;
119
+ heap.clear();
120
+ mark[from] = open;
121
+ best[from] = 0;
122
+ prev[from] = -1;
123
+ heap.push(0, 0, from);
124
+ let settled = 0;
125
+ while (heap.size > 0) {
126
+ heap.pop();
127
+ const c = heap.cost[heap.size];
128
+ const u = heap.node[heap.size];
129
+ if (mark[u] === done || c > best[u])
130
+ continue;
131
+ mark[u] = done;
132
+ if (u === to)
133
+ break;
134
+ if (++settled >= o.maxNodes)
135
+ return null;
136
+ const k = gridNeighbours(g, u, nb);
137
+ for (let j = 0; j < k; j++) {
138
+ const v = nb[j];
139
+ if (mark[v] === done)
140
+ continue;
141
+ const step = cost(u, v);
142
+ if (step === Infinity)
143
+ continue;
144
+ checkCost(step, u, v);
145
+ const nc = c + step;
146
+ if (mark[v] !== open) {
147
+ mark[v] = open;
148
+ best[v] = nc;
149
+ prev[v] = u;
150
+ heap.push(nc, 0, v);
151
+ }
152
+ else if (nc < best[v]) {
153
+ best[v] = nc;
154
+ prev[v] = u;
155
+ heap.push(nc, 0, v);
156
+ }
157
+ }
158
+ }
159
+ if (mark[to] !== done)
160
+ return null;
161
+ let n = 1;
162
+ for (let v = to; v !== from; v = prev[v])
163
+ n++;
164
+ const out = new Uint32Array(n);
165
+ let i = n - 1;
166
+ for (let v = to;; v = prev[v]) {
167
+ out[i--] = v;
168
+ if (v === from)
169
+ break;
170
+ }
171
+ return out;
172
+ }
173
+ /**
174
+ * The regions of many sources: one search from all of them at once. A node no source reaches within `maxNodes`
175
+ * settled nodes has owner −1, cost Infinity and prev −1. A node listed twice as a source belongs to its first entry.
176
+ */
177
+ export function routeRegions(g, o) {
178
+ const count = g.count;
179
+ const owner = new Int32Array(count).fill(-1);
180
+ const best = new Float64Array(count).fill(Infinity);
181
+ const prev = new Int32Array(count).fill(-1);
182
+ const done = new Uint8Array(count);
183
+ const heap = new Heap();
184
+ const { cost } = o;
185
+ for (let i = 0; i < o.sources.length; i++) {
186
+ const s = o.sources[i];
187
+ if (!(s >= 0 && s < count))
188
+ throw new Error(`routeRegions: source ${i} (node ${s}) is not on the grid`);
189
+ if (owner[s] !== -1)
190
+ continue;
191
+ owner[s] = i;
192
+ best[s] = 0;
193
+ heap.push(0, i, s);
194
+ }
195
+ let settled = 0;
196
+ while (heap.size > 0 && settled < o.maxNodes) {
197
+ heap.pop();
198
+ const c = heap.cost[heap.size];
199
+ const src = heap.src[heap.size];
200
+ const u = heap.node[heap.size];
201
+ if (done[u] === 1 || c > best[u])
202
+ continue;
203
+ done[u] = 1;
204
+ settled++;
205
+ const k = gridNeighbours(g, u, nb);
206
+ for (let j = 0; j < k; j++) {
207
+ const v = nb[j];
208
+ if (done[v] === 1)
209
+ continue;
210
+ const step = cost(u, v);
211
+ if (step === Infinity)
212
+ continue;
213
+ checkCost(step, u, v);
214
+ const nc = c + step;
215
+ if (nc < best[v]) {
216
+ best[v] = nc;
217
+ owner[v] = src;
218
+ prev[v] = u;
219
+ heap.push(nc, src, v);
220
+ }
221
+ }
222
+ }
223
+ // Nodes seen but not settled before the cap belong to no one.
224
+ if (heap.size > 0) {
225
+ for (let i = 0; i < count; i++) {
226
+ if (done[i] === 1)
227
+ continue;
228
+ owner[i] = -1;
229
+ best[i] = Infinity;
230
+ prev[i] = -1;
231
+ }
232
+ }
233
+ return { owner, cost: best, prev };
234
+ }
235
+ /**
236
+ * The links between the regions of `routeRegions`: every step from a node of region a to a neighbour of region b
237
+ * (a < b) is a candidate; per pair the least cost wins, ties the first in node order and then neighbour order.
238
+ */
239
+ export function regionLinks(g, r, cost) {
240
+ const count = g.count;
241
+ if (r.owner.length !== count)
242
+ throw new Error(`regionLinks: regions of ${r.owner.length} nodes for a grid of ${count}`);
243
+ let sources = 0;
244
+ for (let i = 0; i < count; i++)
245
+ if (r.owner[i] >= sources)
246
+ sources = r.owner[i] + 1;
247
+ // Per pair (key a · sources + b): index into the lists below. The map is only looked up, never iterated.
248
+ const index = new Map();
249
+ const la = [];
250
+ const lb = [];
251
+ const lc = [];
252
+ const na = [];
253
+ const nbs = [];
254
+ for (let u = 0; u < count; u++) {
255
+ const a = r.owner[u];
256
+ if (a < 0)
257
+ continue;
258
+ const k = gridNeighbours(g, u, nb);
259
+ for (let j = 0; j < k; j++) {
260
+ const v = nb[j];
261
+ const b = r.owner[v];
262
+ if (b <= a)
263
+ continue;
264
+ const step = cost(u, v);
265
+ if (step === Infinity)
266
+ continue;
267
+ checkCost(step, u, v);
268
+ const c = r.cost[u] + step + r.cost[v];
269
+ const key = a * sources + b;
270
+ const at = index.get(key);
271
+ if (at === undefined) {
272
+ index.set(key, la.length);
273
+ la.push(a);
274
+ lb.push(b);
275
+ lc.push(c);
276
+ na.push(u);
277
+ nbs.push(v);
278
+ }
279
+ else if (c < lc[at]) {
280
+ lc[at] = c;
281
+ na[at] = u;
282
+ nbs[at] = v;
283
+ }
284
+ }
285
+ }
286
+ const order = la.map((_, i) => i).sort((p, q) => la[p] - la[q] || lb[p] - lb[q]);
287
+ const n = order.length;
288
+ const out = { a: new Uint32Array(n), b: new Uint32Array(n), cost: new Float64Array(n), nodeA: new Uint32Array(n), nodeB: new Uint32Array(n) };
289
+ order.forEach((i, k) => {
290
+ out.a[k] = la[i];
291
+ out.b[k] = lb[i];
292
+ out.cost[k] = lc[i];
293
+ out.nodeA[k] = na[i];
294
+ out.nodeB[k] = nbs[i];
295
+ });
296
+ return out;
297
+ }
@@ -0,0 +1,32 @@
1
+ import type { SphereGrid } from './grid.ts';
2
+ /**
3
+ * Per node: the steps over the 8-neighbourhood (`gridNeighbours`, across the edges of the cube too) to the nearest
4
+ * node with `marks[node] ≠ 0`, capped at `maxSteps` (at most 255). A marked node has 0; a node farther than the cap,
5
+ * or with no marked node at all, has `maxSteps`.
6
+ */
7
+ export declare function gridSteps(g: SphereGrid, marks: ArrayLike<number>, maxSteps: number): Uint8Array;
8
+ /**
9
+ * The steepest rise or fall from a node to one of its neighbours: `|Δheight| · unitM` over the straight distance
10
+ * between the two node middles on the sphere of `g.radiusM`. `heights` holds one value per node in units of `unitM`.
11
+ */
12
+ export declare function gridSlopeAt(g: SphereGrid, heights: ArrayLike<number>, unitM: number, node: number): number;
13
+ /** Options of `pickSites`. */
14
+ export interface PickOptions {
15
+ /** At most this many nodes are returned. */
16
+ count: number;
17
+ /** Least straight (chord) distance between two taken nodes, metres; 0 or less: none. */
18
+ spacingM: number;
19
+ /** Nodes with a lower score are never candidates. */
20
+ minScore: number;
21
+ /** Nodes taken before the call: they keep their spacing and are not returned. */
22
+ taken?: ArrayLike<number>;
23
+ /** Asked once per node that would be taken; false skips it for good. */
24
+ accept?: (node: number) => boolean;
25
+ }
26
+ /**
27
+ * Picks nodes best first. Candidates are the nodes with `score ≥ minScore`, visited by descending score, ties by
28
+ * ascending node index (the exact order of the given numbers). A candidate is taken when its chord distance to every
29
+ * taken node is at least `spacingM` and `accept`, if given, returns true. Stops at `count`. Returns the nodes in the
30
+ * order taken.
31
+ */
32
+ export declare function pickSites(g: SphereGrid, score: ArrayLike<number>, o: PickOptions): Uint32Array;
@@ -0,0 +1,209 @@
1
+ // Tools for choosing nodes of a sphere grid by a score: steps over the grid to the nearest marked node, the steepest
2
+ // slope at a node, and a best-first pick of nodes with a least straight distance between them. The caller gives the
3
+ // score and decides what a picked node stands for. Arithmetic and `Math.sqrt/floor/abs/min/max` only, so the same
4
+ // input gives the same picks in every runtime.
5
+ import { gridDirection, gridNeighbours } from './grid.js';
6
+ /**
7
+ * Per node: the steps over the 8-neighbourhood (`gridNeighbours`, across the edges of the cube too) to the nearest
8
+ * node with `marks[node] ≠ 0`, capped at `maxSteps` (at most 255). A marked node has 0; a node farther than the cap,
9
+ * or with no marked node at all, has `maxSteps`.
10
+ */
11
+ export function gridSteps(g, marks, maxSteps) {
12
+ if (!(maxSteps >= 0 && maxSteps <= 255 && Number.isInteger(maxSteps)))
13
+ throw new Error(`gridSteps: maxSteps ${maxSteps} out of 0…255`);
14
+ const count = g.count;
15
+ if (marks.length !== count)
16
+ throw new Error(`gridSteps: ${marks.length} marks for ${count} nodes`);
17
+ const out = new Uint8Array(count).fill(255);
18
+ const queue = new Int32Array(count);
19
+ let end = 0;
20
+ for (let i = 0; i < count; i++) {
21
+ if (marks[i] !== 0) {
22
+ out[i] = 0;
23
+ queue[end++] = i;
24
+ }
25
+ }
26
+ const nb = new Int32Array(8);
27
+ // Breadth first: every node is queued once, when its step is first known (the least one).
28
+ for (let head = 0; head < end; head++) {
29
+ const u = queue[head];
30
+ const next = out[u] + 1;
31
+ if (next > maxSteps)
32
+ break;
33
+ const k = gridNeighbours(g, u, nb);
34
+ for (let j = 0; j < k; j++) {
35
+ const v = nb[j];
36
+ if (out[v] !== 255)
37
+ continue;
38
+ out[v] = next;
39
+ queue[end++] = v;
40
+ }
41
+ }
42
+ if (maxSteps < 255)
43
+ for (let i = 0; i < count; i++)
44
+ if (out[i] > maxSteps)
45
+ out[i] = maxSteps;
46
+ return out;
47
+ }
48
+ const slopeNb = new Int32Array(8);
49
+ const slopeA = [0, 0, 0];
50
+ const slopeB = [0, 0, 0];
51
+ /**
52
+ * The steepest rise or fall from a node to one of its neighbours: `|Δheight| · unitM` over the straight distance
53
+ * between the two node middles on the sphere of `g.radiusM`. `heights` holds one value per node in units of `unitM`.
54
+ */
55
+ export function gridSlopeAt(g, heights, unitM, node) {
56
+ const k = gridNeighbours(g, node, slopeNb);
57
+ gridDirection(g, node, slopeA);
58
+ const h = heights[node];
59
+ let best = 0;
60
+ for (let j = 0; j < k; j++) {
61
+ const v = slopeNb[j];
62
+ gridDirection(g, v, slopeB);
63
+ const dx = slopeB[0] - slopeA[0];
64
+ const dy = slopeB[1] - slopeA[1];
65
+ const dz = slopeB[2] - slopeA[2];
66
+ const d = Math.sqrt(dx * dx + dy * dy + dz * dz) * g.radiusM;
67
+ if (!(d > 0))
68
+ continue;
69
+ const s = (Math.abs(heights[v] - h) * unitM) / d;
70
+ if (s > best)
71
+ best = s;
72
+ }
73
+ return best;
74
+ }
75
+ /** Buckets of the first ordering pass of `pickSites`. */
76
+ const PICK_BUCKETS = 65536;
77
+ /**
78
+ * Picks nodes best first. Candidates are the nodes with `score ≥ minScore`, visited by descending score, ties by
79
+ * ascending node index (the exact order of the given numbers). A candidate is taken when its chord distance to every
80
+ * taken node is at least `spacingM` and `accept`, if given, returns true. Stops at `count`. Returns the nodes in the
81
+ * order taken.
82
+ */
83
+ export function pickSites(g, score, o) {
84
+ const count = g.count;
85
+ if (score.length !== count)
86
+ throw new Error(`pickSites: ${score.length} scores for ${count} nodes`);
87
+ const want = Math.max(0, Math.floor(o.count));
88
+ const picked = [];
89
+ if (want === 0)
90
+ return new Uint32Array(0);
91
+ // Candidates, and the range of their scores.
92
+ let m = 0;
93
+ let lo = Infinity;
94
+ let hi = -Infinity;
95
+ for (let i = 0; i < count; i++) {
96
+ const s = score[i];
97
+ if (!(s >= o.minScore))
98
+ continue;
99
+ m++;
100
+ if (s < lo)
101
+ lo = s;
102
+ if (s > hi)
103
+ hi = s;
104
+ }
105
+ if (m === 0)
106
+ return new Uint32Array(0);
107
+ // Buckets by a key that never falls as the score rises (rounding is monotone), so a higher bucket never holds a
108
+ // lower score and equal scores share one bucket. Counting sort by bucket, nodes ascending inside it.
109
+ const span = hi - lo;
110
+ const top = PICK_BUCKETS - 1;
111
+ const bucketOf = (s) => (span > 0 ? Math.min(top, Math.floor(((s - lo) / span) * top)) : 0);
112
+ const starts = new Uint32Array(PICK_BUCKETS + 1);
113
+ for (let i = 0; i < count; i++) {
114
+ const s = score[i];
115
+ if (s >= o.minScore)
116
+ starts[bucketOf(s) + 1]++;
117
+ }
118
+ for (let b = 0; b < PICK_BUCKETS; b++)
119
+ starts[b + 1] += starts[b];
120
+ const order = new Uint32Array(m);
121
+ const fill = starts.slice(0, PICK_BUCKETS);
122
+ for (let i = 0; i < count; i++) {
123
+ const s = score[i];
124
+ if (s >= o.minScore)
125
+ order[fill[bucketOf(s)]++] = i;
126
+ }
127
+ // Taken nodes in a hash of cubes of the spacing, in metres.
128
+ const R = g.radiusM;
129
+ const spacing = o.spacingM;
130
+ const cellM = spacing > 0 ? spacing : 1;
131
+ const cells = new Map();
132
+ const pos = [];
133
+ const d = [0, 0, 0];
134
+ const keyOf = (x, y, z) => `${Math.floor(x / cellM)},${Math.floor(y / cellM)},${Math.floor(z / cellM)}`;
135
+ const put = (node) => {
136
+ gridDirection(g, node, d);
137
+ const x = d[0] * R;
138
+ const y = d[1] * R;
139
+ const z = d[2] * R;
140
+ const k = pos.length / 3;
141
+ pos.push(x, y, z);
142
+ const key = keyOf(x, y, z);
143
+ const list = cells.get(key);
144
+ if (list)
145
+ list.push(k);
146
+ else
147
+ cells.set(key, [k]);
148
+ };
149
+ const free = (x, y, z) => {
150
+ if (!(spacing > 0))
151
+ return true;
152
+ const cx = Math.floor(x / cellM);
153
+ const cy = Math.floor(y / cellM);
154
+ const cz = Math.floor(z / cellM);
155
+ const s2 = spacing * spacing;
156
+ for (let a = -1; a <= 1; a++) {
157
+ for (let b = -1; b <= 1; b++) {
158
+ for (let c = -1; c <= 1; c++) {
159
+ const list = cells.get(`${cx + a},${cy + b},${cz + c}`);
160
+ if (!list)
161
+ continue;
162
+ for (const k of list) {
163
+ const dx = pos[3 * k] - x;
164
+ const dy = pos[3 * k + 1] - y;
165
+ const dz = pos[3 * k + 2] - z;
166
+ if (dx * dx + dy * dy + dz * dz < s2)
167
+ return false;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ return true;
173
+ };
174
+ const before = new Set();
175
+ if (o.taken) {
176
+ for (let i = 0; i < o.taken.length; i++) {
177
+ const node = o.taken[i];
178
+ before.add(node);
179
+ put(node);
180
+ }
181
+ }
182
+ // Best first: the buckets from the top, each sorted exactly when it is reached.
183
+ const bucket = [];
184
+ for (let b = top; b >= 0 && picked.length < want; b--) {
185
+ const a = starts[b];
186
+ const e = starts[b + 1];
187
+ if (a === e)
188
+ continue;
189
+ bucket.length = 0;
190
+ for (let k = a; k < e; k++)
191
+ bucket.push(order[k]);
192
+ if (bucket.length > 1)
193
+ bucket.sort((p, q) => score[q] - score[p] || p - q);
194
+ for (const node of bucket) {
195
+ if (before.has(node))
196
+ continue;
197
+ gridDirection(g, node, d);
198
+ if (!free(d[0] * R, d[1] * R, d[2] * R))
199
+ continue;
200
+ if (o.accept && !o.accept(node))
201
+ continue;
202
+ picked.push(node);
203
+ put(node);
204
+ if (picked.length >= want)
205
+ break;
206
+ }
207
+ }
208
+ return Uint32Array.from(picked);
209
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * A rectangle of cells of a raster laid over the x–z plane: cell (col, row) covers x from `col × step` and z from
3
+ * `row × step`, one step wide. `col0`, `row0` are the first cell of the rectangle in the whole raster.
4
+ */
5
+ export interface CodeRegion {
6
+ col0: number;
7
+ row0: number;
8
+ cols: number;
9
+ rows: number;
10
+ /** Cell size in metres. */
11
+ step: number;
12
+ }
13
+ export declare class CodeStamp {
14
+ /** Cells stamped so far (a cell stamped twice counts twice). */
15
+ stamped: number;
16
+ readonly region: CodeRegion;
17
+ /** The cells of the region, `cols × rows` bytes, row `row0` first. Fill it with what lies under the stamps. */
18
+ readonly codes: Uint8Array;
19
+ private readonly seed;
20
+ private counts;
21
+ constructor(region: CodeRegion, codes: Uint8Array, seed: number);
22
+ /** Whether a cell with `hits` covered samples takes the code. */
23
+ private take;
24
+ /**
25
+ * Stamps a polygon: rings of x, z pairs (not closed, either winding), inside by the even-odd rule, so later rings
26
+ * cut holes. `salt` tells shapes apart (two shapes on one cell decide independently). Returns the cells stamped.
27
+ */
28
+ polygon(rings: readonly ArrayLike<number>[], code: number, salt: number): number;
29
+ /** Stamps a disc around (x, z). Returns the cells stamped. */
30
+ disc(x: number, z: number, radius: number, code: number, salt: number): number;
31
+ }