Skip to content

spatial-monorepo


spatial-monorepo / wayfinding/src / buildOccupancyGrid

Function: buildOccupancyGrid()

buildOccupancyGrid(units, openings, opts?): OccupancyGrid

Defined in: packages/wayfinding/src/occupancy-grid.ts:586

Rasterizes a single level's unit polygons + openings into a binary occupancy grid (Wayfinding v2 plan §3.2–3.3; issue #472). Issue #477 extends this with fixture/kiosk obstacle stamping, wall-vertex clearance discs, and a dynamic "blocked unit" layer (restricted rooms / avoidance zones) — all opt-in via opts, defaulting to off so a bare buildOccupancyGrid(units, openings) call rasterizes exactly as it did pre-#477.

units, openings, and opts.fixtures must already be filtered to one level — use buildOccupancyGridForLevel to do that filtering from a full IMDFArchive.

Convenience wrapper around buildBaseOccupancyGrid + restampOccupancyGrid (issue #483) — every caller that doesn't need per-rung restamping (i.e. everything outside the relaxation ladder) can keep calling this exactly as before; findGridRouteWithLadder/findGridRouteWithLadderOnLevel call the two halves directly instead, so the ladder can restamp a cached base grid without re-rasterizing walls on every rung.

Grid semantics (data[y * width + x]): starts fully blocked, then

  1. every unit polygon's interior is scanline-filled walkable,
  2. every unit polygon boundary edge is stroked back to blocked (~wallStrokeWidthCells wide),
  3. every Opening carves a walkable gap through the stroke it crosses,
  4. a clearance disc is stamped at every unit-ring vertex when wallVertexClearanceM/ wallVertexClearanceOpeningM is set (issue #477),
  5. every fixture/kiosk footprint in opts.fixtures is stamped blocked, upscaled about its own centroid by opts.fixtureUpscale (issue #477), and
  6. every unit in opts.blockedUnitIds (minus opts.preserveUnitIds) is filled solid, overriding its own interior/door-gap cells (issue #477's dynamic "blocked room" layer for the relaxation ladder).

Space outside every unit polygon is therefore blocked by default (not just the wall strokes) — this matters for a single concave (e.g. L-shaped) unit, where the concave notch is genuinely outside the polygon and must be routed around, not treated as open space.

Parameters

units

IMDFFeature`<UnitProps>`[]

openings

IMDFFeature`<OpeningProps>`[]

opts?

OccupancyGridOptions = {}

Returns

OccupancyGrid

Released under commercial licensing.