Files
SirStoneandClaude Sonnet 5.5 e0705a8533 bench: harness with synthetic 5k-wall scenes (devbox run bench), scenegen + tests
Targets met without a spatial grid: polygon+cells 0.048 ms (<= 0.451) on the prototype scene, polygon 0.083 ms
(< 1 ms) on 5k sparse. 5k dense stress layout reported (1.28 ms). Logs: results/bench.log, nimble-test.log.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 12:15:31 +01:00

31 lines
1.8 KiB
Nim

## Synthetic wall scenes for the wall-count scaling bench (DESIGN 5.3 / 13 M2, H3).
## Layout: a square world of `world` px split into G x G rooms, G = ceil(sqrt(n / 2)); every room owns its EAST and SOUTH
## edge (2 candidate walls per room, west/north belong to the neighbour), so an n = 5000 scene is exactly 50 x 50 rooms.
## Each edge becomes ONE wall segment covering 55..95 % of the edge at a random offset (the rest is a doorway gap, so vision
## really passes between rooms); endpoints are jittered by up to +-6 px (no axis-aligned degeneracy); every 10th wall is a
## closed door. Generation stops after exactly n walls (row-major). Fully determined by (world, n, seed): xorshift64.
## Density: walls per vision bbox (800 x 800, radius 400) ~= 2 * (800 / pitch)^2: pitch 327.68 (world 16384) -> ~12,
## pitch 81.92 (world 4096, "dense") -> ~190.
import std/math
import geometry
import ../tests/testutil # Rng
proc genScene*(world: float, n: int, seed: uint64): seq[Wall] =
var r = Rng(s: seed)
let g = int(ceil(sqrt(n.float / 2)))
let pitch = world / g.float
proc jit(r: var Rng): float = r.uni(-6, 6)
for gy in 0 ..< g:
for gx in 0 ..< g:
for edge in 0 .. 1: # 0 = east edge (vertical), 1 = south edge (horizontal)
if result.len >= n: return
let frac = r.uni(0.55, 0.95)
let off = r.uni(0, 1 - frac)
let (x0, y0) = (gx.float * pitch, gy.float * pitch)
var a, b: Vec
if edge == 0:
a = (x0 + pitch + r.jit, y0 + off * pitch + r.jit); b = (x0 + pitch + r.jit, y0 + (off + frac) * pitch + r.jit)
else:
a = (x0 + off * pitch + r.jit, y0 + pitch + r.jit); b = (x0 + (off + frac) * pitch + r.jit, y0 + pitch + r.jit)
result.add Wall(a: a, b: b, door: result.len mod 10 == 9, open: false)