Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version

## [Unreleased]

### Changed

- `tcod.map.compute_fov` now raises `ValueError` instead of warning when `pov` is outside the transparency array, as previously announced by the warning.

## [21.2.2] - 2026-10-22

### Changed
Expand Down
10 changes: 3 additions & 7 deletions tcod/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def compute_fov(
`pov` is the point-of-view origin point. Areas are visible if they can
be seen from this position. `pov` should be a 2D index matching the axes
of the `transparency` array, and must be within the bounds of the
`transparency` array.
`transparency` array. A `ValueError` is raised if `pov` is out of bounds.

`radius` is the maximum view distance from `pov`. If this is zero then
the maximum distance is used.
Expand Down Expand Up @@ -240,12 +240,8 @@ def compute_fov(
msg = "The tcod.map.compute_fov function has changed. The `x` and `y` parameters should now be given as a single tuple."
raise TypeError(msg)
if not (0 <= pov[0] < transparency.shape[0] and 0 <= pov[1] < transparency.shape[1]):
warnings.warn(
f"Given pov index {pov!r} is outside the array of shape {transparency.shape!r}."
"\nThis will raise an error in future versions.",
RuntimeWarning,
stacklevel=2,
)
msg = f"Given pov index {pov!r} is outside the array of shape {transparency.shape!r}."
raise ValueError(msg)
map_buffer: NDArray[np.bool_] = np.empty(
transparency.shape,
dtype=[("transparent", bool), ("walkable", bool), ("fov", bool)],
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tcod.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ def test_tcod_bsp() -> None:
str(bsp)


@pytest.mark.parametrize("pov", [(-1, 0), (0, -1), (3, 0), (0, 5)])
def test_compute_fov_out_of_bounds(pov: tuple[int, int]) -> None:
transparency = np.ones((3, 5), dtype=bool)
with pytest.raises(ValueError, match="outside the array"):
tcod.map.compute_fov(transparency, pov)


@pytest.mark.parametrize("pov", [(0, 0), (0, 4), (2, 0), (2, 4)])
def test_compute_fov_at_boundary(pov: tuple[int, int]) -> None:
transparency = np.ones((3, 5), dtype=bool)
visible = tcod.map.compute_fov(transparency, pov)
assert visible.shape == transparency.shape
assert visible.all()


@pytest.mark.filterwarnings("ignore:Use map.+ to check for this")
@pytest.mark.filterwarnings("ignore:This class may perform poorly")
def test_tcod_map_set_bits() -> None:
Expand Down
Loading