Hex

Struct Hex 

Source
pub struct Hex {
    pub x: i32,
    pub y: i32,
}
Expand description

Hexagonal axial coordinates

§Why Axial ?

Axial coordinates allow to compute and use cubic coordinates with less storage, and allow:

  • Vector operations
  • Rotations
  • Symmetry
  • Simple algorithms

when offset and doubled coordinates don’t. Furthermore, it makes the Hex behave like classic 2D coordinates (IVec2) and therefore more user friendly.

Check out this comparison article for more information.

§Conversions

Fields§

§x: i32

x axial coordinate (sometimes called q or i)

§y: i32

y axial coordinate (sometimes called r or j)

Implementations§

Source§

impl Hex

Source

pub const fn to_doubled_coordinates(self, mode: DoubledHexMode) -> [i32; 2]

Converts self to doubled coordinates according to the given mode.

The coordinates are returned as [COLUMN, ROW]

Source

pub const fn to_offset_coordinates(self, mode: OffsetHexMode) -> [i32; 2]

Converts self to offset coordinates according to the given mode.

The coordinates are returned as [COLUMN, ROW]

Source

pub const fn to_hexmod_coordinates(self, range: u32) -> u32

Converts self to hexmod coordinates according to the given range

Source

pub const fn from_hexmod_coordinates(coord: u32, range: u32) -> Hex

Converts hexmod to axial coordinates according to the given range

§Note

The resulting coordinate will be wrong if coord is not a valid hexmod value in the given range. coord should be lesser or equal to 3 * range * (range + 1) + 1

Source

pub const fn from_doubled_coordinates(_: [i32; 2], mode: DoubledHexMode) -> Hex

Converts doubled to axial coordinates according to the given mode.

Source

pub const fn from_offset_coordinates(_: [i32; 2], mode: OffsetHexMode) -> Hex

Converts offset to axial coordinates according to the given mode.

Source§

impl Hex

Source

pub const fn from_u64(value: u64) -> Hex

Unpack from a u64. x is read from the most signifigant 32 bits; y is read from the least signifigant 32 bits. Intended to be used with Hex::as_u64.

§Example
let x: u64 = 0x000000AA_FFFFFF45;
assert_eq!(Hex::from_u64(x), Hex::new(0xAA, -0xBB));
Source

pub const fn as_u64(self) -> u64

Pack into a u64. x is placed in the most signifigant 32 bits; y is placed in the least signifigant 32 bits. Can be used as a sort key, or for saving in a binary format. Intended to be used with Hex::from_u64.

§Example
let x = Hex::new(0xAA, -0xBB).as_u64();
assert_eq!(x, 0x000000AA_FFFFFF45u64);
Source§

impl Hex

Source

pub fn all_edges(self) -> [GridEdge; 6]

Return all 6 edges of the coordinate

Source§

impl Hex

Source

pub fn all_vertices(self) -> [GridVertex; 6]

Returns all vertices of the given coordinate

Source§

impl Hex

Source

pub fn custom_ring( self, range: u32, start_dir: EdgeDirection, clockwise: bool, ) -> impl ExactSizeIterator

Retrieves one Hex ring around self in a given range. The returned coordinates start from start_dir and loop counter clockwise around self unless clockwise is set to true.

If you only need the coordinates see Self::ring

§Note

The returned iterator will have 6 * range (Self::ring_count) items, unless range is 0 which will return self

Source

pub fn ring(self, range: u32) -> impl ExactSizeIterator

Retrieves one Hex ring around self in a given range. The returned coordinates start from EdgeDirection::default and loop around self counter clockwise.

See Self::custom_ring for more options.

§Note

The returned iterator will have 6 * range (Self::ring_count) items, unless range is 0 which will return self

Source

pub fn rings( self, range: impl Iterator<Item = u32>, ) -> impl Iterator<Item = Vec<Hex>>

Retrieves range Hex rings around self in a given range. The returned coordinates start from EdgeDirection::default and loop around self counter clockwise.

See Self::custom_rings for more options. If you only need the coordinates see Self::spiral_range.

§Example
let rings: Vec<Vec<Hex>> = Hex::ZERO.rings(3..10).collect();
assert_eq!(rings.len(), 7);
Source

pub fn custom_rings( self, range: impl Iterator<Item = u32>, start_dir: EdgeDirection, clockwise: bool, ) -> impl Iterator<Item = Vec<Hex>>

Retrieves range Hex rings around self in a given range. The returned coordinates start from start_dir and loop around self counter clockwise unless clockwise is set to true.

If you only need the coordinates see Self::spiral_range or Self::rings.

§Example
let rings: Vec<Vec<Hex>> = Hex::ZERO
    .custom_rings(3..10, EdgeDirection::FLAT_TOP, true)
    .collect();
assert_eq!(rings.len(), 7);
Source

pub fn custom_ring_edge( self, radius: u32, direction: VertexDirection, clockwise: bool, ) -> impl ExactSizeIterator

Retrieves one Hex ring edge around self in a given radius and direction. The returned coordinates are sorted counter clockwise unless clockwise is set to true.

If you only need the coordinates see Self::ring_edge.

§Note

The returned vector will be of radius + 1 length

Source

pub fn ring_edge( self, radius: u32, direction: VertexDirection, ) -> impl ExactSizeIterator

Retrieves one Hex ring edge around self in a given radius and direction. The returned coordinates are sorted counter clockwise around self.

See Self::custom_ring_edge for more options.

§Note

The returned vector will be of radius + 1 length

Source

pub fn ring_edges( self, ranges: impl Iterator<Item = u32>, direction: VertexDirection, ) -> impl Iterator<Item = impl ExactSizeIterator>

Retrieves all successive Hex ring edges around self in given ranges and direction. The returned edges coordinates are sorted counter clockwise around self.

§Example
let edges: Vec<_> = Hex::ZERO
    .ring_edges(3..10, VertexDirection::FLAT_RIGHT)
    .collect();
assert_eq!(edges.len(), 7);

See also Self::custom_ring_edges If you only need the coordinates see Self::custom_wedge

Source

pub fn custom_ring_edges( self, ranges: impl Iterator<Item = u32>, direction: VertexDirection, clockwise: bool, ) -> impl Iterator<Item = impl ExactSizeIterator>

Retrieves all successive Hex ring edges around self in given ranges and direction. The returned edges coordinates are sorted counter clockwise around self unless clockwise is set to true.

§Example
let edges: Vec<_> = Hex::ZERO
    .custom_ring_edges(3..10, VertexDirection::FLAT_RIGHT, true)
    .collect();
assert_eq!(edges.len(), 7);

See also Self::ring_edges If you only need the coordinates see Self::wedge

Source

pub fn custom_wedge( self, ranges: impl Iterator<Item = u32>, direction: VertexDirection, clockwise: bool, ) -> impl Iterator<Item = Hex>

Retrieves all successive Hex ring edges around self in given ranges and direction. The returned edges coordinates are sorted counter clockwise around self unless clockwise is set to true.

See also Self::custom_ring_edges If you only need the coordinates see Self::wedge If you want a full wedge see Self::custom_full_wedge

Source

pub fn custom_wedge_to( self, rhs: Hex, clockwise: bool, ) -> impl ExactSizeIterator

Retrieves all successive Hex ring edges from self to rhs The returned edges coordinates are sorted counter clockwise around self unless clockwise is set to true.

See also Self::custom_ring_edges and Self::wedge_to

Source

pub fn custom_full_wedge( self, range: u32, direction: VertexDirection, clockwise: bool, ) -> impl ExactSizeIterator

Retrieves all successive Hex ring edges around self in a given range and direction The returned edges coordinates are sorted counter clockwise around self unless clockwise is set to true.

See also Self::custom_wedge and Self::full_wedge

Source

pub const fn wedge_count(range: u32) -> u32

Counts how many coordinates there are in a wedge of given range

§Example
let point = Hex::new(3, -6);
let wedge: Vec<Hex> = point.wedge(0..=13, VertexDirection::FLAT_RIGHT).collect();
assert_eq!(wedge.len(), Hex::wedge_count(13) as usize);
Source

pub fn wedge( self, range: impl Iterator<Item = u32>, direction: VertexDirection, ) -> impl Iterator<Item = Hex>

Retrieves all successive Hex ring edges around self in a given range and direction. The returned edges coordinates are sorted counter clockwise around self.

See also Self::custom_ring_edges and Self::custom_wedge

Source

pub fn wedge_to(self, rhs: Hex) -> impl ExactSizeIterator

Retrieves all successive Hex ring edges from self to rhs The returned edges coordinates are sorted counter clockwise.

See also Self::custom_ring_edges and Self::custom_wedge_to

Source

pub fn full_wedge( self, range: u32, direction: VertexDirection, ) -> impl ExactSizeIterator

Retrieves all successive Hex ring edges around self in a given range and direction The returned edges coordinates are sorted counter clockwise around self.

See also Self::custom_full_wedge and Self::wedge

Source

pub fn corner_wedge( self, range: impl Iterator<Item = u32>, direction: EdgeDirection, ) -> impl Iterator<Item = Hex>

Retrieves all successive Hex half ring edges around self in a given range and direction.

See also Self::corner_wedge_to and Self::wedge

Source

pub fn corner_wedge_to(self, rhs: Hex) -> impl Iterator<Item = Hex>

Retrieves all successive Hex half ring edges from self to rhs

See also Self::corner_wedge_to and Self::wedge_to

Source

pub fn cached_custom_ring_edges<const RANGE: usize>( self, direction: VertexDirection, clockwise: bool, ) -> [Vec<Hex>; RANGE]

Retrieves all successive Hex ring edges around self in a given RANGE and direction as an array of edges. The returned edges coordinates are sorted counter clockwise around self unless clockwise is set to true.

See also Self::cached_ring_edges If you only need the coordinates see Self::ring_edges or Self::wedge.

§Usage

This function’s objective is to pre-compute edges around a coordinate, the returned array can be used as a cache to avoid extra computation.

§Example

// We cache 10 rings around the origin
let cache = Hex::ORIGIN.cached_custom_ring_edges::<10>(VertexDirection::FLAT_RIGHT, true);
// We have our target center
let target = Hex::new(11, 24);
// We retrieve the ring of range 5 and offset it to match the target
let five_ring = cache[5].iter().map(|h| *h + target);

See this article for more information

Source

pub fn cached_ring_edges<const RANGE: usize>( self, direction: VertexDirection, ) -> [Vec<Hex>; RANGE]

Retrieves all successive Hex ring edges around self in a given RANGE and direction as an array of edges. The returned edges coordinates are sorted counter clockwise around self.

See also Self::cached_custom_ring_edges If you only need the coordinates see Self::ring_edges or Self::wedge.

§Usage

This function’s objective is to pre-compute edges around a coordinate, the returned array can be used as a cache to avoid extra computation.

§Example

// We cache 10 rings around the origin
let cache = Hex::ORIGIN.cached_ring_edges::<10>(VertexDirection::FLAT_RIGHT);
// We have our target center
let target = Hex::new(11, 24);
// We retrieve the ring of range 5 and offset it to match the target
let five_ring = cache[5].iter().map(|h| *h + target);

See this article for more information

Source

pub fn cached_rings<const RANGE: usize>(self) -> [Vec<Hex>; RANGE]

Retrieves all successive Hex rings around self in a given RANGE as an array of rings. The returned rings start from EdgeDirection::default and loop around self counter clockwise.

See also Self::cached_custom_rings If you only need the coordinates see Self::range or Self::spiral_range.

§Usage

This function’s objective is to pre-compute rings around a coordinate, the returned array can be used as a cache to avoid extra computation.

§Example

// We cache 10 rings around the origin
let cache = Hex::ORIGIN.cached_rings::<10>();
// We have our target center
let target = Hex::new(11, 24);
// We retrieve the ring of range 5 and offset it to match the target
let five_ring = cache[5].iter().map(|h| *h + target);

See this article for more information

Source

pub fn cached_custom_rings<const RANGE: usize>( self, start_dir: EdgeDirection, clockwise: bool, ) -> [Vec<Hex>; RANGE]

Retrieves all successive Hex rings around self in a given RANGE as an array of rings. The returned rings start from start_dir] and loop around self counter clockwise unless clockwise is set to true.

See also Self::cached_rings If you only need the coordinates see Self::range or Self::custom_spiral_range.

§Usage

This function’s objective is to pre-compute rings around a coordinate, the returned array can be used as a cache to avoid extra computation.

§Example

// We cache 10 rings around the origin
let cache = Hex::ORIGIN.cached_custom_rings::<10>(EdgeDirection::FLAT_TOP, true);
// We have our target center
let target = Hex::new(11, 24);
// We retrieve the ring of range 5 and offset it to match the target
let five_ring = cache[5].iter().map(|h| *h + target);

See this article for more information

Source

pub fn custom_spiral_range( self, range: impl Iterator<Item = u32>, start_dir: EdgeDirection, clockwise: bool, ) -> impl Iterator<Item = Hex>

Retrieves all Hex around self in a given range but ordered as successive rings, starting from start_dir and looping counter clockwise unless clockwise is set to true, forming a spiral

If you only need the coordinates see Self::spiral_range.

See this article for more information

Source

pub fn spiral_range( self, range: impl Iterator<Item = u32>, ) -> impl Iterator<Item = Hex>

Retrieves all Hex around self in a given range but ordered as successive rings, starting from EdgeDirection::FLAT_TOP_RIGHT and looping counter clockwise, forming a spiral.

See Self::custom_spiral_range for more options

See this article for more information

Source

pub const fn ring_count(range: u32) -> usize

Counts how many coordinates there are in a ring at the given range

Source§

impl Hex

Source

pub const fn xx(self) -> Hex

Returns a new Hex with both x and y set to the current x value

§Example

let point = Hex::new(1, 2);
assert_eq!(point.xx(), Hex::new(1, 1));
Source

pub const fn yy(self) -> Hex

Returns a new Hex with both x and y set to the current y value

§Example

let point = Hex::new(1, 2);
assert_eq!(point.yy(), Hex::new(2, 2));
Source

pub const fn zz(self) -> Hex

Returns a new Hex with both x and y set to the current z value

§Example

let point = Hex::new(1, 2);
assert_eq!(point.zz(), Hex::new(-3, -3));
Source

pub const fn yx(self) -> Hex

Returns a new Hex with invertex x and y values

§Example

let point = Hex::new(1, 2);
assert_eq!(point.yx(), Hex::new(2, 1));
Source

pub const fn yz(self) -> Hex

Returns a new Hex with its y valye as x and its z value as y

§Example

let point = Hex::new(1, 2);
assert_eq!(point.yz(), Hex::new(2, -3));
Source

pub const fn xz(self) -> Hex

Returns a new Hex with its z value as y

§Example

let point = Hex::new(1, 2);
assert_eq!(point.xz(), Hex::new(1, -3));
Source

pub const fn zx(self) -> Hex

Returns a new Hex with its z value as x and its x value as y

§Example

let point = Hex::new(1, 2);
assert_eq!(point.zx(), Hex::new(-3, 1));
Source

pub const fn zy(self) -> Hex

Returns a new Hex with its z value as x

§Example

let point = Hex::new(1, 2);
assert_eq!(point.zy(), Hex::new(-3, 2));
Source§

impl Hex

Source

pub const ORIGIN: Hex = Self::ZERO

(0, 0)

Source

pub const ZERO: Hex

(0, 0)

Source

pub const ONE: Hex

(1, 1)

Source

pub const NEG_ONE: Hex

(-1, -1)

Source

pub const X: Hex

+X (Q) (1, 0)

Source

pub const NEG_X: Hex

-X (-Q) (-1, 0)

Source

pub const Y: Hex

+Y (R) (0, 1)

Source

pub const NEG_Y: Hex

-Y (-R) (0, -1)

Source

pub const INCR_X: [Hex; 2]

Unit vectors that increase the X axis in clockwise order

Source

pub const INCR_Y: [Hex; 2]

Unit vectors that increase the Y axis in clockwise order

Source

pub const INCR_Z: [Hex; 2]

Unit vectors that increase the Z axis in clockwise order

Source

pub const DECR_X: [Hex; 2]

Unit vectors that decrease the X axis in clockwise order

Source

pub const DECR_Y: [Hex; 2]

Unit vectors that decrease the Y axis in clockwise order

Source

pub const DECR_Z: [Hex; 2]

Unit vectors that decrease the Z axis in clockwise order

Source

pub const NEIGHBORS_COORDS: [Hex; 6]

Hexagon edge neighbor coordinates array, following EdgeDirection order

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

Cubic coordinates:

             (0, -1, 1)
                 ___
                /   \
 (-1, 0, 1) +--+  4  +--+ (1, -1, 0)
           / 3  \___/  5 \
           \    /   \    /
            +--+     +--+
           /    \___/    \
(-1, 1, 0) \ 2  /   \  0 / (1, 0, -1)
            +--+  1  +--+
                \___/
              (0, 1, -1)
Source

pub const DIAGONAL_COORDS: [Hex; 6]

Hexagon diagonal neighbor coordinates array, following VertexDirection order

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

      Y           -Z
Source

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

Instantiates a new hexagon from axial coordinates

§Example
let coord = Hex::new(3, 5);
assert_eq!(coord.x, 3);
assert_eq!(coord.y, 5);
assert_eq!(coord.z(), -3 - 5);
Source

pub const fn splat(v: i32) -> Hex

Instantiates a new hexagon with all coordinates set to v

§Example
let coord = Hex::splat(3);
assert_eq!(coord.x, 3);
assert_eq!(coord.y, 3);
assert_eq!(coord.z(), -3 - 3);
Source

pub const fn new_cubic(x: i32, y: i32, z: i32) -> Hex

Instantiates new hexagonal coordinates in cubic space

§Panics

Will panic if the coordinates are invalid, meaning that the sum of coordinates is not equal to zero

§Example
let coord = Hex::new_cubic(3, 5, -8);
assert_eq!(coord.x, 3);
assert_eq!(coord.y, 5);
assert_eq!(coord.z(), -8);
Source

pub const fn x(self) -> i32

x coordinate (sometimes called q or i)

Source

pub const fn y(self) -> i32

y coordinate (sometimes called r or j)

Source

pub const fn z(self) -> i32

z coordinate (sometimes called s or k).

This cubic space coordinate is computed as -x - y

Source

pub const fn from_array(_: [i32; 2]) -> Hex

Creates a Hex from an array

§Example
let p = Hex::from_array([3, 5]);
assert_eq!(p.x, 3);
assert_eq!(p.y, 5);
Source

pub const fn to_array(self) -> [i32; 2]

Converts self to an array as [x, y]

§Example
let coord = Hex::new(3, 5);
let [x, y] = coord.to_array();
assert_eq!(x, 3);
assert_eq!(y, 5);
Source

pub const fn to_array_f32(self) -> [f32; 2]

Converts self to an f32 array as [x, y]

Source

pub const fn to_cubic_array(self) -> [i32; 3]

Converts self to cubic coordinates array as [x, y, z]

§Example
let coord = Hex::new(3, 5);
let [x, y, z] = coord.to_cubic_array();
assert_eq!(x, 3);
assert_eq!(y, 5);
assert_eq!(z, -3 - 5);
Source

pub const fn to_cubic_array_f32(self) -> [f32; 3]

Converts self to cubic f32 coordinates array as [x, y, z]

Source

pub const fn from_slice(slice: &[i32]) -> Hex

Creates a Hex from the first 2 values in slice.

§Panics

Panics if slice is less than 2 elements long.

Source

pub fn write_to_slice(self, slice: &mut [i32])

Writes the elements of self to the first 2 elements in slice.

§Panics

Panics if slice is less than 2 elements long.

Source

pub const fn as_ivec2(self) -> IVec2

Converts self to an IVec2. This operation is a direct mapping of coordinates, no hex to square coordinates are performed. To convert hex coordinates to world space use HexLayout

Source

pub const fn as_ivec3(self) -> IVec3

Converts self to an IVec3 using cubic coordinates. This operation is a direct mapping of coordinates. To convert hex coordinates to world space use HexLayout

Source

pub const fn as_vec2(self) -> Vec2

Converts self to a Vec2. This operation is a direct mapping of coordinates. To convert hex coordinates to world space use HexLayout

Source

pub const fn const_neg(self) -> Hex

Negates the coordinate, giving its reflection (symmetry) around the origin.

Hex implements Neg (- operator) but this method is const.

Source

pub const fn const_add(self, other: Hex) -> Hex

adds self and other.

Hex implements Add (+ operator) but this method is const.

Source

pub const fn const_sub(self, rhs: Hex) -> Hex

substracts self and rhs.

Hex implements Sub (- operator) but this method is const.

Source

pub fn round(_: [f32; 2]) -> Hex

Rounds floating point coordinates to Hex. This method is used for operations like multiplications and divisions with floating point numbers. See the original author Jacob Rus’s article for more details

§Example
let point = [0.6, 10.2];
let coord = Hex::round(point);
assert_eq!(coord.x, 1);
assert_eq!(coord.y, 10);
Source

pub const fn abs(self) -> Hex

Computes the absolute value of self

§Example
let coord = Hex::new(-1, -32).abs();
assert_eq!(coord.x, 1);
assert_eq!(coord.y, 32);
Source

pub fn min(self, rhs: Hex) -> Hex

Returns a vector containing the minimum values for each element of self and rhs.

In other words this computes [self.x.min(rhs.x), self.y.min(rhs.y), ..].

Source

pub fn max(self, rhs: Hex) -> Hex

Returns a vector containing the maximum values for each element of self and rhs.

In other words this computes [self.x.max(rhs.x), self.y.max(rhs.y), ..].

Source

pub const fn dot(self, rhs: Hex) -> i32

Computes the dot product of self and rhs.

Source

pub const fn signum(self) -> Hex

Returns a Hex with elements representing the sign of self.

  • 0 if the number is zero
  • 1 if the number is positive
  • -1 if the number is negative
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.

See Self::ulength for the unsigned version

§Example
let coord = Hex::new(10, 0);
assert_eq!(coord.length(), 10);
Source

pub const fn ulength(self) -> u32

Computes coordinates length as an unsigned integer The length of a Hex coordinate is equal to its distance from the origin.

See Self::length for the signed version

§Example
let coord = Hex::new(10, 0);
assert_eq!(coord.ulength(), 10);
Source

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

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

See Self::unsigned_distance_to for the unsigned version

Source

pub const fn unsigned_distance_to(self, rhs: Hex) -> u32

Computes the distance from self to rhs in hexagonal space as an unsigned integer

See Self::distance_to for the signed version

Source

pub const fn neighbor_coord(direction: EdgeDirection) -> Hex

Retrieves the hexagonal neighbor coordinates matching the given direction

Source

pub const fn diagonal_neighbor_coord(direction: VertexDirection) -> Hex

Retrieves the diagonal neighbor coordinates matching the given direction

Source

pub const fn neighbor(self, direction: EdgeDirection) -> Hex

Retrieves the neighbor coordinates matching the given direction

§Example
let coord = Hex::new(10, 5);
let bottom = coord.neighbor(EdgeDirection::FLAT_BOTTOM);
assert_eq!(bottom, Hex::new(10, 6));
Source

pub const fn diagonal_neighbor(self, direction: VertexDirection) -> Hex

Retrieves the diagonal neighbor coordinates matching the given direction

§Example
let coord = Hex::new(10, 5);
let bottom = coord.diagonal_neighbor(VertexDirection::FLAT_RIGHT);
assert_eq!(bottom, Hex::new(12, 4));
Source

pub fn neighbor_direction(self, other: Hex) -> Option<EdgeDirection>

Retrieves the direction of the given neighbor. Will return None if other is not a neighbor of self

§Example
let coord = Hex::new(10, 5);
let bottom = coord.neighbor(EdgeDirection::FLAT_BOTTOM);
let dir = coord.neighbor_direction(bottom).unwrap();
assert_eq!(dir, EdgeDirection::FLAT_BOTTOM);
Source

pub fn main_diagonal_to(self, rhs: Hex) -> VertexDirection

Find in which VertexDirection wedge rhs is relative to self.

This method can be innaccurate in case of a tie between directions, prefer using Self::diagonal_way_to instead

Source

pub fn diagonal_way_to(self, rhs: Hex) -> DirectionWay<VertexDirection>

Find in which VertexDirection wedge rhs is relative to self

Source

pub fn main_direction_to(self, rhs: Hex) -> EdgeDirection

Find in which EdgeDirection wedge rhs is relative to self

This method can be innaccurate in case of a tie between directions, prefer using Self::way_to for accuracy

Source

pub fn way_to(self, rhs: Hex) -> DirectionWay<EdgeDirection>

Find in which EdgeDirection wedge rhs is relative to self

Source

pub fn all_neighbors(self) -> [Hex; 6]

Retrieves all 6 neighbor coordinates around self

Source

pub fn all_diagonals(self) -> [Hex; 6]

Retrieves all 6 neighbor diagonal coordinates around self

Source

pub const fn counter_clockwise(self) -> Hex

Rotates self around Hex::ZERO counter clockwise (by -60 degrees)

§Example

let p = Hex::new(1, 2);
assert_eq!(p.counter_clockwise(), Hex::new(3, -1));
Source

pub const fn ccw_around(self, center: Hex) -> Hex

Rotates self around center counter clockwise (by -60 degrees)

Source

pub const fn rotate_ccw(self, m: u32) -> Hex

Rotates self around Hex::ZERO counter clockwise by m (by -60 * m degrees)

Source

pub const fn rotate_ccw_around(self, center: Hex, m: u32) -> Hex

Rotates self around center counter clockwise by m (by -60 * m degrees)

Source

pub const fn clockwise(self) -> Hex

Rotates self around Hex::ZERO clockwise (by 60 degrees)

§Example

let p = Hex::new(1, 2);
assert_eq!(p.clockwise(), Hex::new(-2, 3));
Source

pub const fn cw_around(self, center: Hex) -> Hex

Rotates self around center clockwise (by 60 degrees)

Source

pub const fn rotate_cw(self, m: u32) -> Hex

Rotates self around Hex::ZERO clockwise by m (by 60 * m degrees)

Source

pub const fn rotate_cw_around(self, center: Hex, m: u32) -> Hex

Rotates self around center clockwise by m (by 60 * m degrees)

Source

pub const fn reflect_x(self) -> Hex

Computes the reflection of self accross the x axis

Source

pub const fn reflect_y(self) -> Hex

Computes the reflection of self accross the y axis

Source

pub const fn reflect_z(self) -> Hex

Computes the reflection of self accross the z axis

Source

pub fn line_to(self, other: Hex) -> impl ExactSizeIterator

Computes all coordinates in a line from self to other.

§Example
let start = Hex::ZERO;
let end = Hex::new(5, 0);

let line = start.line_to(end);
assert_eq!(line.len(), 6);
let line: Vec<Hex> = line.collect();
assert_eq!(line.len(), 6);
Source

pub fn rectiline_to(self, other: Hex, clockwise: bool) -> impl ExactSizeIterator

Computes all coordinate in a two segment rectiline path from self to other

§Arguments
  • other - The destination coordinate
  • clockwise - If set to true the line paths will be clockwise
§Example
let start = Hex::ZERO;
let end = Hex::new(5, 0);

let line = start.rectiline_to(end, true);
assert_eq!(line.len(), 6);
let line: Vec<Hex> = line.collect();
assert_eq!(line.len(), 6);
assert_eq!(line[0], start);
assert_eq!(line[5], end);
Source

pub fn lerp(self, rhs: Hex, s: f32) -> Hex

Performs a linear interpolation between self and rhs based on the value s.

When s is 0.0, the result will be equal to self. When s is 1.0, the result will be equal to rhs. When s is outside of range [0, 1], the result is linearly extrapolated.

Source

pub fn range(self, range: u32) -> impl ExactSizeIterator

Retrieves all Hex around self in a given range. The number of returned coordinates is equal to Hex::range_count(range)

See also Hex::xrange to retrieve all coordinates excluding self

§Example
let coord = hex(12, 34);
assert_eq!(coord.range(0).len(), 1);
assert_eq!(coord.range(1).len(), 7);
Source

pub fn xrange(self, range: u32) -> impl ExactSizeIterator

Retrieves all Hex around self in a given range except self. The number of returned coordinates is equal to Hex::range_count(range) - 1

See also Hex::range to retrieve all coordinates including self

§Example
let coord = hex(12, 34);
assert_eq!(coord.xrange(0).len(), 0);
assert_eq!(coord.xrange(1).len(), 6);
Source

pub fn to_lower_res(self, radius: u32) -> Hex

Computes the coordinate of a lower resolution hexagon containing self of a given radius. The lower resolution coordinate can be considered parent of the contained higher resolution coordinates. The radius can be thought of as a chunk size, as if the grid was split in hexagonal chunks of that radius. The returned value are the coordinates of that chunk, in its own coordinates system.

See the source documentation for more information

See also Self::to_higher_res and Self::to_local

§Example

// We define a coordinate
let coord = hex(23, 45);
// We take its *parent* in a coordinate system of size 5
let parent = coord.to_lower_res(5);
// We can then retrieve the center of that parent in the same system as `coord`
let center = parent.to_higher_res(5);
// Therefore the distance between the parent center and `coord` should be lower than 5
assert!(coord.distance_to(center) <= 5);
Source

pub const fn to_higher_res(self, radius: u32) -> Hex

Computes the center coordinates of self in a higher resolution system of a given radius. The higher resolution coordinate can be considered as a child of self as it is contained by it in a lower resolution coordinates system. The radius can be thought of as a chunk size, as if the grid was split in hexagonal chunks of that radius. The returned value are the coordinates of the center that chunk, in a higher resolution coordinates system.

See the source documentation for more information

See also Self::to_lower_res and Self::to_local

§Example

// We define a coordinate
let coord = hex(23, 45);
// We take its *parent* in a coordinate system of size 5
let parent = coord.to_lower_res(5);
// We can then retrieve the center of that parent in the same system as `coord`
let center = parent.to_higher_res(5);
// Therefore the distance between the parent center and `coord` should be lower than 5
assert!(coord.distance_to(center) <= 5);
Source

pub fn to_local(self, radius: u32) -> Hex

Computes the local coordinates of self in a lower resolution coordinates system relative to its containing parent hexagon

See the source documentation for more information

See also Self::to_lower_res and Self::to_local

§Example

// We define a coordinate
let coord = hex(23, 45);
// We can then retrieve the center of that hexagon in a higher res of size 5
let center = coord.to_higher_res(5);
// Therefore, the local coordinates of `center` relative to `coord` should be zero
assert_eq!(center.to_local(5), Hex::ZERO);
Source

pub const fn range_count(range: u32) -> u32

Counts how many coordinates there are in the given range

§Example
assert_eq!(Hex::range_count(15), 721);
assert_eq!(Hex::range_count(0), 1);
Source

pub fn wrap_in_range(self, range: u32) -> Hex

Wraps self in an hex range around the origin (Hex::ZERO). this allows for seamless wraparound hexagonal maps. See this article for more information.

Use HexBounds for custom wrapping

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 Add<VertexDirection> for Hex

Source§

type Output = Hex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Hex

Source§

type Output = Hex

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Hex) -> <Hex as Add>::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 AddAssign<VertexDirection> for Hex

Source§

fn add_assign(&mut self, rhs: VertexDirection)

Performs the += operation. Read more
Source§

impl AddAssign<i32> for Hex

Source§

fn add_assign(&mut self, rhs: i32)

Performs the += operation. Read more
Source§

impl AddAssign for Hex

Source§

fn add_assign(&mut self, rhs: Hex)

Performs the += operation. Read more
Source§

impl BitAnd<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: i32) -> <Hex as BitAnd<i32>>::Output

Performs the & operation. Read more
Source§

impl BitAnd for Hex

Source§

type Output = Hex

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Hex) -> <Hex as BitAnd>::Output

Performs the & operation. Read more
Source§

impl BitOr<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: i32) -> <Hex as BitOr<i32>>::Output

Performs the | operation. Read more
Source§

impl BitOr for Hex

Source§

type Output = Hex

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Hex) -> <Hex as BitOr>::Output

Performs the | operation. Read more
Source§

impl BitXor<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: i32) -> <Hex as BitXor<i32>>::Output

Performs the ^ operation. Read more
Source§

impl BitXor for Hex

Source§

type Output = Hex

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Hex) -> <Hex as BitXor>::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 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Hex

Source§

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

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

impl Default for Hex

Source§

fn default() -> Hex

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

impl<'de> Deserialize<'de> for Hex

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Hex, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Div<f32> for Hex

Source§

type Output = Hex

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> <Hex as Div<f32>>::Output

Performs the / operation. Read more
Source§

impl Div<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the / operator.
Source§

fn div(self, rhs: i32) -> <Hex as Div<i32>>::Output

Performs the / operation. Read more
Source§

impl Div for Hex

Source§

type Output = Hex

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Hex) -> <Hex as Div>::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Hex

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign<i32> for Hex

Source§

fn div_assign(&mut self, rhs: i32)

Performs the /= operation. Read more
Source§

impl DivAssign for Hex

Source§

fn div_assign(&mut self, rhs: Hex)

Performs the /= operation. Read more
Source§

impl From<[f32; 2]> for Hex

Source§

fn from(v: [f32; 2]) -> Hex

Converts to this type from the input type.
Source§

impl From<[i32; 2]> for Hex

Source§

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

Converts to this type from the input type.
Source§

impl From<(f32, f32)> for Hex

Source§

fn from(v: (f32, f32)) -> Hex

Converts to this type from the input type.
Source§

impl From<(i32, i32)> for Hex

Source§

fn from(_: (i32, i32)) -> Hex

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 From<Hex> for Tile

Source§

fn from(value: Hex) -> Self

Converts to this type from the input type.
Source§

impl From<IVec2> for Hex

Source§

fn from(v: IVec2) -> Hex

Converts to this type from the input type.
Source§

impl From<Vec2> for Hex

Source§

fn from(value: Vec2) -> Hex

Converts to this type from the input type.
Source§

impl From<VertexDirection> for Hex

Source§

fn from(value: VertexDirection) -> Hex

Converts to this type from the input type.
Source§

impl FromIterator<Hex> for Maze

Source§

fn from_iter<T: IntoIterator<Item = Hex>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromReflect for Hex
where Hex: Any + Send + Sync, i32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Hex>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetTypeRegistration for Hex
where Hex: Any + Send + Sync, i32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl Hash for Hex

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<f32> for Hex

Source§

type Output = Hex

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> <Hex as Mul<f32>>::Output

Performs the * operation. Read more
Source§

impl Mul<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for Hex

Source§

type Output = Hex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Hex

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign<i32> for Hex

Source§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
Source§

impl MulAssign for Hex

Source§

fn mul_assign(&mut self, rhs: Hex)

Performs the *= operation. Read more
Source§

impl Neg for Hex

Source§

type Output = Hex

The resulting type after applying the - operator.
Source§

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

Performs the unary - operation. Read more
Source§

impl PartialEq<Hex> for &Hex

Source§

fn eq(&self, other: &Hex) -> 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 PartialEq for Hex

Source§

fn eq(&self, other: &Hex) -> 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 PartialReflect for Hex
where Hex: Any + Send + Sync, i32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn clone_value(&self) -> Box<dyn PartialReflect>

Clones the value as a Reflect trait object. Read more
Source§

fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Hex>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<Hex>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>

Attempts to cast this type to a boxed, fully-reflected value.
Source§

fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>

Attempts to cast this type to a fully-reflected value.
Source§

fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>

Attempts to cast this type to a mutable, fully-reflected value.
Source§

fn into_partial_reflect(self: Box<Hex>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)

Casts this type to a reflected value. Read more
Source§

fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)

Casts this type to a mutable, reflected value. Read more
Source§

fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn apply(&mut self, value: &(dyn PartialReflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

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

Debug formatter for the value. Read more
Source§

fn serializable(&self) -> Option<Serializable<'_>>

Returns a serializable version of the value. Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl<'a> Product<&'a Hex> for Hex

Source§

fn product<I>(iter: I) -> Hex
where I: Iterator<Item = &'a Hex>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Product for Hex

Source§

fn product<I>(iter: I) -> Hex
where I: Iterator<Item = Hex>,

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Reflect for Hex
where Hex: Any + Send + Sync, i32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_any(self: Box<Hex>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<Hex>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a fully-reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl Rem<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: i32) -> <Hex as Rem<i32>>::Output

Performs the % operation. Read more
Source§

impl Rem for Hex

Source§

type Output = Hex

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Hex) -> <Hex as Rem>::Output

Performs the % operation. Read more
Source§

impl RemAssign<i32> for Hex

Source§

fn rem_assign(&mut self, rhs: i32)

Performs the %= operation. Read more
Source§

impl RemAssign for Hex

Source§

fn rem_assign(&mut self, rhs: Hex)

Performs the %= operation. Read more
Source§

impl Serialize for Hex

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Shl<i16> for Hex

Source§

type Output = Hex

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

fn shl(self, rhs: i16) -> <Hex as Shl<i16>>::Output

Performs the << operation. Read more
Source§

impl Shl<i32> for Hex

Source§

type Output = Hex

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

fn shl(self, rhs: i32) -> <Hex as Shl<i32>>::Output

Performs the << operation. Read more
Source§

impl Shl<i8> for Hex

Source§

type Output = Hex

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

fn shl(self, rhs: i8) -> <Hex as Shl<i8>>::Output

Performs the << operation. Read more
Source§

impl Shl<u16> for Hex

Source§

type Output = Hex

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

fn shl(self, rhs: u16) -> <Hex as Shl<u16>>::Output

Performs the << operation. Read more
Source§

impl Shl<u32> for Hex

Source§

type Output = Hex

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

fn shl(self, rhs: u32) -> <Hex as Shl<u32>>::Output

Performs the << operation. Read more
Source§

impl Shl<u8> for Hex

Source§

type Output = Hex

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

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

Performs the << operation. Read more
Source§

impl Shl for Hex

Source§

type Output = Hex

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

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

Performs the << operation. Read more
Source§

impl Shr<i16> for Hex

Source§

type Output = Hex

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

fn shr(self, rhs: i16) -> <Hex as Shr<i16>>::Output

Performs the >> operation. Read more
Source§

impl Shr<i32> for Hex

Source§

type Output = Hex

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

fn shr(self, rhs: i32) -> <Hex as Shr<i32>>::Output

Performs the >> operation. Read more
Source§

impl Shr<i8> for Hex

Source§

type Output = Hex

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

fn shr(self, rhs: i8) -> <Hex as Shr<i8>>::Output

Performs the >> operation. Read more
Source§

impl Shr<u16> for Hex

Source§

type Output = Hex

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

fn shr(self, rhs: u16) -> <Hex as Shr<u16>>::Output

Performs the >> operation. Read more
Source§

impl Shr<u32> for Hex

Source§

type Output = Hex

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

fn shr(self, rhs: u32) -> <Hex as Shr<u32>>::Output

Performs the >> operation. Read more
Source§

impl Shr<u8> for Hex

Source§

type Output = Hex

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

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

Performs the >> operation. Read more
Source§

impl Struct for Hex
where Hex: Any + Send + Sync, i32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field named name as a &dyn PartialReflect.
Source§

fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn PartialReflect.
Source§

fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn PartialReflect.
Source§

fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn PartialReflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
Source§

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.
Source§

fn get_represented_struct_info(&self) -> Option<&'static StructInfo>

Will return None if TypeInfo is not available.
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 Sub<VertexDirection> for Hex

Source§

type Output = Hex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<i32> for Hex

Source§

type Output = Hex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for Hex

Source§

type Output = Hex

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Hex) -> <Hex as Sub>::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 SubAssign<VertexDirection> for Hex

Source§

fn sub_assign(&mut self, rhs: VertexDirection)

Performs the -= operation. Read more
Source§

impl SubAssign<i32> for Hex

Source§

fn sub_assign(&mut self, rhs: i32)

Performs the -= operation. Read more
Source§

impl SubAssign for Hex

Source§

fn sub_assign(&mut self, rhs: Hex)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a Hex> for Hex

Source§

fn sum<I>(iter: I) -> Hex
where I: Iterator<Item = &'a Hex>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for Hex

Source§

fn sum<I>(iter: I) -> Hex
where I: Iterator<Item = Hex>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl TypePath for Hex
where Hex: Any + Send + Sync,

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for Hex
where Hex: Any + Send + Sync, i32: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.
Source§

impl Copy for Hex

Source§

impl Eq for Hex

Source§

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 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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'p, T>( &self, path: impl ReflectPath<'p>, ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T> Reflectable for T

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,