[−][src]Struct foundry::Grid
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]
pub fn guess_pattern_origin(&self) -> (usize, usize)
[src]
Returns the coordinates of the cell at the upper left corner of
the current Grid
.
pub fn guess_pattern_size(&self) -> (usize, usize)
[src]
Returns the size of the current Grid
's pattern.
pub fn compute_pattern_boundaries(
&self
) -> (Option<usize>, Option<usize>, Option<usize>, Option<usize>)
[src]
&self
) -> (Option<usize>, Option<usize>, Option<usize>, Option<usize>)
impl Grid
[src]
pub fn from_file(path: &str) -> Result<Grid, FileParsingErrorKind>
[src]
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]
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]
pub fn randomize(&mut self)
[src]
Randomizes the current Grid
by setting a random state to
each cell.
pub fn next_gen(&mut self)
[src]
Computes the next generation of the current Grid
and updates it.
pub fn recenter_pattern(&mut self, border_width: usize)
[src]
impl Grid
[src]
pub fn render(
&self,
x_pos: usize,
y_pos: usize,
view_width: usize,
view_height: usize,
img_width: usize,
img_height: usize
) -> Vec<u8>
[src]
&self,
x_pos: usize,
y_pos: usize,
view_width: usize,
view_height: usize,
img_width: usize,
img_height: usize
) -> Vec<u8>
impl Grid
[src]
pub fn new(
frmt: &String,
trdl: bool,
srvl: &Vec<u32>,
brth: &Vec<u32>,
width: usize,
height: usize
) -> Grid
[src]
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]
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]
Returns the file format used.
pub fn set_format(&mut self, frmt: &String)
[src]
Sets a new file format for this Grid
.
pub fn is_toroidal(&self) -> bool
[src]
Returns true
if the grid is toroidal. Otherwise the grid is resizable.
pub fn get_survival(&self) -> Vec<u32>
[src]
Returns the survival conditions of the cellular automaton.
pub fn set_survival(&mut self, srvl: &Vec<u32>)
[src]
Redefines the survival conditions of the cellular automaton.
pub fn get_birth(&self) -> Vec<u32>
[src]
Returns the birth conditions of the cellular automaton.
pub fn set_birth(&mut self, brth: &Vec<u32>)
[src]
Redefines the birth conditions of the cellular automaton.
pub fn get_width(&self) -> usize
[src]
Returns the width of the grid.
pub fn get_height(&self) -> usize
[src]
Returns the height of the grid.
pub fn get_cell_state(&self, x: i64, y: i64) -> u8
[src]
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]
&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 Unpin for Grid
impl Sync for Grid
impl Send for Grid
impl UnwindSafe for Grid
impl RefUnwindSafe for Grid
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,