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 <noreply@anthropic.com>
This commit is contained in:
parent
9ebb8296c9
commit
46a991f352
1 changed files with 21 additions and 13 deletions
|
|
@ -85,20 +85,28 @@ public static class HeightCurve
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void AssertMonotonic()
|
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.
|
// 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 = -7.0 + 0.01; h < 0.10; h += 0.01) Check(h);
|
||||||
for (double h = 0.10; h <= 2.0; h += 0.0001) prev = Step(prev, (float)h);
|
for (double h = 0.10; h <= 2.0; h += 0.0001) Check(h);
|
||||||
for (double h = 2.0; h <= 8.0; h += 0.05) prev = Step(prev, (float)h);
|
for (double h = 2.05; h <= 8.0; h += 0.05) Check(h);
|
||||||
GD.Print("[HeightCurve] Monotonicity assertion passed (v" + VERSION + ").");
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue