feat(walls): one-way sight per-viewer filter and ONEWAY fault (#58)

The vision fan blocks a sight-blocking one-way wall only for a viewer on
its blind side (sight_dir names it; left is the (-dy,dx) normal of a->b),
one sign test inline after the radius cull, so the hoisted wall list stays
viewer-independent. Movement never reads the direction: one-way walls block
both ways. Explored and tiles therefore differ by side and only ever grow.

- geometry: WallDir + Wall.sightDir + blindTo, filter in visibilityPolygon.
- worldmap: sight_dir mapping (movement mapping unchanged).
- vision: the ONEWAY leak-fault build drops sight_dir player-side.
- leakcheck: own side test for the fan and the clear-segment oracle; ONEWAY
  class detected against the sight_dir-dropped fan.
- leak scenario gains a one-way wall the subject sees across; fault test
  asserts exactly ONEWAY.
- oneway.test.mjs: both sides, tile sweep with its own oracle, flip with
  fixed endpoints, monotone explored/tiles, restart, two-way movement.
- docs: DESIGN 5.8 mechanism sentence corrected; TESTING #58 markers built.
- nginx harness: temp dirs created recursively (restart on one state dir).
This commit is contained in:
2026-11-19 22:57:39 +01:00
parent 0f3aa2300f
commit 9fcbe885c1
14 changed files with 649 additions and 78 deletions
+30
View File
@@ -3,6 +3,9 @@
## Fixed in M2 (DESIGN 5.5): token exactly on a wall can move off it (moverules escape rule); the move check is the
## swept circle, not centre path + destination only; `moveBlocked` is gone from this module; cellsTouched is a scanline
## (prototype per-cell version kept test-only in tests/refold.nim, differential-tested).
## One-way sight (DESIGN 5.8, #58): `Wall.sightDir` names the blind side of `a -> b` (`left` = the `(-dy, dx)` normal)
## and `visibilityPolygon` blocks such a wall only for a viewer on that side; the other side casts rays past it.
## Movement never reads it: `moverules` gets the same wall and blocks both ways.
## Known limitations (DESIGN 5.4 / 12):
## - boundary epsilon ambiguity: RayEps 1e-4 rad, inclusive tests; token on a vision boundary is ambiguous
## (leak checker and explored oracle use a 0.5 px neighbourhood).
@@ -15,9 +18,19 @@ import std/[math, algorithm]
type
Vec* = tuple[x, y: float]
WallDir* = enum
## Which side of the drawn `a -> b` order cannot see across (DESIGN 5.8, #47/#58). `left` is
## the `(-dy, dx)` side, the same formula as `position` (5.10) and the door-push side (5.5).
## This is a sight-only field: movement is always two-way and never reads it.
wdBoth = "both"
wdLeft = "left"
wdRight = "right"
Wall* = object
a*, b*: Vec
door*, open*: bool
sightDir*: WallDir
const
Eps* = 1e-9 # geometric tolerance (px)
@@ -28,6 +41,19 @@ proc blocks*(w: Wall): bool = not (w.door and w.open)
proc cross*(a, b: Vec): float = a.x * b.y - a.y * b.x
proc `-`*(a, b: Vec): Vec = (a.x - b.x, a.y - b.y)
proc blindTo*(w: Wall, o: Vec): bool =
## DESIGN 5.8: true when `o` stands on the side the wall's `sight_dir` names blind. One sign test
## of the viewer against the `a -> b` left normal: cross(a->b, o - a) is the signed distance along
## `(-dy, dx)`, so positive is the left side. A viewer exactly on the drawn line (|s| <= Eps) is
## blind to either direction: the predicate is never ambiguous, even though the fan's own rays
## start on the segment and a token standing on a wall already sees along it (5.5).
if w.sightDir == wdBoth: return false
let s = cross(w.b - w.a, o - w.a)
case w.sightDir
of wdBoth: false
of wdLeft: s >= -Eps
of wdRight: s <= Eps
proc rayHit(o, d: Vec, a, b: Vec): float =
## smallest t > Eps where o + t*d hits segment ab (end-inclusive), else Inf
let e = b - a
@@ -54,6 +80,10 @@ proc visibilityPolygon*(o: Vec, walls: openArray[Wall], radius: float,
# shortcut: walls beyond the circle are only culled by ray clipping, O(rays*walls); upgrade: spatial grid
if max(w.a.x, w.b.x) < o.x - radius or min(w.a.x, w.b.x) > o.x + radius or
max(w.a.y, w.b.y) < o.y - radius or min(w.a.y, w.b.y) > o.y + radius: continue
# Per-viewer one-way filter (5.8, #58), inline and after the radius cull so the hoisted wall
# list stays viewer-independent: a sight-blocking one-way wall blocks only a viewer on its
# blind side; the other side sees across it. Two-way walls skip the test entirely.
if w.sightDir != wdBoth and not w.blindTo(o): continue
segs.add((w.a, w.b))
for p in [w.a, w.b]:
if abs(p.x - o.x) < Eps and abs(p.y - o.y) < Eps: continue # token on endpoint