1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//! Facts about the geometry and topology of hexagons, and portions thereof,
//! with respect to their use in a globe voxmap. These hexagonal portions
//! are analogous to circular sectors, and are used in rendering the edges and
//! corners of chunks where a full hexagon will not fit.
use GridCoord;
// We can imagine a hexagon laid out on a quad
// that wraps in both directions, such that its
// center exists at all four corners of the quad:
//
// (0, 0)
// ● y
// x ◌ ↘
// ↓ ◌ ◌
// ◌ ●
// ◌ ◌ / ◌
// ◌ / ◌ ◌ (0, 0)
// ●-----● ◌ ●
// ◌ \ ◌ ◌
// ◌ ◌ \ ◌ ◌
// ◌ ● ◌
// ◌ ◌ \ ◌ ◌
// ◌ ◌ \ ◌
// ● ◌ ●-----●
// (0, 0) ◌ ◌ / ◌
// ◌ / ◌ ◌
// ● ◌
// ◌ ◌
// ◌
// ●
// (0, 0)
//
// This makes it visually obvious that we're dealing
// with a grid of 6 units between hexagon centers (count it)
// to calculate cell vertex positions (if we want all vertices
// to lie at integer coordinate pairs) as opposed to the 1 unit
// between cell centers when we're only concerned with the
// center points of each cell.
//
// Then, if we list out points for the middle of each side and each vertex,
// starting from the middle of the side in the positive x direction and
// travelling counterclockwise, we end up with 12 offset coordinate pairs
// in this grid, labelled as follows:
//
// 6
// 7 5
// ●-----●-----●
// / ◌ ◌ \
// / ◌ ◌ ◌ \
// 8 ● ◌ ◌ ● 4
// / ◌ ◌ ◌ \
// / ◌ ◌ ◌ ◌ \
// 9 ● ◌ ● ◌ ● 3
// \ ◌ ◌ ◌ ◌ /
// \ ◌ ◌ ◌ /
// ● ◌ ◌ ●
// 10 \ ◌ ◌ ◌ / 2
// \ ◌ ◌ / y
// ●-----●-----● ↘
// 11 1
// 0
//
// x
// ↓
//
// Referring to the top figure for the offsets and the
// bottom for the labelling, that gives us:
pub const DIR_OFFSETS: = ;
// There are 9 different shapes that we need for drawing cells in various
// parts of a chunk. Here is a cross-section of the smallest chunk that
// demonstrates all 9 shapes:
//
// ● y
// x |`~◌ ↘
// ↓ ◌ `~◌
// | ◌ `~●
// ◌ ◌ / `~◌
// | ◌ / ◌ `~◌
// ●-----● ◌ `~◌
// | ◌ \ ◌ ◌ `~◌
// ◌ ◌ \ ◌ ◌ `~◌
// | ◌ ◌ ◌ ◌ `~●
// ◌ ◌ \ ◌ ◌ ◌ / `~◌
// | ◌ ◌ \ ◌ ◌ / ◌ `~◌
// ◌ ◌ ●-----◌-----● ◌ `~●
// | ◌ ◌ / ◌ ◌ \ ◌ ◌ |
// ◌ ◌ / ◌ ◌ ◌ \ ◌ ◌
// | ◌ ◌ ◌ ◌ ◌ ◌ |
// ◌ ◌ / ◌ ◌ ◌ \ ◌ ◌
// | ◌ / ◌ ◌ ◌ \ ◌ |
// ●-----● ◌ ◌ ◌ ●-----●
// | ◌ \ ◌ ◌ ◌ ◌ / ◌ |
// ◌ ◌ \ ◌ ◌ ◌ / ◌ ◌
// | ◌ ◌ ◌ ◌ ◌ ◌ |
// ◌ ◌ \ ◌ ◌ ◌ / ◌ ◌
// | ◌ ◌ \ ◌ ◌ / ◌ ◌ |
// ● ◌ ●-----◌-----● ◌ ◌
// `~◌ ◌ / ◌ ◌ \ ◌ ◌ |
// `~◌ / ◌ ◌ ◌ \ ◌ ◌
// `~● ◌ ◌ ◌ ◌ |
// `~◌ ◌ ◌ \ ◌ ◌
// `~◌ ◌ ◌ \ ◌ |
// `~◌ ◌ ●-----●
// `~◌ ◌ / ◌ |
// `~◌ / ◌ ◌
// `~● ◌ |
// `~◌ ◌
// `~◌ |
// `~●
//
// The filled circles represent vertices that will be used in the
// geometry for a given shape. Note that cell centres are included
// explicitly only where needed.
//
// For consistency with the orientation of chunks on a globe,
// we will refer to the corner at (0, 0) as "North".
pub const FULL_HEX: CellShape = CellShape ;
pub const NORTH_PORTION: CellShape = CellShape ;
pub const SOUTH_PORTION: CellShape = CellShape ;
pub const WEST_PORTION: CellShape = CellShape ;
pub const EAST_PORTION: CellShape = CellShape ;
pub const NORTH_WEST_PORTION: CellShape = CellShape ;
pub const NORTH_EAST_PORTION: CellShape = CellShape ;
pub const SOUTH_WEST_PORTION: CellShape = CellShape ;
pub const SOUTH_EAST_PORTION: CellShape = CellShape ;
// If we number hexagonal cell edges from 0 through 5,
// then the (x, y) offsets to reach each neighbouring hexagon are:
//
// (-1, 0)
// \ 3 /
// \ /
// (0, -1) ●-------● (-1, +1)
// 4 / \ 2
// / \
// / \
// -----● ◌ ●-----
// \ /
// \ /
// 5 \ / 1
// (+1, -1) ●-------● (0, +1)
// / \
// / 0 \
// (+1, 0)
//
// x
// ↓
pub static NEIGHBOR_OFFSETS: =
;