pub struct Grid { /* private fields */ }
Expand description
This struct contains the grid of a life cellular automaton.
This grid is stored as a Vec<bool>
.
When it is toroidal, its size is constant. When it is not,
it is resized when computing the next generation
according to the size of the contained pattern.
The origin of the pattern is also stored in Grid
:
the coordinates of its north west corner is stored as a
(usize, usize)
.
It also contains the cellular automaton’s rules stored as two Vec<u8>
s.
These are the survival and birth conditions into survival
and birth
respectivly.
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn guess_pattern_origin(&self) -> (usize, usize)
pub fn guess_pattern_origin(&self) -> (usize, usize)
Returns the coordinates of the cell at the upper left corner of
the current Grid
.
Sourcepub fn guess_pattern_size(&self) -> (usize, usize)
pub fn guess_pattern_size(&self) -> (usize, usize)
Returns the size of the current Grid
’s pattern.
pub fn compute_pattern_boundaries( &self, ) -> (Option<usize>, Option<usize>, Option<usize>, Option<usize>)
Source§impl Grid
impl Grid
Source§impl Grid
impl Grid
Sourcepub fn new(
frmt: &String,
trdl: bool,
srvl: &Vec<u32>,
brth: &Vec<u32>,
width: usize,
height: usize,
) -> Grid
pub fn new( frmt: &String, trdl: bool, srvl: &Vec<u32>, brth: &Vec<u32>, width: usize, height: usize, ) -> Grid
Returns a new Grid
:
- containing the file format
frmt
- toroidal if
trdl
istrue
, resizable otherwise - containing the rules given by
srvl
andbrth
- whose grid’s size is determined by
width
andheight
Sourcepub fn new_random(
frmt: &String,
trdl: bool,
srvl: &Vec<u32>,
brth: &Vec<u32>,
width: usize,
height: usize,
) -> Grid
pub fn new_random( frmt: &String, trdl: bool, srvl: &Vec<u32>, brth: &Vec<u32>, width: usize, height: usize, ) -> Grid
Returns a new Grid
and initializes its cells randomly.
Sourcepub fn get_format(&self) -> String
pub fn get_format(&self) -> String
Returns the file format used.
Sourcepub fn set_format(&mut self, frmt: &String)
pub fn set_format(&mut self, frmt: &String)
Sets a new file format for this Grid
.
Sourcepub fn is_toroidal(&self) -> bool
pub fn is_toroidal(&self) -> bool
Returns true
if the grid is toroidal. Otherwise the grid is resizable.
Sourcepub fn get_survival(&self) -> Vec<u32>
pub fn get_survival(&self) -> Vec<u32>
Returns the survival conditions of the cellular automaton.
Sourcepub fn set_survival(&mut self, srvl: &Vec<u32>)
pub fn set_survival(&mut self, srvl: &Vec<u32>)
Redefines the survival conditions of the cellular automaton.
Sourcepub fn set_birth(&mut self, brth: &Vec<u32>)
pub fn set_birth(&mut self, brth: &Vec<u32>)
Redefines the birth conditions of the cellular automaton.
Sourcepub fn get_height(&self) -> usize
pub fn get_height(&self) -> usize
Returns the height of the grid.
Sourcepub fn get_cell_state(&self, x: i64, y: i64) -> u8
pub fn get_cell_state(&self, x: i64, y: i64) -> u8
Returns the state of the cell at the coordinates (x
, y
).
If the coordinates are out of bounds and the grid is toroidal,
then it returns the state of the cell at the coordinates
modulo the size of the grid.
Otherwise, if the coordinates are out of bounds but
the grid is not toroidal, it returns 0u8
.
Sourcepub fn set_cell_state(
&mut self,
x: usize,
y: usize,
state: u8,
) -> Result<(), GridErrorKind>
pub fn set_cell_state( &mut self, x: usize, y: usize, state: u8, ) -> Result<(), GridErrorKind>
Modifies the state of the cell at the coordinates (x
, y
)
with state
.
Returns Err(GridErrorKind::OutOfBoundCoords)
if the
coordinates are out of bounds.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Grid
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)