pub enum Direction {
Up,
Down,
Left,
Right,
}
Expand description
Basic direction in a plane.
Variants§
Up
Direction up (towards negative Y).
Down
Direction down (towards positive Y).
Left
Direction left (towards negative X).
Right
Direction right (towards positive X).
Implementations§
source§impl Direction
impl Direction
sourcepub const ALL: [Direction; 4] = _
pub const ALL: [Direction; 4] = _
List of all possible directions. Please note that this requires no heap-allocation and is very cheap.
sourcepub fn iter() -> Iter ⓘ
pub fn iter() -> Iter ⓘ
Iterator over all directions.
Examples
Note that these examples put the directions in a vector, but if you want
an array of directions, just use Direction::ALL
.
Default Order
use gardiz::direc::{self, Direction};
let direcs: Vec<Direction> = Direction::iter().collect();
assert_eq!(
vec![Direction::Up, Direction::Down, Direction::Left, Direction::Right],
direcs
);
Reverse Order
use gardiz::direc::{self, Direction};
let direcs: Vec<Direction> = Direction::iter().rev().collect();
assert_eq!(
vec![Direction::Right, Direction::Left, Direction::Down, Direction::Up],
direcs
);
sourcepub fn from_axis_pos(axis: Axis) -> Self
pub fn from_axis_pos(axis: Axis) -> Self
Creates a direction from the given axis in the positive direction (i.e.
X -> Right
and Y -> Down
).
sourcepub fn from_axis_neg(axis: Axis) -> Self
pub fn from_axis_neg(axis: Axis) -> Self
Creates a direction from the given axis in the negative direction (i.e.
X -> Left
and Y -> Up
).
sourcepub fn rotate_clockwise(self) -> Self
pub fn rotate_clockwise(self) -> Self
Rotates the direction clockwise.
sourcepub fn rotate_countercw(self) -> Self
pub fn rotate_countercw(self) -> Self
Rotates the direction counter-clockwise.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Direction
impl<'de> Deserialize<'de> for Direction
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Direction
impl Ord for Direction
source§impl PartialEq<Direction> for Direction
impl PartialEq<Direction> for Direction
source§impl PartialOrd<Direction> for Direction
impl PartialOrd<Direction> for Direction
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more