← hex_grid · version 0.1.4
19 public items, in source order. Generated from the registry index, which re-derives them from the package source at publish time — so a signature here is the one that version actually ships.
pub fn hex_to_px(q: integer, r: integer) -> (float, float)
Hex (col,row) -> world-plane centre (x,y). Pointy-top, ODD-R OFFSET (moros's convention): odd rows shifted half a hex right, so a rectangle of cells stays UPRIGHT (axial sheared them). Throughout the kernel (q,r) ARE offset (col,row).
pub fn hex_round(qf: float, rf: float) -> (integer, integer)
Round fractional cube coords to the nearest hex; return AXIAL (q,r) — NOT the odd-r offset (col,row) the rest of this module takes. Both are (integer, integer), so mixing them type-checks and lands on a neighbouring hex. Use px_to_hex unless you already hold axial coordinates.
pub fn px_to_hex(x: float, y: float) -> (integer, integer)
World-plane point (x,y) -> nearest hex (col,row). Axial-fractional inverse + cube round, then convert axial -> odd-r offset (col = q + (r - (r&1))/2). This is the conversion to reach for: it answers the OFFSET pair every other function here expects, where hex_round alone answers the axial one.
pub fn hex_neighbor(q: integer, r: integer, dir: integer) -> (integer, integer)
The six neighbour directions (0=E, 1=SE, 2=SW, 3=W, 4=NW, 5=NE; r increases upward). ODD-R OFFSET, so the four diagonal deltas differ by row parity. The compass order matches the old axial one, so edge_corners/canon_edge are unchanged. Only E and W are parity-free: a hardcoded six-entry delta table is right on every even row and hands back the wrong NEIGHBOUR — not a bad cell — on odd ones.
pub fn hex_distance(q1: integer, r1: integer, q2: integer, r2: integer) -> integer
Hex distance in steps — convert odd-r offset -> axial, then cube distance.
pub fn hex_neighbor_dir(q1: integer, r1: integer, q2: integer, r2: integer) -> integer
Which of the 6 neighbour directions leads from (q1,r1) to adjacent (q2,r2)? Inverse of hex_neighbor (odd-r offset, parity-dependent on r1); -1 if not adjacent. -1 is an ordinary integer, not a null: it flows into every function that takes a direction, where hex_neighbor and hex_edge_corners absorb it as direction 5 and hex_canon_edge keeps it as an edge index. Check it here.
pub fn hex_corner_offset(i: integer) -> (float, float)
Corner offset of a pointy-top unit hex (circumradius 1), corner 0 = top, going counter-clockwise. Used to place edge endpoints and wall segments. +y is NORTH here. The cell_* family below uses +y SOUTH, with the same (float, float) return type — see the example before assuming either.
pub fn hex_corner_px(q: integer, r: integer, i: integer) -> (float, float)
World-plane position of corner i of hex (q,r).
pub fn hex_edge_corners(dir: integer) -> (integer, integer)
The two corner indices bounding the edge in neighbour direction dir. Out-of-range directions fall through to the direction-5 arm rather than raising, which is how a -1 from hex_neighbor_dir becomes a real answer.
pub fn hex_canon_edge(q: integer, r: integer, dir: integer) -> (integer, integer, integer)
Resolve any of the 6 directions to the owning hex + canonical edge index (0,1,2). Dirs 0,1,2 are stored on this hex; 3,4,5 on the neighbour. Call this before you key a wall on anything. A wall keyed on the raw (q, r, dir) a caller happened to approach from becomes TWO half-walls that disagree — blocking from one side and open from the other.
pub fn px_to_cell(x: float, y: float) -> (integer, integer)
World point -> the cell containing it (cells centred on integers).
pub fn cell_neighbor(q: integer, r: integer, dir: integer) -> (integer, integer)
4 orthogonal directions: 0=E, 1=S, 2=W, 3=N. Note r increases SOUTH here, where in the hex_* family it increases NORTH — hex_neighbor(q, r, 5) and cell_neighbor(q, r, 1) return the same pair for opposite compass directions.
pub fn cell_neighbor_dir(q1: integer, r1: integer, q2: integer, r2: integer) -> integer
Inverse of cell_neighbor; -1 if not orthogonally adjacent. This — not cell_distance(a, b) == 1 — is the adjacency test: the metric is Chebyshev and answers 1 for diagonals no single step can reach.
pub fn cell_distance(q1: integer, r1: integer, q2: integer, r2: integer) -> integer
King-move (Chebyshev) distance — matches 8-directional movement, which is NOT the 4-directional move set cell_neighbor offers. So == 1 admits diagonals and is not an adjacency test; use cell_neighbor_dir(…) >= 0 for that.
pub fn cell_corner_offset(i: integer) -> (float, float)
Corner offsets of a unit cell (centre origin): 0=NW,1=NE,2=SE,3=SW (y down). +y is SOUTH here, the opposite of hex_corner_offset above.
pub fn cell_corner_px(q: integer, r: integer, i: integer) -> (float, float)
One corner of a cell in pixels. The last step before drawing: everything above it is exact, and this is where a renderer's coordinates begin.