Struct sark_grids::world_grid::WorldGrid
source · pub struct WorldGrid {
pub world_space: WorldSpace,
pub pixels_per_tile: UVec2,
pub tile_count: UVec2,
}
Expand description
A sized grid which can be used to translate world positions to
tile positions based on WorldSpace
and the size of the grid.
Fields§
§world_space: WorldSpace
The WorldSpace
for this grid.
pixels_per_tile: UVec2
How many pixels constitute a “tile” in the grid.
tile_count: UVec2
How many tiles the grid has.
Implementations§
source§impl WorldGrid
impl WorldGrid
sourcepub fn unit_grid(
tile_count: impl GridPoint,
pixels_per_tile: impl GridPoint
) -> Self
pub fn unit_grid( tile_count: impl GridPoint, pixels_per_tile: impl GridPoint ) -> Self
Create a WorldGrid
set to WorldSpace::Units
.
sourcepub fn pixel_grid(
tile_count: impl GridPoint,
pixels_per_tile: impl GridPoint
) -> Self
pub fn pixel_grid( tile_count: impl GridPoint, pixels_per_tile: impl GridPoint ) -> Self
Create a WorldGrid
set to WorldSpace::Pixels
.
sourcepub fn tile_size_world(&self) -> Vec2
pub fn tile_size_world(&self) -> Vec2
The size of a tile in world space, given pixels_per_tile
and world_space
.
sourcepub fn pos_to_index(&self, pos: impl Point2d) -> IVec2
pub fn pos_to_index(&self, pos: impl Point2d) -> IVec2
Convert a position to it’s corresponding tile index.
sourcepub fn get_pos_to_index(&self, pos: impl Point2d) -> Option<IVec2>
pub fn get_pos_to_index(&self, pos: impl Point2d) -> Option<IVec2>
Try to get the corresponding tile index of a given position.
Returns none if the position is out of grid bounds.
sourcepub fn index_to_pos(&self, pos: impl GridPoint) -> Vec2
pub fn index_to_pos(&self, pos: impl GridPoint) -> Vec2
Convert a tile index to it’s corresponding position.
The returned position is the bottom left of the tile.
sourcepub fn world_size(&self) -> Vec2
pub fn world_size(&self) -> Vec2
How large the grid is in world space, given the WorldSpace
of the grid.
sourcepub fn pos_to_tile_pos(&self, pos: impl Point2d) -> Vec2
pub fn pos_to_tile_pos(&self, pos: impl Point2d) -> Vec2
Convert a position to it’s tile position in the grid.
sourcepub fn index_to_tile_center(&self, index: impl GridPoint) -> Vec2
pub fn index_to_tile_center(&self, index: impl GridPoint) -> Vec2
Return the world center of the tile at the given index.
sourcepub fn pivot_pos(&self, pivot: Pivot) -> Vec2
pub fn pivot_pos(&self, pivot: Pivot) -> Vec2
Return the tile position of a pivot point given the size of the grid.
pub fn pivot_pos_world(&self, pivot: Pivot) -> Vec2
pub fn index_in_bounds(&self, index: impl GridPoint) -> bool
pub fn pos_in_bounds(&self, pos: impl Point2d) -> bool
sourcepub fn tile_pos_iter(&self) -> impl Iterator<Item = Vec2>
pub fn tile_pos_iter(&self) -> impl Iterator<Item = Vec2>
An iterator over the position of every tile in the grid.
A tile’s “position” refers to the bottom left point on the tile.
sourcepub fn tile_center_iter(&self) -> impl Iterator<Item = Vec2>
pub fn tile_center_iter(&self) -> impl Iterator<Item = Vec2>
An iterator over the center of every tile in the grid.