[][src]Enum cogs_gamedev::directions::Direction8

pub enum Direction8 {
    North,
    NorthEast,
    East,
    SouthEast,
    South,
    SouthWest,
    West,
    NorthWest,
}

Eight-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
NorthEast
East
SouthEast
South
SouthWest
West
NorthWest

Implementations

impl Direction8[src]

pub const DIRECTIONS: [Direction8; 8][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 Direction8::*;
let north = North;
assert_eq!(north.rotate(1), NorthEast);
assert_eq!(north.rotate(2), East);
assert_eq!(north.rotate(-1), NorthWest);
assert_eq!(north.rotate(4), South);
assert_eq!(north.rotate(5).rotate(-11), East);

pub fn flip(self) -> Self[src]

Flip this direction.

use Direction8::*;
assert_eq!(North.flip(), South);
assert_eq!(West.flip(), East);
assert_eq!(SouthWest.flip(), NorthEast);
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 Direction8::*;
use std::f32::consts::TAU;

let north_radians = North.radians();
assert!((north_radians - (TAU / 8.0 * 6.0)).abs() < 1e-10);

let west_radians = West.radians();
assert!((west_radians - (TAU / 8.0 * 4.0)).abs() < 1e-10);

let southeast_radians = SouthEast.radians();
assert!((southeast_radians - (TAU / 8.0)).abs() < 1e-10);

pub fn deltas(self) -> ICoord[src]

Get the deltas a step in this direction would result in, as an ICoord.

use Direction8::*;

assert_eq!(East.deltas(), ICoord {x: 1, y: 0});
assert_eq!(NorthWest.deltas(), ICoord {x: -1, y: -1});

Trait Implementations

impl Clone for Direction8[src]

impl Copy for Direction8[src]

impl Debug for Direction8[src]

impl Eq for Direction8[src]

impl Ord for Direction8[src]

impl PartialEq<Direction8> for Direction8[src]

impl PartialOrd<Direction8> for Direction8[src]

impl StructuralEq for Direction8[src]

impl StructuralPartialEq for Direction8[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.