Recursive shadowcasting: which tiles an observer can see from where it stands.
Cauldron2D.Grid.Fov.compute(&transparent?/1, {12, 9}, 8)
#=> MapSet.new([{12, 9}, {12, 8}, ...])The map is walked as eight octants, each a wedge scanned row by row away from the observer; an opaque tile splits the wedge and what is behind it is not visited, so the cost follows what is visible rather than the area of the circle.
Two rules a caller can rely on:
- Walls bounding a lit area are lit: an opaque tile is added to the set before it stops the scan.
- Visibility is mutual: if
bis in the set computed froma,ais in the set computed frombat the same radius.
transparent? is a function from a tile to whether sight passes through it; a tile
outside the map should answer false. origin itself is always in the set.
Summary
Functions
The set of tiles visible from origin within radius, measured as Euclidean distance.
Types
Functions
@spec compute(transparent(), point(), pos_integer()) :: MapSet.t(point())
The set of tiles visible from origin within radius, measured as Euclidean distance.