Shape

Trait Shape 

Source
pub trait Shape: Clone {
    type Axis: Axis;
    type Coordinate: Coordinate;
    type OffsetConvertError: Debug + Clone;
    type CoordinateMoveError: Debug + Clone;

Show 16 methods // Required methods fn horizontal(&self) -> usize; fn vertical(&self) -> usize; fn to_offset( &self, coord: Self::Coordinate, ) -> Result<Offset, Self::OffsetConvertError>; fn offset_to_coordinate(&self, offset: Offset) -> Self::Coordinate; fn move_coord( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Result<Self::Coordinate, Self::CoordinateMoveError>; // Provided methods fn node_count(&self) -> usize { ... } unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset { ... } fn index_to_coordinate(&self, index: usize) -> Self::Coordinate { ... } fn to_index(&self, coord: Self::Coordinate) -> Option<usize> { ... } fn index_to_offset(&self, index: usize) -> Offset { ... } fn offset_to_index(&self, o: Offset) -> usize { ... } fn horizontal_edge_size(&self, _axis: Self::Axis) -> usize { ... } fn vertical_edge_size(&self, _axis: Self::Axis) -> usize { ... } unsafe fn move_coord_unchecked( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Self::Coordinate { ... } fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool { ... } fn get_direction( &self, source: Self::Coordinate, target: Self::Coordinate, ) -> Option<<Self::Axis as Axis>::Direction> { ... }
}
Expand description

Shape of the 2d lattice. It decides the behavior of the coordinate.

Required Associated Types§

Source

type Axis: Axis

Axis of the lattice.

Source

type Coordinate: Coordinate

Coordinate of the lattice graph.

Source

type OffsetConvertError: Debug + Clone

Error to return when to_offset fails. Should set Infallible when the graph is looped and never to fail.

Source

type CoordinateMoveError: Debug + Clone

Error to return when move_coord fails. Should set Infallible when the graph is looped and never to fail.

Required Methods§

Source

fn horizontal(&self) -> usize

Horizontal node count.

Source

fn vertical(&self) -> usize

Vertical node count.

Source

fn to_offset( &self, coord: Self::Coordinate, ) -> Result<Offset, Self::OffsetConvertError>

Convert coordinate to Offset.

Source

fn offset_to_coordinate(&self, offset: Offset) -> Self::Coordinate

Convert coordinate from Offset.

Source

fn move_coord( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Result<Self::Coordinate, Self::CoordinateMoveError>

Move coordinates to the next coordinate in the direction. Coordinate should be a valid coordinate and should be checked before using move_coord. This is because the target coordinate might be valid even thought the souce coord is invalid, and some code validate the direction by moveing the coord.

Provided Methods§

Source

fn node_count(&self) -> usize

Node count.

Source

unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset

Convert coordinate to Offset without a check.

Source

fn index_to_coordinate(&self, index: usize) -> Self::Coordinate

Convert coordinate from index.

Source

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

Covert coordinate to index.

Source

fn index_to_offset(&self, index: usize) -> Offset

Convert index to offset.

Source

fn offset_to_index(&self, o: Offset) -> usize

Covert offset to index.

Source

fn horizontal_edge_size(&self, _axis: Self::Axis) -> usize

👎Deprecated

Edge count of horizontal. May differ by the axis info.

Source

fn vertical_edge_size(&self, _axis: Self::Axis) -> usize

👎Deprecated

Edge count of vertical. May differ by the axis info.

Source

unsafe fn move_coord_unchecked( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Self::Coordinate

Move coordinates to the next coordinate in the direction. Caller should be sure that the source and the target coord is valid coord.

Source

fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool

Check whether two coordinate is in neighbor.

Source

fn get_direction( &self, source: Self::Coordinate, target: Self::Coordinate, ) -> Option<<Self::Axis as Axis>::Direction>

Get direction if two coordiante is in neighbor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<S: Shape> Shape for &S

Source§

type Axis = <S as Shape>::Axis

Source§

type Coordinate = <S as Shape>::Coordinate

Source§

type OffsetConvertError = <S as Shape>::OffsetConvertError

Source§

type CoordinateMoveError = <S as Shape>::CoordinateMoveError

Source§

fn to_offset( &self, coord: Self::Coordinate, ) -> Result<Offset, Self::OffsetConvertError>

Source§

unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset

Source§

fn offset_to_coordinate(&self, offset: Offset) -> Self::Coordinate

Source§

fn horizontal(&self) -> usize

Source§

fn vertical(&self) -> usize

Source§

fn move_coord( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Result<Self::Coordinate, Self::CoordinateMoveError>

Source§

unsafe fn move_coord_unchecked( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Self::Coordinate

Source§

fn node_count(&self) -> usize

Source§

fn index_to_coordinate(&self, index: usize) -> Self::Coordinate

Source§

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

Source§

fn index_to_offset(&self, index: usize) -> Offset

Source§

fn offset_to_index(&self, o: Offset) -> usize

Source§

fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool
where Self::Coordinate: PartialEq,

Source§

fn get_direction( &self, source: Self::Coordinate, target: Self::Coordinate, ) -> Option<<Self::Axis as Axis>::Direction>
where Self::Coordinate: PartialEq,

Implementors§

Source§

impl Shape for SquareDiagonalShape

Source§

impl Shape for SquareDiagonalShape<Directed>

Source§

impl Shape for SquareShape

Source§

impl Shape for SquareShape<Directed>

Source§

impl<B, H, V> Shape for DoubleCoordShape<B, (), H, V, AxisR>
where B: DoubleCoordShapeBase<Axis = AxisR>, H: Clone + Into<usize>, V: Clone + Into<usize>,

Source§

impl<B, H, V> Shape for HexOffsetShape<B, LoopEW, H, V>
where B: HexOffsetShapeBaseLoopEW, H: Into<usize> + Copy, V: Into<usize> + Copy,

Source§

impl<B, H, V> Shape for HexOffsetShape<B, (), H, V>
where B: HexOffsetShapeBase, H: Into<usize> + Copy, V: Into<usize> + Copy,

Source§

impl<B, H, V, HA> Shape for HexAxialShape<B, LoopEW, H, V, HA>
where HA: AxialCoord, B: HexAxialShapeBase<HA>, H: Clone + Into<usize>, V: Clone + Into<usize>,

Source§

type Axis = <B as HexAxialShapeBase<HA>>::Axis

Source§

type Coordinate = HA

Source§

type OffsetConvertError = ()

Source§

type CoordinateMoveError = ()

Source§

impl<B, H, V, HA> Shape for HexAxialShape<B, (), H, V, HA>
where HA: AxialCoord, B: HexAxialShapeBase<HA>, H: Clone + Into<usize>, V: Clone + Into<usize>,

Source§

type Axis = <B as HexAxialShapeBase<HA>>::Axis

Source§

type Coordinate = HA

Source§

type OffsetConvertError = ()

Source§

type CoordinateMoveError = ()