[][src]Struct foundry::Grid

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]

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]

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]

impl Grid[src]

pub fn new(
    frmt: &String,
    trdl: bool,
    srvl: &Vec<u32>,
    brth: &Vec<u32>,
    width: usize,
    height: usize
) -> Grid
[src]

Returns a new Grid:

  • containing the file format frmt
  • toroidal if trdl is true, resizable otherwise
  • containing the rules given by srvl and brth
  • whose grid's size is determined by width and height

pub fn new_random(
    frmt: &String,
    trdl: bool,
    srvl: &Vec<u32>,
    brth: &Vec<u32>,
    width: usize,
    height: usize
) -> Grid
[src]

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]

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 Display for Grid[src]

impl Debug for Grid[src]

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]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Content for T[src]

impl<T> Erased for T