hexagon
简介
支持六边形坐标计算
base: https://www.redblobgames.com/grids/hexagons/
组件接口
hexagon.gs
样例
int q = 0;
int r = 0;
int x = hexagon.calc_cube_x_from_qr(q, r);
test_equal(x, 0);
int z = hexagon.calc_cube_z_from_qr(q, r);
test_equal(z, 0);
int y = hexagon.calc_cube_y_from_cube_xz(x, z);
test_equal(y, 0);
let int dx, int dz = hexagon.calc_cube_offset_from_qr(2, 2, 3, 2);
test_equal(dx, -1);
test_equal(dz, 0);
test_equal(hexagon.get_distance(1, 1, 0, 0), 2);
test_equal(hexagon.get_distance(2, 2, 5, 0), 4);
test_equal(hexagon.get_distance(2, 2, 4, 0), 3);
let int q_in_right, int r_in_right = hexagon.get_neighbor_in_direction(2, 1, hexagon.DIRECTION_RIGHTTOP);
test_equal(q_in_right, 3);
test_equal(r_in_right, 0);
hexagon.iterate_line(0, 0, 3, 1, (int q, int r) {
printf("(%d, %d)\n", q, r);
});
printf("-----------------\n");
hexagon.iterate_rectangle(0, 0, 3, 2, (int q, int r) {
printf("(%d, %d)\n", q, r);
});