adic_shape/shape/direction.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
/// The four cardinal directions
pub enum Direction {
/// Up direction
Up,
/// Down direction
Down,
/// Left direction
Left,
/// Right direction
Right,
}
impl Direction {
#[must_use]
/// Return opposite direction
pub fn opposite(&self) -> Self {
match self {
Self::Up => Self::Down,
Self::Down => Self::Up,
Self::Left => Self::Right,
Self::Right => Self::Left,
}
}
#[must_use]
/// Return counterclockwise direction
pub fn ccwise(&self) -> Self {
match self {
Self::Up => Self::Left,
Self::Down => Self::Right,
Self::Left => Self::Down,
Self::Right => Self::Up,
}
}
#[must_use]
/// Return clockwise direction
pub fn cwise(&self) -> Self {
match self {
Self::Up => Self::Right,
Self::Down => Self::Left,
Self::Left => Self::Up,
Self::Right => Self::Down,
}
}
}
// TODO: Add double-direction, single/double-direction, and multi-direction