Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version

### Fixed

- `tcod.image.Image.rotate90` updates the width and height of rectangular images, keeping NumPy array conversions consistent with the rotated pixels.
- Adding a root to an already resolved `tcod.path.Pathfinder` resets its predecessor only when its value improves the current distance. This prevents cyclic paths while preserving routes to cheaper roots.
- Lazy pathfinder queries reconsider previously visited goals after adding a root or lowering a root's distance.

Expand Down
1 change: 1 addition & 0 deletions tcod/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def rotate90(self, rotations: int = 1) -> None:
rotations (int): Number of 90 degree clockwise rotations.
"""
lib.TCOD_image_rotate90(self.image_c, rotations)
self.width, self.height = self._get_size()

def vflip(self) -> None:
"""Vertically flip this Image."""
Expand Down
27 changes: 27 additions & 0 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Tests for the image object and its NumPy interface."""

import numpy as np
import pytest

import tcod.image


@pytest.mark.parametrize("shape", [(4, 6), (6, 4), (4, 4)])
@pytest.mark.parametrize("rotations", [-5, -2, -1, 0, 1, 2, 3, 4, 5])
def test_rotate90_dimensions(shape: tuple[int, int], rotations: int) -> None:
pixels = np.arange(shape[0] * shape[1] * 3, dtype=np.uint8).reshape(*shape, 3)
image = tcod.image.Image.from_array(pixels)
image.rotate90(rotations)
expected = np.rot90(pixels, -rotations)
assert (image.height, image.width) == expected.shape[:2]
np.testing.assert_array_equal(np.asarray(image), expected)


def test_rotate90_sequence() -> None:
pixels = np.arange(4 * 6 * 3, dtype=np.uint8).reshape(4, 6, 3)
image = tcod.image.Image.from_array(pixels)
for _ in range(4):
image.rotate90()
pixels = np.rot90(pixels, -1)
assert (image.height, image.width) == pixels.shape[:2]
np.testing.assert_array_equal(np.asarray(image), pixels)
Loading