[][src]Enum cogs_gamedev::directions::Direction4

pub enum Direction4 {
    North,
    East,
    South,
    West,
}

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

North
East
South
West

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]

impl Copy for Direction4[src]

impl Debug for Direction4[src]

impl Eq for Direction4[src]

impl Ord for Direction4[src]

impl PartialEq<Direction4> for Direction4[src]

impl PartialOrd<Direction4> for Direction4[src]

impl StructuralEq for Direction4[src]

impl StructuralPartialEq for Direction4[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.