foundry

Struct Grid

Source
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

Source

pub fn guess_pattern_origin(&self) -> (usize, usize)

Returns the coordinates of the cell at the upper left corner of the current Grid.

Source

pub fn guess_pattern_size(&self) -> (usize, usize)

Returns the size of the current Grid’s pattern.

Source

pub fn compute_pattern_boundaries( &self, ) -> (Option<usize>, Option<usize>, Option<usize>, Option<usize>)

Source§

impl Grid

Source

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.

Source

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.

Source§

impl Grid

Source

pub fn randomize(&mut self)

Randomizes the current Grid by setting a random state to each cell.

Source

pub fn next_gen(&mut self)

Computes the next generation of the current Grid and updates it.

Source

pub fn recenter_pattern(&mut self, border_width: usize)

Source§

impl Grid

Source

pub fn render( &self, x_pos: usize, y_pos: usize, view_width: usize, view_height: usize, img_width: usize, img_height: usize, ) -> Vec<u8>

Source§

impl Grid

Source

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 is true, resizable otherwise
  • containing the rules given by srvl and brth
  • whose grid’s size is determined by width and height
Source

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.

Source

pub fn get_format(&self) -> String

Returns the file format used.

Source

pub fn set_format(&mut self, frmt: &String)

Sets a new file format for this Grid.

Source

pub fn is_toroidal(&self) -> bool

Returns true if the grid is toroidal. Otherwise the grid is resizable.

Source

pub fn get_survival(&self) -> Vec<u32>

Returns the survival conditions of the cellular automaton.

Source

pub fn set_survival(&mut self, srvl: &Vec<u32>)

Redefines the survival conditions of the cellular automaton.

Source

pub fn get_birth(&self) -> Vec<u32>

Returns the birth conditions of the cellular automaton.

Source

pub fn set_birth(&mut self, brth: &Vec<u32>)

Redefines the birth conditions of the cellular automaton.

Source

pub fn get_width(&self) -> usize

Returns the width of the grid.

Source

pub fn get_height(&self) -> usize

Returns the height of the grid.

Source

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.

Source

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§

Source§

impl Clone for Grid

Source§

fn clone(&self) -> Grid

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Grid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Grid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Content for T

Source§

fn ref_from_ptr<'a>(ptr: *mut c_void, size: usize) -> Option<*mut T>

Builds a pointer to this type from a raw pointer.
Source§

fn is_size_suitable(size: usize) -> bool

Returns true if the size is suitable to store a type like this.
Source§

fn indiv_size() -> usize

Returns the size of an individual element.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T