fix: hold the coast shelf strictly below sea in float32 (terrain-water task 11)

The shelf remap is strictly positive on positive depth, so in exact
arithmetic it cannot move the waterline -- which is the whole reason it is
separable from elongation and safe to toggle against an md5 oracle.

In float32 it can. For a pixel a few microns under water, the shallower
depth falls below the ULP of the sea constant, so (sea - depth) rounds back
up to exactly sea, and the `H < sea` test then calls it land. The batch
measured it: coast-only vs steep came out with land area identical, zero
above-sea heights changed, and 5 biome pixels of 67 M moved.

Five pixels is immaterial on its own. Falsifying the invariant is not --
"the coast shelf is biome-neutral" is now written in BLUEPRINT_FORMAT.md,
and an invariant that holds to six decimal places is the kind that bites
somebody later with a mysterious oracle failure. Clamping to
BitDecrement(sea) makes it exact.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stewart Howe 2026-08-09 00:22:12 -04:00
parent 5ba868f038
commit 28095f25c5

View file

@ -545,7 +545,15 @@ public partial class MapGenerator : TextureRect
if (_coastWide && finalH < seaHere) if (_coastWide && finalH < seaHere)
{ {
float depthM = (seaHere - finalH) * 251f; float depthM = (seaHere - finalH) * 251f;
finalH = seaHere - IslandFalloff.CoastShelf(depthM) / 251f; // The remap is strictly positive on positive depth, so in exact
// arithmetic the waterline cannot move. In float32 it can: for a
// pixel a few microns under water, (sea - shallowerDepth) rounds
// back up to exactly sea, and `H < sea` then calls it land. That
// cost 5 px of 67 M on the first batch — immaterial in itself, but
// it falsifies the invariant the whole separability argument rests
// on. Hold the result strictly below sea and the invariant is exact.
finalH = Mathf.Min(seaHere - IslandFalloff.CoastShelf(depthM) / 251f,
System.MathF.BitDecrement(seaHere));
} }
// --- 6. OFFSHORE ISLANDS (task 11) --- // --- 6. OFFSHORE ISLANDS (task 11) ---