Trait lattice_graph::lattice_abstract::shapes::Shape
source · [−]pub trait Shape: Clone {
type Axis: Axis;
type Coordinate: Coordinate;
type OffsetConvertError: Debug + Clone;
type CoordinateMoveError: Debug + Clone;
Show 16 methods
fn horizontal(&self) -> usize;
fn vertical(&self) -> usize;
fn to_offset(
&self,
coord: Self::Coordinate
) -> Result<Offset, Self::OffsetConvertError>;
fn from_offset(&self, offset: Offset) -> Self::Coordinate;
fn move_coord(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction
) -> Result<Self::Coordinate, Self::CoordinateMoveError>;
fn node_count(&self) -> usize { ... }
unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset { ... }
fn from_index(&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.
Associated Types
type Coordinate: Coordinate
type Coordinate: Coordinate
Coordinate of the lattice graph.
type OffsetConvertError: Debug + Clone
type OffsetConvertError: Debug + Clone
Error to return when to_offset
fails.
Should set Infallible
when the graph is looped and never to fail.
type CoordinateMoveError: Debug + Clone
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
fn horizontal(&self) -> usize
fn horizontal(&self) -> usize
Horizontal node count.
fn to_offset(
&self,
coord: Self::Coordinate
) -> Result<Offset, Self::OffsetConvertError>
fn to_offset(
&self,
coord: Self::Coordinate
) -> Result<Offset, Self::OffsetConvertError>
Convert coordinate to Offset
.
fn from_offset(&self, offset: Offset) -> Self::Coordinate
fn from_offset(&self, offset: Offset) -> Self::Coordinate
Convert coordinate from Offset
.
fn move_coord(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction
) -> Result<Self::Coordinate, Self::CoordinateMoveError>
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
fn node_count(&self) -> usize
fn node_count(&self) -> usize
Node count.
unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset
unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset
Convert coordinate to Offset without a check.
fn from_index(&self, index: usize) -> Self::Coordinate
fn from_index(&self, index: usize) -> Self::Coordinate
Convert coordinate from index.
fn to_index(&self, coord: Self::Coordinate) -> Option<usize>
fn to_index(&self, coord: Self::Coordinate) -> Option<usize>
Covert coordinate to index.
fn index_to_offset(&self, index: usize) -> Offset
fn index_to_offset(&self, index: usize) -> Offset
Convert index to offset.
fn offset_to_index(&self, o: Offset) -> usize
fn offset_to_index(&self, o: Offset) -> usize
Covert offset to index.
fn horizontal_edge_size(&self, _axis: Self::Axis) -> usize
fn horizontal_edge_size(&self, _axis: Self::Axis) -> usize
Edge count of horizontal. May differ by the axis info.
fn vertical_edge_size(&self, _axis: Self::Axis) -> usize
fn vertical_edge_size(&self, _axis: Self::Axis) -> usize
Edge count of vertical. May differ by the axis info.
unsafe fn move_coord_unchecked(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction
) -> Self::Coordinate
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.
fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool
fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool
Check whether two coordinate is in neighbor.
fn get_direction(
&self,
source: Self::Coordinate,
target: Self::Coordinate
) -> Option<<Self::Axis as Axis>::Direction>
fn get_direction(
&self,
source: Self::Coordinate,
target: Self::Coordinate
) -> Option<<Self::Axis as Axis>::Direction>
Get direction if two coordiante is in neighbor.