Coverage Report

Created: 2023-09-25 06:53

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