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

hex_grid

一个用于轻松处理任意形状的2D六边形网格的库

5个版本

使用旧的Rust 2015

0.2.1 2019年10月28日
0.2.0 2018年4月15日
0.1.2 2018年1月7日
0.1.1 2018年1月7日
0.1.0 2018年1月1日

#1372 in 算法

MIT/Apache

14KB
358

六边形网格

Build Status crates.io

文档

一个用于轻松处理任意形状的2D六边形网格的库。此库目前仅支持“尖顶”六边形。

使用方法

将以下内容添加到您的 Cargo.toml

[dependencies]
hex_grid = "*"

并将以下内容添加到您的crate根目录

extern crate hex_grid;

快速入门

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);

无运行时依赖