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,31 @@
1
+ import type { Vec3 } from '../base/math.ts';
2
+ /**
3
+ * Smooths a line of unit directions (x, y, z per point). Per round every inner point becomes the normalised mix of a
4
+ * quarter of the point before, half of its own and a quarter of the point after, all from the previous round. The
5
+ * two ends keep their bits. Returns a new array.
6
+ */
7
+ export declare function smoothLine(points: Float64Array, rounds: number): Float64Array;
8
+ /** A profile that never rises along the line: `out[0] = heights[0]`, `out[i] = min(heights[i], out[i − 1] − minDrop)`. */
9
+ export declare function fallingGrade(heights: ArrayLike<number>, minDrop: number): Float64Array;
10
+ /**
11
+ * Metres along a line of unit directions (x, y, z per point) up to each point, along great arcs of a sphere of
12
+ * `radiusM`; `[0] = 0`. Each arc is `2 R · atan(h / √(R² − h²))` of the half chord h (reproducible arc tangent).
13
+ */
14
+ export declare function lineLengths(points: ArrayLike<number>, radiusM: number): Float64Array;
15
+ /**
16
+ * Heights along a line (at `lengthsM`, non-decreasing) changed so that no step rises or falls faster than `maxGrade`:
17
+ * `|g[i+1] − g[i]| ≤ maxGrade · (lengthsM[i+1] − lengthsM[i])`, both ends kept. The middle of the highest profile
18
+ * under the heights' upper cone and the lowest over their lower cone (`up[i] = max_j(h[j] − G·|s_i − s_j|)`,
19
+ * `lo[i] = min_j(h[j] + G·|s_i − s_j|)`), clamped into the cones of the two ends. A profile within the limit comes back
20
+ * unchanged; when the ends alone break the limit, the result is the straight ramp between them.
21
+ */
22
+ export declare function limitGrade(lengthsM: ArrayLike<number>, heights: ArrayLike<number>, maxGrade: number): Float64Array;
23
+ /**
24
+ * The point at `alongM` metres (clamped to the line) of a line of unit directions with lengths from `lineLengths`:
25
+ * `dir = normalise((1 − t)·p[i] + t·p[i+1])`, t linear in metres along piece i; `heading` the unit tangent toward the
26
+ * end, square to `dir`. Writes `out.dir` and `out.heading`.
27
+ */
28
+ export declare function lineAt(points: ArrayLike<number>, lengthsM: ArrayLike<number>, alongM: number, out: {
29
+ dir: Vec3;
30
+ heading: Vec3;
31
+ }): void;
@@ -0,0 +1,183 @@
1
+ // Lines over a sphere as unit directions: smoothing that keeps the ends, a profile that never rises, lengths along
2
+ // great arcs, a profile with a limited grade and the point at a distance along a line.
3
+ import { detAtan } from '../base/trig.js';
4
+ /**
5
+ * Smooths a line of unit directions (x, y, z per point). Per round every inner point becomes the normalised mix of a
6
+ * quarter of the point before, half of its own and a quarter of the point after, all from the previous round. The
7
+ * two ends keep their bits. Returns a new array.
8
+ */
9
+ export function smoothLine(points, rounds) {
10
+ const count = Math.floor(points.length / 3);
11
+ let a = Float64Array.from(points);
12
+ if (count < 3)
13
+ return a;
14
+ let b = Float64Array.from(points);
15
+ for (let r = 0; r < rounds; r++) {
16
+ for (let i = 1; i < count - 1; i++) {
17
+ const p = 3 * i;
18
+ const x = 0.25 * a[p - 3] + 0.5 * a[p] + 0.25 * a[p + 3];
19
+ const y = 0.25 * a[p - 2] + 0.5 * a[p + 1] + 0.25 * a[p + 4];
20
+ const z = 0.25 * a[p - 1] + 0.5 * a[p + 2] + 0.25 * a[p + 5];
21
+ const l = Math.sqrt(x * x + y * y + z * z);
22
+ b[p] = x / l;
23
+ b[p + 1] = y / l;
24
+ b[p + 2] = z / l;
25
+ }
26
+ const t = a;
27
+ a = b;
28
+ b = t;
29
+ }
30
+ return a;
31
+ }
32
+ /** A profile that never rises along the line: `out[0] = heights[0]`, `out[i] = min(heights[i], out[i − 1] − minDrop)`. */
33
+ export function fallingGrade(heights, minDrop) {
34
+ const out = new Float64Array(heights.length);
35
+ if (heights.length === 0)
36
+ return out;
37
+ out[0] = heights[0];
38
+ for (let i = 1; i < heights.length; i++)
39
+ out[i] = Math.min(heights[i], out[i - 1] - minDrop);
40
+ return out;
41
+ }
42
+ /**
43
+ * Metres along a line of unit directions (x, y, z per point) up to each point, along great arcs of a sphere of
44
+ * `radiusM`; `[0] = 0`. Each arc is `2 R · atan(h / √(R² − h²))` of the half chord h (reproducible arc tangent).
45
+ */
46
+ export function lineLengths(points, radiusM) {
47
+ const count = Math.floor(points.length / 3);
48
+ const out = new Float64Array(count);
49
+ const R = radiusM;
50
+ for (let i = 1; i < count; i++) {
51
+ const dx = (points[3 * i] - points[3 * i - 3]) * R;
52
+ const dy = (points[3 * i + 1] - points[3 * i - 2]) * R;
53
+ const dz = (points[3 * i + 2] - points[3 * i - 1]) * R;
54
+ const h = Math.sqrt(dx * dx + dy * dy + dz * dz) / 2;
55
+ out[i] = out[i - 1] + 2 * R * detAtan(h / Math.sqrt(Math.max(0, R * R - h * h)));
56
+ }
57
+ return out;
58
+ }
59
+ /**
60
+ * Heights along a line (at `lengthsM`, non-decreasing) changed so that no step rises or falls faster than `maxGrade`:
61
+ * `|g[i+1] − g[i]| ≤ maxGrade · (lengthsM[i+1] − lengthsM[i])`, both ends kept. The middle of the highest profile
62
+ * under the heights' upper cone and the lowest over their lower cone (`up[i] = max_j(h[j] − G·|s_i − s_j|)`,
63
+ * `lo[i] = min_j(h[j] + G·|s_i − s_j|)`), clamped into the cones of the two ends. A profile within the limit comes back
64
+ * unchanged; when the ends alone break the limit, the result is the straight ramp between them.
65
+ */
66
+ export function limitGrade(lengthsM, heights, maxGrade) {
67
+ const n = heights.length;
68
+ if (lengthsM.length !== n)
69
+ throw new Error(`limitGrade: ${lengthsM.length} lengths for ${n} heights`);
70
+ const out = new Float64Array(n);
71
+ if (n === 0)
72
+ return out;
73
+ const G = maxGrade;
74
+ const s = lengthsM;
75
+ const h0 = heights[0];
76
+ const hn = heights[n - 1];
77
+ const S = s[n - 1] - s[0];
78
+ if (Math.abs(hn - h0) > G * S) {
79
+ for (let i = 0; i < n; i++)
80
+ out[i] = S > 0 ? h0 + ((hn - h0) * (s[i] - s[0])) / S : i === n - 1 ? hn : h0;
81
+ return out;
82
+ }
83
+ const up = new Float64Array(n);
84
+ const lo = new Float64Array(n);
85
+ up[0] = heights[0];
86
+ lo[0] = heights[0];
87
+ for (let i = 1; i < n; i++) {
88
+ const d = G * (s[i] - s[i - 1]);
89
+ up[i] = Math.max(heights[i], up[i - 1] - d);
90
+ lo[i] = Math.min(heights[i], lo[i - 1] + d);
91
+ }
92
+ for (let i = n - 2; i >= 0; i--) {
93
+ const d = G * (s[i + 1] - s[i]);
94
+ up[i] = Math.max(up[i], up[i + 1] - d);
95
+ lo[i] = Math.min(lo[i], lo[i + 1] + d);
96
+ }
97
+ for (let i = 0; i < n; i++) {
98
+ const a = s[i] - s[0];
99
+ const b = s[n - 1] - s[i];
100
+ const floor = Math.max(h0 - G * a, hn - G * b);
101
+ const ceil = Math.min(h0 + G * a, hn + G * b);
102
+ const m = (up[i] + lo[i]) / 2;
103
+ out[i] = m < floor ? floor : m > ceil ? ceil : m;
104
+ }
105
+ out[0] = h0;
106
+ out[n - 1] = hn;
107
+ return out;
108
+ }
109
+ /**
110
+ * The point at `alongM` metres (clamped to the line) of a line of unit directions with lengths from `lineLengths`:
111
+ * `dir = normalise((1 − t)·p[i] + t·p[i+1])`, t linear in metres along piece i; `heading` the unit tangent toward the
112
+ * end, square to `dir`. Writes `out.dir` and `out.heading`.
113
+ */
114
+ export function lineAt(points, lengthsM, alongM, out) {
115
+ const n = lengthsM.length;
116
+ if (n === 0 || points.length < 3 * n)
117
+ throw new Error(`lineAt: ${n} lengths for ${Math.floor(points.length / 3)} points`);
118
+ const s0 = lengthsM[0];
119
+ const s1 = lengthsM[n - 1];
120
+ const s = alongM < s0 ? s0 : alongM > s1 ? s1 : alongM;
121
+ // The piece that holds s: the last i with lengths[i] ≤ s, at most n − 2.
122
+ let lo = 0;
123
+ let hi = Math.max(0, n - 2);
124
+ while (lo < hi) {
125
+ const mid = (lo + hi + 1) >> 1;
126
+ if (lengthsM[mid] <= s)
127
+ lo = mid;
128
+ else
129
+ hi = mid - 1;
130
+ }
131
+ const i = lo;
132
+ const j = Math.min(n - 1, i + 1);
133
+ const len = lengthsM[j] - lengthsM[i];
134
+ const t = len > 0 ? (s - lengthsM[i]) / len : 0;
135
+ const x = (1 - t) * points[3 * i] + t * points[3 * j];
136
+ const y = (1 - t) * points[3 * i + 1] + t * points[3 * j + 1];
137
+ const z = (1 - t) * points[3 * i + 2] + t * points[3 * j + 2];
138
+ const l = Math.sqrt(x * x + y * y + z * z) || 1;
139
+ const d = out.dir;
140
+ d[0] = x / l;
141
+ d[1] = y / l;
142
+ d[2] = z / l;
143
+ // Tangent: the nearest piece with a length, toward the end, made square to dir.
144
+ let a = i;
145
+ let b = j;
146
+ if (!(len > 0)) {
147
+ for (let k = i; k + 1 < n; k++) {
148
+ if (lengthsM[k + 1] > lengthsM[k]) {
149
+ a = k;
150
+ b = k + 1;
151
+ break;
152
+ }
153
+ }
154
+ if (!(lengthsM[b] > lengthsM[a])) {
155
+ for (let k = i; k > 0; k--) {
156
+ if (lengthsM[k] > lengthsM[k - 1]) {
157
+ a = k - 1;
158
+ b = k;
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ }
164
+ let ex = points[3 * b] - points[3 * a];
165
+ let ey = points[3 * b + 1] - points[3 * a + 1];
166
+ let ez = points[3 * b + 2] - points[3 * a + 2];
167
+ const dot = ex * d[0] + ey * d[1] + ez * d[2];
168
+ ex -= dot * d[0];
169
+ ey -= dot * d[1];
170
+ ez -= dot * d[2];
171
+ const el = Math.sqrt(ex * ex + ey * ey + ez * ez);
172
+ const h = out.heading;
173
+ if (el > 0) {
174
+ h[0] = ex / el;
175
+ h[1] = ey / el;
176
+ h[2] = ez / el;
177
+ }
178
+ else {
179
+ h[0] = 0;
180
+ h[1] = 0;
181
+ h[2] = 0;
182
+ }
183
+ }
@@ -0,0 +1,40 @@
1
+ /** One plot: a rectangle on the plane of the lines. */
2
+ export interface Plot {
3
+ /** Index in the result. */
4
+ id: number;
5
+ /** Centre. */
6
+ x: number;
7
+ z: number;
8
+ /** Unit vector from the plot toward its line (its front looks there). */
9
+ hx: number;
10
+ hz: number;
11
+ /** Size along the line and away from it, metres. */
12
+ widthM: number;
13
+ depthM: number;
14
+ /** Index of the line in the input. */
15
+ line: number;
16
+ }
17
+ /** Options of `plotsAlong`. */
18
+ export interface PlotOptions {
19
+ /** Range of the width along the line, metres. */
20
+ frontM: readonly [number, number];
21
+ /** Range of the depth away from the line, metres. */
22
+ depthM: readonly [number, number];
23
+ /** Distance of the middle of a front edge from the centre line, metres; no line comes nearer to a plot. */
24
+ setbackM: number;
25
+ /** Least distance between two plots, metres. */
26
+ gapM: number;
27
+ seed: number;
28
+ /** True where no plot may stand; asked at the centre and the four corners. */
29
+ blocked?: (x: number, z: number) => boolean;
30
+ }
31
+ /**
32
+ * Plots along `lines` (each a flat list of x z pairs on a plane, metres). Lines in order; per line the left side, then
33
+ * the right (left of the direction of travel: (−dz, dx)); a walk from the start of the line. Width and depth of the
34
+ * next plot come from `hashInts(seed, line, side, k)` (k counts the tries on that side) within `frontM` and `depthM`.
35
+ * The middle of its front edge lies `setbackM` from the centre line at the middle of its width, and the rectangle is
36
+ * squared to the line's direction there. It is kept when it is at least `gapM` from every plot kept so far, no line
37
+ * passes nearer than `setbackM` − 1 mm to it, and `blocked` is false at its centre and four corners; the walk then
38
+ * moves on by its width plus `gapM`, else by 2 m. At most 4096 plots.
39
+ */
40
+ export declare function plotsAlong(lines: readonly ArrayLike<number>[], o: PlotOptions): Plot[];
@@ -0,0 +1,282 @@
1
+ // Plots along lines on a plane: rectangles whose front faces a line at a setback, laid one after the other along
2
+ // each side of every line. What a line and a plot stand for is up to the caller. Pure: the lines and the seed decide
3
+ // the result; arithmetic and `Math.sqrt/floor/abs/min/max` only.
4
+ import { hashInts } from '../gen-core/hash.js';
5
+ /** At most this many plots. */
6
+ const MAX_PLOTS = 4096;
7
+ /** A dropped plot moves the walk on by this much, metres. */
8
+ const DROP_STEP_M = 2;
9
+ /** Tolerance of the setback test, metres. */
10
+ const SETBACK_TOLERANCE_M = 0.001;
11
+ function walkOf(points) {
12
+ const n = Math.floor(points.length / 2);
13
+ const along = new Float64Array(Math.max(1, n));
14
+ for (let i = 1; i < n; i++) {
15
+ const dx = points[2 * i] - points[2 * i - 2];
16
+ const dz = points[2 * i + 1] - points[2 * i - 1];
17
+ along[i] = along[i - 1] + Math.sqrt(dx * dx + dz * dz);
18
+ }
19
+ return { points, along, length: n > 0 ? along[n - 1] : 0 };
20
+ }
21
+ /** Point and unit direction of a walk at `t` metres along it. */
22
+ function walkAt(w, t, out) {
23
+ const n = w.along.length;
24
+ let i = 0;
25
+ while (i + 2 < n && w.along[i + 1] < t)
26
+ i++;
27
+ const ax = w.points[2 * i];
28
+ const az = w.points[2 * i + 1];
29
+ const bx = w.points[2 * i + 2];
30
+ const bz = w.points[2 * i + 3];
31
+ const dx = bx - ax;
32
+ const dz = bz - az;
33
+ const l = Math.sqrt(dx * dx + dz * dz) || 1;
34
+ const f = (t - w.along[i]) / l;
35
+ out[0] = ax + dx * f;
36
+ out[1] = az + dz * f;
37
+ out[2] = dx / l;
38
+ out[3] = dz / l;
39
+ }
40
+ /** Corners of a plot: centre (cx, cz), axis u along its width, v along its depth, half sizes. */
41
+ function cornersOf(cx, cz, ux, uz, hw, hd, out) {
42
+ const vx = -uz;
43
+ const vz = ux;
44
+ out[0] = cx - ux * hw - vx * hd;
45
+ out[1] = cz - uz * hw - vz * hd;
46
+ out[2] = cx + ux * hw - vx * hd;
47
+ out[3] = cz + uz * hw - vz * hd;
48
+ out[4] = cx + ux * hw + vx * hd;
49
+ out[5] = cz + uz * hw + vz * hd;
50
+ out[6] = cx - ux * hw + vx * hd;
51
+ out[7] = cz - uz * hw + vz * hd;
52
+ }
53
+ /** Whether the corners of two rectangles are at least `gap` apart along one of their four axes (separating axes). */
54
+ function apart(a, b, gap) {
55
+ for (const r of [a, b]) {
56
+ for (let e = 0; e < 2; e++) {
57
+ const ax = r[2 * e + 2] - r[2 * e];
58
+ const az = r[2 * e + 3] - r[2 * e + 1];
59
+ const l = Math.sqrt(ax * ax + az * az);
60
+ if (!(l > 0))
61
+ continue;
62
+ const nx = ax / l;
63
+ const nz = az / l;
64
+ let a0 = Infinity;
65
+ let a1 = -Infinity;
66
+ let b0 = Infinity;
67
+ let b1 = -Infinity;
68
+ for (let k = 0; k < 4; k++) {
69
+ const pa = a[2 * k] * nx + a[2 * k + 1] * nz;
70
+ const pb = b[2 * k] * nx + b[2 * k + 1] * nz;
71
+ a0 = Math.min(a0, pa);
72
+ a1 = Math.max(a1, pa);
73
+ b0 = Math.min(b0, pb);
74
+ b1 = Math.max(b1, pb);
75
+ }
76
+ if (b0 - a1 >= gap || a0 - b1 >= gap)
77
+ return true;
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+ /** Squared distance from point (px, pz) to segment (a, b). */
83
+ function pointSegment2(px, pz, ax, az, bx, bz) {
84
+ const dx = bx - ax;
85
+ const dz = bz - az;
86
+ const l2 = dx * dx + dz * dz;
87
+ let t = l2 > 0 ? ((px - ax) * dx + (pz - az) * dz) / l2 : 0;
88
+ t = Math.min(1, Math.max(0, t));
89
+ const ex = ax + dx * t - px;
90
+ const ez = az + dz * t - pz;
91
+ return ex * ex + ez * ez;
92
+ }
93
+ /** Whether segments (a, b) and (c, d) cross or touch. */
94
+ function segmentsMeet(ax, az, bx, bz, cx, cz, dx, dz) {
95
+ const o = (px, pz, qx, qz, rx, rz) => (qx - px) * (rz - pz) - (qz - pz) * (rx - px);
96
+ const o1 = o(ax, az, bx, bz, cx, cz);
97
+ const o2 = o(ax, az, bx, bz, dx, dz);
98
+ const o3 = o(cx, cz, dx, dz, ax, az);
99
+ const o4 = o(cx, cz, dx, dz, bx, bz);
100
+ return o1 * o2 <= 0 && o3 * o4 <= 0;
101
+ }
102
+ /** Whether point (px, pz) lies inside the rectangle of corners `c` (in order round it). */
103
+ function insideRect(c, px, pz) {
104
+ let sign = 0;
105
+ for (let k = 0; k < 4; k++) {
106
+ const ax = c[2 * k];
107
+ const az = c[2 * k + 1];
108
+ const bx = c[(2 * k + 2) % 8];
109
+ const bz = c[(2 * k + 3) % 8];
110
+ const cr = (bx - ax) * (pz - az) - (bz - az) * (px - ax);
111
+ const s = cr > 0 ? 1 : cr < 0 ? -1 : 0;
112
+ if (s === 0)
113
+ continue;
114
+ if (sign === 0)
115
+ sign = s;
116
+ else if (s !== sign)
117
+ return false;
118
+ }
119
+ return true;
120
+ }
121
+ /** Squared distance between segment (a, b) and the rectangle of corners `c`. */
122
+ function segmentRect2(ax, az, bx, bz, c) {
123
+ if (insideRect(c, ax, az) || insideRect(c, bx, bz))
124
+ return 0;
125
+ let best = Infinity;
126
+ for (let k = 0; k < 4; k++) {
127
+ const px = c[2 * k];
128
+ const pz = c[2 * k + 1];
129
+ const qx = c[(2 * k + 2) % 8];
130
+ const qz = c[(2 * k + 3) % 8];
131
+ if (segmentsMeet(ax, az, bx, bz, px, pz, qx, qz))
132
+ return 0;
133
+ best = Math.min(best, pointSegment2(px, pz, ax, az, bx, bz), pointSegment2(ax, az, px, pz, qx, qz), pointSegment2(bx, bz, px, pz, qx, qz));
134
+ }
135
+ return best;
136
+ }
137
+ /** A square bucket grid of items with boxes. */
138
+ class Buckets {
139
+ cells = new Map();
140
+ sizeM;
141
+ constructor(sizeM) {
142
+ this.sizeM = sizeM;
143
+ }
144
+ add(item, x0, z0, x1, z1) {
145
+ const s = this.sizeM;
146
+ for (let i = Math.floor(x0 / s); i <= Math.floor(x1 / s); i++) {
147
+ for (let j = Math.floor(z0 / s); j <= Math.floor(z1 / s); j++) {
148
+ const key = `${i},${j}`;
149
+ const list = this.cells.get(key);
150
+ if (list)
151
+ list.push(item);
152
+ else
153
+ this.cells.set(key, [item]);
154
+ }
155
+ }
156
+ }
157
+ /** Items whose boxes may touch the box; each once, ascending. */
158
+ near(x0, z0, x1, z1, out) {
159
+ out.length = 0;
160
+ const s = this.sizeM;
161
+ for (let i = Math.floor(x0 / s); i <= Math.floor(x1 / s); i++) {
162
+ for (let j = Math.floor(z0 / s); j <= Math.floor(z1 / s); j++) {
163
+ const list = this.cells.get(`${i},${j}`);
164
+ if (list)
165
+ for (const v of list)
166
+ out.push(v);
167
+ }
168
+ }
169
+ out.sort((a, b) => a - b);
170
+ let k = 0;
171
+ for (let i = 0; i < out.length; i++)
172
+ if (i === 0 || out[i] !== out[i - 1])
173
+ out[k++] = out[i];
174
+ out.length = k;
175
+ return out;
176
+ }
177
+ }
178
+ /**
179
+ * Plots along `lines` (each a flat list of x z pairs on a plane, metres). Lines in order; per line the left side, then
180
+ * the right (left of the direction of travel: (−dz, dx)); a walk from the start of the line. Width and depth of the
181
+ * next plot come from `hashInts(seed, line, side, k)` (k counts the tries on that side) within `frontM` and `depthM`.
182
+ * The middle of its front edge lies `setbackM` from the centre line at the middle of its width, and the rectangle is
183
+ * squared to the line's direction there. It is kept when it is at least `gapM` from every plot kept so far, no line
184
+ * passes nearer than `setbackM` − 1 mm to it, and `blocked` is false at its centre and four corners; the walk then
185
+ * moves on by its width plus `gapM`, else by 2 m. At most 4096 plots.
186
+ */
187
+ export function plotsAlong(lines, o) {
188
+ const walks = lines.map(walkOf);
189
+ const maxDepth = Math.max(o.depthM[0], o.depthM[1]);
190
+ const maxFront = Math.max(o.frontM[0], o.frontM[1]);
191
+ const bucketM = Math.max(8, maxFront + maxDepth);
192
+ // Segments of every line in a bucket grid.
193
+ const segs = [];
194
+ const segBuckets = new Buckets(bucketM);
195
+ for (const w of walks) {
196
+ const n = w.along.length;
197
+ for (let i = 0; i + 1 < n; i++) {
198
+ const ax = w.points[2 * i];
199
+ const az = w.points[2 * i + 1];
200
+ const bx = w.points[2 * i + 2];
201
+ const bz = w.points[2 * i + 3];
202
+ segBuckets.add(segs.length / 4, Math.min(ax, bx), Math.min(az, bz), Math.max(ax, bx), Math.max(az, bz));
203
+ segs.push(ax, az, bx, bz);
204
+ }
205
+ }
206
+ const plots = [];
207
+ const corners = [];
208
+ const plotBuckets = new Buckets(bucketM);
209
+ const at = new Float64Array(4);
210
+ const c = new Float64Array(8);
211
+ const near = [];
212
+ const limit2 = Math.max(0, o.setbackM - SETBACK_TOLERANCE_M) ** 2;
213
+ for (let line = 0; line < walks.length && plots.length < MAX_PLOTS; line++) {
214
+ const w = walks[line];
215
+ if (w.length <= 0)
216
+ continue;
217
+ for (let side = 0; side < 2 && plots.length < MAX_PLOTS; side++) {
218
+ const sign = side === 0 ? 1 : -1;
219
+ let t = 0;
220
+ for (let k = 0; plots.length < MAX_PLOTS; k++) {
221
+ const h = hashInts(o.seed, line, side, k) >>> 0;
222
+ const width = o.frontM[0] + (o.frontM[1] - o.frontM[0]) * ((h & 0xffff) / 65535);
223
+ const depth = o.depthM[0] + (o.depthM[1] - o.depthM[0]) * ((h >>> 16) / 65535);
224
+ if (t + width > w.length)
225
+ break;
226
+ walkAt(w, t + width / 2, at);
227
+ const ux = at[2];
228
+ const uz = at[3];
229
+ // Outward normal of this side.
230
+ const nx = -uz * sign;
231
+ const nz = ux * sign;
232
+ const cx = at[0] + nx * (o.setbackM + depth / 2);
233
+ const cz = at[1] + nz * (o.setbackM + depth / 2);
234
+ cornersOf(cx, cz, ux, uz, width / 2, depth / 2, c);
235
+ let x0 = Infinity;
236
+ let z0 = Infinity;
237
+ let x1 = -Infinity;
238
+ let z1 = -Infinity;
239
+ for (let q = 0; q < 4; q++) {
240
+ x0 = Math.min(x0, c[2 * q]);
241
+ x1 = Math.max(x1, c[2 * q]);
242
+ z0 = Math.min(z0, c[2 * q + 1]);
243
+ z1 = Math.max(z1, c[2 * q + 1]);
244
+ }
245
+ let ok = true;
246
+ if (o.blocked) {
247
+ ok = !o.blocked(cx, cz);
248
+ for (let q = 0; q < 4 && ok; q++)
249
+ ok = !o.blocked(c[2 * q], c[2 * q + 1]);
250
+ }
251
+ if (ok) {
252
+ const m = o.setbackM;
253
+ for (const s of segBuckets.near(x0 - m, z0 - m, x1 + m, z1 + m, near)) {
254
+ if (segmentRect2(segs[4 * s], segs[4 * s + 1], segs[4 * s + 2], segs[4 * s + 3], c) < limit2) {
255
+ ok = false;
256
+ break;
257
+ }
258
+ }
259
+ }
260
+ if (ok) {
261
+ const g = o.gapM;
262
+ for (const p of plotBuckets.near(x0 - g, z0 - g, x1 + g, z1 + g, near)) {
263
+ if (!apart(corners[p], c, g)) {
264
+ ok = false;
265
+ break;
266
+ }
267
+ }
268
+ }
269
+ if (!ok) {
270
+ t += DROP_STEP_M;
271
+ continue;
272
+ }
273
+ const id = plots.length;
274
+ plots.push({ id, x: cx, z: cz, hx: -nx, hz: -nz, widthM: width, depthM: depth, line });
275
+ corners.push(Float64Array.from(c));
276
+ plotBuckets.add(id, x0, z0, x1, z1);
277
+ t += width + o.gapM;
278
+ }
279
+ }
280
+ }
281
+ return plots;
282
+ }
@@ -0,0 +1,55 @@
1
+ import type { SphereGrid } from './grid.ts';
2
+ /** Cost of the step from node a to its neighbour b: finite and > 0, or Infinity = the step is closed. */
3
+ export type StepCost = (a: number, b: number) => number;
4
+ /**
5
+ * Per-node arrays of one grid, reused between calls of `routeGrid` (a stamp per call, no clearing). Opaque: make it
6
+ * with `routeScratch` and pass it back.
7
+ */
8
+ export interface RouteScratch {
9
+ /** Nodes of the grid it was made for. */
10
+ readonly count: number;
11
+ }
12
+ /** Scratch arrays for `routeGrid` on grid `g` (about 20 bytes per node). */
13
+ export declare function routeScratch(g: SphereGrid): RouteScratch;
14
+ /**
15
+ * Nodes from `from` to `to` inclusive along the least total cost; null if `to` is unreachable or not settled within
16
+ * `maxNodes` settled nodes. `from === to` gives `[from]`.
17
+ */
18
+ export declare function routeGrid(g: SphereGrid, o: {
19
+ from: number;
20
+ to: number;
21
+ cost: StepCost;
22
+ maxNodes: number;
23
+ scratch?: RouteScratch;
24
+ }): Uint32Array | null;
25
+ /** Per node: index into `sources` of the source that reaches it most cheaply (−1 none), that cost, the node it came from (−1 at a source). */
26
+ export interface RouteRegions {
27
+ owner: Int32Array;
28
+ cost: Float64Array;
29
+ prev: Int32Array;
30
+ }
31
+ /**
32
+ * The regions of many sources: one search from all of them at once. A node no source reaches within `maxNodes`
33
+ * settled nodes has owner −1, cost Infinity and prev −1. A node listed twice as a source belongs to its first entry.
34
+ */
35
+ export declare function routeRegions(g: SphereGrid, o: {
36
+ sources: ArrayLike<number>;
37
+ cost: StepCost;
38
+ maxNodes: number;
39
+ }): RouteRegions;
40
+ /**
41
+ * Per pair of sources whose regions touch (a < b, sorted by a then b) the cheapest step between the two regions:
42
+ * cost = r.cost[nodeA] + cost(nodeA, nodeB) + r.cost[nodeB], nodeA in the region of a, nodeB in that of b.
43
+ */
44
+ export interface RegionLinks {
45
+ a: Uint32Array;
46
+ b: Uint32Array;
47
+ cost: Float64Array;
48
+ nodeA: Uint32Array;
49
+ nodeB: Uint32Array;
50
+ }
51
+ /**
52
+ * The links between the regions of `routeRegions`: every step from a node of region a to a neighbour of region b
53
+ * (a < b) is a candidate; per pair the least cost wins, ties the first in node order and then neighbour order.
54
+ */
55
+ export declare function regionLinks(g: SphereGrid, r: RouteRegions, cost: StepCost): RegionLinks;