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
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
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 Direction4
impl Send for Direction4
impl Sync for Direction4
impl Unpin for Direction4
impl UnwindSafe for Direction4
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V