Struct sark_grids::world_grid::WorldGrid
source · [−]pub struct WorldGrid { /* private fields */ }
Expand description
A sized grid with a custom pivot for translating between aligned grid points and world space.
Implementations
sourceimpl WorldGrid
impl WorldGrid
pub fn new(size: impl Size2d, pivot: Pivot) -> Self
sourcepub fn tile_pos_from_index2d(&self, grid_pos: impl GridPoint) -> Vec2
pub fn tile_pos_from_index2d(&self, grid_pos: impl GridPoint) -> Vec2
Returns the tile position of a given tile from a given grid point.
A tile’s “position” refers to the bottom left point on the tile.
sourcepub fn tile_center_from_index2d(&self, grid_pos: impl GridPoint) -> Vec2
pub fn tile_center_from_index2d(&self, grid_pos: impl GridPoint) -> Vec2
Returns the center point of a given tile.
sourcepub fn grid_pos_in_bounds(&self, grid_pos: impl GridPoint) -> bool
pub fn grid_pos_in_bounds(&self, grid_pos: impl GridPoint) -> bool
Whether or not the given grid position is inside the grid bounds.
A grid’s bounds are determined by it’s pivot - a grid’s pivot always sits on the world new.
sourcepub fn index_2d_in_bounds(&self, index: impl GridPoint) -> bool
pub fn index_2d_in_bounds(&self, index: impl GridPoint) -> bool
Whether or not the given 2d index is inside the grid bounds.
sourcepub fn try_grid_to_index_2d(&self, grid_pos: impl GridPoint) -> Option<IVec2>
pub fn try_grid_to_index_2d(&self, grid_pos: impl GridPoint) -> Option<IVec2>
Convert a grid point to it’s corresponding 2d index.
Returns none if the given grid point is out of bounds.
sourcepub fn grid_to_index_2d(&self, grid_pos: impl GridPoint) -> IVec2
pub fn grid_to_index_2d(&self, grid_pos: impl GridPoint) -> IVec2
Converts from a local grid position to it’s corresponding 2d index.
This function will return out of bounds values if given out of bounds grid positions.
For a bound-checked version use try_grid_to_index_2d
sourcepub fn index_2d_to_grid(&self, i: impl GridPoint) -> IVec2
pub fn index_2d_to_grid(&self, i: impl GridPoint) -> IVec2
Convert from a 2d index to it’s corresponding grid position.
sourcepub fn point_to_tile_center(&self, point: impl Point2d) -> Vec2
pub fn point_to_tile_center(&self, point: impl Point2d) -> Vec2
Convert from a an arbitrary local position to the tile center at that position’s tile.
sourcepub fn world_to_local(&self, point: impl Point2d) -> Vec2
pub fn world_to_local(&self, point: impl Point2d) -> Vec2
Convert a world position to it’s local position on the grid (it’s position relative to the grid’s pivot).
pub fn local_to_world(&self, point: impl Point2d) -> Vec2
pub fn width(&self) -> usize
pub fn height(&self) -> usize
pub fn size(&self) -> UVec2
sourcepub fn tile_pos_iter(&self) -> impl Iterator<Item = Vec2>
pub fn tile_pos_iter(&self) -> impl Iterator<Item = Vec2>
An iterator over the tile 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 tile center of every tile in the grid.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for WorldGrid
impl Send for WorldGrid
impl Sync for WorldGrid
impl Unpin for WorldGrid
impl UnwindSafe for WorldGrid
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more