pub struct Hex(IVec2);Expand description
Hexagonal grid coordinate in axial (cube) coordinate system.
Tuple Fields§
§0: IVec2Implementations§
Source§impl Hex
impl Hex
Sourcepub const HEX_DIRECTIONS: [Self; 6]
pub const HEX_DIRECTIONS: [Self; 6]
Hexagon neighbor coordinates array, following HexOrientation::POINTY_EDGE or HexOrientation::FLAT_EDGE order.
These 6 direction vectors represent the offset from a hex to each of its neighbors. The order corresponds to clockwise directions starting from East (for pointy-top) or NorthEast (for flat-top).
§Direction Mapping
| Index | Pointy-Top | Flat-Top | Vector (Hex) |
|---|---|---|---|
| 0 | East | NE | (1, 0) |
| 1 | SE | SE | (1, -1) |
| 2 | SW | South | (0, -1) |
| 3 | West | SW | (-1, 0) |
| 4 | NW | NW | (-1, 1) |
| 5 | NE | North | (0, 1) |
pub const fn new(x: i32, y: i32) -> Self
Sourcepub const fn from_offset(
offset_coordinate: OffsetCoordinate,
orientation: HexOrientation,
offset: Offset,
) -> Self
pub const fn from_offset( offset_coordinate: OffsetCoordinate, orientation: HexOrientation, offset: Offset, ) -> Self
Creates a new Hex from an OffsetCoordinate.
pub const fn x(self) -> i32
pub const fn y(self) -> i32
pub const fn z(self) -> i32
pub const fn into_inner(self) -> IVec2
Sourcepub fn to_offset(
self,
orientation: HexOrientation,
offset: Offset,
) -> OffsetCoordinate
pub fn to_offset( self, orientation: HexOrientation, offset: Offset, ) -> OffsetCoordinate
Converts a hex coordinate to an offset coordinate.
Sourcepub fn neighbor(self, orientation: HexOrientation, direction: Direction) -> Hex
pub fn neighbor(self, orientation: HexOrientation, direction: Direction) -> Hex
Get the hex at the given direction from self, according to the given orientation is HexOrientation::Pointy or HexOrientation::Flat.
Sourcepub const fn length(self) -> i32
pub const fn length(self) -> i32
Computes coordinates length as a signed integer.
The length of a Hex coordinate is equal to its distance from the origin.
Sourcepub fn distance_to(self, rhs: Self) -> i32
pub fn distance_to(self, rhs: Self) -> i32
Computes the distance from self to rhs in hexagonal space as a signed integer.
Sourcepub fn hexes_at_distance(self, distance: u32) -> Vec<Hex>
pub fn hexes_at_distance(self, distance: u32) -> Vec<Hex>
Sourcepub fn hexes_in_distance(self, distance: u32) -> Vec<Hex>
pub fn hexes_in_distance(self, distance: u32) -> Vec<Hex>
Trait Implementations§
impl Copy for Hex
impl Eq for Hex
impl StructuralPartialEq for Hex
Auto Trait Implementations§
impl Freeze for Hex
impl RefUnwindSafe for Hex
impl Send for Hex
impl Sync for Hex
impl Unpin for Hex
impl UnsafeUnpin for Hex
impl UnwindSafe for Hex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more