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
§Operations
Directions can be:
- rotated clockwise with:
Self::clockwise
andSelf::rotate_cw
- The shift right
>>
operator
- rotated counter clockwise with:
Self::counter_clockwise
andSelf::rotate_ccw
- The shift left
<<
operator
- negated using the minus
-
operator - multiplied by an
i32
, returning aHex
vector
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
impl EdgeDirection
Sourcepub const X_NEG_Y: EdgeDirection
pub const X_NEG_Y: EdgeDirection
Direction towards X, -Y
Sourcepub const FLAT_TOP_RIGHT: EdgeDirection
pub const FLAT_TOP_RIGHT: EdgeDirection
Direction to (1, -1)
Represents “Top right” edge in flat orientation
Sourcepub const FLAT_NORTH_EAST: EdgeDirection
pub const FLAT_NORTH_EAST: EdgeDirection
Direction to (1, -1)
Represents “North East” edge in flat orientation
Sourcepub const POINTY_TOP_RIGHT: EdgeDirection
pub const POINTY_TOP_RIGHT: EdgeDirection
Direction to (1, -1)
Represents “Top Right” edge in pointy orientation
Sourcepub const POINTY_NORTH_EAST: EdgeDirection
pub const POINTY_NORTH_EAST: EdgeDirection
Direction to (1, -1)
Represents “North East” edge in pointy orientation
Sourcepub const NEG_Y: EdgeDirection
pub const NEG_Y: EdgeDirection
Direction towards -Y
Sourcepub const FLAT_TOP: EdgeDirection
pub const FLAT_TOP: EdgeDirection
Direction to (0, -1)
Represents “Top” edge in flat orientation
Sourcepub const FLAT_NORTH: EdgeDirection
pub const FLAT_NORTH: EdgeDirection
Direction to (0, -1)
Represents “North” edge in flat orientation
Sourcepub const POINTY_TOP_LEFT: EdgeDirection
pub const POINTY_TOP_LEFT: EdgeDirection
Direction to (0, -1)
Represents “Top Left” edge in pointy orientation
Sourcepub const POINTY_NORTH_WEST: EdgeDirection
pub const POINTY_NORTH_WEST: EdgeDirection
Direction to (0, -1)
Represents “North West” edge in pointy orientation
Sourcepub const NEG_X: EdgeDirection
pub const NEG_X: EdgeDirection
Direction towards -X
Sourcepub const FLAT_TOP_LEFT: EdgeDirection
pub const FLAT_TOP_LEFT: EdgeDirection
Direction to (-1, 0)
Represents “Top Left” in flat orientation
Sourcepub const FLAT_NORTH_WEST: EdgeDirection
pub const FLAT_NORTH_WEST: EdgeDirection
Direction to (-1, 0)
Represents “North West” in flat orientation
Sourcepub const POINTY_LEFT: EdgeDirection
pub const POINTY_LEFT: EdgeDirection
Direction to (-1, 0)
Represents “Left” in pointy orientation
Sourcepub const POINTY_WEST: EdgeDirection
pub const POINTY_WEST: EdgeDirection
Direction to (-1, 0)
Represents “West” in pointy orientation
Sourcepub const NEG_X_Y: EdgeDirection
pub const NEG_X_Y: EdgeDirection
Direction towards -X, Y
Sourcepub const FLAT_BOTTOM_LEFT: EdgeDirection
pub const FLAT_BOTTOM_LEFT: EdgeDirection
Direction to (-1, 1)
Represents “Bottom Left” in flat orientation
Sourcepub const FLAT_SOUTH_WEST: EdgeDirection
pub const FLAT_SOUTH_WEST: EdgeDirection
Direction to (-1, 1)
Represents “South West” in flat orientation
Sourcepub const POINTY_BOTTOM_LEFT: EdgeDirection
pub const POINTY_BOTTOM_LEFT: EdgeDirection
Direction to (-1, 1)
Represents “Bottom Left” in pointy orientation
Sourcepub const POINTY_SOUTH_WEST: EdgeDirection
pub const POINTY_SOUTH_WEST: EdgeDirection
Direction to (-1, 1)
Represents “South West” in pointy orientation
Sourcepub const Y: EdgeDirection
pub const Y: EdgeDirection
Direction towards Y
Sourcepub const FLAT_BOTTOM: EdgeDirection
pub const FLAT_BOTTOM: EdgeDirection
Direction to (0, 1)
Represents “Bottom” in flat orientation
Sourcepub const FLAT_SOUTH: EdgeDirection
pub const FLAT_SOUTH: EdgeDirection
Direction to (0, 1)
Represents “South” in flat orientation
Sourcepub const POINTY_BOTTOM_RIGHT: EdgeDirection
pub const POINTY_BOTTOM_RIGHT: EdgeDirection
Direction to (0, 1)
Represents “Bottom Right” in pointy orientation
Sourcepub const POINTY_SOUTH_EAST: EdgeDirection
pub const POINTY_SOUTH_EAST: EdgeDirection
Direction to (0, 1)
Represents “South East” in pointy orientation
Sourcepub const X: EdgeDirection
pub const X: EdgeDirection
Direction towards X
Sourcepub const FLAT_BOTTOM_RIGHT: EdgeDirection
pub const FLAT_BOTTOM_RIGHT: EdgeDirection
Direction to (1, 0)
Represents “Bottom Right” in flat orientation
Sourcepub const FLAT_SOUTH_EAST: EdgeDirection
pub const FLAT_SOUTH_EAST: EdgeDirection
Direction to (1, 0)
Represents “South East” in flat orientation
Sourcepub const POINTY_RIGHT: EdgeDirection
pub const POINTY_RIGHT: EdgeDirection
Direction to (1, 0)
Represents “Right” in pointy orientation
Sourcepub const POINTY_EAST: EdgeDirection
pub const POINTY_EAST: EdgeDirection
Direction to (1, 0)
Represents “East” in pointy orientation
Sourcepub const ALL_DIRECTIONS: [EdgeDirection; 6]
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
Sourcepub fn iter() -> impl ExactSizeIterator
pub fn iter() -> impl ExactSizeIterator
Iterates through all directions in clockwise order
Sourcepub const fn const_neg(self) -> EdgeDirection
pub const fn const_neg(self) -> EdgeDirection
Computes the opposite direction of self
§Example
assert_eq!(
EdgeDirection::FLAT_TOP.const_neg(),
EdgeDirection::FLAT_BOTTOM
);
Sourcepub const fn clockwise(self) -> EdgeDirection
pub const fn clockwise(self) -> EdgeDirection
Returns the next direction in clockwise order
§Example
assert_eq!(
EdgeDirection::FLAT_TOP.clockwise(),
EdgeDirection::FLAT_TOP_RIGHT
);
Sourcepub const fn counter_clockwise(self) -> EdgeDirection
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
);
Sourcepub const fn rotate_ccw(self, offset: u8) -> EdgeDirection
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)
);
Sourcepub const fn rotate_cw(self, offset: u8) -> EdgeDirection
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)
);
Sourcepub fn angle_between(a: EdgeDirection, b: EdgeDirection) -> f32
pub fn angle_between(a: EdgeDirection, b: EdgeDirection) -> f32
Computes the angle between a
and b
in radians.
Sourcepub fn angle_degrees_between(a: EdgeDirection, b: EdgeDirection) -> f32
pub fn angle_degrees_between(a: EdgeDirection, b: EdgeDirection) -> f32
Computes the angle between a
and b
in degrees.
Sourcepub fn angle_to(self, rhs: EdgeDirection) -> f32
pub fn angle_to(self, rhs: EdgeDirection) -> f32
Computes the angle between self
and rhs
in radians.
Sourcepub fn angle_degrees_to(self, rhs: EdgeDirection) -> f32
pub fn angle_degrees_to(self, rhs: EdgeDirection) -> f32
Computes the angle between self
and rhs
in degrees.
Sourcepub fn angle_flat(self) -> f32
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
Sourcepub fn angle_pointy(self) -> f32
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
Sourcepub fn angle(self, orientation: HexOrientation) -> f32
pub fn angle(self, orientation: HexOrientation) -> f32
Returns the angle in radians of the given direction in the given
orientation
Sourcepub fn unit_vector(self, orientation: HexOrientation) -> Vec2
pub fn unit_vector(self, orientation: HexOrientation) -> Vec2
Returns the unit vector of the direction in the given orientation
Sourcepub fn angle_flat_degrees(self) -> f32
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
Sourcepub fn angle_pointy_degrees(self) -> f32
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
Sourcepub fn angle_degrees(self, orientation: HexOrientation) -> f32
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
Sourcepub fn from_pointy_angle_degrees(angle: f32) -> EdgeDirection
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);
Sourcepub fn from_flat_angle_degrees(angle: f32) -> EdgeDirection
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);
Sourcepub fn from_pointy_angle(angle: f32) -> EdgeDirection
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);
Sourcepub fn from_flat_angle(angle: f32) -> EdgeDirection
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);
Sourcepub fn from_angle_degrees(
angle: f32,
orientation: HexOrientation,
) -> EdgeDirection
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
);
Sourcepub fn from_angle(angle: f32, orientation: HexOrientation) -> EdgeDirection
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
);
Sourcepub const fn diagonal_ccw(self) -> VertexDirection
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);
Sourcepub const fn vertex_ccw(self) -> VertexDirection
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);
Sourcepub const fn diagonal_cw(self) -> VertexDirection
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);
Sourcepub const fn vertex_cw(self) -> VertexDirection
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);
Sourcepub const fn vertex_directions(self) -> [VertexDirection; 2]
pub const fn vertex_directions(self) -> [VertexDirection; 2]
Computes the two adjacent VertexDirection
in clockwise order
Trait Implementations§
Source§impl Add<EdgeDirection> for Hex
impl Add<EdgeDirection> for Hex
Source§impl AddAssign<EdgeDirection> for Hex
impl AddAssign<EdgeDirection> for Hex
Source§fn add_assign(&mut self, rhs: EdgeDirection)
fn add_assign(&mut self, rhs: EdgeDirection)
+=
operation. Read moreSource§impl Clone for EdgeDirection
impl Clone for EdgeDirection
Source§fn clone(&self) -> EdgeDirection
fn clone(&self) -> EdgeDirection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for EdgeDirection
impl Debug for EdgeDirection
Source§impl Default for EdgeDirection
impl Default for EdgeDirection
Source§fn default() -> EdgeDirection
fn default() -> EdgeDirection
Source§impl From<EdgeDirection> for GridEdge
impl From<EdgeDirection> for GridEdge
Source§fn from(direction: EdgeDirection) -> GridEdge
fn from(direction: EdgeDirection) -> GridEdge
Source§impl From<EdgeDirection> for Hex
impl From<EdgeDirection> for Hex
Source§fn from(value: EdgeDirection) -> Hex
fn from(value: EdgeDirection) -> Hex
Source§impl Hash for EdgeDirection
impl Hash for EdgeDirection
Source§impl Mul<i32> for EdgeDirection
impl Mul<i32> for EdgeDirection
Source§impl Neg for EdgeDirection
impl Neg for EdgeDirection
Source§impl PartialEq for EdgeDirection
impl PartialEq for EdgeDirection
Source§impl Shl<u8> for EdgeDirection
impl Shl<u8> for EdgeDirection
Source§impl Shr<u8> for EdgeDirection
impl Shr<u8> for EdgeDirection
Source§impl Sub<EdgeDirection> for Hex
impl Sub<EdgeDirection> for Hex
Source§impl SubAssign<EdgeDirection> for Hex
impl SubAssign<EdgeDirection> for Hex
Source§fn sub_assign(&mut self, rhs: EdgeDirection)
fn sub_assign(&mut self, rhs: EdgeDirection)
-=
operation. Read more