Enum cogs_gamedev::grids::directions::Direction4 [−][src]
pub enum Direction4 { North, East, South, West, }
Expand description
Four-way directions.
These start at North and increment counter-clockwise,
so you can convert them to integers with as
and use them
in rotational calculations if you need.
Variants
Implementations
impl Direction4
[src]
impl Direction4
[src]pub const DIRECTIONS: [Direction4; 4]
[src]
pub const DIRECTIONS: [Direction4; 4]
[src]All the directions in order. This is used internally for rotations and flips. I made it public just in case it’s helpful for you the programmer.
pub fn rotate(self, rot: Rotation) -> Self
[src]
pub fn rotate(self, rot: Rotation) -> Self
[src]Rotate this by the given amount.
use Direction4::*; use Rotation::*; assert_eq!(North.rotate(Clockwise), East); assert_eq!(North.rotate(CounterClockwise), West);
pub fn rotate_by(self, steps_clockwise: isize) -> Self
[src]
pub fn rotate_by(self, steps_clockwise: isize) -> Self
[src]Get this direction, rotated by this many steps clockwise. Negative numbers go counter-clockwise.
use Direction4::*; assert_eq!(North.rotate_by(1), East); assert_eq!(North.rotate_by(2), South); assert_eq!(North.rotate_by(-1), West); assert_eq!(North.rotate_by(5).rotate_by(-11), South);
pub fn flip(self) -> Self
[src]
pub fn flip(self) -> Self
[src]Flip this direction.
use Direction4::*; assert_eq!(North.flip(), South); assert_eq!(West.flip(), East); assert_eq!(East.flip().flip(), East);
pub fn radians(self) -> f32
[src]
pub fn radians(self) -> f32
[src]Get this direction in radians.
This uses trigonometric + graphical standard, where:
- 0 radians is to the right
- Positive radians increment clockwise. NOTE: this is opposite from normal trig, but makes sense in computer graphics where +Y is downwards.
If you need it in degrees just call .to_degrees
on the result.
use Direction4::*; use std::f32::consts::TAU; let north_radians = North.radians(); assert!((north_radians - (TAU / 4.0 * 3.0)).abs() < 1e-10); let west_radians = West.radians(); assert!((west_radians - (TAU / 4.0 * 2.0)).abs() < 1e-10);
Trait Implementations
impl Add<Direction4> for ICoord
[src]
impl Add<Direction4> for ICoord
[src]impl AddAssign<Direction4> for ICoord
[src]
impl AddAssign<Direction4> for ICoord
[src]fn add_assign(&mut self, rhs: Direction4)
[src]
fn add_assign(&mut self, rhs: Direction4)
[src]Performs the +=
operation. Read more
impl Clone for Direction4
[src]
impl Clone for Direction4
[src]fn clone(&self) -> Direction4
[src]
fn clone(&self) -> Direction4
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for Direction4
[src]
impl Debug for Direction4
[src]impl<V> Enum<V> for Direction4
[src]
impl<V> Enum<V> for Direction4
[src]fn from_usize(value: usize) -> Self
[src]
fn from_usize(value: usize) -> Self
[src]Takes an usize, and returns an element matching into_usize
function.
fn into_usize(self) -> usize
[src]
fn into_usize(self) -> usize
[src]Returns an unique identifier for a value within range of 0..Array::LENGTH
.
impl Hash for Direction4
[src]
impl Hash for Direction4
[src]impl Ord for Direction4
[src]
impl Ord for Direction4
[src]impl PartialEq<Direction4> for Direction4
[src]
impl PartialEq<Direction4> for Direction4
[src]impl PartialOrd<Direction4> for Direction4
[src]
impl PartialOrd<Direction4> for Direction4
[src]fn partial_cmp(&self, other: &Direction4) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Direction4) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Direction4
[src]
impl Eq for Direction4
[src]
impl StructuralEq for Direction4
[src]
impl StructuralPartialEq for Direction4
[src]
Auto Trait Implementations
impl RefUnwindSafe for Direction4
impl Send for Direction4
impl Sync for Direction4
impl Unpin for Direction4
impl UnwindSafe for Direction4
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,