4 releases

0.1.3 Aug 21, 2022
0.1.2 Aug 14, 2022
0.1.1 Aug 14, 2022
0.1.0 Aug 13, 2022

#21 in #cube

Apache-2.0

55KB
1K SLoC

hex-coordinates

crates.io docs.rs

A library for handling hex coordinates.

Massive credit to Hexagonal Grids from Red Blob Games.

OffsetDoubledAxialCube
Pointy Rotationevenr, oddrdoublewidthaxialcube
Flat Rotationevenq, oddqdoubleheight
Other Rotationsnoyes
Vector operations (add, subtract, scale)noyesyesyes
Array storagerectangularno*rhombus*no*
Hash storageany shapeany shape
Hexagonal symmetrynononoyes
Easy algorithmsfewsomemostmost

The article notes:

My recommendation: if you are only going to use non-rotated rectangular maps, consider the doubled or offset system that matches your map orientation. For maps with Rotation, or non-rectangularly shaped maps, use axial/cube. Either choose to store the s coordinate (cube), or calculate it when needed as -q-r (axial).

No runtime deps