close #127 (user-gated + desk pin): distant-building flood flap died with the W=0 clip port

User re-gate 2026-06-12: ran past distant buildings, 'Seems to have
been fixed' - no flicker/vanish. The per-building flood-admission
bistability (#127, the building-flap mechanism behind the tower roof
flap and #123 'buildings vanish when running past') is gone.

Root: the bistable knife-edge admission died with the W=0
polyClipFinish clip port (987313a - the #119/#120 work that 'kills the
knife-edge class everywhere') plus the #120 containment-rejection
growth fix. The captured-pair evidence (tower-viewer-capture.log,
2026-06-11) PRE-dates all of those - it was that same near-eye knife
edge, not a separate distant mechanism.

Desk confirmation (both green at HEAD):
- CapturedFlipPair_AdmissionIsStable: the original 4 cm flip pair is
  now |A|=|B| with zero diff across all FOVs and both pre-gate states.
- DistantBuildingStrafe_NoAdmissionChurn (new regression pin): 0
  admission churn across all 21 building groups x {10,30,60,120,190} m
  x 100 mm-step run-past strafes, both pre-gate states. A stable flood
  toggles each cell at most once over a monotone eye path; this asserts
  no cell toggles >=2x.

ISSUES.md #127 -> CLOSED with the DO-NOT-RETRY note (no re-opening the
BuildFromExterior seed gates for a flap symptom without a fresh HEAD
repro - the captured-pair lead is dead). Render digest banner updated.

Suites: App 264+1skip / Core 1443+2skip / UI 420 / Net 294.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-13 10:03:33 +02:00
parent bf800677f0
commit 4ad6fb9184
2 changed files with 144 additions and 2 deletions

View file

@ -218,4 +218,133 @@ public class Issue127FloodFlipReplayTests
Assert.Fail($"flood admission differs across the captured 4 cm pair (preGate={preGate}, fov={fov:F2}) — see output for the flipping cells");
}
}
// Centre of a building group's exit-portal AABB (world space).
private static (bool Has, Vector3 Center) PortalCenterFor(List<LoadedCell> group)
{
var (has, min, max) = PortalBoundsFor(group);
return (has, (min + max) * 0.5f);
}
// Per-building admitted cells (this group only) at one (eye, gaze) — the
// production per-building flood + optional PortalBounds frustum pre-gate.
private static HashSet<uint> BuildingAdmits(
World w, List<LoadedCell> group, Vector3 eye, Matrix4x4 viewProj,
FrustumPlanes frustum, bool withPreGate)
{
var result = new HashSet<uint>();
if (withPreGate)
{
var (has, min, max) = PortalBoundsFor(group);
if (has && !FrustumCuller.IsAabbVisible(frustum, min, max))
return result;
}
var bf = PortalVisibilityBuilder.ConstructViewBuilding(group, eye, w.Lookup, viewProj);
foreach (uint id in bf.OrderedVisibleCells)
result.Add(id);
return result;
}
/// <summary>
/// #127 distant-building churn detector. The captured 4 cm pair is now
/// stable (the near-eye W=0 clip port), but the user symptom is buildings
/// flickering when RUNNING PAST at a distance. This strafes the eye past
/// each loaded building at several distances in 1 mm steps with the gaze
/// fixed forward (the run-past geometry) and counts, per building cell, how
/// many times its admission toggles over the monotone strafe. A stable
/// flood toggles a cell AT MOST ONCE along a monotone eye path (it enters
/// or leaves the view a single time); >=2 toggles is churn — the building
/// flickers. preGate off vs on separates flood-math churn from the
/// PortalBounds frustum pre-gate.
///
/// RESULT (2026-06-12, HEAD post-W=0-clip-port + #120 containment): ZERO
/// churning cases across all 21 building groups x {10,30,60,120,190} m x
/// 100 mm-steps, both preGate states. The near-eye knife-edge class the
/// W=0 polyClipFinish port (987313a) killed was the distant-building
/// flicker too; the user re-gate ("Seems to have been fixed") agrees.
/// Now the REGRESSION PIN — it asserts zero churn.
/// </summary>
[Fact]
public void DistantBuildingStrafe_NoAdmissionChurn()
{
var w = LoadWorld();
if (w is null) return;
const float fovY = MathF.PI / 3f;
const float eyeHeight = 1.8f;
const float strafeSpanM = 0.10f; // 10 cm strafe
const int strafeSteps = 100; // 1 mm/step
var distances = new[] { 10f, 30f, 60f, 120f, 190f };
int totalChurn = 0;
foreach (bool preGate in new[] { false, true })
{
int worstToggles = 0;
string worstDesc = "(none)";
int churningCases = 0;
for (int gi = 0; gi < w.BuildingGroups.Count; gi++)
{
var group = w.BuildingGroups[gi];
var (has, center) = PortalCenterFor(group);
if (!has) continue;
foreach (float dist in distances)
{
// Eye south of the building at eye height, gaze NORTH toward
// the building centre; strafe along world +X (run-past).
var gaze = Vector3.Normalize(new Vector3(0f, 1f, -0.05f));
var strafeDir = Vector3.Normalize(Vector3.Cross(Vector3.UnitZ, gaze)); // ~world +X
var eyeBase = new Vector3(center.X, center.Y - dist, center.Z + eyeHeight)
- strafeDir * (strafeSpanM * 0.5f);
var toggleCount = new Dictionary<uint, int>();
var prevIn = new Dictionary<uint, bool>();
for (int s = 0; s <= strafeSteps; s++)
{
var eye = eyeBase + strafeDir * (strafeSpanM * s / strafeSteps);
var vp = ViewProjFor(eye, gaze, fovY);
var frustum = FrustumPlanes.FromViewProjection(vp);
var admits = BuildingAdmits(w, group, eye, vp, frustum, preGate);
var seen = new HashSet<uint>(admits);
foreach (uint id in seen)
{
bool wasIn = prevIn.TryGetValue(id, out var p) && p;
if (!wasIn && prevIn.ContainsKey(id))
toggleCount[id] = toggleCount.GetValueOrDefault(id) + 1;
prevIn[id] = true;
}
foreach (var id in new List<uint>(prevIn.Keys))
if (!seen.Contains(id))
{
if (prevIn[id])
toggleCount[id] = toggleCount.GetValueOrDefault(id) + 1;
prevIn[id] = false;
}
}
foreach (var (id, toggles) in toggleCount)
{
if (toggles < 2) continue; // <=1 = clean enter/leave
churningCases++;
if (toggles > worstToggles)
{
worstToggles = toggles;
worstDesc = FormattableString.Invariant(
$"group#{gi} dist={dist:F0}m cell=0x{id:X8} toggles={toggles}");
}
}
}
}
_out.WriteLine(FormattableString.Invariant(
$"preGate={preGate}: churningCases={churningCases} worst={worstDesc} (worstToggles={worstToggles})"));
totalChurn += churningCases;
}
Assert.True(totalChurn == 0,
$"{totalChurn} distant-building admission churn case(s) — a building's cells toggle >=2x " +
"over a monotone run-past strafe (the #127 flicker); see output for the worst building/distance/cell");
}
}