hexal
Axial hex coordinates for no_std and embedded targets.
Overview
hexal provides axial hex coordinates (q, r) with no runtime dependencies
and no allocator. Every operation is pure integer arithmetic; no floats, no
lookup tables, no heap.
+r
/
-q --●-- +q
\
-r (pointy-top orientation)
The s axis (-q - r) satisfies the cube constraint q + r + s = 0 and is
derived on demand.
Quick start
use ;
// Construct
let a = hex!;
let b = ORIGIN;
// Distance (pure integer, no float)
assert_eq!;
// Neighbors
assert_eq!;
// Ring iterator — no allocation
let ring: = b.ring.collect;
assert_eq!;
// Line iterator — no allocation
let line: = hex!.line_to.collect;
assert_eq!;
Offset coordinates
For screen/storage mapping, convert via one of four standard schemes:
| Type | Orientation | Shift |
|---|---|---|
OddR |
Pointy-top | Odd rows shifted right |
EvenR |
Pointy-top | Even rows shifted right |
OddQ |
Flat-top | Odd cols shifted down |
EvenQ |
Flat-top | Even cols shifted up |
use ;
let offset = hex!.;
assert_eq!;
assert_eq!;
assert_eq!;
Features
| Feature | Description |
|---|---|
serde |
Serialize/Deserialize on Hex and OffsetHex |
ixy |
From/Into with ixy::Pos<T> via OddR offset |
Type aliases
| Alias | Type | Use case |
|---|---|---|
HexI |
Hex<i32> |
General purpose (default) |
HexI16 |
Hex<i16> |
Large embedded maps |
HexI8 |
Hex<i8> |
Tiny grids (±127 per axis) |
no_std
hexal is unconditionally no_std. No extern crate alloc is needed; all
iterators are stack-only.
MSRV
Rust 1.87 (edition 2024).
License
Licensed under either of MIT or Apache-2.0 at your option.