pub struct Grid<T> {
pub cells: Vec<Option<T>>,
pub rows: Vec<NotNan<fsize>>,
pub cols: Vec<NotNan<fsize>>,
pub n_rows: usize,
pub n_cols: usize,
pub n_elements: usize,
}
Expand description
Representation of a grid of optional elements of type T Divided into rows and columns, where each row and column has a unique coordinate
Fields§
§cells: Vec<Option<T>>
§rows: Vec<NotNan<fsize>>
§cols: Vec<NotNan<fsize>>
§n_rows: usize
§n_cols: usize
§n_elements: usize
Implementations§
Source§impl<T> Grid<T>
impl<T> Grid<T>
Sourcepub fn new(elements: Vec<(T, Point)>) -> Self
pub fn new(elements: Vec<(T, Point)>) -> Self
Creates a new grid from a vector of values of type T and their coordinates
pub fn rows_in_range( &self, y_range: RangeInclusive<fsize>, ) -> RangeInclusive<usize>
pub fn cols_in_range( &self, x_range: RangeInclusive<fsize>, ) -> RangeInclusive<usize>
Sourcepub fn get_neighbors(&self, idx: usize) -> [usize; 8]
pub fn get_neighbors(&self, idx: usize) -> [usize; 8]
Returns the indices of the 8 directly neighboring cells. If the cell is on the edge, the index of the cell itself is returned instead for neighbors out of bounds
pub fn to_index(&self, row: usize, col: usize) -> Result<usize, OutOfBounds>
pub fn to_row_col(&self, index: usize) -> Option<(usize, usize)>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Grid<T>
impl<T> RefUnwindSafe for Grid<T>where
T: RefUnwindSafe,
impl<T> Send for Grid<T>where
T: Send,
impl<T> Sync for Grid<T>where
T: Sync,
impl<T> Unpin for Grid<T>where
T: Unpin,
impl<T> UnwindSafe for Grid<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more