geometry: scanline cellsTouched, differential + independent oracle tests, prototype corpus
cellsTouched is now a scanline over cell rows (prototype per-cell version kept test-only in tests/refold.nim). Differential tests (random polygons, concave, grid-aligned) and a brute-force explored oracle (0.5 px tolerance) cover it; regression corpus = prototype leak-run polygons. moveBlocked leaves geometry.nim (replaced by server/moverules.nim next); geometry primitives exported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
## TEST-ONLY reference: the prototype implementations that M2 replaced, kept verbatim (renamed) as differential oracles.
|
||||
## Never imported by server code. Source: prototype-server-vision/src/geometry.nim (M1 port).
|
||||
import std/math
|
||||
import geometry
|
||||
|
||||
proc cellsTouchedOld*(poly: openArray[Vec], cell: float): seq[(int, int)] =
|
||||
## per-cell polygon test (O(cells x edges)); grid cells overlapped by the polygon, sorted by (iy, ix).
|
||||
## Quirk kept on purpose: the bbox loop starts at floor(min/cell), so a cell that only touches the polygon's
|
||||
## bbox minimum edge (min exactly on a cell line) is not visited; every other touch is inclusive.
|
||||
if poly.len < 3: return
|
||||
var x0, y0 = Inf
|
||||
var x1, y1 = -Inf
|
||||
for p in poly:
|
||||
x0 = min(x0, p.x); x1 = max(x1, p.x); y0 = min(y0, p.y); y1 = max(y1, p.y)
|
||||
for iy in int(floor(y0 / cell)) .. int(floor(y1 / cell)):
|
||||
for ix in int(floor(x0 / cell)) .. int(floor(x1 / cell)):
|
||||
let (cx0, cy0, cx1, cy1) = (ix.float * cell, iy.float * cell, (ix + 1).float * cell, (iy + 1).float * cell)
|
||||
let c = [(cx0, cy0), (cx1, cy0), (cx1, cy1), (cx0, cy1)]
|
||||
var hit = inside(poly, c[0]) or
|
||||
(poly[0].x >= cx0 and poly[0].x <= cx1 and poly[0].y >= cy0 and poly[0].y <= cy1)
|
||||
if not hit:
|
||||
for i in 0 ..< poly.len:
|
||||
let p = poly[i]; let q = poly[(i + 1) mod poly.len]
|
||||
for k in 0 .. 3:
|
||||
if segsCross(p, q, c[k], c[(k + 1) mod 4]): hit = true; break
|
||||
if hit: break
|
||||
if hit: result.add (ix, iy)
|
||||
|
||||
proc moveBlockedOld*(walls: openArray[Wall], a, b: Vec, r = 0.0): bool =
|
||||
## prototype move check: centre path a->b (inclusive crossing) + destination circle only. Used as a LOS oracle
|
||||
## (r = 0) by tests; its policy was replaced by server/moverules.nim.
|
||||
for w in walls:
|
||||
if w.blocks and (segsCross(a, b, w.a, w.b) or segDist(b, w.a, w.b) < r): return true
|
||||
Reference in New Issue
Block a user