Skip to content

Conversation

@uwulasm
Copy link

@uwulasm uwulasm commented Jan 9, 2026

This adds a corresponding and opposite function to TilemapChunk::calculate_tile_transform. Similarly to that function, which ignores whether or not the given coordinates are outside of the chunk, returns the IVec2 of the coordinates the tile would have been at if such a tile existed, including returning negative values.

Objective

There is currently an awkward asymmetry in the fact that the TilemapChunk allows converting from a tile position to a Transform, but does not allow converting from a general translation to a tile position. This seeks to fix this.

Solution

This adds the function TilemapChunk::calculate_tile_pos

Testing

Testing this function is simple. ideally, it should always do the opposite of the calculate_tile_transform function.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

This adds a corresponding and opposite function to
TilemapChunk::calculate_tile_transform. Similarly to that function,
which ignores whether or not the given coordinates are outside of the
chunk, returns the IVec2 of the coordinates the tile would have been at
if such a tile existed, including returning negative values.
@uwulasm uwulasm force-pushed the add_calculate_tile_pos branch from 90b907f to 002dbf6 Compare January 9, 2026 14:39
// divided by display size for a tile
/ self.tile_display_size.x as f32
// minus 3/2 to reverse the center correction
- 3. / 2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did 3/2 come from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has to be done to prevent an off-by-one error

@kfc35 kfc35 added A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants