#grid #shapes #hex #hexagon #2d #top #pointy

hex_grid

A library to easily work with 2d hex grids of arbitrary shapes

5 releases

Uses old Rust 2015

0.2.1 Oct 28, 2019
0.2.0 Apr 15, 2018
0.1.2 Jan 7, 2018
0.1.1 Jan 7, 2018
0.1.0 Jan 1, 2018

#1372 in Algorithms

MIT/Apache

14KB
358 lines

Hex Grid

Build Status crates.io

Documentation

A library to easily work with 2d hex grids of arbitrary shapes. This library currently only supports "Pointy Top" hexagons.

Usage

Add this to your Cargo.toml:

[dependencies]
hex_grid = "*"

and this to your crate root:

extern crate hex_grid;

Quick Start

use hex_grid::*;
use std::collections::HashMap;

struct CustomData{
    //..whatever data you want associated with each tile
}

//empty grid
let mut grid: HashMap<Coordinate, CustomData> = HashMap::new();

//fill the grid with tiles in a hexagon shape of size 3
let coords = CENTER + Offset::fill_hex(3);
for coord in coords {
    let data:CustomData = //...
    grid.insert(coord, data);
}

//get the tile that is to the right 2 tiles from the center tile
let tile:Option<CustomData> = grid.get(CENTER + RIGHT*2);

No runtime deps