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

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 Direction4::*;
use Rotation::*;

assert_eq!(North.rotate(Clockwise), East);
assert_eq!(North.rotate(CounterClockwise), West);

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

Flip this direction.

use Direction4::*;
assert_eq!(North.flip(), South);
assert_eq!(West.flip(), East);
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 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);

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

See if this direction points horizontally (ie, is East or West).

use Direction4::*;

assert!(East.is_horizontal());
assert!(!South.is_horizontal());

See if this direction points vertically (ie, is North or South).

use Direction4::*;

assert!(North.is_vertical());
assert!(!West.is_vertical());

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.