From 46a991f3520e3e607725a48a9ec11ffb294e6165 Mon Sep 17 00:00:00 2001 From: beezm Date: Fri, 7 Aug 2026 15:36:43 -0400 Subject: [PATCH] fix: dedupe float samples in the monotonicity assertion (terrain-water task 05) The coarse and fine sampling loops both touched h=0.10 and the two doubles round to the same float32, so the strict check compared the identity value against itself and threw on every curve-on run. Only strictly increasing float samples are compared now. The curve itself was never non-monotonic. Co-Authored-By: Claude Fable 5 --- Tools/Scripts/HeightCurve.cs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Tools/Scripts/HeightCurve.cs b/Tools/Scripts/HeightCurve.cs index 7bc2043..c4dd534 100644 --- a/Tools/Scripts/HeightCurve.cs +++ b/Tools/Scripts/HeightCurve.cs @@ -85,20 +85,28 @@ public static class HeightCurve /// public static void AssertMonotonic() { - float prev = Apply(-7f); + float prevH = -7f; + float prev = Apply(prevH); + + // Successive double samples can round to the SAME float32 (the two loops + // meeting at 0.10 did exactly that and tripped the strict check against + // itself) — so only strictly increasing float samples are compared. + void Check(double hd) + { + float h = (float)hd; + if (h <= prevH) return; + float v = Apply(h); + if (v <= prev) + throw new System.InvalidOperationException( + $"[HeightCurve] MONOTONICITY VIOLATION at h={h}: {v} <= {prev}. Refusing to generate."); + prev = v; + prevH = h; + } + // Coarse below the identity region, fine through every knot, out past the tail. - for (double h = -7.0 + 0.01; h < 0.10; h += 0.01) prev = Step(prev, (float)h); - for (double h = 0.10; h <= 2.0; h += 0.0001) prev = Step(prev, (float)h); - for (double h = 2.0; h <= 8.0; h += 0.05) prev = Step(prev, (float)h); + for (double h = -7.0 + 0.01; h < 0.10; h += 0.01) Check(h); + for (double h = 0.10; h <= 2.0; h += 0.0001) Check(h); + for (double h = 2.05; h <= 8.0; h += 0.05) Check(h); GD.Print("[HeightCurve] Monotonicity assertion passed (v" + VERSION + ")."); } - - private static float Step(float prev, float h) - { - float v = Apply(h); - if (v <= prev) - throw new System.InvalidOperationException( - $"[HeightCurve] MONOTONICITY VIOLATION at h={h}: {v} <= {prev}. Refusing to generate."); - return v; - } }