Expand description
Axial hex coordinates for no_std and embedded targets.
§Coordinate system
hexal uses axial coordinates (q, r) as the primary representation.
Axial is the cleanest system for arithmetic: neighbors, distance, rings, and
lines are all simple expressions with no lookup tables.
The third cube axis s satisfies q + r + s = 0 and is derived on demand.
+r
/
-q --●-- +q
\
-r (pointy-top orientation)§Offset coordinates
For screen/storage mapping, use OffsetHex with one of the four standard
schemes: OddR, EvenR, OddQ, EvenQ. Convert with
Hex::to_offset and OffsetHex::to_hex.
§Type aliases
HexI (i32), HexI16 (i16), and HexI8 (i8) cover the most
common embedded and desktop use cases.
§Features
serde— deriveSerialize/DeserializeonHexandOffsetHex.ixy— enableFrom/Intoconversions withixy::Pos<T>viaOddRoffset (the natural screen mapping).
§Examples
use hexal::{hex, Hex, Direction};
let a = hex!(1, 0);
let b = hex!(0, 1);
assert_eq!(a.distance(b), 1);
assert_eq!(a.neighbor(Direction::W), hex!(0, 0));Modules§
- int
- Signed integer bound used throughout
hexal.
Macros§
Structs§
- EvenQ
- Flat-top orientation, even columns shifted up.
- EvenR
- Pointy-top orientation, even rows shifted right.
- Hex
- An axial hex coordinate
(q, r). - HexLine
- Iterator over the hex line from one hex to another.
- HexRange
- Iterator over all hexes within
radiussteps of a center (inclusive). - HexRing
- Iterator over the ring of hexes at exactly
radiussteps from a center. - OddQ
- Flat-top orientation, odd columns shifted down.
- OddR
- Pointy-top orientation, odd rows shifted right.
- Offset
Hex - A hex coordinate stored as
(col, row)under a specific offset scheme.
Enums§
- Direction
- One of the six axial directions on a pointy-top hex grid.
Traits§
- Offset
Scheme - Conversion scheme between axial and offset coordinates.