EdgeDirection

Struct EdgeDirection 

Source
pub struct EdgeDirection(/* private fields */);
Expand description

All 6 possible neighbor/edge directions in hexagonal space.

      Z    ___   -Y
          /   \
      +--+  4  +--+
     / 3  \___/  5 \
     \    /   \    /
 -X   +--+     +--+    X
     /    \___/    \
     \ 2  /   \  0 /
      +--+  1  +--+
          \___/
      Y           -Z

See Hex::NEIGHBORS_COORDS

§Operations

Directions can be:

Example:

let direction = EdgeDirection::FLAT_TOP;
assert_eq!(-direction, EdgeDirection::FLAT_BOTTOM);
assert_eq!(direction >> 1, EdgeDirection::FLAT_TOP_RIGHT);
assert_eq!(direction << 1, EdgeDirection::FLAT_TOP_LEFT);

§Storage

Both EdgeDirection and VertexDirection store a u8 byte between 0 and 5 as following:

          e4
      v4_____ v5
    e3 /     \ e5
      /       \
  v3 (         ) v0
      \       /
    e2 \_____/ e0
     v2   e1  v1

On pointy orientation the hexagon is shifted by 30 degrees clockwise

Implementations§

Source§

impl EdgeDirection

Source

pub const X_NEG_Y: EdgeDirection

Direction towards X, -Y

Source

pub const FLAT_TOP_RIGHT: EdgeDirection

Direction to (1, -1)

Represents “Top right” edge in flat orientation

Source

pub const FLAT_NORTH_EAST: EdgeDirection

Direction to (1, -1)

Represents “North East” edge in flat orientation

Source

pub const POINTY_TOP_RIGHT: EdgeDirection

Direction to (1, -1)

Represents “Top Right” edge in pointy orientation

Source

pub const POINTY_NORTH_EAST: EdgeDirection

Direction to (1, -1)

Represents “North East” edge in pointy orientation

Source

pub const NEG_Y: EdgeDirection

Direction towards -Y

Source

pub const FLAT_TOP: EdgeDirection

Direction to (0, -1)

Represents “Top” edge in flat orientation

Source

pub const FLAT_NORTH: EdgeDirection

Direction to (0, -1)

Represents “North” edge in flat orientation

Source

pub const POINTY_TOP_LEFT: EdgeDirection

Direction to (0, -1)

Represents “Top Left” edge in pointy orientation

Source

pub const POINTY_NORTH_WEST: EdgeDirection

Direction to (0, -1)

Represents “North West” edge in pointy orientation

Source

pub const NEG_X: EdgeDirection

Direction towards -X

Source

pub const FLAT_TOP_LEFT: EdgeDirection

Direction to (-1, 0)

Represents “Top Left” in flat orientation

Source

pub const FLAT_NORTH_WEST: EdgeDirection

Direction to (-1, 0)

Represents “North West” in flat orientation

Source

pub const POINTY_LEFT: EdgeDirection

Direction to (-1, 0)

Represents “Left” in pointy orientation

Source

pub const POINTY_WEST: EdgeDirection

Direction to (-1, 0)

Represents “West” in pointy orientation

Source

pub const NEG_X_Y: EdgeDirection

Direction towards -X, Y

Source

pub const FLAT_BOTTOM_LEFT: EdgeDirection

Direction to (-1, 1)

Represents “Bottom Left” in flat orientation

Source

pub const FLAT_SOUTH_WEST: EdgeDirection

Direction to (-1, 1)

Represents “South West” in flat orientation

Source

pub const POINTY_BOTTOM_LEFT: EdgeDirection

Direction to (-1, 1)

Represents “Bottom Left” in pointy orientation

Source

pub const POINTY_SOUTH_WEST: EdgeDirection

Direction to (-1, 1)

Represents “South West” in pointy orientation

Source

pub const Y: EdgeDirection

Direction towards Y

Source

pub const FLAT_BOTTOM: EdgeDirection

Direction to (0, 1)

Represents “Bottom” in flat orientation

Source

pub const FLAT_SOUTH: EdgeDirection

Direction to (0, 1)

Represents “South” in flat orientation

Source

pub const POINTY_BOTTOM_RIGHT: EdgeDirection

Direction to (0, 1)

Represents “Bottom Right” in pointy orientation

Source

pub const POINTY_SOUTH_EAST: EdgeDirection

Direction to (0, 1)

Represents “South East” in pointy orientation

Source

pub const X: EdgeDirection

Direction towards X

Source

pub const FLAT_BOTTOM_RIGHT: EdgeDirection

Direction to (1, 0)

Represents “Bottom Right” in flat orientation

Source

pub const FLAT_SOUTH_EAST: EdgeDirection

Direction to (1, 0)

Represents “South East” in flat orientation

Source

pub const POINTY_RIGHT: EdgeDirection

Direction to (1, 0)

Represents “Right” in pointy orientation

Source

pub const POINTY_EAST: EdgeDirection

Direction to (1, 0)

Represents “East” in pointy orientation

Source

pub const ALL_DIRECTIONS: [EdgeDirection; 6]

All 6 hexagonal directions matching Hex::NEIGHBORS_COORDS

      Z    ___   -Y
          /   \
      +--+  4  +--+
     / 3  \___/  5 \
     \    /   \    /
 -X   +--+     +--+    X
     /    \___/    \
     \ 2  /   \  0 /
      +--+  1  +--+
          \___/
      Y           -Z
Source

pub fn iter() -> impl ExactSizeIterator

Iterates through all directions in clockwise order

Source

pub const fn index(self) -> u8

Returns the inner index of the edge direction, from 0 to 5

Source

pub const fn into_hex(self) -> Hex

Converts the direction to a normalized hex coordinate

Source

pub const fn const_neg(self) -> EdgeDirection

Computes the opposite direction of self

§Example
assert_eq!(
    EdgeDirection::FLAT_TOP.const_neg(),
    EdgeDirection::FLAT_BOTTOM
);
Source

pub const fn clockwise(self) -> EdgeDirection

Returns the next direction in clockwise order

§Example
assert_eq!(
    EdgeDirection::FLAT_TOP.clockwise(),
    EdgeDirection::FLAT_TOP_RIGHT
);
Source

pub const fn counter_clockwise(self) -> EdgeDirection

Returns the next direction in counter clockwise order

§Example
assert_eq!(
    EdgeDirection::FLAT_TOP.counter_clockwise(),
    EdgeDirection::FLAT_TOP_LEFT
);
Source

pub const fn rotate_ccw(self, offset: u8) -> EdgeDirection

Rotates self counter clockwise by offset amount.

§Example
assert_eq!(
    EdgeDirection::FLAT_TOP,
    EdgeDirection::FLAT_TOP.rotate_ccw(6)
);
Source

pub const fn rotate_cw(self, offset: u8) -> EdgeDirection

Rotates self clockwise by offset amount.

§Example
assert_eq!(
    EdgeDirection::FLAT_TOP,
    EdgeDirection::FLAT_TOP.rotate_cw(6)
);
Source

pub fn angle_between(a: EdgeDirection, b: EdgeDirection) -> f32

Computes the angle between a and b in radians.

Source

pub fn angle_degrees_between(a: EdgeDirection, b: EdgeDirection) -> f32

Computes the angle between a and b in degrees.

Source

pub fn angle_to(self, rhs: EdgeDirection) -> f32

Computes the angle between self and rhs in radians.

Source

pub fn angle_degrees_to(self, rhs: EdgeDirection) -> f32

Computes the angle between self and rhs in degrees.

Source

pub fn angle_flat(self) -> f32

Returns the angle in radians of the given direction for flat hexagons

See Self::angle_pointy for pointy hexagons

Source

pub fn angle_pointy(self) -> f32

Returns the angle in radians of the given direction for pointy hexagons

See Self::angle_flat for flat hexagons

Source

pub fn angle(self, orientation: HexOrientation) -> f32

Returns the angle in radians of the given direction in the given orientation

Source

pub fn unit_vector(self, orientation: HexOrientation) -> Vec2

Returns the unit vector of the direction in the given orientation

Source

pub fn angle_flat_degrees(self) -> f32

Returns the angle in degrees of the given direction for pointy hexagons

See Self::angle_pointy_degrees for flat hexagons

Source

pub fn angle_pointy_degrees(self) -> f32

Returns the angle in degrees of the given direction for pointy hexagons

See Self::angle_flat_degrees for flat hexagons

Source

pub fn angle_degrees(self, orientation: HexOrientation) -> f32

Returns the angle in degrees of the given direction according to its orientation

See Self::angle for radians angles

Source

pub fn from_pointy_angle_degrees(angle: f32) -> EdgeDirection

Returns the direction from the given angle in degrees

§Example

let direction = EdgeDirection::from_pointy_angle_degrees(35.0);
assert_eq!(direction, EdgeDirection::FLAT_BOTTOM);
Source

pub fn from_flat_angle_degrees(angle: f32) -> EdgeDirection

Returns the direction from the given angle in degrees

§Example

let direction = EdgeDirection::from_flat_angle_degrees(35.0);
assert_eq!(direction, EdgeDirection::FLAT_BOTTOM_RIGHT);
Source

pub fn from_pointy_angle(angle: f32) -> EdgeDirection

Returns the direction from the given angle in radians

§Example

let direction = EdgeDirection::from_pointy_angle(0.6);
assert_eq!(direction, EdgeDirection::FLAT_BOTTOM);
Source

pub fn from_flat_angle(angle: f32) -> EdgeDirection

Returns the direction from the given angle in radians

§Example

let direction = EdgeDirection::from_flat_angle(0.6);
assert_eq!(direction, EdgeDirection::FLAT_BOTTOM_RIGHT);
Source

pub fn from_angle_degrees( angle: f32, orientation: HexOrientation, ) -> EdgeDirection

Returns the direction from the given angle in degrees according the orientation

§Example

let angle = 35.0;
assert_eq!(
    EdgeDirection::from_angle_degrees(angle, HexOrientation::Flat),
    EdgeDirection::FLAT_BOTTOM_RIGHT
);
assert_eq!(
    EdgeDirection::from_angle_degrees(angle, HexOrientation::Pointy),
    EdgeDirection::FLAT_BOTTOM
);
Source

pub fn from_angle(angle: f32, orientation: HexOrientation) -> EdgeDirection

Returns the direction from the given angle in radians according the orientation

§Example

let angle = 0.6;
assert_eq!(
    EdgeDirection::from_angle(angle, HexOrientation::Flat),
    EdgeDirection::FLAT_BOTTOM_RIGHT
);
assert_eq!(
    EdgeDirection::from_angle(angle, HexOrientation::Pointy),
    EdgeDirection::FLAT_BOTTOM
);
Source

pub const fn diagonal_ccw(self) -> VertexDirection

Computes the counter clockwise VertexDirection neighbor of self.

§Example
let diagonal = EdgeDirection::FLAT_TOP.diagonal_ccw();
assert_eq!(diagonal, VertexDirection::FLAT_TOP_LEFT);
Source

pub const fn vertex_ccw(self) -> VertexDirection

Computes the counter clockwise VertexDirection neighbor of self.

§Example
let diagonal = EdgeDirection::FLAT_TOP.vertex_ccw();
assert_eq!(diagonal, VertexDirection::FLAT_TOP_LEFT);
Source

pub const fn diagonal_cw(self) -> VertexDirection

Computes the clockwise VertexDirection neighbor of self.

§Example
let diagonal = EdgeDirection::FLAT_TOP.diagonal_cw();
assert_eq!(diagonal, VertexDirection::FLAT_TOP_RIGHT);
Source

pub const fn vertex_cw(self) -> VertexDirection

Computes the clockwise VertexDirection neighbor of self.

§Example
let diagonal = EdgeDirection::FLAT_TOP.vertex_cw();
assert_eq!(diagonal, VertexDirection::FLAT_TOP_RIGHT);
Source

pub const fn vertex_directions(self) -> [VertexDirection; 2]

Computes the two adjacent VertexDirection in clockwise order

Trait Implementations§

Source§

impl Add<EdgeDirection> for Hex

Source§

type Output = Hex

The resulting type after applying the + operator.
Source§

fn add(self, rhs: EdgeDirection) -> <Hex as Add<EdgeDirection>>::Output

Performs the + operation. Read more
Source§

impl AddAssign<EdgeDirection> for Hex

Source§

fn add_assign(&mut self, rhs: EdgeDirection)

Performs the += operation. Read more
Source§

impl Clone for EdgeDirection

Source§

fn clone(&self) -> EdgeDirection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EdgeDirection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for EdgeDirection

Source§

fn default() -> EdgeDirection

Returns the “default value” for a type. Read more
Source§

impl From<EdgeDirection> for GridEdge

Source§

fn from(direction: EdgeDirection) -> GridEdge

Converts to this type from the input type.
Source§

impl From<EdgeDirection> for Hex

Source§

fn from(value: EdgeDirection) -> Hex

Converts to this type from the input type.
Source§

impl Hash for EdgeDirection

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Mul<i32> for EdgeDirection

Source§

type Output = Hex

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i32) -> <EdgeDirection as Mul<i32>>::Output

Performs the * operation. Read more
Source§

impl Neg for EdgeDirection

Source§

type Output = EdgeDirection

The resulting type after applying the - operator.
Source§

fn neg(self) -> <EdgeDirection as Neg>::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for EdgeDirection

Source§

fn eq(&self, other: &EdgeDirection) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Shl<u8> for EdgeDirection

Source§

type Output = EdgeDirection

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u8) -> <EdgeDirection as Shl<u8>>::Output

Performs the << operation. Read more
Source§

impl Shr<u8> for EdgeDirection

Source§

type Output = EdgeDirection

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u8) -> <EdgeDirection as Shr<u8>>::Output

Performs the >> operation. Read more
Source§

impl Sub<EdgeDirection> for Hex

Source§

type Output = Hex

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: EdgeDirection) -> <Hex as Sub<EdgeDirection>>::Output

Performs the - operation. Read more
Source§

impl SubAssign<EdgeDirection> for Hex

Source§

fn sub_assign(&mut self, rhs: EdgeDirection)

Performs the -= operation. Read more
Source§

impl Copy for EdgeDirection

Source§

impl Eq for EdgeDirection

Source§

impl StructuralPartialEq for EdgeDirection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.