Skip to main content

Hex

Struct Hex 

Source
pub struct Hex(IVec2);
Expand description

Hexagonal grid coordinate in axial (cube) coordinate system.

Tuple Fields§

§0: IVec2

Implementations§

Source§

impl Hex

Source

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
IndexPointy-TopFlat-TopVector (Hex)
0EastNE(1, 0)
1SESE(1, -1)
2SWSouth(0, -1)
3WestSW(-1, 0)
4NWNW(-1, 1)
5NENorth(0, 1)
Source

pub const fn new(x: i32, y: i32) -> Self

Source

pub const fn from_offset( offset_coordinate: OffsetCoordinate, orientation: HexOrientation, offset: Offset, ) -> Self

Creates a new Hex from an OffsetCoordinate.

Source

pub const fn x(self) -> i32

Source

pub const fn y(self) -> i32

Source

pub const fn z(self) -> i32

Source

pub const fn into_inner(self) -> IVec2

Source

pub fn to_offset( self, orientation: HexOrientation, offset: Offset, ) -> OffsetCoordinate

Converts a hex coordinate to an offset coordinate.

Source

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.

Source

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.

Source

pub fn distance_to(self, rhs: Self) -> i32

Computes the distance from self to rhs in hexagonal space as a signed integer.

Source

pub fn hexes_at_distance(self, distance: u32) -> Vec<Hex>

Return a Vec<Hex> containing all Hex which are exactly at a given distance from self. If distance = 0 the Vec<Hex> will be empty.
The number of returned hexes is equal to 6 * distance.

Source

pub fn hexes_in_distance(self, distance: u32) -> Vec<Hex>

Return a Vec<Hex> containing all Hex around self in a given distance, including self.
The number of returned hexes is equal to 3 * distance * (distance + 1) + 1.

Source

pub fn round(fractional_hex: Vec2) -> Self

Rounds floating point coordinates to Hex.

Trait Implementations§

Source§

impl Add for Hex

Source§

type Output = Hex

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Hex

Source§

fn clone(&self) -> Hex

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Hex

Source§

impl Debug for Hex

Source§

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

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

impl Eq for Hex

Source§

impl From<[i32; 2]> for Hex

Source§

fn from(a: [i32; 2]) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Hex

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Hex

Source§

impl Sub for Hex

Source§

type Output = Hex

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.