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
Required Methods§
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]
Sourcefn as_index(&self, size: impl GridSize) -> usize
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.
Sourcefn get_index(&self, size: impl GridSize) -> Option<usize>
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.
Sourcefn up(&self, amount: i32) -> IVec2
fn up(&self, amount: i32) -> IVec2
Returns the grid point the given number of spaces above this one.
Sourcefn down(&self, amount: i32) -> IVec2
fn down(&self, amount: i32) -> IVec2
Returns the grid point the given number of spaces below this one.
Sourcefn right(&self, amount: i32) -> IVec2
fn right(&self, amount: i32) -> IVec2
Returns the grid point the given number of spaces to the right of this one.
Sourcefn left(&self, amount: i32) -> IVec2
fn left(&self, amount: i32) -> IVec2
Returns the grid point the given number of spaces to the left of this one.
Sourcefn offset(&self, xy: impl GridPoint) -> IVec2
fn offset(&self, xy: impl GridPoint) -> IVec2
Returns this grid point offset by the given amount.
fn min(&self, other: impl GridPoint) -> IVec2
fn max(&self, other: impl GridPoint) -> IVec2
Sourcefn pivot(self, pivot: Pivot) -> PivotedPoint
fn pivot(self, pivot: Pivot) -> PivotedPoint
Sourcefn taxi_dist(self, other: impl GridPoint) -> usize
fn taxi_dist(self, other: impl GridPoint) -> usize
The taxicab distance between two points on a four-way grid.
Sourcefn king_dist(self, other: impl GridPoint) -> usize
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.
Sourcefn lerp(self, other: impl GridPoint, t: f32) -> IVec2
fn lerp(self, other: impl GridPoint, t: f32) -> IVec2
Linearly interpolate between points a and b by the amount t.
Sourcefn adj_4(&self) -> AdjIterator<'_> ⓘ
fn adj_4(&self) -> AdjIterator<'_> ⓘ
Returns an iterator over the 4 grid points orthogonally adjacent to this one.
Sourcefn adj_8(&self) -> AdjIterator<'_> ⓘ
fn adj_8(&self) -> AdjIterator<'_> ⓘ
Returns an iterator over the 8 points adjacent to this one.
Sourcefn is_cardinal(&self, other: impl GridPoint) -> bool
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.