diff --git a/CHANGELOG.md b/CHANGELOG.md index cd1db159..8185d75c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tcod/map.py b/tcod/map.py index e1f4403b..2ae1725b 100644 --- a/tcod/map.py +++ b/tcod/map.py @@ -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. @@ -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)], diff --git a/tests/test_tcod.py b/tests/test_tcod.py index 3f8c1d9b..27801343 100644 --- a/tests/test_tcod.py +++ b/tests/test_tcod.py @@ -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: