Struct sark_grids::world_grid::WorldGrid
source · [−]pub struct WorldGrid {
pub world_pos: Vec2,
/* private fields */
}
Expand description
A sized grid with a custom pivot for translating between aligned grid points and world space.
Fields
world_pos: Vec2
Implementations
sourceimpl WorldGrid
impl WorldGrid
pub fn new(world_pos: impl Point2d, size: impl Size2d, pivot: Pivot) -> Self
sourcepub fn origin(size: impl Size2d, pivot: Pivot) -> Self
pub fn origin(size: impl Size2d, pivot: Pivot) -> Self
Create a grid with it’s world position set to origin.
sourcepub fn tile_pos(&self, grid_pos: impl Point2d) -> Vec2
pub fn tile_pos(&self, grid_pos: impl Point2d) -> Vec2
Returns the tile position of a given tile.
A tile’s “position” refers to the bottom left point on the tile.
sourcepub fn tile_center(&self, grid_pos: impl Point2d) -> Vec2
pub fn tile_center(&self, grid_pos: impl Point2d) -> Vec2
Returns the center point of a given tile.
sourcepub fn tile_pos_world(&self, grid_pos: impl Point2d) -> Vec2
pub fn tile_pos_world(&self, grid_pos: impl Point2d) -> Vec2
Returns the position of the given tile in world space.
A tile’s “position” refers to the bottom left point on the tile.
sourcepub fn tile_center_world(&self, grid_pos: [i32; 2]) -> Vec2
pub fn tile_center_world(&self, grid_pos: [i32; 2]) -> Vec2
Return’s the center of the given tile in world space.
sourcepub fn grid_pos_in_bounds(&self, grid_pos: [i32; 2]) -> bool
pub fn grid_pos_in_bounds(&self, grid_pos: [i32; 2]) -> 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 origin.
sourcepub fn index_2d_in_bounds(&self, index: impl Point2d) -> bool
pub fn index_2d_in_bounds(&self, index: impl Point2d) -> bool
Whether or not the given 2d index is inside the grid bounds.
sourcepub fn try_grid_to_index_2d(&self, grid_pos: [i32; 2]) -> Option<IVec2>
pub fn try_grid_to_index_2d(&self, grid_pos: [i32; 2]) -> 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 Point2d) -> IVec2
pub fn grid_to_index_2d(&self, grid_pos: impl Point2d) -> 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 Point2d) -> IVec2
pub fn index_2d_to_grid(&self, i: impl Point2d) -> IVec2
Convert from a 2d index to it’s corresponding grid position.
pub fn width(&self) -> usize
pub fn height(&self) -> usize
pub fn size(&self) -> IVec2
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.
sourcepub fn tile_pos_iter_world(&self) -> impl Iterator<Item = Vec2>
pub fn tile_pos_iter_world(&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.
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more