Enum cogs_gamedev::directions::Direction8 [−][src]
pub enum Direction8 { North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest, }
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
impl Direction8
[src]
impl Direction8
[src]pub const DIRECTIONS: [Direction8; 8]
[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, steps_clockwise: isize) -> Self
[src]
Get this direction, rotated by this many steps clockwise. Negative numbers go counter-clockwise.
use Direction8::*; let north = North; assert_eq!(north.rotate(1), NorthEast); assert_eq!(north.rotate(2), East); assert_eq!(north.rotate(-1), NorthWest); assert_eq!(north.rotate(4), South); assert_eq!(north.rotate(5).rotate(-11), East);
pub fn flip(self) -> Self
[src]
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);
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 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);
pub fn deltas(self) -> ICoord
[src]
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
impl Add<Direction8> for ICoord
[src]
impl Add<Direction8> for ICoord
[src]type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Direction8) -> Self::Output
[src]
impl AddAssign<Direction8> for ICoord
[src]
impl AddAssign<Direction8> for ICoord
[src]fn add_assign(&mut self, rhs: Direction8)
[src]
impl Clone for Direction8
[src]
impl Clone for Direction8
[src]fn clone(&self) -> Direction8
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Direction8
[src]
impl Copy for Direction8
[src]impl<V> Enum<V> for Direction8
[src]
impl<V> Enum<V> for Direction8
[src]type Array = [V; 8]
Representation of an enum map for type V
.
fn from_usize(value: usize) -> Self
[src]
fn into_usize(self) -> usize
[src]
impl Eq for Direction8
[src]
impl Eq for Direction8
[src]impl Hash for Direction8
[src]
impl Hash for Direction8
[src]impl Ord for Direction8
[src]
impl Ord for Direction8
[src]impl PartialEq<Direction8> for Direction8
[src]
impl PartialEq<Direction8> for Direction8
[src]impl PartialOrd<Direction8> for Direction8
[src]
impl PartialOrd<Direction8> for Direction8
[src]impl StructuralEq for Direction8
[src]
impl StructuralEq for Direction8
[src]impl StructuralPartialEq for Direction8
[src]
impl StructuralPartialEq for Direction8
[src]Auto Trait Implementations
impl RefUnwindSafe for Direction8
impl RefUnwindSafe for Direction8
impl Send for Direction8
impl Send for Direction8
impl Sync for Direction8
impl Sync for Direction8
impl Unpin for Direction8
impl Unpin for Direction8
impl UnwindSafe for Direction8
impl UnwindSafe for Direction8