Struct advent_of_code_2022::util::grid::Grid
source · pub struct Grid {
pub numbers: Vec<u8>,
pub width: usize,
}
Expand description
A representation of a 2D grid of u8s.
Fields§
§numbers: Vec<u8>
Store the numbers in a 1D list…
width: usize
…and use the width to determine the 1D offset as a 2D co-ordinate
Implementations§
source§impl Grid
impl Grid
sourcepub fn new<F>(width: usize, height: usize, init: F) -> Selfwhere
F: Fn(usize, usize) -> u8,
pub fn new<F>(width: usize, height: usize, init: F) -> Selfwhere F: Fn(usize, usize) -> u8,
Build a new grid with a mapping function to generate the date for each cell
pub fn from_string_with_mapping( input: &String, mapping: fn(_: char) -> u8 ) -> Self
sourcepub fn iter(&self) -> GridCoords<'_> ⓘ
pub fn iter(&self) -> GridCoords<'_> ⓘ
Helper to abstract iterating over the whole grid
sourcepub fn pos_of(&self, (y, x): (usize, usize)) -> Option<usize>
pub fn pos_of(&self, (y, x): (usize, usize)) -> Option<usize>
Turn (y, x) coordinates into a position in the underlying array
sourcepub fn get_with_coords(&self, pos: usize) -> Option<((usize, usize), u8)>
pub fn get_with_coords(&self, pos: usize) -> Option<((usize, usize), u8)>
Used by GridCoords::next
pub fn get_orthogonal_surrounds( &self, (y, x): (usize, usize) ) -> Vec<((usize, usize), u8)>
pub fn get_relative( &self, y: usize, x: usize, dy: isize, dx: isize ) -> Option<((usize, usize), u8)>
sourcepub fn print(&self) -> String
pub fn print(&self) -> String
Dump the grid to stdout - useful for visualising the grid when debugging
pub fn print_with<F>(&self, cell_renderer: F) -> Stringwhere F: Fn(u8) -> String,
Trait Implementations§
source§impl PartialEq<Grid> for Grid
impl PartialEq<Grid> for Grid
impl Eq for Grid
impl StructuralEq for Grid
impl StructuralPartialEq for Grid
Auto Trait Implementations§
impl RefUnwindSafe for Grid
impl Send for Grid
impl Sync for Grid
impl Unpin for Grid
impl UnwindSafe for Grid
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