feat: nonlinear deposit curve (lever 4) - #39
Merged
Conversation
…fp-equivalence test
Fix field_reassign_with_default clippy errors in deposit test code (config.rs and simulation/mod.rs); add fold_deposits_sqrt bench case to diffusion_benchmark.rs. All 5 gate steps pass: fmt clean, clippy zero warnings, 800 tests pass, 812 all-features pass, 47 goldens unchanged.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lever 4 — Nonlinear deposit
Adds a per-frame deposit-accumulation buffer with a selectable nonlinear curve so density spikes compress into filaments instead of blowing out to flat blobs. Fully off by default — byte-identical to current behavior.
How it works
Agents accumulate their existing per-agent unit (
deposit_amount · dt) into a per-TrailMapscratch buffer (mirrors the lever-7blend_srcpattern). Once per frame, before diffuse/decay, a fold pass appliescurve(accum) · scale, an optional clampcap, adds the result to the trail, and zeros the buffer.The accumulation path is gated: when
curve=linear && scale=1 && cap=0, the buffer is never touched and deposits go straight to the trail (the existing code path) — so the off case is byte-identical by construction, avoiding the float-reassociation drift a naive accumulate-then-fold would introduce.Curves
linear—x(identity, default)sqrt—x.sqrt()(compresses density → filaments)log—ln(1 + x)(log1p; 0 at 0, guards log(0))pow—x.powf(gamma)(--deposit-gammais the exponent)Knobs
--deposit-curve <linear|sqrt|log|pow>,--deposit-scale,--deposit-gamma,--deposit-cap(0 = off). All onSimConfig(mirrors lever-7decay_gamma/diffuse_weight); CLI flags + saved-config round-trip (serde(default)back-compat). Buffer is per-TrailMap, giving per-species structure in separate-trails mode for free. Per-preset tuning is intentionally deferred to the showcase-preset work.Testing
deposit_off_path_is_deterministicand a linear-accum fp-equivalence test (active identity config matches the direct path within a magnitude-relative tolerance, accounting for float reassociation);deposit_sqrt_curve_changes_output.cargo test800 pass ·cargo test --all-features --lib812 pass ·cargo clippy --all-targets --all-features -- -D warningsclean.linearandpow γ=1identical to baseline;sqrt/log/pow γ=0.5differ sensibly.bench_fold_deposits_sqrt.Closes #31.