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§

source

fn x(&self) -> i32

source

fn y(&self) -> i32

source

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§

source

fn width(&self) -> i32

source

fn height(&self) -> i32

source

fn len(&self) -> usize

source

fn as_ivec2(&self) -> IVec2

source

fn as_uvec2(&self) -> UVec2

source

fn as_vec2(&self) -> Vec2

source

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

source

fn as_index(&self, grid_width: usize) -> usize

Get the grid point’s corresponding 1d index.

source

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

Return a PivotedPoint.

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 the grid point offset by the given amount.

source

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

The taxicab distance between two grid points.

source

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

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

source

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

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

source

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

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl GridPoint for IVec2

source§

fn x(&self) -> i32

source§

fn y(&self) -> i32

source§

fn get_pivot(self) -> Option<Pivot>

source§

impl GridPoint for UVec2

source§

fn x(&self) -> i32

source§

fn y(&self) -> i32

source§

fn get_pivot(self) -> Option<Pivot>

source§

impl GridPoint for [i32; 2]

source§

fn x(&self) -> i32

source§

fn y(&self) -> i32

source§

fn get_pivot(self) -> Option<Pivot>

source§

impl GridPoint for [u32; 2]

source§

fn x(&self) -> i32

source§

fn y(&self) -> i32

source§

fn get_pivot(self) -> Option<Pivot>

source§

impl GridPoint for [usize; 2]

source§

fn x(&self) -> i32

source§

fn y(&self) -> i32

source§

fn get_pivot(self) -> Option<Pivot>

Implementors§