Sight with thick and low walls

Throwaway prototype for issue #43 (wayfinder map #38). Pictures, explored cells and cost of what our polygon code does when a wall has a width and a height. Branch prototype/wall-sight, never pushed, server/ untouched.

This is a prototype, not a design. It wraps the real server/geometry.nim (the same ray fan, the same cellsTouched) and adds only the model the tickets are arguing about: the 5.8 switch filter, a thickness expansion and a per-target height predicate. Nothing here is production code and nothing was folded back.

How to read every picture

Every picture is generated from scratch by pictures.nim. The filter is 5.8's and nothing else: a wall enters the fan only if blocks_sight, never when it is an open door, a one-way wall only for the blocked side — no kind logic anywhere. Height never enters the polygon; it is a per-target 3D test (eye + t·(target − eye) > wall height), which is what research #39 §3.3 said has to happen because a nearest-hit fan can shorten a ray but never resume it.

The six pictures

thin wall vs thick wall, same layout

1 — Thin vs thick, same layout (t = 14 px)

Left: today's zero-width wall. Right: the same wall as a 3-face rectangle (near face + two end caps). The wall's own body becomes hidden floor, the shadow edge moves out by t/2 (7 px here — visible only if you compare the two panels), and the polygon is a strict subset: 228 explored cells thin, 227 thick, 0 gained, 1 lost.

Surprise: at 14 px on a 400 px room the pictures are almost identical. Thickness costs cells in proportion to cell size vs room size, so on a normal map it is a border cell here and there — the dense 5k layout is where it eats half the view.

two thick walls meeting at a corner

2 — Corner where two thick walls meet

Same L-shaped room, thin then thick. Thin: the polygon reaches the shared vertex exactly. Thick: the two bodies overlap at the joint, the inner corner loses its cells (242 → 232 explored, 0 gained, 10 lost), and the eye sees less into the corner because the near faces are 7 px closer.

Surprise: no crack at the joint in either panel. The expected zero-width sliver leak at a shared vertex did not appear at this scale — the ±RayEps fan already covers it — so "thickness is needed to close the joints" is not what this layout shows; the polygon change comes from the wall bodies alone.

doorway in a thick wall, closed and open

3 — Doorway in a thick wall, closed vs open, viewer at an angle

The wall has a 90 px opening with a 14 px thick leaf. Closed (left): nothing passes. Open (right): the door is gone from the input, but the two jambs are 14 px deep, so the view through is a narrow diagonal beam — token A (right behind the opening) is visible, token C (left of it) is behind the wall, and token B is clipped by the far corner of the right jamb even though it is well past the opening.

Surprise: opening a thick door does not reveal the doorway's width, it reveals a keyhole whose shape depends on where the viewer stands. On a 32 px grid that beam is 1–2 cells wide, so a player standing two steps to the side unlocks almost nothing through a door they just opened.

1 m wall, tall and short viewer, tokens of different heights

4 — A 1 m wall, tall viewer (1.8 m) vs short viewer (1.0 m)

Wall 12 px thick, 1.0 m high; the eye is 70 px in front of it. For the 1.8 m viewer (eye 1.67 m) the floor behind the wall is hidden out to d = s·h_eye/(h_eye−h_wall) = 174 px from the eye — the salmon band — and visible again beyond it. The dashed polygon is the same fan with the low wall ignored: exactly the extra floor a "low walls never block" rule would reveal. For the 1.0 m viewer (eye 0.93 m, below the wall top) no floor behind is ever visible: the whole far side is salmon, but a 1.8 m token's head still shows over the wall.

Surprise: the target's height matters as much as the wall's. In 4a a 1.0 m token 75 px behind the wall is visible while a 0.3 m crate 45 px behind it is not; in 4b (eye below the wall top) two tall tokens are visible and nothing else is. A wall-only flag ("low wall = see over") gets both of those wrong.

Surprise: the fog has to pick an error. Solid polygon = the floor behind a low wall is never explored from a distance, so a token you can see stands on a black tile. Dashed polygon = the fog reveals a band nobody can see. There is no polygon that does the right thing; that is #44's decision.

terrain wall vs no wall

5 — Terrain wall = no wall (the 5.8 payoff)

Left: no wall at all. Right: the same layout with a 14 px thick terrain wall (blocks_sight:false, blocks_movement:true). The two polygons are vertex-identical (64/64, 318 explored cells both), the explored sets are equal and nothing is drawn differently apart from the wall itself.

Confirmed rather than surprising: blocks_sight:false costs literally zero polygon work, thickness and height included, because the wall never reaches the geometry. Any "cheap terrain" argument in #44/#45 can rely on that.

one-way wall seen from both sides

6 — One-way wall, from both sides

One 12 px thick wall, sight_dir:"left", a → b pointing down the page, so the left (west) side is the blocked one. Left: a viewer west of it gets a polygon that stops at the wall, and both east tokens stay in fog. Right: a viewer east of it has the wall absent from the geometry (one filter decision, not a special case in the fan) and sees west through it, including the two west tokens.

Surprise: this is the only scenario where the explored maps of two players in the same room differ permanently, and it is the only place where the 5.8 filter must run per observer — i.e. per polygon, not per scene (see the cost table: that filter is not free).

Cost

Same harness as tools/bench.nim (2000 iterations, 50 warm-up, -d:release, avg ms per one visibility polygon, radius 400, cell 32). "Today" = the blocking walls pre-expanded into the segment list the fan already takes, which is what production does. Thick = 10 px, 3 faces (near + 2 caps, exact for a viewer on the near side but observer-dependent) or 4 faces (a quad, exact and hoistable once per wall edit). Cells = explored cells per polygon.

scenearmpoly msvertscellsvs today
prototype (60 walls, 4096 px)thin (today)0.031884121.00×
thin + 5.8 filter per query0.033884121.06×
thick 3 faces, per query0.0511193961.65×
thick 4 faces, per query0.0641423942.06×
thick 4 faces, hoisted0.0571423941.84×
5k sparse (16384 px, 15.8 walls in box)thin (today)0.0831622411.00×
thin + 5.8 filter per query0.2371622412.84×
thick 3 faces, per query0.6993142198.37×
thick 4 faces, per query0.94341021711.30×
thick 4 faces, hoisted0.2634102173.15×
5k dense (4096 px, 206 walls in box)thin (today)1.2541332541.00×
thin + 5.8 filter per query1.3991332541.12×
thick 3 faces, per query7.8513724266.26×
thick 4 faces, per query13.22949762110.55×
thick 4 faces, hoisted12.72149762110.15×

Read: on the realistic (sparse) density a hoisted quad costs 0.26 ms per polygon — inside the 1 ms target, and it reproduces the 0.257 ms measured for #39. The dense stress layout is 10× over and stays over for every exact variant. Two costs hide in the numbers: the 5.8 filter is +0.15 ms per polygon at 5k walls (because it scans every wall in the scene: 2.8× the sparse baseline, ≈ 0.9 ms for a 6-token party — the whole per-move budget), and the 3-face silhouette is observer-dependent so it can never be hoisted. Raw output: cost.txt.

Surprises and open questions (for #44 and #45)

Not done (do not read the pictures for these)

Rebuild

nim c -r prototype-wall-sight/pictures.nim          # rewrites img/*.svg
nim c -d:release -r prototype-wall-sight/bench_thick.nim   # rewrites the table above (cost.txt)

Files: sightmodel.nim (filter, thickness expansion, height predicate), pictures.nim (scenarios + SVG), bench_thick.nim (cost), cost.txt (raw run).