Trait sark_grids::point::GridPoint
source · pub trait GridPoint: Clone + Copy {
Show 21 methods
// Required methods
fn x(&self) -> i32;
fn y(&self) -> i32;
fn get_pivot(self) -> Option<Pivot>;
// Provided methods
fn width(&self) -> i32 { ... }
fn height(&self) -> i32 { ... }
fn len(&self) -> usize { ... }
fn as_ivec2(&self) -> IVec2 { ... }
fn as_uvec2(&self) -> UVec2 { ... }
fn as_vec2(&self) -> Vec2 { ... }
fn as_array(&self) -> [i32; 2] { ... }
fn as_index(&self, grid_width: usize) -> usize { ... }
fn pivot(&self, pivot: Pivot) -> PivotedPoint { ... }
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 taxi_dist(self, other: impl GridPoint) -> usize { ... }
fn lerp(self, other: impl GridPoint, t: f32) -> IVec2 { ... }
fn adj_8(&self) -> AdjIterator<'_> ⓘ { ... }
fn adj_4(&self) -> AdjIterator<'_> ⓘ { ... }
}
Expand description
A trait for types representing an integer point on a 2d grid.
Required Methods§
fn x(&self) -> i32
fn y(&self) -> i32
sourcefn get_pivot(self) -> Option<Pivot>
fn get_pivot(self) -> Option<Pivot>
Retrieve the pivot-aligned point on the grid.
If no pivot has been applied this will simply return the point
directly.
Retrieve the PivotedPoint
with applied pivots, if any.
Provided Methods§
fn width(&self) -> i32
fn height(&self) -> i32
fn len(&self) -> usize
fn as_ivec2(&self) -> IVec2
fn as_uvec2(&self) -> UVec2
fn as_vec2(&self) -> Vec2
fn as_array(&self) -> [i32; 2]
sourcefn pivot(&self, pivot: Pivot) -> PivotedPoint
fn pivot(&self, pivot: Pivot) -> PivotedPoint
Return a PivotedPoint.
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 the grid point offset by the given amount.
sourcefn taxi_dist(self, other: impl GridPoint) -> usize
fn taxi_dist(self, other: impl GridPoint) -> usize
The taxicab distance between two grid points.
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_8(&self) -> AdjIterator<'_> ⓘ
fn adj_8(&self) -> AdjIterator<'_> ⓘ
Returns an iterator over the 8 points adjacent to this one.
sourcefn adj_4(&self) -> AdjIterator<'_> ⓘ
fn adj_4(&self) -> AdjIterator<'_> ⓘ
Returns an iterator over the 4 points adjacent to this one.