[][src]Trait spacebattleship::board::Dimensions

pub trait Dimensions: Debug {
    type Coordinate: Coordinate;
    type NeighborIterState: NeighborIterState<Dimensions = Self>;
    fn total_size(&self) -> usize;
fn try_linearize(&self, coord: &Self::Coordinate) -> Option<usize>; fn linearize(&self, coord: &Self::Coordinate) -> usize { ... }
fn neighbors(
        &self,
        coord: Self::Coordinate
    ) -> NeighborIter<Self::NeighborIterState> { ... }
fn is_neighbor(&self, c1: &Self::Coordinate, c2: &Self::Coordinate) -> bool { ... } }

Dimensions of a board. Implements methods needed for the board to check bounds, linearize indexes, and compute neighbor cells.

Associated Types

type Coordinate: Coordinate

The type used to identify cells on the board.

type NeighborIterState: NeighborIterState<Dimensions = Self>

Type used in the neighbor iterator.

Loading content...

Required methods

fn total_size(&self) -> usize

Compute the total size of the dimensions. Used to allocate storage for the board.

fn try_linearize(&self, coord: &Self::Coordinate) -> Option<usize>

Convert a coordinate to a linear index within this dimension. Returns None if the coordinate is out of bound for the dimension.

Loading content...

Provided methods

fn linearize(&self, coord: &Self::Coordinate) -> usize

Convert a coordinate to a linear index within this dimension. Panics if the coordinate is out of range for the dimension.

fn neighbors(
    &self,
    coord: Self::Coordinate
) -> NeighborIter<Self::NeighborIterState>

Iterate the neighbors of the given coordinate.

fn is_neighbor(&self, c1: &Self::Coordinate, c2: &Self::Coordinate) -> bool

Return true if the given coordinates are neighbors. Defeault implemntation checks the neighbors iter. A board may wish to provide a more efficient implementation.

Loading content...

Implementors

impl Dimensions for RectDimensions[src]

type Coordinate = Coordinate

type NeighborIterState = RectNeighbors

fn total_size(&self) -> usize[src]

Compute the linear total size of these Dimensions.

fn try_linearize(&self, coord: &Self::Coordinate) -> Option<usize>[src]

Convert a coordinate to a linear index within this dimension. Returns None if the coordinate is out of range for the dimension.

Loading content...