Trait GridPoint

Source
pub trait GridPoint: Clone + Copy {
Show 26 methods // Required method fn xy(&self) -> IVec2; // Provided methods fn x(&self) -> i32 { ... } fn y(&self) -> i32 { ... } fn width(&self) -> usize { ... } fn height(&self) -> usize { ... } fn to_ivec2(&self) -> IVec2 { ... } fn to_uvec2(&self) -> UVec2 { ... } fn to_vec2(&self) -> Vec2 { ... } fn to_array(&self) -> [i32; 2] { ... } fn to_usize_array(&self) -> [usize; 2] { ... } fn as_index(&self, size: impl GridSize) -> usize { ... } fn get_index(&self, size: impl GridSize) -> Option<usize> { ... } fn up(&self, amount: i32) -> IVec2 { ... } fn down(&self, amount: i32) -> IVec2 { ... } fn right(&self, amount: i32) -> IVec2 { ... } fn left(&self, amount: i32) -> IVec2 { ... } fn offset(&self, xy: impl GridPoint) -> IVec2 { ... } fn min(&self, other: impl GridPoint) -> IVec2 { ... } fn max(&self, other: impl GridPoint) -> IVec2 { ... } fn pivot(self, pivot: Pivot) -> PivotedPoint { ... } fn taxi_dist(self, other: impl GridPoint) -> usize { ... } fn king_dist(self, other: impl GridPoint) -> usize { ... } fn lerp(self, other: impl GridPoint, t: f32) -> IVec2 { ... } fn adj_4(&self) -> AdjIterator<'_> { ... } fn adj_8(&self) -> AdjIterator<'_> { ... } fn is_cardinal(&self, other: impl GridPoint) -> bool { ... }
}
Expand description

A trait for types representing an integer point on a 2d grid.

This trait is implemented for most 2d vector types such as IVec2, UVec2, `[i32;2]``, etc

Required Methods§

Source

fn xy(&self) -> IVec2

Provided Methods§

Source

fn x(&self) -> i32

Source

fn y(&self) -> i32

Source

fn width(&self) -> usize

Source

fn height(&self) -> usize

Source

fn to_ivec2(&self) -> IVec2

Source

fn to_uvec2(&self) -> UVec2

Source

fn to_vec2(&self) -> Vec2

Source

fn to_array(&self) -> [i32; 2]

Source

fn to_usize_array(&self) -> [usize; 2]

Source

fn as_index(&self, size: impl GridSize) -> usize

Calculate the 1d index of this position within a sized grid.

This will panic if the grid position or the resulting 1d index is out of bounds.

Source

fn get_index(&self, size: impl GridSize) -> Option<usize>

Calculate the 1d index of this position within a sized grid.

Returns None if the position is out of bounds.

Source

fn up(&self, amount: i32) -> IVec2

Returns the grid point the given number of spaces above this one.

Source

fn down(&self, amount: i32) -> IVec2

Returns the grid point the given number of spaces below this one.

Source

fn right(&self, amount: i32) -> IVec2

Returns the grid point the given number of spaces to the right of this one.

Source

fn left(&self, amount: i32) -> IVec2

Returns the grid point the given number of spaces to the left of this one.

Source

fn offset(&self, xy: impl GridPoint) -> IVec2

Returns this grid point offset by the given amount.

Source

fn min(&self, other: impl GridPoint) -> IVec2

Source

fn max(&self, other: impl GridPoint) -> IVec2

Source

fn pivot(self, pivot: Pivot) -> PivotedPoint

Applies a Pivot to this position, which can be used to calculate a final pivot adjusted point within a sized grid.

§Example:
use sark_grids::{GridPoint, Pivot};
let point = [0,0].pivot(Pivot::TopRight);
assert_eq!([8,8], point.calculate([9,9]).to_array());
Source

fn taxi_dist(self, other: impl GridPoint) -> usize

The taxicab distance between two points on a four-way grid.

Source

fn king_dist(self, other: impl GridPoint) -> usize

The king’s distance between two points on an eight-way grid, assuming diagonal moves cost the same as cardinal moves.

Source

fn lerp(self, other: impl GridPoint, t: f32) -> IVec2

Linearly interpolate between points a and b by the amount t.

Source

fn adj_4(&self) -> AdjIterator<'_>

Returns an iterator over the 4 grid points orthogonally adjacent to this one.

Source

fn adj_8(&self) -> AdjIterator<'_>

Returns an iterator over the 8 points adjacent to this one.

Source

fn is_cardinal(&self, other: impl GridPoint) -> bool

Whether or not the given point is cardinal (not diagonal) to this one.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl GridPoint for IVec2

Source§

fn xy(&self) -> IVec2

Source§

impl GridPoint for UVec2

Source§

fn xy(&self) -> IVec2

Source§

impl GridPoint for [i32; 2]

Source§

fn xy(&self) -> IVec2

Source§

impl GridPoint for [u32; 2]

Source§

fn xy(&self) -> IVec2

Source§

impl GridPoint for [usize; 2]

Source§

fn xy(&self) -> IVec2

Implementors§