From 28095f25c53994ac4b07fefa9ce0c58f1b0993bd Mon Sep 17 00:00:00 2001 From: beezm Date: Sun, 9 Aug 2026 00:22:12 -0400 Subject: [PATCH] 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) --- Tools/Scripts/MapGenerator.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Tools/Scripts/MapGenerator.cs b/Tools/Scripts/MapGenerator.cs index 66b6991..f44835d 100644 --- a/Tools/Scripts/MapGenerator.cs +++ b/Tools/Scripts/MapGenerator.cs @@ -545,7 +545,15 @@ public partial class MapGenerator : TextureRect if (_coastWide && finalH < seaHere) { 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) ---