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
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), SouthWest);
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);
Trait Implementations
Performs the += operation. Read more
Takes an usize, and returns an element matching into_usize function.
Returns an unique identifier for a value within range of 0..Array::LENGTH.
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
Auto Trait Implementations
impl RefUnwindSafe for Direction8impl Send for Direction8impl Sync for Direction8impl Unpin for Direction8impl UnwindSafe for Direction8Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V