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

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

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

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.

Rotate this by the given amount.

use Direction8::*;
use Rotation::*;

assert_eq!(NorthEast.rotate(Clockwise), East);
assert_eq!(South.rotate(CounterClockwise), SouthEast);

Get this direction, rotated by this many steps clockwise. Negative numbers go counter-clockwise.

use Direction8::*;
let north = North;
assert_eq!(north.rotate_by(1), NorthEast);
assert_eq!(north.rotate_by(2), East);
assert_eq!(north.rotate_by(-1), NorthWest);
assert_eq!(north.rotate_by(4), South);
assert_eq!(north.rotate_by(5).rotate_by(-11), East);

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);

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);

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

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Representation of an enum map for type V.

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

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

Feeds this value into the given Hasher. Read more

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

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

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

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.