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

source

pub fn unit_grid( tile_count: impl GridPoint, pixels_per_tile: impl GridPoint ) -> Self

Create a WorldGrid set to WorldSpace::Units.

source

pub fn pixel_grid( tile_count: impl GridPoint, pixels_per_tile: impl GridPoint ) -> Self

Create a WorldGrid set to WorldSpace::Pixels.

source

pub fn tile_size_world(&self) -> Vec2

The size of a tile in world space, given pixels_per_tile and world_space.

source

pub fn pos_to_index(&self, pos: impl Point2d) -> IVec2

Convert a position to it’s corresponding tile index.

source

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.

source

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.

source

pub fn world_size(&self) -> Vec2

How large the grid is in world space, given the WorldSpace of the grid.

source

pub fn pos_to_tile_pos(&self, pos: impl Point2d) -> Vec2

Convert a position to it’s tile position in the grid.

source

pub fn index_to_tile_center(&self, index: impl GridPoint) -> Vec2

Return the world center of the tile at the given index.

source

pub fn pivot_pos(&self, pivot: Pivot) -> Vec2

Return the tile position of a pivot point given the size of the grid.

source

pub fn pivot_pos_world(&self, pivot: Pivot) -> Vec2

source

pub fn index_in_bounds(&self, index: impl GridPoint) -> bool

source

pub fn pos_in_bounds(&self, pos: impl Point2d) -> bool

source

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.

source

pub fn tile_center_iter(&self) -> impl Iterator<Item = Vec2>

An iterator over the center of every tile in the grid.

Trait Implementations§

source§

impl Clone for WorldGrid

source§

fn clone(&self) -> WorldGrid

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WorldGrid

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for WorldGrid

source§

fn eq(&self, other: &WorldGrid) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for WorldGrid

source§

impl StructuralPartialEq for WorldGrid

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.