[][src]Struct gridsim::SquareGrid

pub struct SquareGrid<'a, S: Sim<'a>> { /* fields omitted */ }

Represents the state of the simulation.

Methods

impl<'a, S: Sim<'a>> SquareGrid<'a, S>[src]

pub fn new(width: usize, height: usize) -> Self where
    S::Cell: Default
[src]

Make a new grid using the Cell's Default impl.

pub fn new_default(width: usize, height: usize, default: S::Cell) -> Self where
    S::Cell: Clone
[src]

Make a new grid by cloning a default Cell.

pub fn new_iter<I>(width: usize, height: usize, iter: I) -> Self where
    I: IntoIterator<Item = S::Cell>, 
[src]

Make a new grid directly from an initial iter.

pub fn new_coord_map<F>(width: usize, height: usize, coord_map: F) -> Self where
    F: FnMut(isize, isize) -> S::Cell
[src]

Make a grid by evaluating each centered signed coordinate to a cell with a closure.

pub fn new_coords<I>(width: usize, height: usize, coords: I) -> Self where
    I: IntoIterator<Item = ((isize, isize), S::Cell)>,
    S::Cell: Default
[src]

Make a grid using a collection of centered signed coordinates with associated cells.

pub fn new_true_coords<I>(width: usize, height: usize, coords: I) -> Self where
    I: IntoIterator<Item = (isize, isize)>,
    S: Sim<'a, Cell = bool>, 
[src]

Make a grid using a collection of centered signed coordinates that indicate true cells.

pub fn delta_index(&self, i: usize, delta: (isize, isize)) -> usize[src]

Offset an index to a new index.

pub fn get_cell(&self, i: usize) -> &S::Cell[src]

Get a &Cell. Panics if out of bounds.

pub fn get_cell_at(&self, x: usize, y: usize) -> &S::Cell[src]

Get a &Cell. Panics if out of bounds.

pub unsafe fn get_cell_unchecked(&self, i: usize) -> &S::Cell[src]

Get a &Cell. Panics if out of bounds.

pub fn get_cell_mut(&mut self, i: usize) -> &mut S::Cell[src]

Get a &mut Cell. Panics if out of bounds.

pub fn get_cell_at_mut(&mut self, x: usize, y: usize) -> &mut S::Cell[src]

Get a &mut Cell. Panics if out of bounds.

pub unsafe fn get_move_neighbors(&self, i: usize) -> &S::MoveNeighbors[src]

This can only be called in the trait TakeMoveDirection when implmenting a new Neighborhood.

pub unsafe fn get_diff(&self, i: usize) -> &S::Diff[src]

This can only be called in the trait TakeMoveDirection when implmenting a new Neighborhood.

pub fn get_cells(&self) -> &[S::Cell][src]

Get the Grid's Cell slice.

pub fn get_cells_mut(&mut self) -> &mut [S::Cell][src]

Get the Grid's Cell slice mutably.

pub fn get_width(&self) -> usize[src]

Get the Grid's width.

pub fn get_height(&self) -> usize[src]

Get the Grid's height.

pub fn size(&self) -> usize[src]

Get the Grid's size.

impl<'a, S, C, D, M, N, MN> SquareGrid<'a, S> where
    S: Sim<'a, Cell = C, Diff = D, Move = M, Neighbors = N, MoveNeighbors = MN> + 'a,
    S::Cell: Sync + Send,
    S::Diff: Sync + Send,
    S::Move: Sync + Send,
    S::Neighbors: Sync + Send,
    S::MoveNeighbors: Sync + Send,
    Self: GetNeighbors<'a, usize, N>,
    Self: TakeMoveNeighbors<usize, MN>, 
[src]

pub fn cycle(&mut self)[src]

Run the Grid for one cycle and parallelize the simulation.

impl<'a, S, C, D, M, N, MN> SquareGrid<'a, S> where
    S: Sim<'a, Cell = C, Diff = D, Move = M, Neighbors = N, MoveNeighbors = MN> + 'a,
    S::Cell: Sync + Send + Serialize + Deserialize<'dc> + 'a,
    S::Diff: Sync + Send,
    S::Move: Sync + Send,
    S::Neighbors: Sync + Send,
    S::MoveNeighbors: Sync + Send,
    Self: GetNeighbors<'a, usize, N>,
    Self: TakeMoveNeighbors<usize, MN>, 
[src]

pub unsafe fn cycle_multi<I0: Read, I1: Read, I2: Read, I3: Read, I4: Read, I5: Read, I6: Read, I7: Read, O0: Write, O1: Write, O2: Write, O3: Write, O4: Write, O5: Write, O6: Write, O7: Write>(
    &mut self,
    in_right: I0,
    in_up_right: I1,
    in_up: I2,
    in_up_left: I3,
    in_left: I4,
    in_down_left: I5,
    in_down: I6,
    in_down_right: I7,
    out_right: O0,
    out_up_right: O1,
    out_up: O2,
    out_up_left: O3,
    out_left: O4,
    out_down_left: O5,
    out_down: O6,
    out_down_right: O7
) -> Result<()>
[src]

Run the Grid for one cycle and parallelize the simulation.

Make sure the reads and writes are only connected to other SquareGrid::cycle running on any machine using THE EXACT SAME simulation or else there may be undefined behavior.

Trait Implementations

impl<'a, C, S> GetNeighbors<'a, usize, MooreNeighbors<&'a C>> for SquareGrid<'a, S> where
    S: Sim<'a, Cell = C>, 
[src]

impl<'a, C, S> GetNeighbors<'a, usize, NeumannNeighbors<&'a C>> for SquareGrid<'a, S> where
    S: Sim<'a, Cell = C>, 
[src]

impl<'a, S, M> TakeMoveDirection<usize, MooreDirection, M> for SquareGrid<'a, S> where
    S: Sim<'a, Move = M, MoveNeighbors = MooreNeighbors<M>>, 
[src]

impl<'a, S, M> TakeMoveDirection<usize, NeumannDirection, M> for SquareGrid<'a, S> where
    S: Sim<'a, Move = M, MoveNeighbors = NeumannNeighbors<M>>, 
[src]

impl<'a, S: Sim<'a>> TakeMoveNeighbors<usize, ()> for SquareGrid<'a, S>[src]

impl<'a, S, M> TakeMoveNeighbors<usize, MooreNeighbors<M>> for SquareGrid<'a, S> where
    S: Sim<'a, Move = M, MoveNeighbors = MooreNeighbors<M>>, 
[src]

impl<'a, S, M> TakeMoveNeighbors<usize, NeumannNeighbors<M>> for SquareGrid<'a, S> where
    S: Sim<'a, Move = M, MoveNeighbors = NeumannNeighbors<M>>, 
[src]

impl<'a, S, D> TakeDiff<usize, D> for SquareGrid<'a, S> where
    S: Sim<'a, Diff = D>, 
[src]

impl<'a, S: Clone + Sim<'a>> Clone for SquareGrid<'a, S> where
    S::Cell: Clone,
    S::Diff: Clone,
    S::MoveNeighbors: Clone
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a, S: Debug + Sim<'a>> Debug for SquareGrid<'a, S> where
    S::Cell: Debug,
    S::Diff: Debug,
    S::MoveNeighbors: Debug
[src]

Auto Trait Implementations

impl<'a, S> Send for SquareGrid<'a, S> where
    <S as Sim<'a>>::Cell: Send,
    <S as Sim<'a>>::Diff: Send,
    <S as Sim<'a>>::MoveNeighbors: Send

impl<'a, S> Unpin for SquareGrid<'a, S> where
    <S as Sim<'a>>::Cell: Unpin,
    <S as Sim<'a>>::Diff: Unpin,
    <S as Sim<'a>>::MoveNeighbors: Unpin

impl<'a, S> Sync for SquareGrid<'a, S> where
    <S as Sim<'a>>::Cell: Sync,
    <S as Sim<'a>>::Diff: Sync,
    <S as Sim<'a>>::MoveNeighbors: Sync

impl<'a, S> UnwindSafe for SquareGrid<'a, S> where
    <S as Sim<'a>>::Cell: UnwindSafe,
    <S as Sim<'a>>::Diff: UnwindSafe,
    <S as Sim<'a>>::MoveNeighbors: UnwindSafe

impl<'a, S> RefUnwindSafe for SquareGrid<'a, S> where
    <S as Sim<'a>>::Cell: RefUnwindSafe,
    <S as Sim<'a>>::Diff: RefUnwindSafe,
    <S as Sim<'a>>::MoveNeighbors: RefUnwindSafe

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

impl<T, U> Into<U> for T where
    U: From<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]