[−][src]Enum cogs_gamedev::directions::Direction4
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]
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, steps_clockwise: isize) -> Self
[src]
Get this direction, rotated by this many steps clockwise. Negative numbers go counter-clockwise.
use Direction4::*; let north = North; assert_eq!(north.rotate(1), East); assert_eq!(north.rotate(2), South); assert_eq!(north.rotate(-1), West); assert_eq!(north.rotate(5).rotate(-11), South);
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]
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);
pub fn deltas(self) -> ICoord
[src]
Get the deltas a step in this direction would result in, as a ICoord.
use Direction4::*; assert_eq!(North.deltas(), ICoord {x: 0, y: -1}); assert_eq!(West.deltas(), ICoord {x: -1, y: 0});
Trait Implementations
impl Clone for Direction4
[src]
pub fn clone(&self) -> Direction4
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Direction4
[src]
impl Debug for Direction4
[src]
impl Eq for Direction4
[src]
impl Ord for Direction4
[src]
pub fn cmp(&self, other: &Direction4) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Direction4> for Direction4
[src]
pub fn eq(&self, other: &Direction4) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Direction4> for Direction4
[src]
pub fn partial_cmp(&self, other: &Direction4) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,