1/*
2 * Copyright 2016-2018 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/** @file baseCells.c
17 * @brief Base cell related lookup tables and access functions.
18 */
19
20#include "baseCells.h"
21#include "h3Index.h"
22
23/** @struct BaseCellOrient
24 * @brief base cell at a given ijk and required rotations into its system
25 */
26typedef struct {
27 int baseCell; ///< base cell number
28 int ccwRot60; ///< number of ccw 60 degree rotations relative to current
29 /// face
30} BaseCellOrient;
31
32/** @brief Neighboring base cell ID in each IJK direction.
33 *
34 * For each base cell, for each direction, the neighboring base
35 * cell ID is given. 127 indicates there is no neighbor in that direction.
36 */
37const int baseCellNeighbors[NUM_BASE_CELLS][7] = {
38 {0, 1, 5, 2, 4, 3, 8}, // base cell 0
39 {1, 7, 6, 9, 0, 3, 2}, // base cell 1
40 {2, 6, 10, 11, 0, 1, 5}, // base cell 2
41 {3, 13, 1, 7, 4, 12, 0}, // base cell 3
42 {4, INVALID_BASE_CELL, 15, 8, 3, 0, 12}, // base cell 4 (pentagon)
43 {5, 2, 18, 10, 8, 0, 16}, // base cell 5
44 {6, 14, 11, 17, 1, 9, 2}, // base cell 6
45 {7, 21, 9, 19, 3, 13, 1}, // base cell 7
46 {8, 5, 22, 16, 4, 0, 15}, // base cell 8
47 {9, 19, 14, 20, 1, 7, 6}, // base cell 9
48 {10, 11, 24, 23, 5, 2, 18}, // base cell 10
49 {11, 17, 23, 25, 2, 6, 10}, // base cell 11
50 {12, 28, 13, 26, 4, 15, 3}, // base cell 12
51 {13, 26, 21, 29, 3, 12, 7}, // base cell 13
52 {14, INVALID_BASE_CELL, 17, 27, 9, 20, 6}, // base cell 14 (pentagon)
53 {15, 22, 28, 31, 4, 8, 12}, // base cell 15
54 {16, 18, 33, 30, 8, 5, 22}, // base cell 16
55 {17, 11, 14, 6, 35, 25, 27}, // base cell 17
56 {18, 24, 30, 32, 5, 10, 16}, // base cell 18
57 {19, 34, 20, 36, 7, 21, 9}, // base cell 19
58 {20, 14, 19, 9, 40, 27, 36}, // base cell 20
59 {21, 38, 19, 34, 13, 29, 7}, // base cell 21
60 {22, 16, 41, 33, 15, 8, 31}, // base cell 22
61 {23, 24, 11, 10, 39, 37, 25}, // base cell 23
62 {24, INVALID_BASE_CELL, 32, 37, 10, 23, 18}, // base cell 24 (pentagon)
63 {25, 23, 17, 11, 45, 39, 35}, // base cell 25
64 {26, 42, 29, 43, 12, 28, 13}, // base cell 26
65 {27, 40, 35, 46, 14, 20, 17}, // base cell 27
66 {28, 31, 42, 44, 12, 15, 26}, // base cell 28
67 {29, 43, 38, 47, 13, 26, 21}, // base cell 29
68 {30, 32, 48, 50, 16, 18, 33}, // base cell 30
69 {31, 41, 44, 53, 15, 22, 28}, // base cell 31
70 {32, 30, 24, 18, 52, 50, 37}, // base cell 32
71 {33, 30, 49, 48, 22, 16, 41}, // base cell 33
72 {34, 19, 38, 21, 54, 36, 51}, // base cell 34
73 {35, 46, 45, 56, 17, 27, 25}, // base cell 35
74 {36, 20, 34, 19, 55, 40, 54}, // base cell 36
75 {37, 39, 52, 57, 24, 23, 32}, // base cell 37
76 {38, INVALID_BASE_CELL, 34, 51, 29, 47, 21}, // base cell 38 (pentagon)
77 {39, 37, 25, 23, 59, 57, 45}, // base cell 39
78 {40, 27, 36, 20, 60, 46, 55}, // base cell 40
79 {41, 49, 53, 61, 22, 33, 31}, // base cell 41
80 {42, 58, 43, 62, 28, 44, 26}, // base cell 42
81 {43, 62, 47, 64, 26, 42, 29}, // base cell 43
82 {44, 53, 58, 65, 28, 31, 42}, // base cell 44
83 {45, 39, 35, 25, 63, 59, 56}, // base cell 45
84 {46, 60, 56, 68, 27, 40, 35}, // base cell 46
85 {47, 38, 43, 29, 69, 51, 64}, // base cell 47
86 {48, 49, 30, 33, 67, 66, 50}, // base cell 48
87 {49, INVALID_BASE_CELL, 61, 66, 33, 48, 41}, // base cell 49 (pentagon)
88 {50, 48, 32, 30, 70, 67, 52}, // base cell 50
89 {51, 69, 54, 71, 38, 47, 34}, // base cell 51
90 {52, 57, 70, 74, 32, 37, 50}, // base cell 52
91 {53, 61, 65, 75, 31, 41, 44}, // base cell 53
92 {54, 71, 55, 73, 34, 51, 36}, // base cell 54
93 {55, 40, 54, 36, 72, 60, 73}, // base cell 55
94 {56, 68, 63, 77, 35, 46, 45}, // base cell 56
95 {57, 59, 74, 78, 37, 39, 52}, // base cell 57
96 {58, INVALID_BASE_CELL, 62, 76, 44, 65, 42}, // base cell 58 (pentagon)
97 {59, 63, 78, 79, 39, 45, 57}, // base cell 59
98 {60, 72, 68, 80, 40, 55, 46}, // base cell 60
99 {61, 53, 49, 41, 81, 75, 66}, // base cell 61
100 {62, 43, 58, 42, 82, 64, 76}, // base cell 62
101 {63, INVALID_BASE_CELL, 56, 45, 79, 59, 77}, // base cell 63 (pentagon)
102 {64, 47, 62, 43, 84, 69, 82}, // base cell 64
103 {65, 58, 53, 44, 86, 76, 75}, // base cell 65
104 {66, 67, 81, 85, 49, 48, 61}, // base cell 66
105 {67, 66, 50, 48, 87, 85, 70}, // base cell 67
106 {68, 56, 60, 46, 90, 77, 80}, // base cell 68
107 {69, 51, 64, 47, 89, 71, 84}, // base cell 69
108 {70, 67, 52, 50, 83, 87, 74}, // base cell 70
109 {71, 89, 73, 91, 51, 69, 54}, // base cell 71
110 {72, INVALID_BASE_CELL, 73, 55, 80, 60, 88}, // base cell 72 (pentagon)
111 {73, 91, 72, 88, 54, 71, 55}, // base cell 73
112 {74, 78, 83, 92, 52, 57, 70}, // base cell 74
113 {75, 65, 61, 53, 94, 86, 81}, // base cell 75
114 {76, 86, 82, 96, 58, 65, 62}, // base cell 76
115 {77, 63, 68, 56, 93, 79, 90}, // base cell 77
116 {78, 74, 59, 57, 95, 92, 79}, // base cell 78
117 {79, 78, 63, 59, 93, 95, 77}, // base cell 79
118 {80, 68, 72, 60, 99, 90, 88}, // base cell 80
119 {81, 85, 94, 101, 61, 66, 75}, // base cell 81
120 {82, 96, 84, 98, 62, 76, 64}, // base cell 82
121 {83, INVALID_BASE_CELL, 74, 70, 100, 87, 92}, // base cell 83 (pentagon)
122 {84, 69, 82, 64, 97, 89, 98}, // base cell 84
123 {85, 87, 101, 102, 66, 67, 81}, // base cell 85
124 {86, 76, 75, 65, 104, 96, 94}, // base cell 86
125 {87, 83, 102, 100, 67, 70, 85}, // base cell 87
126 {88, 72, 91, 73, 99, 80, 105}, // base cell 88
127 {89, 97, 91, 103, 69, 84, 71}, // base cell 89
128 {90, 77, 80, 68, 106, 93, 99}, // base cell 90
129 {91, 73, 89, 71, 105, 88, 103}, // base cell 91
130 {92, 83, 78, 74, 108, 100, 95}, // base cell 92
131 {93, 79, 90, 77, 109, 95, 106}, // base cell 93
132 {94, 86, 81, 75, 107, 104, 101}, // base cell 94
133 {95, 92, 79, 78, 109, 108, 93}, // base cell 95
134 {96, 104, 98, 110, 76, 86, 82}, // base cell 96
135 {97, INVALID_BASE_CELL, 98, 84, 103, 89, 111}, // base cell 97 (pentagon)
136 {98, 110, 97, 111, 82, 96, 84}, // base cell 98
137 {99, 80, 105, 88, 106, 90, 113}, // base cell 99
138 {100, 102, 83, 87, 108, 114, 92}, // base cell 100
139 {101, 102, 107, 112, 81, 85, 94}, // base cell 101
140 {102, 101, 87, 85, 114, 112, 100}, // base cell 102
141 {103, 91, 97, 89, 116, 105, 111}, // base cell 103
142 {104, 107, 110, 115, 86, 94, 96}, // base cell 104
143 {105, 88, 103, 91, 113, 99, 116}, // base cell 105
144 {106, 93, 99, 90, 117, 109, 113}, // base cell 106
145 {107, INVALID_BASE_CELL, 101, 94, 115, 104,
146 112}, // base cell 107 (pentagon)
147 {108, 100, 95, 92, 118, 114, 109}, // base cell 108
148 {109, 108, 93, 95, 117, 118, 106}, // base cell 109
149 {110, 98, 104, 96, 119, 111, 115}, // base cell 110
150 {111, 97, 110, 98, 116, 103, 119}, // base cell 111
151 {112, 107, 102, 101, 120, 115, 114}, // base cell 112
152 {113, 99, 116, 105, 117, 106, 121}, // base cell 113
153 {114, 112, 100, 102, 118, 120, 108}, // base cell 114
154 {115, 110, 107, 104, 120, 119, 112}, // base cell 115
155 {116, 103, 119, 111, 113, 105, 121}, // base cell 116
156 {117, INVALID_BASE_CELL, 109, 118, 113, 121,
157 106}, // base cell 117 (pentagon)
158 {118, 120, 108, 114, 117, 121, 109}, // base cell 118
159 {119, 111, 115, 110, 121, 116, 120}, // base cell 119
160 {120, 115, 114, 112, 121, 119, 118}, // base cell 120
161 {121, 116, 120, 119, 117, 113, 118}, // base cell 121
162};
163
164/** @brief Neighboring base cell rotations in each IJK direction.
165 *
166 * For each base cell, for each direction, the number of 60 degree
167 * CCW rotations to the coordinate system of the neighbor is given.
168 * -1 indicates there is no neighbor in that direction.
169 */
170const int baseCellNeighbor60CCWRots[NUM_BASE_CELLS][7] = {
171 {0, 5, 0, 0, 1, 5, 1}, // base cell 0
172 {0, 0, 1, 0, 1, 0, 1}, // base cell 1
173 {0, 0, 0, 0, 0, 5, 0}, // base cell 2
174 {0, 5, 0, 0, 2, 5, 1}, // base cell 3
175 {0, -1, 1, 0, 3, 4, 2}, // base cell 4 (pentagon)
176 {0, 0, 1, 0, 1, 0, 1}, // base cell 5
177 {0, 0, 0, 3, 5, 5, 0}, // base cell 6
178 {0, 0, 0, 0, 0, 5, 0}, // base cell 7
179 {0, 5, 0, 0, 0, 5, 1}, // base cell 8
180 {0, 0, 1, 3, 0, 0, 1}, // base cell 9
181 {0, 0, 1, 3, 0, 0, 1}, // base cell 10
182 {0, 3, 3, 3, 0, 0, 0}, // base cell 11
183 {0, 5, 0, 0, 3, 5, 1}, // base cell 12
184 {0, 0, 1, 0, 1, 0, 1}, // base cell 13
185 {0, -1, 3, 0, 5, 2, 0}, // base cell 14 (pentagon)
186 {0, 5, 0, 0, 4, 5, 1}, // base cell 15
187 {0, 0, 0, 0, 0, 5, 0}, // base cell 16
188 {0, 3, 3, 3, 3, 0, 3}, // base cell 17
189 {0, 0, 0, 3, 5, 5, 0}, // base cell 18
190 {0, 3, 3, 3, 0, 0, 0}, // base cell 19
191 {0, 3, 3, 3, 0, 3, 0}, // base cell 20
192 {0, 0, 0, 3, 5, 5, 0}, // base cell 21
193 {0, 0, 1, 0, 1, 0, 1}, // base cell 22
194 {0, 3, 3, 3, 0, 3, 0}, // base cell 23
195 {0, -1, 3, 0, 5, 2, 0}, // base cell 24 (pentagon)
196 {0, 0, 0, 3, 0, 0, 3}, // base cell 25
197 {0, 0, 0, 0, 0, 5, 0}, // base cell 26
198 {0, 3, 0, 0, 0, 3, 3}, // base cell 27
199 {0, 0, 1, 0, 1, 0, 1}, // base cell 28
200 {0, 0, 1, 3, 0, 0, 1}, // base cell 29
201 {0, 3, 3, 3, 0, 0, 0}, // base cell 30
202 {0, 0, 0, 0, 0, 5, 0}, // base cell 31
203 {0, 3, 3, 3, 3, 0, 3}, // base cell 32
204 {0, 0, 1, 3, 0, 0, 1}, // base cell 33
205 {0, 3, 3, 3, 3, 0, 3}, // base cell 34
206 {0, 0, 3, 0, 3, 0, 3}, // base cell 35
207 {0, 0, 0, 3, 0, 0, 3}, // base cell 36
208 {0, 3, 0, 0, 0, 3, 3}, // base cell 37
209 {0, -1, 3, 0, 5, 2, 0}, // base cell 38 (pentagon)
210 {0, 3, 0, 0, 3, 3, 0}, // base cell 39
211 {0, 3, 0, 0, 3, 3, 0}, // base cell 40
212 {0, 0, 0, 3, 5, 5, 0}, // base cell 41
213 {0, 0, 0, 3, 5, 5, 0}, // base cell 42
214 {0, 3, 3, 3, 0, 0, 0}, // base cell 43
215 {0, 0, 1, 3, 0, 0, 1}, // base cell 44
216 {0, 0, 3, 0, 0, 3, 3}, // base cell 45
217 {0, 0, 0, 3, 0, 3, 0}, // base cell 46
218 {0, 3, 3, 3, 0, 3, 0}, // base cell 47
219 {0, 3, 3, 3, 0, 3, 0}, // base cell 48
220 {0, -1, 3, 0, 5, 2, 0}, // base cell 49 (pentagon)
221 {0, 0, 0, 3, 0, 0, 3}, // base cell 50
222 {0, 3, 0, 0, 0, 3, 3}, // base cell 51
223 {0, 0, 3, 0, 3, 0, 3}, // base cell 52
224 {0, 3, 3, 3, 0, 0, 0}, // base cell 53
225 {0, 0, 3, 0, 3, 0, 3}, // base cell 54
226 {0, 0, 3, 0, 0, 3, 3}, // base cell 55
227 {0, 3, 3, 3, 0, 0, 3}, // base cell 56
228 {0, 0, 0, 3, 0, 3, 0}, // base cell 57
229 {0, -1, 3, 0, 5, 2, 0}, // base cell 58 (pentagon)
230 {0, 3, 3, 3, 3, 3, 0}, // base cell 59
231 {0, 3, 3, 3, 3, 3, 0}, // base cell 60
232 {0, 3, 3, 3, 3, 0, 3}, // base cell 61
233 {0, 3, 3, 3, 3, 0, 3}, // base cell 62
234 {0, -1, 3, 0, 5, 2, 0}, // base cell 63 (pentagon)
235 {0, 0, 0, 3, 0, 0, 3}, // base cell 64
236 {0, 3, 3, 3, 0, 3, 0}, // base cell 65
237 {0, 3, 0, 0, 0, 3, 3}, // base cell 66
238 {0, 3, 0, 0, 3, 3, 0}, // base cell 67
239 {0, 3, 3, 3, 0, 0, 0}, // base cell 68
240 {0, 3, 0, 0, 3, 3, 0}, // base cell 69
241 {0, 0, 3, 0, 0, 3, 3}, // base cell 70
242 {0, 0, 0, 3, 0, 3, 0}, // base cell 71
243 {0, -1, 3, 0, 5, 2, 0}, // base cell 72 (pentagon)
244 {0, 3, 3, 3, 0, 0, 3}, // base cell 73
245 {0, 3, 3, 3, 0, 0, 3}, // base cell 74
246 {0, 0, 0, 3, 0, 0, 3}, // base cell 75
247 {0, 3, 0, 0, 0, 3, 3}, // base cell 76
248 {0, 0, 0, 3, 0, 5, 0}, // base cell 77
249 {0, 3, 3, 3, 0, 0, 0}, // base cell 78
250 {0, 0, 1, 3, 1, 0, 1}, // base cell 79
251 {0, 0, 1, 3, 1, 0, 1}, // base cell 80
252 {0, 0, 3, 0, 3, 0, 3}, // base cell 81
253 {0, 0, 3, 0, 3, 0, 3}, // base cell 82
254 {0, -1, 3, 0, 5, 2, 0}, // base cell 83 (pentagon)
255 {0, 0, 3, 0, 0, 3, 3}, // base cell 84
256 {0, 0, 0, 3, 0, 3, 0}, // base cell 85
257 {0, 3, 0, 0, 3, 3, 0}, // base cell 86
258 {0, 3, 3, 3, 3, 3, 0}, // base cell 87
259 {0, 0, 0, 3, 0, 5, 0}, // base cell 88
260 {0, 3, 3, 3, 3, 3, 0}, // base cell 89
261 {0, 0, 0, 0, 0, 0, 1}, // base cell 90
262 {0, 3, 3, 3, 0, 0, 0}, // base cell 91
263 {0, 0, 0, 3, 0, 5, 0}, // base cell 92
264 {0, 5, 0, 0, 5, 5, 0}, // base cell 93
265 {0, 0, 3, 0, 0, 3, 3}, // base cell 94
266 {0, 0, 0, 0, 0, 0, 1}, // base cell 95
267 {0, 0, 0, 3, 0, 3, 0}, // base cell 96
268 {0, -1, 3, 0, 5, 2, 0}, // base cell 97 (pentagon)
269 {0, 3, 3, 3, 0, 0, 3}, // base cell 98
270 {0, 5, 0, 0, 5, 5, 0}, // base cell 99
271 {0, 0, 1, 3, 1, 0, 1}, // base cell 100
272 {0, 3, 3, 3, 0, 0, 3}, // base cell 101
273 {0, 3, 3, 3, 0, 0, 0}, // base cell 102
274 {0, 0, 1, 3, 1, 0, 1}, // base cell 103
275 {0, 3, 3, 3, 3, 3, 0}, // base cell 104
276 {0, 0, 0, 0, 0, 0, 1}, // base cell 105
277 {0, 0, 1, 0, 3, 5, 1}, // base cell 106
278 {0, -1, 3, 0, 5, 2, 0}, // base cell 107 (pentagon)
279 {0, 5, 0, 0, 5, 5, 0}, // base cell 108
280 {0, 0, 1, 0, 4, 5, 1}, // base cell 109
281 {0, 3, 3, 3, 0, 0, 0}, // base cell 110
282 {0, 0, 0, 3, 0, 5, 0}, // base cell 111
283 {0, 0, 0, 3, 0, 5, 0}, // base cell 112
284 {0, 0, 1, 0, 2, 5, 1}, // base cell 113
285 {0, 0, 0, 0, 0, 0, 1}, // base cell 114
286 {0, 0, 1, 3, 1, 0, 1}, // base cell 115
287 {0, 5, 0, 0, 5, 5, 0}, // base cell 116
288 {0, -1, 1, 0, 3, 4, 2}, // base cell 117 (pentagon)
289 {0, 0, 1, 0, 0, 5, 1}, // base cell 118
290 {0, 0, 0, 0, 0, 0, 1}, // base cell 119
291 {0, 5, 0, 0, 5, 5, 0}, // base cell 120
292 {0, 0, 1, 0, 1, 5, 1}, // base cell 121
293};
294
295/** @brief Resolution 0 base cell lookup table for each face.
296 *
297 * Given the face number and a resolution 0 ijk+ coordinate in that face's
298 * face-centered ijk coordinate system, gives the base cell located at that
299 * coordinate and the number of 60 ccw rotations to rotate into that base
300 * cell's orientation.
301 *
302 * Valid lookup coordinates are from (0, 0, 0) to (2, 2, 2).
303 *
304 * This table can be accessed using the functions `_faceIjkToBaseCell` and
305 * `_faceIjkToBaseCellCCWrot60`
306 */
307static const BaseCellOrient faceIjkBaseCells[NUM_ICOSA_FACES][3][3][3] = {
308 {// face 0
309 {
310 // i 0
311 {{16, 0}, {18, 0}, {24, 0}}, // j 0
312 {{33, 0}, {30, 0}, {32, 3}}, // j 1
313 {{49, 1}, {48, 3}, {50, 3}} // j 2
314 },
315 {
316 // i 1
317 {{8, 0}, {5, 5}, {10, 5}}, // j 0
318 {{22, 0}, {16, 0}, {18, 0}}, // j 1
319 {{41, 1}, {33, 0}, {30, 0}} // j 2
320 },
321 {
322 // i 2
323 {{4, 0}, {0, 5}, {2, 5}}, // j 0
324 {{15, 1}, {8, 0}, {5, 5}}, // j 1
325 {{31, 1}, {22, 0}, {16, 0}} // j 2
326 }},
327 {// face 1
328 {
329 // i 0
330 {{2, 0}, {6, 0}, {14, 0}}, // j 0
331 {{10, 0}, {11, 0}, {17, 3}}, // j 1
332 {{24, 1}, {23, 3}, {25, 3}} // j 2
333 },
334 {
335 // i 1
336 {{0, 0}, {1, 5}, {9, 5}}, // j 0
337 {{5, 0}, {2, 0}, {6, 0}}, // j 1
338 {{18, 1}, {10, 0}, {11, 0}} // j 2
339 },
340 {
341 // i 2
342 {{4, 1}, {3, 5}, {7, 5}}, // j 0
343 {{8, 1}, {0, 0}, {1, 5}}, // j 1
344 {{16, 1}, {5, 0}, {2, 0}} // j 2
345 }},
346 {// face 2
347 {
348 // i 0
349 {{7, 0}, {21, 0}, {38, 0}}, // j 0
350 {{9, 0}, {19, 0}, {34, 3}}, // j 1
351 {{14, 1}, {20, 3}, {36, 3}} // j 2
352 },
353 {
354 // i 1
355 {{3, 0}, {13, 5}, {29, 5}}, // j 0
356 {{1, 0}, {7, 0}, {21, 0}}, // j 1
357 {{6, 1}, {9, 0}, {19, 0}} // j 2
358 },
359 {
360 // i 2
361 {{4, 2}, {12, 5}, {26, 5}}, // j 0
362 {{0, 1}, {3, 0}, {13, 5}}, // j 1
363 {{2, 1}, {1, 0}, {7, 0}} // j 2
364 }},
365 {// face 3
366 {
367 // i 0
368 {{26, 0}, {42, 0}, {58, 0}}, // j 0
369 {{29, 0}, {43, 0}, {62, 3}}, // j 1
370 {{38, 1}, {47, 3}, {64, 3}} // j 2
371 },
372 {
373 // i 1
374 {{12, 0}, {28, 5}, {44, 5}}, // j 0
375 {{13, 0}, {26, 0}, {42, 0}}, // j 1
376 {{21, 1}, {29, 0}, {43, 0}} // j 2
377 },
378 {
379 // i 2
380 {{4, 3}, {15, 5}, {31, 5}}, // j 0
381 {{3, 1}, {12, 0}, {28, 5}}, // j 1
382 {{7, 1}, {13, 0}, {26, 0}} // j 2
383 }},
384 {// face 4
385 {
386 // i 0
387 {{31, 0}, {41, 0}, {49, 0}}, // j 0
388 {{44, 0}, {53, 0}, {61, 3}}, // j 1
389 {{58, 1}, {65, 3}, {75, 3}} // j 2
390 },
391 {
392 // i 1
393 {{15, 0}, {22, 5}, {33, 5}}, // j 0
394 {{28, 0}, {31, 0}, {41, 0}}, // j 1
395 {{42, 1}, {44, 0}, {53, 0}} // j 2
396 },
397 {
398 // i 2
399 {{4, 4}, {8, 5}, {16, 5}}, // j 0
400 {{12, 1}, {15, 0}, {22, 5}}, // j 1
401 {{26, 1}, {28, 0}, {31, 0}} // j 2
402 }},
403 {// face 5
404 {
405 // i 0
406 {{50, 0}, {48, 0}, {49, 3}}, // j 0
407 {{32, 0}, {30, 3}, {33, 3}}, // j 1
408 {{24, 3}, {18, 3}, {16, 3}} // j 2
409 },
410 {
411 // i 1
412 {{70, 0}, {67, 0}, {66, 3}}, // j 0
413 {{52, 3}, {50, 0}, {48, 0}}, // j 1
414 {{37, 3}, {32, 0}, {30, 3}} // j 2
415 },
416 {
417 // i 2
418 {{83, 0}, {87, 3}, {85, 3}}, // j 0
419 {{74, 3}, {70, 0}, {67, 0}}, // j 1
420 {{57, 1}, {52, 3}, {50, 0}} // j 2
421 }},
422 {// face 6
423 {
424 // i 0
425 {{25, 0}, {23, 0}, {24, 3}}, // j 0
426 {{17, 0}, {11, 3}, {10, 3}}, // j 1
427 {{14, 3}, {6, 3}, {2, 3}} // j 2
428 },
429 {
430 // i 1
431 {{45, 0}, {39, 0}, {37, 3}}, // j 0
432 {{35, 3}, {25, 0}, {23, 0}}, // j 1
433 {{27, 3}, {17, 0}, {11, 3}} // j 2
434 },
435 {
436 // i 2
437 {{63, 0}, {59, 3}, {57, 3}}, // j 0
438 {{56, 3}, {45, 0}, {39, 0}}, // j 1
439 {{46, 3}, {35, 3}, {25, 0}} // j 2
440 }},
441 {// face 7
442 {
443 // i 0
444 {{36, 0}, {20, 0}, {14, 3}}, // j 0
445 {{34, 0}, {19, 3}, {9, 3}}, // j 1
446 {{38, 3}, {21, 3}, {7, 3}} // j 2
447 },
448 {
449 // i 1
450 {{55, 0}, {40, 0}, {27, 3}}, // j 0
451 {{54, 3}, {36, 0}, {20, 0}}, // j 1
452 {{51, 3}, {34, 0}, {19, 3}} // j 2
453 },
454 {
455 // i 2
456 {{72, 0}, {60, 3}, {46, 3}}, // j 0
457 {{73, 3}, {55, 0}, {40, 0}}, // j 1
458 {{71, 3}, {54, 3}, {36, 0}} // j 2
459 }},
460 {// face 8
461 {
462 // i 0
463 {{64, 0}, {47, 0}, {38, 3}}, // j 0
464 {{62, 0}, {43, 3}, {29, 3}}, // j 1
465 {{58, 3}, {42, 3}, {26, 3}} // j 2
466 },
467 {
468 // i 1
469 {{84, 0}, {69, 0}, {51, 3}}, // j 0
470 {{82, 3}, {64, 0}, {47, 0}}, // j 1
471 {{76, 3}, {62, 0}, {43, 3}} // j 2
472 },
473 {
474 // i 2
475 {{97, 0}, {89, 3}, {71, 3}}, // j 0
476 {{98, 3}, {84, 0}, {69, 0}}, // j 1
477 {{96, 3}, {82, 3}, {64, 0}} // j 2
478 }},
479 {// face 9
480 {
481 // i 0
482 {{75, 0}, {65, 0}, {58, 3}}, // j 0
483 {{61, 0}, {53, 3}, {44, 3}}, // j 1
484 {{49, 3}, {41, 3}, {31, 3}} // j 2
485 },
486 {
487 // i 1
488 {{94, 0}, {86, 0}, {76, 3}}, // j 0
489 {{81, 3}, {75, 0}, {65, 0}}, // j 1
490 {{66, 3}, {61, 0}, {53, 3}} // j 2
491 },
492 {
493 // i 2
494 {{107, 0}, {104, 3}, {96, 3}}, // j 0
495 {{101, 3}, {94, 0}, {86, 0}}, // j 1
496 {{85, 3}, {81, 3}, {75, 0}} // j 2
497 }},
498 {// face 10
499 {
500 // i 0
501 {{57, 0}, {59, 0}, {63, 3}}, // j 0
502 {{74, 0}, {78, 3}, {79, 3}}, // j 1
503 {{83, 3}, {92, 3}, {95, 3}} // j 2
504 },
505 {
506 // i 1
507 {{37, 0}, {39, 3}, {45, 3}}, // j 0
508 {{52, 0}, {57, 0}, {59, 0}}, // j 1
509 {{70, 3}, {74, 0}, {78, 3}} // j 2
510 },
511 {
512 // i 2
513 {{24, 0}, {23, 3}, {25, 3}}, // j 0
514 {{32, 3}, {37, 0}, {39, 3}}, // j 1
515 {{50, 3}, {52, 0}, {57, 0}} // j 2
516 }},
517 {// face 11
518 {
519 // i 0
520 {{46, 0}, {60, 0}, {72, 3}}, // j 0
521 {{56, 0}, {68, 3}, {80, 3}}, // j 1
522 {{63, 3}, {77, 3}, {90, 3}} // j 2
523 },
524 {
525 // i 1
526 {{27, 0}, {40, 3}, {55, 3}}, // j 0
527 {{35, 0}, {46, 0}, {60, 0}}, // j 1
528 {{45, 3}, {56, 0}, {68, 3}} // j 2
529 },
530 {
531 // i 2
532 {{14, 0}, {20, 3}, {36, 3}}, // j 0
533 {{17, 3}, {27, 0}, {40, 3}}, // j 1
534 {{25, 3}, {35, 0}, {46, 0}} // j 2
535 }},
536 {// face 12
537 {
538 // i 0
539 {{71, 0}, {89, 0}, {97, 3}}, // j 0
540 {{73, 0}, {91, 3}, {103, 3}}, // j 1
541 {{72, 3}, {88, 3}, {105, 3}} // j 2
542 },
543 {
544 // i 1
545 {{51, 0}, {69, 3}, {84, 3}}, // j 0
546 {{54, 0}, {71, 0}, {89, 0}}, // j 1
547 {{55, 3}, {73, 0}, {91, 3}} // j 2
548 },
549 {
550 // i 2
551 {{38, 0}, {47, 3}, {64, 3}}, // j 0
552 {{34, 3}, {51, 0}, {69, 3}}, // j 1
553 {{36, 3}, {54, 0}, {71, 0}} // j 2
554 }},
555 {// face 13
556 {
557 // i 0
558 {{96, 0}, {104, 0}, {107, 3}}, // j 0
559 {{98, 0}, {110, 3}, {115, 3}}, // j 1
560 {{97, 3}, {111, 3}, {119, 3}} // j 2
561 },
562 {
563 // i 1
564 {{76, 0}, {86, 3}, {94, 3}}, // j 0
565 {{82, 0}, {96, 0}, {104, 0}}, // j 1
566 {{84, 3}, {98, 0}, {110, 3}} // j 2
567 },
568 {
569 // i 2
570 {{58, 0}, {65, 3}, {75, 3}}, // j 0
571 {{62, 3}, {76, 0}, {86, 3}}, // j 1
572 {{64, 3}, {82, 0}, {96, 0}} // j 2
573 }},
574 {// face 14
575 {
576 // i 0
577 {{85, 0}, {87, 0}, {83, 3}}, // j 0
578 {{101, 0}, {102, 3}, {100, 3}}, // j 1
579 {{107, 3}, {112, 3}, {114, 3}} // j 2
580 },
581 {
582 // i 1
583 {{66, 0}, {67, 3}, {70, 3}}, // j 0
584 {{81, 0}, {85, 0}, {87, 0}}, // j 1
585 {{94, 3}, {101, 0}, {102, 3}} // j 2
586 },
587 {
588 // i 2
589 {{49, 0}, {48, 3}, {50, 3}}, // j 0
590 {{61, 3}, {66, 0}, {67, 3}}, // j 1
591 {{75, 3}, {81, 0}, {85, 0}} // j 2
592 }},
593 {// face 15
594 {
595 // i 0
596 {{95, 0}, {92, 0}, {83, 0}}, // j 0
597 {{79, 0}, {78, 0}, {74, 3}}, // j 1
598 {{63, 1}, {59, 3}, {57, 3}} // j 2
599 },
600 {
601 // i 1
602 {{109, 0}, {108, 0}, {100, 5}}, // j 0
603 {{93, 1}, {95, 0}, {92, 0}}, // j 1
604 {{77, 1}, {79, 0}, {78, 0}} // j 2
605 },
606 {
607 // i 2
608 {{117, 4}, {118, 5}, {114, 5}}, // j 0
609 {{106, 1}, {109, 0}, {108, 0}}, // j 1
610 {{90, 1}, {93, 1}, {95, 0}} // j 2
611 }},
612 {// face 16
613 {
614 // i 0
615 {{90, 0}, {77, 0}, {63, 0}}, // j 0
616 {{80, 0}, {68, 0}, {56, 3}}, // j 1
617 {{72, 1}, {60, 3}, {46, 3}} // j 2
618 },
619 {
620 // i 1
621 {{106, 0}, {93, 0}, {79, 5}}, // j 0
622 {{99, 1}, {90, 0}, {77, 0}}, // j 1
623 {{88, 1}, {80, 0}, {68, 0}} // j 2
624 },
625 {
626 // i 2
627 {{117, 3}, {109, 5}, {95, 5}}, // j 0
628 {{113, 1}, {106, 0}, {93, 0}}, // j 1
629 {{105, 1}, {99, 1}, {90, 0}} // j 2
630 }},
631 {// face 17
632 {
633 // i 0
634 {{105, 0}, {88, 0}, {72, 0}}, // j 0
635 {{103, 0}, {91, 0}, {73, 3}}, // j 1
636 {{97, 1}, {89, 3}, {71, 3}} // j 2
637 },
638 {
639 // i 1
640 {{113, 0}, {99, 0}, {80, 5}}, // j 0
641 {{116, 1}, {105, 0}, {88, 0}}, // j 1
642 {{111, 1}, {103, 0}, {91, 0}} // j 2
643 },
644 {
645 // i 2
646 {{117, 2}, {106, 5}, {90, 5}}, // j 0
647 {{121, 1}, {113, 0}, {99, 0}}, // j 1
648 {{119, 1}, {116, 1}, {105, 0}} // j 2
649 }},
650 {// face 18
651 {
652 // i 0
653 {{119, 0}, {111, 0}, {97, 0}}, // j 0
654 {{115, 0}, {110, 0}, {98, 3}}, // j 1
655 {{107, 1}, {104, 3}, {96, 3}} // j 2
656 },
657 {
658 // i 1
659 {{121, 0}, {116, 0}, {103, 5}}, // j 0
660 {{120, 1}, {119, 0}, {111, 0}}, // j 1
661 {{112, 1}, {115, 0}, {110, 0}} // j 2
662 },
663 {
664 // i 2
665 {{117, 1}, {113, 5}, {105, 5}}, // j 0
666 {{118, 1}, {121, 0}, {116, 0}}, // j 1
667 {{114, 1}, {120, 1}, {119, 0}} // j 2
668 }},
669 {// face 19
670 {
671 // i 0
672 {{114, 0}, {112, 0}, {107, 0}}, // j 0
673 {{100, 0}, {102, 0}, {101, 3}}, // j 1
674 {{83, 1}, {87, 3}, {85, 3}} // j 2
675 },
676 {
677 // i 1
678 {{118, 0}, {120, 0}, {115, 5}}, // j 0
679 {{108, 1}, {114, 0}, {112, 0}}, // j 1
680 {{92, 1}, {100, 0}, {102, 0}} // j 2
681 },
682 {
683 // i 2
684 {{117, 0}, {121, 5}, {119, 5}}, // j 0
685 {{109, 1}, {118, 0}, {120, 0}}, // j 1
686 {{95, 1}, {108, 1}, {114, 0}} // j 2
687 }}};
688
689/** @brief Resolution 0 base cell data table.
690 *
691 * For each base cell, gives the "home" face and ijk+ coordinates on that face,
692 * whether or not the base cell is a pentagon. Additionally, if the base cell
693 * is a pentagon, the two cw offset rotation adjacent faces are given (-1
694 * indicates that no cw offset rotation faces exist for this base cell).
695 */
696const BaseCellData baseCellData[NUM_BASE_CELLS] = {
697
698 {{1, {1, 0, 0}}, 0, {0, 0}}, // base cell 0
699 {{2, {1, 1, 0}}, 0, {0, 0}}, // base cell 1
700 {{1, {0, 0, 0}}, 0, {0, 0}}, // base cell 2
701 {{2, {1, 0, 0}}, 0, {0, 0}}, // base cell 3
702 {{0, {2, 0, 0}}, 1, {-1, -1}}, // base cell 4
703 {{1, {1, 1, 0}}, 0, {0, 0}}, // base cell 5
704 {{1, {0, 0, 1}}, 0, {0, 0}}, // base cell 6
705 {{2, {0, 0, 0}}, 0, {0, 0}}, // base cell 7
706 {{0, {1, 0, 0}}, 0, {0, 0}}, // base cell 8
707 {{2, {0, 1, 0}}, 0, {0, 0}}, // base cell 9
708 {{1, {0, 1, 0}}, 0, {0, 0}}, // base cell 10
709 {{1, {0, 1, 1}}, 0, {0, 0}}, // base cell 11
710 {{3, {1, 0, 0}}, 0, {0, 0}}, // base cell 12
711 {{3, {1, 1, 0}}, 0, {0, 0}}, // base cell 13
712 {{11, {2, 0, 0}}, 1, {2, 6}}, // base cell 14
713 {{4, {1, 0, 0}}, 0, {0, 0}}, // base cell 15
714 {{0, {0, 0, 0}}, 0, {0, 0}}, // base cell 16
715 {{6, {0, 1, 0}}, 0, {0, 0}}, // base cell 17
716 {{0, {0, 0, 1}}, 0, {0, 0}}, // base cell 18
717 {{2, {0, 1, 1}}, 0, {0, 0}}, // base cell 19
718 {{7, {0, 0, 1}}, 0, {0, 0}}, // base cell 20
719 {{2, {0, 0, 1}}, 0, {0, 0}}, // base cell 21
720 {{0, {1, 1, 0}}, 0, {0, 0}}, // base cell 22
721 {{6, {0, 0, 1}}, 0, {0, 0}}, // base cell 23
722 {{10, {2, 0, 0}}, 1, {1, 5}}, // base cell 24
723 {{6, {0, 0, 0}}, 0, {0, 0}}, // base cell 25
724 {{3, {0, 0, 0}}, 0, {0, 0}}, // base cell 26
725 {{11, {1, 0, 0}}, 0, {0, 0}}, // base cell 27
726 {{4, {1, 1, 0}}, 0, {0, 0}}, // base cell 28
727 {{3, {0, 1, 0}}, 0, {0, 0}}, // base cell 29
728 {{0, {0, 1, 1}}, 0, {0, 0}}, // base cell 30
729 {{4, {0, 0, 0}}, 0, {0, 0}}, // base cell 31
730 {{5, {0, 1, 0}}, 0, {0, 0}}, // base cell 32
731 {{0, {0, 1, 0}}, 0, {0, 0}}, // base cell 33
732 {{7, {0, 1, 0}}, 0, {0, 0}}, // base cell 34
733 {{11, {1, 1, 0}}, 0, {0, 0}}, // base cell 35
734 {{7, {0, 0, 0}}, 0, {0, 0}}, // base cell 36
735 {{10, {1, 0, 0}}, 0, {0, 0}}, // base cell 37
736 {{12, {2, 0, 0}}, 1, {3, 7}}, // base cell 38
737 {{6, {1, 0, 1}}, 0, {0, 0}}, // base cell 39
738 {{7, {1, 0, 1}}, 0, {0, 0}}, // base cell 40
739 {{4, {0, 0, 1}}, 0, {0, 0}}, // base cell 41
740 {{3, {0, 0, 1}}, 0, {0, 0}}, // base cell 42
741 {{3, {0, 1, 1}}, 0, {0, 0}}, // base cell 43
742 {{4, {0, 1, 0}}, 0, {0, 0}}, // base cell 44
743 {{6, {1, 0, 0}}, 0, {0, 0}}, // base cell 45
744 {{11, {0, 0, 0}}, 0, {0, 0}}, // base cell 46
745 {{8, {0, 0, 1}}, 0, {0, 0}}, // base cell 47
746 {{5, {0, 0, 1}}, 0, {0, 0}}, // base cell 48
747 {{14, {2, 0, 0}}, 1, {0, 9}}, // base cell 49
748 {{5, {0, 0, 0}}, 0, {0, 0}}, // base cell 50
749 {{12, {1, 0, 0}}, 0, {0, 0}}, // base cell 51
750 {{10, {1, 1, 0}}, 0, {0, 0}}, // base cell 52
751 {{4, {0, 1, 1}}, 0, {0, 0}}, // base cell 53
752 {{12, {1, 1, 0}}, 0, {0, 0}}, // base cell 54
753 {{7, {1, 0, 0}}, 0, {0, 0}}, // base cell 55
754 {{11, {0, 1, 0}}, 0, {0, 0}}, // base cell 56
755 {{10, {0, 0, 0}}, 0, {0, 0}}, // base cell 57
756 {{13, {2, 0, 0}}, 1, {4, 8}}, // base cell 58
757 {{10, {0, 0, 1}}, 0, {0, 0}}, // base cell 59
758 {{11, {0, 0, 1}}, 0, {0, 0}}, // base cell 60
759 {{9, {0, 1, 0}}, 0, {0, 0}}, // base cell 61
760 {{8, {0, 1, 0}}, 0, {0, 0}}, // base cell 62
761 {{6, {2, 0, 0}}, 1, {11, 15}}, // base cell 63
762 {{8, {0, 0, 0}}, 0, {0, 0}}, // base cell 64
763 {{9, {0, 0, 1}}, 0, {0, 0}}, // base cell 65
764 {{14, {1, 0, 0}}, 0, {0, 0}}, // base cell 66
765 {{5, {1, 0, 1}}, 0, {0, 0}}, // base cell 67
766 {{16, {0, 1, 1}}, 0, {0, 0}}, // base cell 68
767 {{8, {1, 0, 1}}, 0, {0, 0}}, // base cell 69
768 {{5, {1, 0, 0}}, 0, {0, 0}}, // base cell 70
769 {{12, {0, 0, 0}}, 0, {0, 0}}, // base cell 71
770 {{7, {2, 0, 0}}, 1, {12, 16}}, // base cell 72
771 {{12, {0, 1, 0}}, 0, {0, 0}}, // base cell 73
772 {{10, {0, 1, 0}}, 0, {0, 0}}, // base cell 74
773 {{9, {0, 0, 0}}, 0, {0, 0}}, // base cell 75
774 {{13, {1, 0, 0}}, 0, {0, 0}}, // base cell 76
775 {{16, {0, 0, 1}}, 0, {0, 0}}, // base cell 77
776 {{15, {0, 1, 1}}, 0, {0, 0}}, // base cell 78
777 {{15, {0, 1, 0}}, 0, {0, 0}}, // base cell 79
778 {{16, {0, 1, 0}}, 0, {0, 0}}, // base cell 80
779 {{14, {1, 1, 0}}, 0, {0, 0}}, // base cell 81
780 {{13, {1, 1, 0}}, 0, {0, 0}}, // base cell 82
781 {{5, {2, 0, 0}}, 1, {10, 19}}, // base cell 83
782 {{8, {1, 0, 0}}, 0, {0, 0}}, // base cell 84
783 {{14, {0, 0, 0}}, 0, {0, 0}}, // base cell 85
784 {{9, {1, 0, 1}}, 0, {0, 0}}, // base cell 86
785 {{14, {0, 0, 1}}, 0, {0, 0}}, // base cell 87
786 {{17, {0, 0, 1}}, 0, {0, 0}}, // base cell 88
787 {{12, {0, 0, 1}}, 0, {0, 0}}, // base cell 89
788 {{16, {0, 0, 0}}, 0, {0, 0}}, // base cell 90
789 {{17, {0, 1, 1}}, 0, {0, 0}}, // base cell 91
790 {{15, {0, 0, 1}}, 0, {0, 0}}, // base cell 92
791 {{16, {1, 0, 1}}, 0, {0, 0}}, // base cell 93
792 {{9, {1, 0, 0}}, 0, {0, 0}}, // base cell 94
793 {{15, {0, 0, 0}}, 0, {0, 0}}, // base cell 95
794 {{13, {0, 0, 0}}, 0, {0, 0}}, // base cell 96
795 {{8, {2, 0, 0}}, 1, {13, 17}}, // base cell 97
796 {{13, {0, 1, 0}}, 0, {0, 0}}, // base cell 98
797 {{17, {1, 0, 1}}, 0, {0, 0}}, // base cell 99
798 {{19, {0, 1, 0}}, 0, {0, 0}}, // base cell 100
799 {{14, {0, 1, 0}}, 0, {0, 0}}, // base cell 101
800 {{19, {0, 1, 1}}, 0, {0, 0}}, // base cell 102
801 {{17, {0, 1, 0}}, 0, {0, 0}}, // base cell 103
802 {{13, {0, 0, 1}}, 0, {0, 0}}, // base cell 104
803 {{17, {0, 0, 0}}, 0, {0, 0}}, // base cell 105
804 {{16, {1, 0, 0}}, 0, {0, 0}}, // base cell 106
805 {{9, {2, 0, 0}}, 1, {14, 18}}, // base cell 107
806 {{15, {1, 0, 1}}, 0, {0, 0}}, // base cell 108
807 {{15, {1, 0, 0}}, 0, {0, 0}}, // base cell 109
808 {{18, {0, 1, 1}}, 0, {0, 0}}, // base cell 110
809 {{18, {0, 0, 1}}, 0, {0, 0}}, // base cell 111
810 {{19, {0, 0, 1}}, 0, {0, 0}}, // base cell 112
811 {{17, {1, 0, 0}}, 0, {0, 0}}, // base cell 113
812 {{19, {0, 0, 0}}, 0, {0, 0}}, // base cell 114
813 {{18, {0, 1, 0}}, 0, {0, 0}}, // base cell 115
814 {{18, {1, 0, 1}}, 0, {0, 0}}, // base cell 116
815 {{19, {2, 0, 0}}, 1, {-1, -1}}, // base cell 117
816 {{19, {1, 0, 0}}, 0, {0, 0}}, // base cell 118
817 {{18, {0, 0, 0}}, 0, {0, 0}}, // base cell 119
818 {{19, {1, 0, 1}}, 0, {0, 0}}, // base cell 120
819 {{18, {1, 0, 0}}, 0, {0, 0}} // base cell 121
820};
821
822/** @brief Return whether or not the indicated base cell is a pentagon. */
823int _isBaseCellPentagon(int baseCell) {
824 return baseCellData[baseCell].isPentagon;
825}
826
827/** @brief Return whether the indicated base cell is a pentagon where all
828 * neighbors are oriented towards it. */
829bool _isBaseCellPolarPentagon(int baseCell) {
830 return baseCell == 4 || baseCell == 117;
831}
832
833/** @brief Find base cell given FaceIJK.
834 *
835 * Given the face number and a resolution 0 ijk+ coordinate in that face's
836 * face-centered ijk coordinate system, return the base cell located at that
837 * coordinate.
838 *
839 * Valid ijk+ lookup coordinates are from (0, 0, 0) to (2, 2, 2).
840 */
841int _faceIjkToBaseCell(const FaceIJK* h) {
842 return faceIjkBaseCells[h->face][h->coord.i][h->coord.j][h->coord.k]
843 .baseCell;
844}
845
846/** @brief Find base cell given FaceIJK.
847 *
848 * Given the face number and a resolution 0 ijk+ coordinate in that face's
849 * face-centered ijk coordinate system, return the number of 60' ccw rotations
850 * to rotate into the coordinate system of the base cell at that coordinates.
851 *
852 * Valid ijk+ lookup coordinates are from (0, 0, 0) to (2, 2, 2).
853 */
854int _faceIjkToBaseCellCCWrot60(const FaceIJK* h) {
855 return faceIjkBaseCells[h->face][h->coord.i][h->coord.j][h->coord.k]
856 .ccwRot60;
857}
858
859/** @brief Find the FaceIJK given a base cell.
860 */
861void _baseCellToFaceIjk(int baseCell, FaceIJK* h) {
862 *h = baseCellData[baseCell].homeFijk;
863}
864
865/** @brief Return whether or not the tested face is a cw offset face.
866 */
867bool _baseCellIsCwOffset(int baseCell, int testFace) {
868 return baseCellData[baseCell].cwOffsetPent[0] == testFace ||
869 baseCellData[baseCell].cwOffsetPent[1] == testFace;
870}
871
872/** @brief Return the neighboring base cell in the given direction.
873 */
874int _getBaseCellNeighbor(int baseCell, Direction dir) {
875 return baseCellNeighbors[baseCell][dir];
876}
877
878/** @brief Return the direction from the origin base cell to the neighbor.
879 * Returns INVALID_DIGIT if the base cells are not neighbors.
880 */
881Direction _getBaseCellDirection(int originBaseCell, int neighboringBaseCell) {
882 for (Direction dir = CENTER_DIGIT; dir < NUM_DIGITS; dir++) {
883 int testBaseCell = _getBaseCellNeighbor(originBaseCell, dir);
884 if (testBaseCell == neighboringBaseCell) {
885 return dir;
886 }
887 }
888 return INVALID_DIGIT;
889}
890
891/**
892 * res0IndexCount returns the number of resolution 0 indexes
893 *
894 * @return int count of resolution 0 indexes
895 */
896int H3_EXPORT(res0IndexCount)() { return NUM_BASE_CELLS; }
897
898/**
899 * getRes0Indexes generates all base cells storing them into the provided
900 * memory pointer. Buffer must be of size NUM_BASE_CELLS * sizeof(H3Index).
901 *
902 * @param out H3Index* the memory to store the resulting base cells in
903 */
904void H3_EXPORT(getRes0Indexes)(H3Index* out) {
905 for (int bc = 0; bc < NUM_BASE_CELLS; bc++) {
906 H3Index baseCell = H3_INIT;
907 H3_SET_MODE(baseCell, H3_HEXAGON_MODE);
908 H3_SET_BASE_CELL(baseCell, bc);
909 out[bc] = baseCell;
910 }
911}