Struct foundry::Grid [−][src]
pub struct Grid { /* fields omitted */ }
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.
Methods
impl Grid
[src]
impl Grid
pub fn guess_pattern_origin(&self) -> (usize, usize)
[src]
pub fn guess_pattern_origin(&self) -> (usize, usize)
Returns the coordinates of the cell at the upper left corner of
the current Grid
.
pub fn guess_pattern_size(&self) -> (usize, usize)
[src]
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>)
[src]
pub fn compute_pattern_boundaries(
&self
) -> (Option<usize>, Option<usize>, Option<usize>, Option<usize>)
impl Grid
[src]
impl Grid
pub fn from_file(path: &str) -> Result<Grid, FileParsingErrorKind>
[src]
pub fn from_file(path: &str) -> Result<Grid, FileParsingErrorKind>
Returns a new Grid
encoded within a file located at path
.
Errors
If there is an IO error or the file isn't a valid life file,
an error of the type FileParsingErrorKind
will be returned.
pub fn save_life_grid(&self, path: &str) -> Result<(), Error>
[src]
pub fn save_life_grid(&self, path: &str) -> Result<(), Error>
Writes the Grid
into a file located at path
.
Errors
If there is an IO error, an error of the type io::Error
will be returned.
impl Grid
[src]
impl Grid
pub fn randomize(&mut self)
[src]
pub fn randomize(&mut self)
Randomizes the current Grid
by setting a random state to
each cell.
pub fn next_gen(&mut self)
[src]
pub fn next_gen(&mut self)
Computes the next generation of the current Grid
and updates it.
pub fn recenter_pattern(&mut self, border_width: usize)
[src]
pub fn recenter_pattern(&mut self, border_width: usize)
impl Grid
[src]
impl Grid
pub fn new(
frmt: &String,
trdl: bool,
srvl: &Vec<u32>,
brth: &Vec<u32>,
width: usize,
height: usize
) -> Grid
[src]
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
pub fn new_random(
frmt: &String,
trdl: bool,
srvl: &Vec<u32>,
brth: &Vec<u32>,
width: usize,
height: usize
) -> Grid
[src]
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.
pub fn get_format(&self) -> String
[src]
pub fn get_format(&self) -> String
Returns the file format used.
pub fn set_format(&mut self, frmt: &String)
[src]
pub fn set_format(&mut self, frmt: &String)
Sets a new file format for this Grid
.
pub fn is_toroidal(&self) -> bool
[src]
pub fn is_toroidal(&self) -> bool
Returns true
if the grid is toroidal. Otherwise the grid is resizable.
pub fn get_survival(&self) -> Vec<u32>
[src]
pub fn get_survival(&self) -> Vec<u32>
Returns the survival conditions of the cellular automaton.
pub fn set_survival(&mut self, srvl: &Vec<u32>)
[src]
pub fn set_survival(&mut self, srvl: &Vec<u32>)
Redefines the survival conditions of the cellular automaton.
pub fn get_birth(&self) -> Vec<u32>
[src]
pub fn get_birth(&self) -> Vec<u32>
Returns the birth conditions of the cellular automaton.
pub fn set_birth(&mut self, brth: &Vec<u32>)
[src]
pub fn set_birth(&mut self, brth: &Vec<u32>)
Redefines the birth conditions of the cellular automaton.
pub fn get_width(&self) -> usize
[src]
pub fn get_width(&self) -> usize
Returns the width of the grid.
pub fn get_height(&self) -> usize
[src]
pub fn get_height(&self) -> usize
Returns the height of the grid.
pub fn get_cell_state(&self, x: i64, y: i64) -> u8
[src]
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
.
pub fn set_cell_state(
&mut self,
x: usize,
y: usize,
state: u8
) -> Result<(), GridErrorKind>
[src]
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
impl Clone for Grid
[src]
impl Clone for Grid
fn clone(&self) -> Grid
[src]
fn clone(&self) -> Grid
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Grid
[src]
impl Debug for Grid
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Display for Grid
[src]
impl Display for Grid