Expand description
§Bestagon
bestagon is a library for working with hexagonal grids.
It supports:
- Axial (
q,r) and Cubic (q,r,s) coordinate systems. - Flat-topped hexagon orientation.
- Neighbour calculation for Hexagons, Edges, and Nodes.
§Modules
- [
hex] - The face of a hexagon (Cells). - [
edge] - The edge between two hexagons. - [
node] - The vertex where three hexagons meet.
§Getting Started
Add bestagon to your Cargo.toml.
use bestagon::prelude::*;
let hex = HexAx::new(0, 0);
let neighbours: Vec<HexAx> = hex.hexes().collect();
assert_eq!(neighbours.len(), 6);
// Convert to cartesian coordinates (Flat-topped)
let point = hex.to_cartesian();§Coordinate Systems
- Axial: Uses
q(column) andr(row). - Cubic: Adds
ssuch thatq + r + s = 0. Useful for algorithms.
Modules§
Structs§
- EdgeAx
- An edge represents the edge between two hex faces. To get the coordinates for an edge, you would want to use the average of the coordinates of the two hexes that touch it. Since we use integers, we cannot use the average so instead just use the sum (in this case the average times 2).
- FEdgeAx
- FHexAx
- Hexagon in floating-point Axial coordinates (q, r).
- FHexCb
- FNodeAx
- HexAx
- Hexagon in Axial coordinates (q, r).
- HexCb
- Hexagon in Cubic coordinates (q, r, s).
- NodeAx
Traits§
- Edge
- A struct can be considered and Edge if it implements a number of other traits and this traits provides default implementations for some behaviour.
- Hex
- A Hex represents the face of a single hexagon in the grid.
- Node
- A node is shared by three edges, and by three hexes. It is the point that connects them.