Struct gol_core::neighbors::grid_surround::NeighborsGridSurround[][src]

pub struct NeighborsGridSurround<T> { /* fields omitted */ }

Implementations

impl<T> NeighborsGridSurround<T>[src]

pub fn new(margin: T) -> Self where
    T: Clone
[src]

Creates a new neighbor calculator with equal margin on all sides and dimensions.

use gol_core::{
    NeighborsGridSurround, BoardNeighborManager, GridPoint2D, GridPoint3D
};

// Create Conway's Game of Life margin: 1 on each side.
let neighbor_calc = NeighborsGridSurround::new(1usize);
let cur_point = GridPoint2D{ x: 10, y: 5 };
let neighbors: Vec<GridPoint2D<i32>> =
    neighbor_calc.get_neighbors_idx(&cur_point).collect();
assert_eq!(neighbors.len(), 8);

let neighbor_calc_2 = NeighborsGridSurround::new(1usize);
let cur_point = GridPoint3D{ x: 10, y: 5, z: 9};
let neighbors_2: Vec<GridPoint3D<i32>> =
    neighbor_calc_2.get_neighbors_idx(&cur_point).collect();
assert_eq!(neighbors_2.len(), 26);

pub fn new_with_variable_margin<'a, 'b, I>(margins: I) -> Self where
    'a: 'b,
    T: 'a + Clone,
    I: Iterator<Item = &'b (T, T)>, 
[src]

Creates a new neighbor calculator with specific margin on each side and dimension. Elements in the vector represents different dimensions, the two values inside the vector represents margin on the negative and positive side along that dimension.

use gol_core::{GridPoint2D, NeighborsGridSurround, BoardNeighborManager}; // Create 2D margin with 2 on all sides but positive y-axis.
let margins = [(2usize, 2), (2usize, 1)];
let neighbor_calc =
    NeighborsGridSurround::new_with_variable_margin(margins.iter());

let cur_point = GridPoint2D{ x: 10, y: 5 };
let neighbors: Vec<GridPoint2D<i32>> =
    neighbor_calc.get_neighbors_idx(&cur_point).collect();
assert_eq!(neighbors.len(), 19);

Trait Implementations

Auto Trait Implementations

impl<T> RefUnwindSafe for NeighborsGridSurround<T> where
    T: RefUnwindSafe

impl<T> Send for NeighborsGridSurround<T> where
    T: Send

impl<T> Sync for NeighborsGridSurround<T> where
    T: Sync

impl<T> Unpin for NeighborsGridSurround<T> where
    T: Unpin

impl<T> UnwindSafe for NeighborsGridSurround<T> where
    T: UnwindSafe

Blanket Implementations

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

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

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

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

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

impl<T> Pointable for T

type Init = T

The type for initializers.

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.