bevy_ecs_tilemap icon indicating copy to clipboard operation
bevy_ecs_tilemap copied to clipboard

Bug: Hex `TilePos` can have its fields equal to map size

Open Piturnah opened this issue 2 years ago • 2 comments

For a hex tilemap it appears you can get the case where the TilePos is equal to its bounds.

E.g. with TilemapSize { x: 10, y: 10 } you can get TilePos { x: 10, .. } and TilePos { y: 10, .. } after calling fill_tilemap_hexagon

This means that calls to TilePos::within_map_bounds will fail, causing issues such as TilePos::from_world_pos returning None even though there is a tile there.

Link to simple example: repo

In the example, clicking on tiles highlights them. It is expected to work for all tiles, but it does not work for the upper left edge and the right edge, as we have the case described above.

Hex tilemap with most tiles grey but two edges are white

Piturnah avatar Sep 10 '23 19:09 Piturnah

I had a workaround for this, providing the true map size + (1,1) in the map_size field of TilePos::from_world_pos. However this workaround no longer works now that this function requires an anchor. Don't understand enough of what's going on to come up with a new workaround. Is the upstream fix as simple as just increasing the bounds for TilePos::within_map_bounds for hex maps? I'm just surprised this issue isn't coming up for other people

Piturnah avatar Jul 07 '25 14:07 Piturnah

This commit fixes the issue for me: https://github.com/Piturnah/bevy_ecs_tilemap/commit/3b95c2cb3777637637319087c2dae0ba993f6e8c

But I don't know what other issues it may cause.

Piturnah avatar Jul 07 '25 14:07 Piturnah