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

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, 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]

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]

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 Add<Direction4> for ICoord[src]

type Output = Self

The resulting type after applying the + operator.

fn add(self, rhs: Direction4) -> Self::Output[src]

Performs the + operation. Read more

impl AddAssign<Direction4> for ICoord[src]

fn add_assign(&mut self, rhs: Direction4)[src]

Performs the += operation. Read more

impl Clone for 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]

Performs copy-assignment from source. Read more

impl Debug for Direction4[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<V> Enum<V> for Direction4[src]

type Array = [V; 4]

Representation of an enum map for type V.

fn from_usize(value: usize) -> Self[src]

Takes an usize, and returns an element matching into_usize function.

fn into_usize(self) -> usize[src]

Returns an unique identifier for a value within range of 0..Array::LENGTH.

impl Hash for Direction4[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl Ord for Direction4[src]

fn cmp(&self, other: &Direction4) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Direction4> for Direction4[src]

fn eq(&self, other: &Direction4) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl PartialOrd<Direction4> for Direction4[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]

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]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater 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

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 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<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

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]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V