fix: hit a wall lying along a sight ray so it casts its line's shadow (#26)

visibilityPolygon casts one ray per 64-gon vertex and ang, ang+-RayEps per wall
endpoint. A wall radial to the viewer is collinear with the ray that crosses it,
and rayHit rejected the collinear case; its own +-RayEps rays meet the wall's
line at the viewer (t = 0, rejected by t > Eps). So the wall got no ray, no
vertex and no shadow, and a token on the line beyond it stayed inside the
polygon: a player-view fog leak (DESIGN 3.1).

Fix: rayHit returns the nearest point of the overlap when the wall lies on the
ray's line (and Inf only for a parallel wall on another line). {.inline.} keeps
the fan's inner loop at its previous cost (CPU-time cross-check on 20k dense
polygons: 25.8s before, 32.5s without the pragma, 24.9s with it).

Proof: tgeometry visibility tests (horizontal k=0, vertical k=16, both wall
directions, a 32 px grid translation, 10 degrees, plus the non-radial and
0.5 px-off negative controls); the leak world gains a wall on the subject's own
column with a hidden token beyond it, and leakcheck's HIDDEN_TOKEN class now
asserts the token-level over-approximation (token centre + viewer->token
segment, 5.4 tolerance), which the GEOMETRY class structurally cannot see.
This commit is contained in:
2026-11-20 22:17:45 +01:00
parent a11782f00d
commit 414bb0326c
7 changed files with 169 additions and 6 deletions
+47
View File
@@ -92,6 +92,12 @@ const WORLD = [
{ role: 'far-locked', a: [1400, 820], b: [1400, 920], door: true, locked: true },
// One-way screen: the wall's right (east) side is blind, so a subject west of it sees across.
{ role: 'one-way-screen', a: [700, 1200], b: [700, 1400], sight_dir: 'right' },
// A wall lying along a vision ray (#26): x = 600 is a 64-gon direction (the k = 16 ray, straight
// up) from the subject's room position (600, 640), and H1 stands beyond it on that same line. The
// fan used to hit no ray at all on such a wall, so the wall cast no shadow and H1 leaked into the
// subject's view. A zero-width wall hides exactly the line's continuation, so this is the only
// arrangement that shows it. `scenarioCoverage` reads the shape back off the frames.
{ role: 'on-ray', a: [600, 700], b: [600, 850] },
// Marked window in the room, the positive marker control: anchor (520, 800) (#59).
{ role: 'marked-window', preset: 'window', a: [520, 700], b: [520, 900] },
// Marked solid wall in the room: the switch is on but the shape is a wall, so no marker may be
@@ -130,6 +136,43 @@ export function scenarioCoverage(gmMsgs, subjMsgs) {
const marked = all.filter(w => w.player_marker)
const windows = marked.filter(isWindow)
const occluded = windows.filter(w => anchorOf(w)[0] > FAR_WALL_X)
// #26: the on-ray fixture, read off the frames rather than the WORLD constant. A subject
// position, an axis-aligned wall on that same row/column and away from it, and someone else's
// token beyond the wall on that same line inside the subject's vision radius: the one arrangement
// where a wall radial to the viewer must cast the line's shadow. A rewrite that moves any of the
// three drops this to 0 and fails in leak.test.mjs, instead of silently losing the obligation.
const mineIds = new Set()
const minePos = []
let visionR = 0
for (const m of subjMsgs) {
if (!m || typeof m.t !== 'string') continue
if (m.t === 'hello' && m.scene) visionR = m.scene.vision_radius_default
if (m.t === 'token' && m.mine) { mineIds.add(m.id); minePos.push(m.pos) }
}
const gmTokens = []
for (const m of gmMsgs) if (m && m.t === 'token') gmTokens.push({ id: m.id, pos: m.pos })
let onRayHidden = 0
for (const w of all) {
const horiz = w.a[1] === w.b[1]
const vert = w.a[0] === w.b[0]
if (!horiz && !vert) continue
const fixed = horiz ? w.a[1] : w.a[0]
const lo = horiz ? Math.min(w.a[0], w.b[0]) : Math.min(w.a[1], w.b[1])
const hi = horiz ? Math.max(w.a[0], w.b[0]) : Math.max(w.a[1], w.b[1])
for (const o of minePos) {
const along = horiz ? o[0] : o[1]
if ((horiz ? o[1] : o[0]) !== fixed) continue
if (along >= lo && along <= hi) continue
const beyond = v => (along < lo ? v < lo : v > hi)
for (const t of gmTokens) {
if (mineIds.has(t.id)) continue
if ((horiz ? t.pos[1] : t.pos[0]) !== fixed) continue
if (!beyond(horiz ? t.pos[0] : t.pos[1])) continue
if (visionR > 0 && Math.hypot(t.pos[0] - o[0], t.pos[1] - o[1]) > visionR) continue
onRayHidden++
}
}
}
return {
walls: all.length,
oneWay: all.filter(w => w.sight_dir !== 'both').length,
@@ -144,6 +187,7 @@ export function scenarioCoverage(gmMsgs, subjMsgs) {
markedWindowsOccluded: occluded.length,
markedWindowsOccludedSeen: occluded.filter(w => received.has(anchorOf(w).join(','))).length,
markers: received.size,
onRayHidden,
}
}
@@ -242,6 +286,9 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
actual_name: 'Brother Ivo' })
await createToken('N4', { kind: 'npc', pos: [1500, 870], descriptive_name: 'a jailer',
actual_name: 'Warden Hale' })
// Hidden behind the on-ray wall (#26) from the subject's (600, 640): same column, beyond it.
await createToken('H1', { kind: 'npc', pos: [600, 950], descriptive_name: 'a shade',
actual_name: 'The Shade' })
})
const A = await connect(origin, playerA.key, 'A', log, () => g)