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.
- package/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,817 @@
|
|
|
1
|
+
// A strip laid along a broken line on the base surface (a plane, or a sphere seen from its centre): data and the
|
|
2
|
+
// height function a cell generator calls to cut or fill the ground under it. The mesh of the strip is gen-mesh's
|
|
3
|
+
// `stripMesh`; what it stands for is up to the content.
|
|
4
|
+
//
|
|
5
|
+
// - A line is a list of points on the base surface with a grade per point (the height of the section's zero above
|
|
6
|
+
// the base surface) and a half-width per point. A profile gives the section across the line: pairs (across, up)
|
|
7
|
+
// from left to right, across in half-widths. Points beyond ±1 are a hem hanging from the edge point.
|
|
8
|
+
// - `stripNet` turns the input into stations: centre, left edge and right edge of the strip at every point, with the
|
|
9
|
+
// grade, a camber factor and the metres along the line. Between two stations the centre and both edges are straight
|
|
10
|
+
// ways (a segment on the plane, a great arc on the sphere), so every station pair is one piece of the strip.
|
|
11
|
+
// - At an inner point the edges are mitred: on the bisector of the two segments, at `w / max(cos, 0.5)` from the
|
|
12
|
+
// centre. A free end, and a node that holds one line only, ends square.
|
|
13
|
+
// - Lines that meet at a node are ordered around it by a pseudo-angle; neighbours meet at one corner each, where
|
|
14
|
+
// their edges cross (at most three times the larger half-width from the node). A line's last station there is flat
|
|
15
|
+
// at the node's height and reaches from the node to its two corners, and one more station stands where the line is
|
|
16
|
+
// as far from the node as its farther corner: the camber returns between the two.
|
|
17
|
+
// - The height function inverts the stations: for a point it finds the share t along each piece and the share a
|
|
18
|
+
// across it, and blends the ground toward the section over the shoulder.
|
|
19
|
+
//
|
|
20
|
+
// Everything is arithmetic and `Math.sqrt` (with the reproducible arc tangent of base for lengths on the sphere): no
|
|
21
|
+
// seed, no clock, no shared state. The output is a function of the input alone.
|
|
22
|
+
import { detAtan } from '../base/trig.js';
|
|
23
|
+
import { directionTangents } from './cube-sphere.js';
|
|
24
|
+
/** Numbers per station: centre xyz, left edge xyz, right edge xyz, grade, camber factor, metres along the line. */
|
|
25
|
+
export const STRIP_STATION_FLOATS = 12;
|
|
26
|
+
/** Height of a section above the grade at across `a` (half-widths), linear between its points, the hem excluded. */
|
|
27
|
+
export function stripUp(profile, a) {
|
|
28
|
+
const s = profile.section;
|
|
29
|
+
const x = a < -1 ? -1 : a > 1 ? 1 : a;
|
|
30
|
+
let prevA = NaN;
|
|
31
|
+
let prevU = NaN;
|
|
32
|
+
for (let i = 0; i < s.length; i += 2) {
|
|
33
|
+
const sa = s[i];
|
|
34
|
+
const su = s[i + 1];
|
|
35
|
+
if (sa < -1)
|
|
36
|
+
continue;
|
|
37
|
+
if (sa >= x) {
|
|
38
|
+
if (sa === x || prevA !== prevA)
|
|
39
|
+
return su;
|
|
40
|
+
return prevU + ((su - prevU) * (x - prevA)) / (sa - prevA);
|
|
41
|
+
}
|
|
42
|
+
prevA = sa;
|
|
43
|
+
prevU = su;
|
|
44
|
+
}
|
|
45
|
+
return prevU;
|
|
46
|
+
}
|
|
47
|
+
/** Length of a line in metres (along the centre, the same measure as `alongM`). */
|
|
48
|
+
export function stripLength(net, line) {
|
|
49
|
+
const l = net.lines[line];
|
|
50
|
+
if (!l)
|
|
51
|
+
throw new Error(`stripLength: no line ${line}`);
|
|
52
|
+
return l.stations[(l.count - 1) * STRIP_STATION_FLOATS + 11];
|
|
53
|
+
}
|
|
54
|
+
// --- Making the net -------------------------------------------------------------------------------------------------
|
|
55
|
+
function norm3(x, y, z) {
|
|
56
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
57
|
+
}
|
|
58
|
+
/** Pseudo-angle 0 … 4 of (p, q), growing with the angle from (1, 0) toward (0, 1). */
|
|
59
|
+
function pseudoAngle(p, q) {
|
|
60
|
+
const s = Math.abs(p) + Math.abs(q);
|
|
61
|
+
return q >= 0 ? 1 - p / s : 3 + p / s;
|
|
62
|
+
}
|
|
63
|
+
/** A point put on the base surface. */
|
|
64
|
+
function onSurface(b, x, y, z, out, at) {
|
|
65
|
+
if (b.sphere) {
|
|
66
|
+
const l = norm3(x, y, z);
|
|
67
|
+
out[at] = (x / l) * b.R;
|
|
68
|
+
out[at + 1] = (y / l) * b.R;
|
|
69
|
+
out[at + 2] = (z / l) * b.R;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
out[at] = x;
|
|
73
|
+
out[at + 1] = 0;
|
|
74
|
+
out[at + 2] = z;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Unit up at a point of the base surface. */
|
|
78
|
+
function upOf(b, p, at) {
|
|
79
|
+
if (!b.sphere)
|
|
80
|
+
return [0, 1, 0];
|
|
81
|
+
const l = norm3(p[at], p[at + 1], p[at + 2]);
|
|
82
|
+
return [p[at] / l, p[at + 1] / l, p[at + 2] / l];
|
|
83
|
+
}
|
|
84
|
+
/** Unit direction along the surface at point `a` toward point `c` (offsets into `p`). */
|
|
85
|
+
function towards(b, p, a, c) {
|
|
86
|
+
let x = p[c] - p[a];
|
|
87
|
+
let y = p[c + 1] - p[a + 1];
|
|
88
|
+
let z = p[c + 2] - p[a + 2];
|
|
89
|
+
const u = upOf(b, p, a);
|
|
90
|
+
const d = x * u[0] + y * u[1] + z * u[2];
|
|
91
|
+
x -= d * u[0];
|
|
92
|
+
y -= d * u[1];
|
|
93
|
+
z -= d * u[2];
|
|
94
|
+
const l = norm3(x, y, z);
|
|
95
|
+
if (!(l > 0))
|
|
96
|
+
throw new Error('stripNet: two points of a line coincide');
|
|
97
|
+
return [x / l, y / l, z / l];
|
|
98
|
+
}
|
|
99
|
+
/** Length of the straight way between two points of the base surface. */
|
|
100
|
+
function wayLength(b, p, a, c) {
|
|
101
|
+
const chord = norm3(p[c] - p[a], p[c + 1] - p[a + 1], p[c + 2] - p[a + 2]);
|
|
102
|
+
if (!b.sphere)
|
|
103
|
+
return chord;
|
|
104
|
+
const h = chord / 2;
|
|
105
|
+
return 2 * b.R * detAtan(h / Math.sqrt(Math.max(0, b.R * b.R - h * h)));
|
|
106
|
+
}
|
|
107
|
+
export function stripNet(input) {
|
|
108
|
+
const R = input.radiusM;
|
|
109
|
+
if (!(R >= 0) || !Number.isFinite(R))
|
|
110
|
+
throw new Error(`stripNet: radiusM must be 0 or positive, got ${R}`);
|
|
111
|
+
const b = { sphere: R > 0, R };
|
|
112
|
+
const profiles = input.profiles.map((pr, i) => {
|
|
113
|
+
const s = pr.section;
|
|
114
|
+
if (s.length < 4 || s.length % 2 !== 0)
|
|
115
|
+
throw new Error(`stripNet: profile ${i}: section needs pairs, at least two`);
|
|
116
|
+
let hasL = false;
|
|
117
|
+
let hasR = false;
|
|
118
|
+
for (let k = 0; k < s.length; k += 2) {
|
|
119
|
+
if (!Number.isFinite(s[k]) || !Number.isFinite(s[k + 1]))
|
|
120
|
+
throw new Error(`stripNet: profile ${i}: section holds a number that is not finite`);
|
|
121
|
+
if (k > 0 && s[k] < s[k - 2])
|
|
122
|
+
throw new Error(`stripNet: profile ${i}: across must not decrease`);
|
|
123
|
+
if (s[k] === -1)
|
|
124
|
+
hasL = true;
|
|
125
|
+
if (s[k] === 1)
|
|
126
|
+
hasR = true;
|
|
127
|
+
}
|
|
128
|
+
if (!hasL || !hasR)
|
|
129
|
+
throw new Error(`stripNet: profile ${i}: section must hold across −1 and 1`);
|
|
130
|
+
if (!(pr.shoulderM >= 0) || !Number.isFinite(pr.shoulderM))
|
|
131
|
+
throw new Error(`stripNet: profile ${i}: shoulderM must be 0 or positive`);
|
|
132
|
+
if (!Number.isFinite(pr.bedM))
|
|
133
|
+
throw new Error(`stripNet: profile ${i}: bedM must be finite`);
|
|
134
|
+
return { section: Array.from(s), shoulderM: pr.shoulderM, bedM: pr.bedM };
|
|
135
|
+
});
|
|
136
|
+
const nodes = (input.nodes ?? []).map((n, i) => {
|
|
137
|
+
if (!n.point.every(Number.isFinite) || !Number.isFinite(n.heightM))
|
|
138
|
+
throw new Error(`stripNet: node ${i} is not finite`);
|
|
139
|
+
const p = [0, 0, 0];
|
|
140
|
+
onSurface(b, n.point[0], n.point[1], n.point[2], p, 0);
|
|
141
|
+
return { p, h: n.heightM };
|
|
142
|
+
});
|
|
143
|
+
// Points, grades and half-widths per line, the ends taken from their nodes.
|
|
144
|
+
const pts = [];
|
|
145
|
+
const grades = [];
|
|
146
|
+
const widths = [];
|
|
147
|
+
input.lines.forEach((ln, li) => {
|
|
148
|
+
const n = ln.points.length / 3;
|
|
149
|
+
if (!Number.isInteger(n) || n < 2)
|
|
150
|
+
throw new Error(`stripNet: line ${li} needs at least two points, x y z each`);
|
|
151
|
+
if (ln.heights.length !== n)
|
|
152
|
+
throw new Error(`stripNet: line ${li}: one height per point`);
|
|
153
|
+
if (typeof ln.halfWidths !== 'number' && ln.halfWidths.length !== n)
|
|
154
|
+
throw new Error(`stripNet: line ${li}: one half-width per point`);
|
|
155
|
+
if (!profiles[ln.profile])
|
|
156
|
+
throw new Error(`stripNet: line ${li}: no profile ${ln.profile}`);
|
|
157
|
+
for (const end of [ln.from, ln.to])
|
|
158
|
+
if (end !== undefined && !nodes[end])
|
|
159
|
+
throw new Error(`stripNet: line ${li}: no node ${end}`);
|
|
160
|
+
if (ln.from !== undefined && ln.from === ln.to)
|
|
161
|
+
throw new Error(`stripNet: line ${li} starts and ends at one node`);
|
|
162
|
+
const p = new Array(n * 3);
|
|
163
|
+
const g = new Array(n);
|
|
164
|
+
const w = new Array(n);
|
|
165
|
+
for (let k = 0; k < n; k++) {
|
|
166
|
+
onSurface(b, ln.points[k * 3], ln.points[k * 3 + 1], ln.points[k * 3 + 2], p, k * 3);
|
|
167
|
+
g[k] = ln.heights[k];
|
|
168
|
+
w[k] = typeof ln.halfWidths === 'number' ? ln.halfWidths : ln.halfWidths[k];
|
|
169
|
+
if (!Number.isFinite(p[k * 3]) || !Number.isFinite(p[k * 3 + 1]) || !Number.isFinite(p[k * 3 + 2]) || !Number.isFinite(g[k]))
|
|
170
|
+
throw new Error(`stripNet: line ${li}: point ${k} is not finite`);
|
|
171
|
+
if (!(w[k] > 0) || !Number.isFinite(w[k]))
|
|
172
|
+
throw new Error(`stripNet: line ${li}: half-width ${k} must be positive`);
|
|
173
|
+
}
|
|
174
|
+
if (ln.from !== undefined) {
|
|
175
|
+
const nd = nodes[ln.from];
|
|
176
|
+
p[0] = nd.p[0];
|
|
177
|
+
p[1] = nd.p[1];
|
|
178
|
+
p[2] = nd.p[2];
|
|
179
|
+
g[0] = nd.h;
|
|
180
|
+
}
|
|
181
|
+
if (ln.to !== undefined) {
|
|
182
|
+
const nd = nodes[ln.to];
|
|
183
|
+
p[(n - 1) * 3] = nd.p[0];
|
|
184
|
+
p[(n - 1) * 3 + 1] = nd.p[1];
|
|
185
|
+
p[(n - 1) * 3 + 2] = nd.p[2];
|
|
186
|
+
g[n - 1] = nd.h;
|
|
187
|
+
}
|
|
188
|
+
for (let k = 0; k + 1 < n; k++)
|
|
189
|
+
if (p[k * 3] === p[k * 3 + 3] && p[k * 3 + 1] === p[k * 3 + 4] && p[k * 3 + 2] === p[k * 3 + 5])
|
|
190
|
+
throw new Error(`stripNet: line ${li}: points ${k} and ${k + 1} coincide`);
|
|
191
|
+
pts.push(p);
|
|
192
|
+
grades.push(g);
|
|
193
|
+
widths.push(w);
|
|
194
|
+
});
|
|
195
|
+
// Corners of the nodes: per line end that sits at a node of two lines or more, its left and right corner.
|
|
196
|
+
const endCorner = input.lines.map(() => [null, null]);
|
|
197
|
+
for (let ni = 0; ni < nodes.length; ni++) {
|
|
198
|
+
const nd = nodes[ni];
|
|
199
|
+
const inc = [];
|
|
200
|
+
let e1 = [0, 0, 1];
|
|
201
|
+
let e2 = [1, 0, 0];
|
|
202
|
+
if (b.sphere) {
|
|
203
|
+
const u = upOf(b, nd.p, 0);
|
|
204
|
+
const t = directionTangents(u);
|
|
205
|
+
e1 = t.t1;
|
|
206
|
+
e2 = t.t2;
|
|
207
|
+
}
|
|
208
|
+
input.lines.forEach((ln, li) => {
|
|
209
|
+
for (const end of [0, 1]) {
|
|
210
|
+
if ((end === 0 ? ln.from : ln.to) !== ni)
|
|
211
|
+
continue;
|
|
212
|
+
const p = pts[li];
|
|
213
|
+
const n = p.length / 3;
|
|
214
|
+
const at = end === 0 ? 0 : (n - 1) * 3;
|
|
215
|
+
const next = end === 0 ? 3 : (n - 2) * 3;
|
|
216
|
+
const d = towards(b, p, at, next);
|
|
217
|
+
const pp = d[0] * e1[0] + d[1] * e1[1] + d[2] * e1[2];
|
|
218
|
+
const qq = d[0] * e2[0] + d[1] * e2[1] + d[2] * e2[2];
|
|
219
|
+
const l = Math.sqrt(pp * pp + qq * qq);
|
|
220
|
+
inc.push({ line: li, end, angle: pseudoAngle(pp / l, qq / l), p: pp / l, q: qq / l, w: widths[li][end === 0 ? 0 : n - 1] });
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (inc.length < 2)
|
|
224
|
+
continue;
|
|
225
|
+
inc.sort((x, y) => x.angle - y.angle || x.line - y.line || x.end - y.end);
|
|
226
|
+
const corners = [];
|
|
227
|
+
for (let k = 0; k < inc.length; k++) {
|
|
228
|
+
const i = inc[k];
|
|
229
|
+
const j = inc[(k + 1) % inc.length];
|
|
230
|
+
// Line i's left edge (toward j) and line j's right edge (toward i), in the node's tangent frame.
|
|
231
|
+
const lp = -i.q;
|
|
232
|
+
const lq = i.p;
|
|
233
|
+
const rp = j.q;
|
|
234
|
+
const rq = -j.p;
|
|
235
|
+
const wMax = Math.max(i.w, j.w);
|
|
236
|
+
const sin = i.p * j.q - i.q * j.p;
|
|
237
|
+
let cp;
|
|
238
|
+
let cq;
|
|
239
|
+
if (sin > 1e-9) {
|
|
240
|
+
const hp = j.w * rp - i.w * lp;
|
|
241
|
+
const hq = j.w * rq - i.w * lq;
|
|
242
|
+
const s = (hp * j.q - hq * j.p) / sin;
|
|
243
|
+
cp = i.w * lp + s * i.p;
|
|
244
|
+
cq = i.w * lq + s * i.q;
|
|
245
|
+
const d = Math.sqrt(cp * cp + cq * cq);
|
|
246
|
+
if (d > 3 * wMax) {
|
|
247
|
+
cp *= (3 * wMax) / d;
|
|
248
|
+
cq *= (3 * wMax) / d;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
// Opposite lines or a wedge wider than a half turn: the plain edge point on the bisector of the two edges.
|
|
253
|
+
const sp = lp + rp;
|
|
254
|
+
const sq = lq + rq;
|
|
255
|
+
const l = Math.sqrt(sp * sp + sq * sq);
|
|
256
|
+
if (!(l > 1e-9))
|
|
257
|
+
throw new Error(`stripNet: two lines leave node ${ni} in one direction`);
|
|
258
|
+
cp = (wMax * sp) / l;
|
|
259
|
+
cq = (wMax * sq) / l;
|
|
260
|
+
}
|
|
261
|
+
const c = [0, 0, 0];
|
|
262
|
+
onSurface(b, nd.p[0] + cp * e1[0] + cq * e2[0], nd.p[1] + cp * e1[1] + cq * e2[1], nd.p[2] + cp * e1[2] + cq * e2[2], c, 0);
|
|
263
|
+
corners.push(c);
|
|
264
|
+
}
|
|
265
|
+
for (let k = 0; k < inc.length; k++) {
|
|
266
|
+
const i = inc[k];
|
|
267
|
+
const left = corners[k];
|
|
268
|
+
const right = corners[(k + inc.length - 1) % inc.length];
|
|
269
|
+
// Left and right as seen from the node into the line; a line that ends at the node looks the other way.
|
|
270
|
+
endCorner[i.line][i.end] = i.end === 0 ? { left, right } : { left: right, right: left };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// Stations.
|
|
274
|
+
let reachM = 0;
|
|
275
|
+
const lines = input.lines.map((ln, li) => {
|
|
276
|
+
const p = pts[li];
|
|
277
|
+
const g = grades[li];
|
|
278
|
+
const w = widths[li];
|
|
279
|
+
const n = p.length / 3;
|
|
280
|
+
const pr = profiles[ln.profile];
|
|
281
|
+
let hem = 1;
|
|
282
|
+
for (let k = 0; k < pr.section.length; k += 2)
|
|
283
|
+
hem = Math.max(hem, Math.abs(pr.section[k]));
|
|
284
|
+
const segLen = [];
|
|
285
|
+
const along = [0];
|
|
286
|
+
for (let k = 0; k + 1 < n; k++) {
|
|
287
|
+
segLen.push(wayLength(b, p, k * 3, k * 3 + 3));
|
|
288
|
+
along.push(along[k] + segLen[k]);
|
|
289
|
+
}
|
|
290
|
+
const st = [];
|
|
291
|
+
const push = (c, l, r, grade, camber, al) => {
|
|
292
|
+
st.push(c[0], c[1], c[2], l[0], l[1], l[2], r[0], r[1], r[2], grade, camber, al);
|
|
293
|
+
};
|
|
294
|
+
/** Station square to the way from point a toward point c, at point `at` of `src`. */
|
|
295
|
+
const square = (src, at, dir, half, grade, al) => {
|
|
296
|
+
const u = upOf(b, src, at);
|
|
297
|
+
// Right = tangent × up.
|
|
298
|
+
const rx = dir[1] * u[2] - dir[2] * u[1];
|
|
299
|
+
const ry = dir[2] * u[0] - dir[0] * u[2];
|
|
300
|
+
const rz = dir[0] * u[1] - dir[1] * u[0];
|
|
301
|
+
const L = [0, 0, 0];
|
|
302
|
+
const Rr = [0, 0, 0];
|
|
303
|
+
onSurface(b, src[at] - rx * half, src[at + 1] - ry * half, src[at + 2] - rz * half, L, 0);
|
|
304
|
+
onSurface(b, src[at] + rx * half, src[at + 1] + ry * half, src[at + 2] + rz * half, Rr, 0);
|
|
305
|
+
push([src[at], src[at + 1], src[at + 2]], L, Rr, grade, 1, al);
|
|
306
|
+
};
|
|
307
|
+
/** A point of the way from point i toward point i + 1 at share t, with its grade and half-width. */
|
|
308
|
+
const onWay = (i, t) => {
|
|
309
|
+
const at = [0, 0, 0];
|
|
310
|
+
onSurface(b, p[i * 3] + (p[i * 3 + 3] - p[i * 3]) * t, p[i * 3 + 1] + (p[i * 3 + 4] - p[i * 3 + 1]) * t, p[i * 3 + 2] + (p[i * 3 + 5] - p[i * 3 + 2]) * t, at, 0);
|
|
311
|
+
return { at, g: g[i] + (g[i + 1] - g[i]) * t, w: w[i] + (w[i + 1] - w[i]) * t };
|
|
312
|
+
};
|
|
313
|
+
const startC = endCorner[li][0];
|
|
314
|
+
const endC = endCorner[li][1];
|
|
315
|
+
const nodeReach = (c, at) => Math.max(norm3(c.left[0] - p[at], c.left[1] - p[at + 1], c.left[2] - p[at + 2]), norm3(c.right[0] - p[at], c.right[1] - p[at + 1], c.right[2] - p[at + 2]));
|
|
316
|
+
const tStart = startC ? nodeReach(startC, 0) / segLen[0] : 0;
|
|
317
|
+
const tEnd = endC ? nodeReach(endC, (n - 1) * 3) / segLen[n - 2] : 0;
|
|
318
|
+
if (tStart >= 1 || tEnd >= 1 || (n === 2 && tStart + tEnd >= 1))
|
|
319
|
+
throw new Error(`stripNet: line ${li}: a segment at a node is shorter than the node's corners reach`);
|
|
320
|
+
// First station(s).
|
|
321
|
+
if (startC) {
|
|
322
|
+
push([p[0], p[1], p[2]], startC.left, startC.right, g[0], 0, 0);
|
|
323
|
+
const d = onWay(0, tStart);
|
|
324
|
+
square(d.at, 0, towards(b, [...d.at, p[3], p[4], p[5]], 0, 3), d.w, d.g, tStart * segLen[0]);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
square(p, 0, towards(b, p, 0, 3), w[0], g[0], 0);
|
|
328
|
+
}
|
|
329
|
+
// Inner points, mitred.
|
|
330
|
+
for (let k = 1; k + 1 < n; k++) {
|
|
331
|
+
const back = towards(b, p, k * 3, (k - 1) * 3);
|
|
332
|
+
const fwd = towards(b, p, k * 3, (k + 1) * 3);
|
|
333
|
+
const u = upOf(b, p, k * 3);
|
|
334
|
+
// Rights of the arriving direction (−back) and the leaving one.
|
|
335
|
+
const r0x = -(back[1] * u[2] - back[2] * u[1]);
|
|
336
|
+
const r0y = -(back[2] * u[0] - back[0] * u[2]);
|
|
337
|
+
const r0z = -(back[0] * u[1] - back[1] * u[0]);
|
|
338
|
+
const r1x = fwd[1] * u[2] - fwd[2] * u[1];
|
|
339
|
+
const r1y = fwd[2] * u[0] - fwd[0] * u[2];
|
|
340
|
+
const r1z = fwd[0] * u[1] - fwd[1] * u[0];
|
|
341
|
+
let mx = r0x + r1x;
|
|
342
|
+
let my = r0y + r1y;
|
|
343
|
+
let mz = r0z + r1z;
|
|
344
|
+
const ml = norm3(mx, my, mz);
|
|
345
|
+
if (!(ml > 1e-9))
|
|
346
|
+
throw new Error(`stripNet: line ${li} turns back at point ${k}`);
|
|
347
|
+
mx /= ml;
|
|
348
|
+
my /= ml;
|
|
349
|
+
mz /= ml;
|
|
350
|
+
const cos = mx * r0x + my * r0y + mz * r0z;
|
|
351
|
+
const half = w[k] / Math.max(cos, 0.5);
|
|
352
|
+
const L = [0, 0, 0];
|
|
353
|
+
const Rr = [0, 0, 0];
|
|
354
|
+
onSurface(b, p[k * 3] - mx * half, p[k * 3 + 1] - my * half, p[k * 3 + 2] - mz * half, L, 0);
|
|
355
|
+
onSurface(b, p[k * 3] + mx * half, p[k * 3 + 1] + my * half, p[k * 3 + 2] + mz * half, Rr, 0);
|
|
356
|
+
push([p[k * 3], p[k * 3 + 1], p[k * 3 + 2]], L, Rr, g[k], 1, along[k]);
|
|
357
|
+
}
|
|
358
|
+
// Last station(s).
|
|
359
|
+
const last = (n - 1) * 3;
|
|
360
|
+
if (endC) {
|
|
361
|
+
const d = onWay(n - 2, 1 - tEnd);
|
|
362
|
+
// Square to the segment, looking along the line.
|
|
363
|
+
const ahead = towards(b, [...d.at, p[last], p[last + 1], p[last + 2]], 0, 3);
|
|
364
|
+
square(d.at, 0, ahead, d.w, d.g, along[n - 1] - tEnd * segLen[n - 2]);
|
|
365
|
+
push([p[last], p[last + 1], p[last + 2]], endC.left, endC.right, g[n - 1], 0, along[n - 1]);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
const back = towards(b, p, last, last - 3);
|
|
369
|
+
square(p, last, [-back[0], -back[1], -back[2]], w[n - 1], g[n - 1], along[n - 1]);
|
|
370
|
+
}
|
|
371
|
+
const stations = Float64Array.from(st);
|
|
372
|
+
const count = stations.length / STRIP_STATION_FLOATS;
|
|
373
|
+
const balls = new Float64Array((count - 1) * 4);
|
|
374
|
+
const box = Float64Array.from([Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity]);
|
|
375
|
+
for (let k = 0; k + 1 < count; k++) {
|
|
376
|
+
const s0 = k * STRIP_STATION_FLOATS;
|
|
377
|
+
const s1 = s0 + STRIP_STATION_FLOATS;
|
|
378
|
+
const cx = (stations[s0] + stations[s1]) / 2;
|
|
379
|
+
const cy = (stations[s0 + 1] + stations[s1 + 1]) / 2;
|
|
380
|
+
const cz = (stations[s0 + 2] + stations[s1 + 2]) / 2;
|
|
381
|
+
let r = 0;
|
|
382
|
+
for (const s of [s0, s1]) {
|
|
383
|
+
const toC = norm3(stations[s] - cx, stations[s + 1] - cy, stations[s + 2] - cz);
|
|
384
|
+
for (const e of [3, 6]) {
|
|
385
|
+
const hw = norm3(stations[s + e] - stations[s], stations[s + e + 1] - stations[s + 1], stations[s + e + 2] - stations[s + 2]);
|
|
386
|
+
reachM = Math.max(reachM, hem * hw + pr.shoulderM);
|
|
387
|
+
r = Math.max(r, toC + hem * hw);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// The shoulder, a millimetre for rounding.
|
|
391
|
+
r += pr.shoulderM + 1e-3;
|
|
392
|
+
balls[k * 4] = cx;
|
|
393
|
+
balls[k * 4 + 1] = cy;
|
|
394
|
+
balls[k * 4 + 2] = cz;
|
|
395
|
+
balls[k * 4 + 3] = r;
|
|
396
|
+
box[0] = Math.min(box[0], cx - r);
|
|
397
|
+
box[1] = Math.min(box[1], cy - r);
|
|
398
|
+
box[2] = Math.min(box[2], cz - r);
|
|
399
|
+
box[3] = Math.max(box[3], cx + r);
|
|
400
|
+
box[4] = Math.max(box[4], cy + r);
|
|
401
|
+
box[5] = Math.max(box[5], cz + r);
|
|
402
|
+
}
|
|
403
|
+
return { profile: ln.profile, count, stations, startSquare: !startC, endSquare: !endC, box, balls };
|
|
404
|
+
});
|
|
405
|
+
return { radiusM: R, lineCount: lines.length, reachM, profiles, lines };
|
|
406
|
+
}
|
|
407
|
+
// --- The height function --------------------------------------------------------------------------------------------
|
|
408
|
+
//
|
|
409
|
+
// Every piece is two halves, (C0, E0, E1, C1) with E the right or the left edge. A point inside a half lies on exactly
|
|
410
|
+
// one section of it: a share t along and a share s across, found from a quadratic, and the target there is exact.
|
|
411
|
+
// Outside the strip a line's share falls with the distance to the nearest half, and its target is the targets at the
|
|
412
|
+
// nearest points of the halves within the shoulder weighed by inverse squared distance: it tends to the edge's own
|
|
413
|
+
// target at the edge, so the height is continuous everywhere, round bends and nodes as well.
|
|
414
|
+
const scratchQ = [0, 0, 0];
|
|
415
|
+
const roots = [0, 0];
|
|
416
|
+
function det3(ax, ay, az, bx, by, bz, cx, cy, cz) {
|
|
417
|
+
return ax * (by * cz - bz * cy) + ay * (bz * cx - bx * cz) + az * (bx * cy - by * cx);
|
|
418
|
+
}
|
|
419
|
+
/** Roots of A t² + B t + C = 0 into `roots`; returns how many. */
|
|
420
|
+
function solveQuadratic(A, B, C) {
|
|
421
|
+
const scale = Math.abs(A) + Math.abs(B) + Math.abs(C);
|
|
422
|
+
if (scale === 0)
|
|
423
|
+
return 0;
|
|
424
|
+
if (Math.abs(A) <= 1e-12 * scale) {
|
|
425
|
+
if (B === 0)
|
|
426
|
+
return 0;
|
|
427
|
+
roots[0] = -C / B;
|
|
428
|
+
return 1;
|
|
429
|
+
}
|
|
430
|
+
const disc = B * B - 4 * A * C;
|
|
431
|
+
if (disc < 0) {
|
|
432
|
+
if (disc < -1e-12 * B * B)
|
|
433
|
+
return 0;
|
|
434
|
+
roots[0] = -B / (2 * A);
|
|
435
|
+
return 1;
|
|
436
|
+
}
|
|
437
|
+
const sq = Math.sqrt(disc);
|
|
438
|
+
const q = -0.5 * (B + (B >= 0 ? sq : -sq));
|
|
439
|
+
roots[0] = q / A;
|
|
440
|
+
if (q === 0)
|
|
441
|
+
return 1;
|
|
442
|
+
roots[1] = C / q;
|
|
443
|
+
return 2;
|
|
444
|
+
}
|
|
445
|
+
const ev = { inside: false, piece: 0, t: 0, a: 0, hw: 0, dist: Infinity, sumW: 0, sumWT: 0, nPiece: 0, nT: 0, nA: 0, nHw: 0, nOnEdge: false };
|
|
446
|
+
/** Point of the query in metres (on the base surface). */
|
|
447
|
+
const qm = [0, 0, 0];
|
|
448
|
+
function smoothstep01(x) {
|
|
449
|
+
const t = x < 0 ? 0 : x > 1 ? 1 : x;
|
|
450
|
+
return t * t * (3 - 2 * t);
|
|
451
|
+
}
|
|
452
|
+
/** Target height of the ground at share t of piece k, across a. */
|
|
453
|
+
function targetAt(line, profile, k, t, a) {
|
|
454
|
+
const s0 = k * STRIP_STATION_FLOATS;
|
|
455
|
+
const s1 = s0 + STRIP_STATION_FLOATS;
|
|
456
|
+
const st = line.stations;
|
|
457
|
+
const grade = st[s0 + 9] + (st[s1 + 9] - st[s0 + 9]) * t;
|
|
458
|
+
const camber = st[s0 + 10] + (st[s1 + 10] - st[s0 + 10]) * t;
|
|
459
|
+
return grade + camber * stripUp(profile, a < -1 ? -1 : a > 1 ? 1 : a) - profile.bedM;
|
|
460
|
+
}
|
|
461
|
+
/** The section through the query inside half (k, side): sets `ev` and returns true when it lies on one. */
|
|
462
|
+
function sectionThrough(net, line, k, side) {
|
|
463
|
+
const st = line.stations;
|
|
464
|
+
const s0 = k * STRIP_STATION_FLOATS;
|
|
465
|
+
const s1 = s0 + STRIP_STATION_FLOATS;
|
|
466
|
+
const e = side > 0 ? 6 : 3;
|
|
467
|
+
const sphere = net.radiusM > 0;
|
|
468
|
+
const R = net.radiusM;
|
|
469
|
+
const qx = scratchQ[0];
|
|
470
|
+
const qy = scratchQ[1];
|
|
471
|
+
const qz = scratchQ[2];
|
|
472
|
+
// Lifted vectors: on the plane (x, 1, z) relative to q, on the sphere unit vectors; c and e relative to q.
|
|
473
|
+
const lx = sphere ? qx : 0;
|
|
474
|
+
const ly = sphere ? qy : 1;
|
|
475
|
+
const lz = sphere ? qz : 0;
|
|
476
|
+
const k0 = sphere ? 1 / R : 1;
|
|
477
|
+
const c0x = st[s0] * k0 - (sphere ? qx : qm[0]);
|
|
478
|
+
const c0y = sphere ? st[s0 + 1] * k0 - qy : 0;
|
|
479
|
+
const c0z = st[s0 + 2] * k0 - (sphere ? qz : qm[2]);
|
|
480
|
+
const e0x = st[s0 + e] * k0 - (sphere ? qx : qm[0]);
|
|
481
|
+
const e0y = sphere ? st[s0 + e + 1] * k0 - qy : 0;
|
|
482
|
+
const e0z = st[s0 + e + 2] * k0 - (sphere ? qz : qm[2]);
|
|
483
|
+
const dcx = (st[s1] - st[s0]) * k0;
|
|
484
|
+
const dcy = sphere ? (st[s1 + 1] - st[s0 + 1]) * k0 : 0;
|
|
485
|
+
const dcz = (st[s1 + 2] - st[s0 + 2]) * k0;
|
|
486
|
+
const dex = (st[s1 + e] - st[s0 + e]) * k0;
|
|
487
|
+
const dey = sphere ? (st[s1 + e + 1] - st[s0 + e + 1]) * k0 : 0;
|
|
488
|
+
const dez = (st[s1 + e + 2] - st[s0 + e + 2]) * k0;
|
|
489
|
+
// q lies on the section at share t when q, C(t) and E(t) lie in one plane through the centre (the plane: on one
|
|
490
|
+
// line): det(q, C(t) − q, E(t) − q) = 0, a quadratic in t.
|
|
491
|
+
const C = det3(lx, ly, lz, c0x, c0y, c0z, e0x, e0y, e0z);
|
|
492
|
+
const B = det3(lx, ly, lz, dcx, dcy, dcz, e0x, e0y, e0z) + det3(lx, ly, lz, c0x, c0y, c0z, dex, dey, dez);
|
|
493
|
+
const A = det3(lx, ly, lz, dcx, dcy, dcz, dex, dey, dez);
|
|
494
|
+
const nr = solveQuadratic(A, B, C);
|
|
495
|
+
for (let r = 0; r < nr; r++) {
|
|
496
|
+
let t = roots[r];
|
|
497
|
+
if (!(t >= -1e-9 && t <= 1 + 1e-9))
|
|
498
|
+
continue;
|
|
499
|
+
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
500
|
+
let cx = c0x + dcx * t;
|
|
501
|
+
let cy = c0y + dcy * t;
|
|
502
|
+
let cz = c0z + dcz * t;
|
|
503
|
+
let ex = e0x + dex * t;
|
|
504
|
+
let ey = e0y + dey * t;
|
|
505
|
+
let ez = e0z + dez * t;
|
|
506
|
+
let s;
|
|
507
|
+
let hw;
|
|
508
|
+
if (sphere) {
|
|
509
|
+
// Back to unit vectors on the sphere; q = λ (C + s D) with D = E − C.
|
|
510
|
+
cx += qx;
|
|
511
|
+
cy += qy;
|
|
512
|
+
cz += qz;
|
|
513
|
+
ex += qx;
|
|
514
|
+
ey += qy;
|
|
515
|
+
ez += qz;
|
|
516
|
+
const cl = norm3(cx, cy, cz);
|
|
517
|
+
const el = norm3(ex, ey, ez);
|
|
518
|
+
cx /= cl;
|
|
519
|
+
cy /= cl;
|
|
520
|
+
cz /= cl;
|
|
521
|
+
ex /= el;
|
|
522
|
+
ey /= el;
|
|
523
|
+
ez /= el;
|
|
524
|
+
const dx = ex - cx;
|
|
525
|
+
const dy = ey - cy;
|
|
526
|
+
const dz = ez - cz;
|
|
527
|
+
const ax = cy * qz - cz * qy;
|
|
528
|
+
const ay = cz * qx - cx * qz;
|
|
529
|
+
const az = cx * qy - cy * qx;
|
|
530
|
+
const bx = dy * qz - dz * qy;
|
|
531
|
+
const by = dz * qx - dx * qz;
|
|
532
|
+
const bz = dx * qy - dy * qx;
|
|
533
|
+
const bb = bx * bx + by * by + bz * bz;
|
|
534
|
+
if (!(bb > 0))
|
|
535
|
+
continue;
|
|
536
|
+
s = -(ax * bx + ay * by + az * bz) / bb;
|
|
537
|
+
hw = norm3(dx, dy, dz) * R;
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
const dx = ex - cx;
|
|
541
|
+
const dz = ez - cz;
|
|
542
|
+
const dd = dx * dx + dz * dz;
|
|
543
|
+
if (!(dd > 0))
|
|
544
|
+
continue;
|
|
545
|
+
s = (-cx * dx - cz * dz) / dd;
|
|
546
|
+
hw = Math.sqrt(dd);
|
|
547
|
+
}
|
|
548
|
+
if (s < -1e-9 || s > 1 + 1e-9)
|
|
549
|
+
continue;
|
|
550
|
+
s = s < 0 ? 0 : s > 1 ? 1 : s;
|
|
551
|
+
ev.inside = true;
|
|
552
|
+
ev.piece = k;
|
|
553
|
+
ev.t = t;
|
|
554
|
+
ev.a = side * s;
|
|
555
|
+
ev.hw = hw;
|
|
556
|
+
ev.dist = 0;
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
/** Nearest point to the query on segment (a, b) of points in metres: its share and the squared distance. */
|
|
562
|
+
function nearestOnSegment(ax, ay, az, bx, by, bz, out) {
|
|
563
|
+
const dx = bx - ax;
|
|
564
|
+
const dy = by - ay;
|
|
565
|
+
const dz = bz - az;
|
|
566
|
+
const dd = dx * dx + dy * dy + dz * dz;
|
|
567
|
+
let u = dd > 0 ? ((qm[0] - ax) * dx + (qm[1] - ay) * dy + (qm[2] - az) * dz) / dd : 0;
|
|
568
|
+
u = u < 0 ? 0 : u > 1 ? 1 : u;
|
|
569
|
+
const x = ax + dx * u - qm[0];
|
|
570
|
+
const y = ay + dy * u - qm[1];
|
|
571
|
+
const z = az + dz * u - qm[2];
|
|
572
|
+
out[0] = u;
|
|
573
|
+
out[1] = x * x + y * y + z * z;
|
|
574
|
+
}
|
|
575
|
+
const seg = [0, 0];
|
|
576
|
+
/**
|
|
577
|
+
* Half (k, side) for a query outside it: the nearest point of its outline (the two sections, the centre and the
|
|
578
|
+
* edge), added to the line's weighted target when within the shoulder. Returns false when the query lies inside.
|
|
579
|
+
*/
|
|
580
|
+
function halfOutside(line, profile, k, side) {
|
|
581
|
+
const st = line.stations;
|
|
582
|
+
const s0 = k * STRIP_STATION_FLOATS;
|
|
583
|
+
const s1 = s0 + STRIP_STATION_FLOATS;
|
|
584
|
+
const e = side > 0 ? 6 : 3;
|
|
585
|
+
// Corners in order C0, E0, E1, C1; their (t, s) on the half.
|
|
586
|
+
const P = [s0, s0 + e, s1 + e, s1];
|
|
587
|
+
const T = [0, 0, 1, 1];
|
|
588
|
+
const S = [0, 1, 1, 0];
|
|
589
|
+
// Inside: on the same side of all four sides, seen along local up.
|
|
590
|
+
const ux = net0.radiusM > 0 ? scratchQ[0] : 0;
|
|
591
|
+
const uy = net0.radiusM > 0 ? scratchQ[1] : 1;
|
|
592
|
+
const uz = net0.radiusM > 0 ? scratchQ[2] : 0;
|
|
593
|
+
let pos = 0;
|
|
594
|
+
let neg = 0;
|
|
595
|
+
for (let i = 0; i < 4; i++) {
|
|
596
|
+
const a = P[i];
|
|
597
|
+
const b = P[(i + 1) % 4];
|
|
598
|
+
const ex = st[b] - st[a];
|
|
599
|
+
const ey = st[b + 1] - st[a + 1];
|
|
600
|
+
const ez = st[b + 2] - st[a + 2];
|
|
601
|
+
const vx = qm[0] - st[a];
|
|
602
|
+
const vy = qm[1] - st[a + 1];
|
|
603
|
+
const vz = qm[2] - st[a + 2];
|
|
604
|
+
const o = (ey * vz - ez * vy) * ux + (ez * vx - ex * vz) * uy + (ex * vy - ey * vx) * uz;
|
|
605
|
+
if (o > 0)
|
|
606
|
+
pos++;
|
|
607
|
+
else if (o < 0)
|
|
608
|
+
neg++;
|
|
609
|
+
}
|
|
610
|
+
if (pos === 0 || neg === 0)
|
|
611
|
+
return false;
|
|
612
|
+
let best = Infinity;
|
|
613
|
+
let bt = 0;
|
|
614
|
+
let bs = 0;
|
|
615
|
+
let edge = false;
|
|
616
|
+
for (let i = 0; i < 4; i++) {
|
|
617
|
+
const a = P[i];
|
|
618
|
+
const b = P[(i + 1) % 4];
|
|
619
|
+
nearestOnSegment(st[a], st[a + 1], st[a + 2], st[b], st[b + 1], st[b + 2], seg);
|
|
620
|
+
if (seg[1] < best) {
|
|
621
|
+
best = seg[1];
|
|
622
|
+
const u = seg[0];
|
|
623
|
+
bt = T[i] + (T[(i + 1) % 4] - T[i]) * u;
|
|
624
|
+
bs = S[i] + (S[(i + 1) % 4] - S[i]) * u;
|
|
625
|
+
edge = i === 1;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const d = Math.sqrt(best);
|
|
629
|
+
if (d < ev.dist) {
|
|
630
|
+
ev.dist = d;
|
|
631
|
+
ev.nPiece = k;
|
|
632
|
+
ev.nT = bt;
|
|
633
|
+
ev.nA = side * bs;
|
|
634
|
+
ev.nOnEdge = edge;
|
|
635
|
+
const hx = st[s0 + e] + (st[s1 + e] - st[s0 + e]) * bt - (st[s0] + (st[s1] - st[s0]) * bt);
|
|
636
|
+
const hy = st[s0 + e + 1] + (st[s1 + e + 1] - st[s0 + e + 1]) * bt - (st[s0 + 1] + (st[s1 + 1] - st[s0 + 1]) * bt);
|
|
637
|
+
const hz = st[s0 + e + 2] + (st[s1 + e + 2] - st[s0 + e + 2]) * bt - (st[s0 + 2] + (st[s1 + 2] - st[s0 + 2]) * bt);
|
|
638
|
+
ev.nHw = norm3(hx, hy, hz);
|
|
639
|
+
}
|
|
640
|
+
const shoulder = profile.shoulderM;
|
|
641
|
+
if (shoulder > 0 && d < shoulder) {
|
|
642
|
+
const fall = 1 - smoothstep01(d / shoulder);
|
|
643
|
+
// Inverse squared distance, a millimetre at least: the nearest half dominates near the edge.
|
|
644
|
+
const w = fall / Math.max(d * d, 1e-12);
|
|
645
|
+
ev.sumW += w;
|
|
646
|
+
ev.sumWT += w * targetAt(line, profile, k, bt, side * bs);
|
|
647
|
+
}
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
/** The net being evaluated (for the up of the inside test). */
|
|
651
|
+
let net0;
|
|
652
|
+
/** Puts the query point into `scratchQ` (unit vector on the sphere, the point on the plane) and `qm` (metres). */
|
|
653
|
+
function setQuery(net, x, y, z) {
|
|
654
|
+
net0 = net;
|
|
655
|
+
if (net.radiusM > 0) {
|
|
656
|
+
const l = norm3(x, y, z);
|
|
657
|
+
if (!(l > 0))
|
|
658
|
+
return false;
|
|
659
|
+
scratchQ[0] = x / l;
|
|
660
|
+
scratchQ[1] = y / l;
|
|
661
|
+
scratchQ[2] = z / l;
|
|
662
|
+
qm[0] = scratchQ[0] * net.radiusM;
|
|
663
|
+
qm[1] = scratchQ[1] * net.radiusM;
|
|
664
|
+
qm[2] = scratchQ[2] * net.radiusM;
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
scratchQ[0] = x;
|
|
668
|
+
scratchQ[1] = 0;
|
|
669
|
+
scratchQ[2] = z;
|
|
670
|
+
qm[0] = x;
|
|
671
|
+
qm[1] = 0;
|
|
672
|
+
qm[2] = z;
|
|
673
|
+
}
|
|
674
|
+
return Number.isFinite(qm[0]) && Number.isFinite(qm[1]) && Number.isFinite(qm[2]);
|
|
675
|
+
}
|
|
676
|
+
/** Evaluates one line at the query into `ev`; false when nothing of it is near enough to matter. */
|
|
677
|
+
function evalLine(net, li) {
|
|
678
|
+
const line = net.lines[li];
|
|
679
|
+
const profile = net.profiles[line.profile];
|
|
680
|
+
const bx = line.box;
|
|
681
|
+
const px = qm[0];
|
|
682
|
+
const py = qm[1];
|
|
683
|
+
const pz = qm[2];
|
|
684
|
+
if (px < bx[0] || py < bx[1] || pz < bx[2] || px > bx[3] || py > bx[4] || pz > bx[5])
|
|
685
|
+
return false;
|
|
686
|
+
ev.inside = false;
|
|
687
|
+
ev.dist = Infinity;
|
|
688
|
+
ev.sumW = 0;
|
|
689
|
+
ev.sumWT = 0;
|
|
690
|
+
let any = false;
|
|
691
|
+
const bl = line.balls;
|
|
692
|
+
for (let k = 0; k + 1 < line.count; k++) {
|
|
693
|
+
const dx = px - bl[k * 4];
|
|
694
|
+
const dy = py - bl[k * 4 + 1];
|
|
695
|
+
const dz = pz - bl[k * 4 + 2];
|
|
696
|
+
const r = bl[k * 4 + 3];
|
|
697
|
+
if (dx * dx + dy * dy + dz * dz > r * r)
|
|
698
|
+
continue;
|
|
699
|
+
any = true;
|
|
700
|
+
for (const side of [1, -1]) {
|
|
701
|
+
if (!halfOutside(line, profile, k, side) && sectionThrough(net, line, k, side))
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return any && ev.dist < Infinity;
|
|
706
|
+
}
|
|
707
|
+
/** Share of the line evaluated last: 1 on the strip, a smoothstep to 0 at `shoulderM` past its edge. */
|
|
708
|
+
function shareOf(profile) {
|
|
709
|
+
if (ev.inside)
|
|
710
|
+
return 1;
|
|
711
|
+
if (!(profile.shoulderM > 0) || ev.dist >= profile.shoulderM)
|
|
712
|
+
return 0;
|
|
713
|
+
return 1 - smoothstep01(ev.dist / profile.shoulderM);
|
|
714
|
+
}
|
|
715
|
+
/** Target of the line evaluated last (its share must be above 0). */
|
|
716
|
+
function targetOf(line, profile) {
|
|
717
|
+
if (ev.inside)
|
|
718
|
+
return targetAt(line, profile, ev.piece, ev.t, ev.a);
|
|
719
|
+
return ev.sumWT / ev.sumW;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* The line whose strip or shoulder holds a point of the base surface most (the largest share; ties: the lower
|
|
723
|
+
* index), with where the point lies on it; null when no share is above 0. Outside the strip the numbers are those of
|
|
724
|
+
* the nearest point of the strip, `acrossM` and `alongM` carried on by the distance to it.
|
|
725
|
+
*/
|
|
726
|
+
export function stripNearest(net, x, y, z, out) {
|
|
727
|
+
if (!setQuery(net, x, y, z))
|
|
728
|
+
return null;
|
|
729
|
+
let bestK = 0;
|
|
730
|
+
let hit = null;
|
|
731
|
+
for (let li = 0; li < net.lineCount; li++) {
|
|
732
|
+
if (!evalLine(net, li))
|
|
733
|
+
continue;
|
|
734
|
+
const line = net.lines[li];
|
|
735
|
+
const profile = net.profiles[line.profile];
|
|
736
|
+
const k = shareOf(profile);
|
|
737
|
+
if (!(k > bestK))
|
|
738
|
+
continue;
|
|
739
|
+
bestK = k;
|
|
740
|
+
hit = out ?? { line: 0, alongM: 0, acrossM: 0, halfWidthM: 0, gradeM: 0, share: 0 };
|
|
741
|
+
const piece = ev.inside ? ev.piece : ev.nPiece;
|
|
742
|
+
const t = ev.inside ? ev.t : ev.nT;
|
|
743
|
+
const a = ev.inside ? ev.a : ev.nA;
|
|
744
|
+
const hw = ev.inside ? ev.hw : ev.nHw;
|
|
745
|
+
const s0 = piece * STRIP_STATION_FLOATS;
|
|
746
|
+
const st = line.stations;
|
|
747
|
+
hit.line = li;
|
|
748
|
+
hit.alongM = st[s0 + 11] + (st[s0 + STRIP_STATION_FLOATS + 11] - st[s0 + 11]) * t;
|
|
749
|
+
hit.acrossM = a * hw;
|
|
750
|
+
if (!ev.inside) {
|
|
751
|
+
if (ev.nOnEdge)
|
|
752
|
+
hit.acrossM += a < 0 ? -ev.dist : ev.dist;
|
|
753
|
+
else if (t === 0 && piece === 0)
|
|
754
|
+
hit.alongM -= ev.dist;
|
|
755
|
+
else if (t === 1 && piece === line.count - 2)
|
|
756
|
+
hit.alongM += ev.dist;
|
|
757
|
+
}
|
|
758
|
+
hit.halfWidthM = hw;
|
|
759
|
+
hit.gradeM = st[s0 + 9] + (st[s0 + STRIP_STATION_FLOATS + 9] - st[s0 + 9]) * t;
|
|
760
|
+
hit.share = k;
|
|
761
|
+
}
|
|
762
|
+
return hit;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Height of the ground at a point of the base surface with the strips cut and filled in: the section less its bed on
|
|
766
|
+
* the strip, blended back to `ownHeightM` over the shoulder. Where lines meet, the shares weigh their targets, so the
|
|
767
|
+
* result is continuous everywhere. Exactly `ownHeightM` where no line has a share.
|
|
768
|
+
*/
|
|
769
|
+
export function stripCarve(net, x, y, z, ownHeightM) {
|
|
770
|
+
if (!setQuery(net, x, y, z))
|
|
771
|
+
return ownHeightM;
|
|
772
|
+
let sumK = 0;
|
|
773
|
+
let sumKT = 0;
|
|
774
|
+
let maxK = 0;
|
|
775
|
+
for (let li = 0; li < net.lineCount; li++) {
|
|
776
|
+
if (!evalLine(net, li))
|
|
777
|
+
continue;
|
|
778
|
+
const line = net.lines[li];
|
|
779
|
+
const profile = net.profiles[line.profile];
|
|
780
|
+
const k = shareOf(profile);
|
|
781
|
+
if (!(k > 0))
|
|
782
|
+
continue;
|
|
783
|
+
sumK += k;
|
|
784
|
+
sumKT += k * targetOf(line, profile);
|
|
785
|
+
if (k > maxK)
|
|
786
|
+
maxK = k;
|
|
787
|
+
}
|
|
788
|
+
if (maxK === 0)
|
|
789
|
+
return ownHeightM;
|
|
790
|
+
return ownHeightM + (sumKT / sumK - ownHeightM) * maxK;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* False only when no line can change the ground or put a vertex within `radiusM` of a point of the base surface: a
|
|
794
|
+
* test against bounding balls, for skipping a cell before any height is asked for.
|
|
795
|
+
*/
|
|
796
|
+
export function stripTouches(net, x, y, z, radiusM) {
|
|
797
|
+
if (!setQuery(net, x, y, z))
|
|
798
|
+
return true;
|
|
799
|
+
const px = qm[0];
|
|
800
|
+
const py = qm[1];
|
|
801
|
+
const pz = qm[2];
|
|
802
|
+
for (const line of net.lines) {
|
|
803
|
+
const bx = line.box;
|
|
804
|
+
if (px < bx[0] - radiusM || py < bx[1] - radiusM || pz < bx[2] - radiusM || px > bx[3] + radiusM || py > bx[4] + radiusM || pz > bx[5] + radiusM)
|
|
805
|
+
continue;
|
|
806
|
+
for (let k = 0; k + 1 < line.count; k++) {
|
|
807
|
+
const bl = line.balls;
|
|
808
|
+
const dx = px - bl[k * 4];
|
|
809
|
+
const dy = py - bl[k * 4 + 1];
|
|
810
|
+
const dz = pz - bl[k * 4 + 2];
|
|
811
|
+
const r = bl[k * 4 + 3] + radiusM;
|
|
812
|
+
if (dx * dx + dy * dy + dz * dz <= r * r)
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return false;
|
|
817
|
+
}
|