Skip to main content

bin_hexagonal

Function bin_hexagonal 

Source
pub fn bin_hexagonal(
    x: &[f64],
    y: &[f64],
    gridsize: usize,
    mincnt: usize,
) -> HexBinResult
Expand description

Bins (x, y) data points into a flat-top hexagonal grid.

The grid is sized so that roughly gridsize hexagons span the x-extent of the data. Only cells with at least mincnt points are included in the result.

§Algorithm

Uses the standard “nearest hex center” approach for flat-top hexagons:

  1. Compute hex size (circumradius) from the data extent and gridsize.
  2. For each point, convert to fractional axial coordinates then round to the nearest hex cell using cube-coordinate rounding.
  3. Accumulate counts in a hash map keyed by axial (q, r).
  4. Convert each cell’s axial coordinates back to Cartesian centers.