h3 3.6.0 → 3.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby_ci.yml +30 -0
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +39 -0
- data/Gemfile.lock +6 -24
- data/LICENSE.md +1 -1
- data/README.md +2 -3
- data/ext/h3/src/.github/workflows/test-linux.yml +118 -0
- data/ext/h3/src/.github/workflows/test-macos.yml +42 -0
- data/ext/h3/src/.github/workflows/test-website.yml +32 -0
- data/ext/h3/src/.github/workflows/test-windows.yml +44 -0
- data/ext/h3/src/.gitignore +5 -0
- data/ext/h3/src/.travis.yml +20 -42
- data/ext/h3/src/CHANGELOG.md +57 -0
- data/ext/h3/src/CMakeLists.txt +135 -33
- data/ext/h3/src/CONTRIBUTING.md +1 -1
- data/ext/h3/src/README.md +61 -11
- data/ext/h3/src/RELEASE.md +3 -1
- data/ext/h3/src/VERSION +1 -1
- data/ext/h3/src/dev-docs/RFCs/rfc-template.md +21 -0
- data/ext/h3/src/dev-docs/RFCs/v4.0.0/error-handling-rfc.md +21 -0
- data/ext/h3/src/dev-docs/RFCs/v4.0.0/names_for_concepts_types_functions.md +276 -0
- data/ext/h3/src/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md +141 -0
- data/ext/h3/src/dev-docs/RFCs/v4.0.0/polyfill-modes-rfc.md +21 -0
- data/ext/h3/src/dev-docs/RFCs/v4.0.0/vertex-mode-rfc.md +50 -0
- data/ext/h3/src/dev-docs/build_windows.md +6 -1
- data/ext/h3/src/dev-docs/creating_bindings.md +3 -3
- data/ext/h3/src/dev-docs/custom_alloc.md +27 -0
- data/ext/h3/src/docs/{overview/mainpage.md → README.md} +2 -3
- data/ext/h3/src/docs/api/misc.md +76 -0
- data/ext/h3/src/docs/community/applications.md +1 -0
- data/ext/h3/src/docs/community/bindings.md +10 -0
- data/ext/h3/src/docs/community/tutorials.md +8 -3
- data/ext/h3/src/docs/core-library/coordsystems.md +5 -4
- data/ext/h3/src/docs/core-library/filters.md +8 -9
- data/ext/h3/src/docs/core-library/geoToH3desc.md +2 -3
- data/ext/h3/src/docs/core-library/h3ToGeoBoundaryDesc.md +4 -5
- data/ext/h3/src/docs/core-library/h3ToGeoDesc.md +3 -4
- data/ext/h3/src/docs/core-library/h3indexing.md +26 -17
- data/ext/h3/src/docs/core-library/overview.md +2 -3
- data/ext/h3/src/docs/core-library/restable.md +1 -2
- data/ext/h3/src/docs/core-library/usage.md +1 -2
- data/ext/h3/src/docs/table-of-contents.json +47 -0
- data/ext/h3/src/docs/{overview/usecases.md → usecases.md} +6 -11
- data/ext/h3/src/scripts/binding_functions.sh +1 -1
- data/ext/h3/src/scripts/coverage.sh.in +1 -1
- data/ext/h3/src/scripts/update_version.sh +2 -2
- data/ext/h3/src/src/apps/applib/include/args.h +1 -0
- data/ext/h3/src/src/apps/applib/include/test.h +1 -0
- data/ext/h3/src/src/apps/applib/include/utility.h +7 -1
- data/ext/h3/src/src/apps/applib/lib/args.c +2 -0
- data/ext/h3/src/src/apps/applib/lib/kml.c +2 -0
- data/ext/h3/src/src/apps/applib/lib/test.c +1 -0
- data/ext/h3/src/src/apps/applib/lib/utility.c +133 -2
- data/ext/h3/src/src/apps/benchmarks/benchmarkH3Api.c +1 -1
- data/ext/h3/src/{website/html.config.js → src/apps/benchmarks/benchmarkH3UniEdge.c} +15 -12
- data/ext/h3/src/src/apps/filters/h3ToComponents.c +1 -0
- data/ext/h3/src/src/apps/filters/h3ToGeo.c +1 -0
- data/ext/h3/src/src/apps/filters/h3ToGeoBoundary.c +1 -0
- data/ext/h3/src/src/apps/filters/h3ToLocalIj.c +1 -0
- data/ext/h3/src/src/apps/filters/hexRange.c +1 -0
- data/ext/h3/src/src/apps/filters/kRing.c +1 -0
- data/ext/h3/src/src/apps/filters/localIjToH3.c +1 -0
- data/ext/h3/src/src/apps/miscapps/generateFaceCenterPoint.c +1 -0
- data/ext/h3/src/src/apps/miscapps/generateNumHexagons.c +1 -0
- data/ext/h3/src/src/apps/miscapps/generatePentagonDirectionFaces.c +67 -0
- data/ext/h3/src/src/apps/miscapps/h3ToGeoBoundaryHier.c +1 -0
- data/ext/h3/src/src/apps/miscapps/h3ToGeoHier.c +1 -0
- data/ext/h3/src/src/apps/miscapps/h3ToHier.c +1 -0
- data/ext/h3/src/src/apps/testapps/mkRandGeo.c +1 -0
- data/ext/h3/src/src/apps/testapps/mkRandGeoBoundary.c +1 -0
- data/ext/h3/src/src/apps/testapps/testBBox.c +1 -0
- data/ext/h3/src/src/apps/testapps/testBaseCells.c +15 -1
- data/ext/h3/src/src/apps/testapps/testCompact.c +109 -2
- data/ext/h3/src/src/apps/testapps/testCoordIj.c +1 -0
- data/ext/h3/src/src/apps/testapps/testGeoCoord.c +47 -8
- data/ext/h3/src/src/apps/testapps/testGeoToH3.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3Api.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3CellArea.c +47 -0
- data/ext/h3/src/src/apps/testapps/testH3CellAreaExhaustive.c +180 -0
- data/ext/h3/src/src/apps/testapps/testH3Distance.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3DistanceExhaustive.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3GetFaces.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3Index.c +33 -3
- data/ext/h3/src/src/apps/testapps/testH3Line.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3LineExhaustive.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3Memory.c +175 -0
- data/ext/h3/src/src/apps/testapps/testH3NeighborRotations.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3SetToLinkedGeo.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3SetToVertexGraph.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3ToCenterChild.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3ToChildren.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3ToGeo.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3ToGeoBoundary.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3ToLocalIj.c +12 -6
- data/ext/h3/src/src/apps/testapps/testH3ToLocalIjExhaustive.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3ToParent.c +1 -0
- data/ext/h3/src/src/apps/testapps/testH3UniEdge.c +45 -16
- data/ext/h3/src/src/apps/testapps/testH3UniEdgeExhaustive.c +111 -0
- data/ext/h3/src/src/apps/testapps/testHexRanges.c +1 -0
- data/ext/h3/src/src/apps/testapps/testHexRing.c +1 -0
- data/ext/h3/src/src/apps/testapps/testKRing.c +19 -0
- data/ext/h3/src/src/apps/testapps/testLinkedGeo.c +1 -0
- data/ext/h3/src/src/apps/testapps/testMaxH3ToChildrenSize.c +1 -0
- data/ext/h3/src/src/apps/testapps/testPentagonIndexes.c +1 -0
- data/ext/h3/src/src/apps/testapps/testPolyfill.c +72 -9
- data/ext/h3/src/src/apps/testapps/testPolyfillReported.c +157 -0
- data/ext/h3/src/src/apps/testapps/testPolygon.c +27 -1
- data/ext/h3/src/src/apps/testapps/testVec2d.c +1 -0
- data/ext/h3/src/src/apps/testapps/testVec3d.c +1 -0
- data/ext/h3/src/src/apps/testapps/testVertex.c +66 -0
- data/ext/h3/src/src/apps/testapps/testVertexGraph.c +1 -0
- data/ext/h3/src/src/h3lib/include/algos.h +8 -0
- data/ext/h3/src/src/h3lib/include/alloc.h +40 -0
- data/ext/h3/src/src/h3lib/include/baseCells.h +4 -0
- data/ext/h3/src/src/h3lib/include/bbox.h +4 -1
- data/ext/h3/src/src/h3lib/include/faceijk.h +3 -2
- data/ext/h3/src/src/h3lib/include/geoCoord.h +2 -3
- data/ext/h3/src/src/h3lib/include/h3Index.h +37 -4
- data/ext/h3/src/src/h3lib/include/h3api.h.in +65 -17
- data/ext/h3/src/src/h3lib/include/linkedGeo.h +1 -0
- data/ext/h3/src/src/h3lib/include/polygon.h +1 -0
- data/ext/h3/src/src/h3lib/include/polygonAlgos.h +1 -0
- data/ext/h3/src/src/h3lib/include/vertex.h +44 -0
- data/ext/h3/src/src/h3lib/include/vertexGraph.h +1 -0
- data/ext/h3/src/src/h3lib/lib/algos.c +304 -76
- data/ext/h3/src/src/h3lib/lib/baseCells.c +26 -4
- data/ext/h3/src/src/h3lib/lib/bbox.c +56 -27
- data/ext/h3/src/src/h3lib/lib/coordijk.c +2 -0
- data/ext/h3/src/src/h3lib/lib/faceijk.c +32 -21
- data/ext/h3/src/src/h3lib/lib/geoCoord.c +162 -44
- data/ext/h3/src/src/h3lib/lib/h3Index.c +83 -42
- data/ext/h3/src/src/h3lib/lib/h3UniEdge.c +42 -57
- data/ext/h3/src/src/h3lib/lib/linkedGeo.c +20 -15
- data/ext/h3/src/src/h3lib/lib/localij.c +1 -1
- data/ext/h3/src/src/h3lib/lib/polygon.c +2 -0
- data/ext/h3/src/src/h3lib/lib/vec2d.c +1 -0
- data/ext/h3/src/src/h3lib/lib/vec3d.c +1 -0
- data/ext/h3/src/src/h3lib/lib/vertex.c +134 -0
- data/ext/h3/src/src/h3lib/lib/vertexGraph.c +8 -5
- data/ext/h3/src/website/.eslintignore +2 -0
- data/ext/h3/src/website/.gitignore +57 -0
- data/ext/h3/src/website/.nvmrc +1 -0
- data/ext/h3/src/website/README.md +8 -6
- data/ext/h3/src/website/gatsby-config.js +83 -0
- data/ext/h3/src/website/package.json +20 -12
- data/ext/h3/src/website/scripts/build-to-gh-pages.sh +7 -5
- data/ext/h3/src/website/src/.gitkeep +0 -0
- data/ext/h3/src/website/templates/documentation.jsx +129 -0
- data/ext/h3/src/website/yarn.lock +13723 -0
- data/h3.gemspec +2 -2
- data/lib/h3/bindings/base.rb +14 -4
- data/lib/h3/bindings/private.rb +12 -9
- data/lib/h3/hierarchy.rb +0 -18
- data/lib/h3/indexing.rb +0 -18
- data/lib/h3/inspection.rb +3 -59
- data/lib/h3/miscellaneous.rb +119 -14
- data/lib/h3/regions.rb +3 -0
- data/lib/h3/traversal.rb +0 -18
- data/lib/h3/unidirectional_edges.rb +5 -60
- data/lib/h3/version.rb +1 -1
- data/spec/geo_json_spec.rb +8 -0
- data/spec/miscellaneous_spec.rb +117 -0
- data/spec/{region_spec.rb → regions_spec.rb} +1 -1
- data/spec/spec_helper.rb +2 -2
- metadata +44 -36
- data/.travis.yml +0 -11
- data/ext/h3/src/.ycm_extra_conf.py +0 -92
- data/ext/h3/src/appveyor.yml +0 -50
- data/ext/h3/src/website/src/config.js +0 -46
- data/ext/h3/src/website/src/mdRoutes.js +0 -151
- data/ext/h3/src/website/src/styles/_variables.scss +0 -16
- data/ext/h3/src/website/src/styles/index.scss +0 -3
- data/ext/h3/src/website/static/index.html +0 -15
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright 2016-
|
|
2
|
+
* Copyright 2016-2020 Uber Technologies, Inc.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
#include "utility.h"
|
|
21
|
+
|
|
21
22
|
#include <assert.h>
|
|
22
23
|
#include <inttypes.h>
|
|
23
24
|
#include <stdio.h>
|
|
24
25
|
#include <stdlib.h>
|
|
25
26
|
#include <string.h>
|
|
26
27
|
#include <time.h>
|
|
28
|
+
|
|
27
29
|
#include "coordijk.h"
|
|
28
30
|
#include "h3Index.h"
|
|
29
31
|
#include "h3api.h"
|
|
@@ -175,6 +177,122 @@ int readBoundary(FILE* f, GeoBoundary* b) {
|
|
|
175
177
|
return 0;
|
|
176
178
|
}
|
|
177
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Move nonzero elements to the front of array `a` of length `n`.
|
|
182
|
+
*
|
|
183
|
+
* Loop invariant: Everything *before* `i` or *after* `j` is "done".
|
|
184
|
+
* Move `i` and `j` inwards until they equal, and exit.
|
|
185
|
+
* You can move `i` forward until there's a zero in front of it.
|
|
186
|
+
* You can move `j` backward until there's a nonzero to the left of it.
|
|
187
|
+
* Anything to the right of `j` is "junk" that can be reallocated.
|
|
188
|
+
*
|
|
189
|
+
* Before:
|
|
190
|
+
* | a | b | 0 | c | d | ... |
|
|
191
|
+
* ^ ^
|
|
192
|
+
* i j
|
|
193
|
+
* After:
|
|
194
|
+
* | a | b | d | c | d | ... |
|
|
195
|
+
* ^ ^
|
|
196
|
+
* i j
|
|
197
|
+
*
|
|
198
|
+
* todo: should this function be in the public API?
|
|
199
|
+
* todo: add tests for this function
|
|
200
|
+
*
|
|
201
|
+
* @param a H3Index array to whose elements will be moved
|
|
202
|
+
* @param n length of the input array
|
|
203
|
+
* @return number of nonzero elements (length of new array); can reallocate
|
|
204
|
+
* memory after this point
|
|
205
|
+
*/
|
|
206
|
+
size_t packNonzeros(H3Index* a, size_t n) {
|
|
207
|
+
size_t i = 0;
|
|
208
|
+
size_t j = n;
|
|
209
|
+
|
|
210
|
+
while (i < j) {
|
|
211
|
+
// move j to the left until the first nonzero
|
|
212
|
+
if (a[j - 1] == 0) {
|
|
213
|
+
j -= 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// move i to the right until the first zero
|
|
218
|
+
if (a[i] != 0) {
|
|
219
|
+
i += 1;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// if we get to this point, we know:
|
|
224
|
+
// a[i] == 0
|
|
225
|
+
// a[j-1] != 0
|
|
226
|
+
// i < j
|
|
227
|
+
// so we can swap! (actually, move a[j-1] -> a[i])
|
|
228
|
+
a[i] = a[j - 1];
|
|
229
|
+
j -= 1;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return i;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Array of all cells at a given resolution.
|
|
237
|
+
*
|
|
238
|
+
* @param res resolution
|
|
239
|
+
*
|
|
240
|
+
* @return array of H3 cells at resolution res
|
|
241
|
+
*/
|
|
242
|
+
H3Index* getCellsAtRes(int res) {
|
|
243
|
+
int num0 = H3_EXPORT(res0IndexCount)();
|
|
244
|
+
H3Index* cells0 = calloc(num0, sizeof(H3Index));
|
|
245
|
+
H3_EXPORT(getRes0Indexes)(cells0);
|
|
246
|
+
|
|
247
|
+
int numRes = H3_EXPORT(maxUncompactSize)(cells0, num0, res);
|
|
248
|
+
|
|
249
|
+
H3Index* cellsRes = calloc(numRes, sizeof(H3Index));
|
|
250
|
+
H3_EXPORT(uncompact)(cells0, num0, cellsRes, numRes, res);
|
|
251
|
+
|
|
252
|
+
free(cells0);
|
|
253
|
+
|
|
254
|
+
numRes = packNonzeros(cellsRes, numRes);
|
|
255
|
+
cellsRes = realloc(cellsRes, numRes * sizeof(H3Index));
|
|
256
|
+
|
|
257
|
+
return cellsRes;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Apply callback to every cell for a given resolution, and sum the results.
|
|
262
|
+
*/
|
|
263
|
+
double mapSumAllCells_double(int res, double (*callback)(H3Index)) {
|
|
264
|
+
H3Index* cells = getCellsAtRes(res);
|
|
265
|
+
int N = H3_EXPORT(numHexagons)(res);
|
|
266
|
+
|
|
267
|
+
double total = 0.0;
|
|
268
|
+
for (int i = 0; i < N; i++) {
|
|
269
|
+
total += (*callback)(cells[i]);
|
|
270
|
+
}
|
|
271
|
+
free(cells);
|
|
272
|
+
|
|
273
|
+
return total;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Apply callback for every unidirectional edge at the given resolution.
|
|
278
|
+
*/
|
|
279
|
+
void iterateAllUnidirectionalEdgesAtRes(int res, void (*callback)(H3Index)) {
|
|
280
|
+
H3Index* cells = getCellsAtRes(res);
|
|
281
|
+
int N = H3_EXPORT(numHexagons)(res);
|
|
282
|
+
|
|
283
|
+
for (int i = 0; i < N; i++) {
|
|
284
|
+
H3Index edges[6] = {H3_NULL};
|
|
285
|
+
int isPentagon = H3_EXPORT(h3IsPentagon)(cells[i]);
|
|
286
|
+
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(cells[i], edges);
|
|
287
|
+
|
|
288
|
+
for (int j = 0; j < 6; j++) {
|
|
289
|
+
if (isPentagon && j == 0) continue;
|
|
290
|
+
(*callback)(edges[j]);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
free(cells);
|
|
294
|
+
}
|
|
295
|
+
|
|
178
296
|
/**
|
|
179
297
|
* Call the callback for every index at the given resolution.
|
|
180
298
|
*/
|
|
@@ -207,7 +325,7 @@ void iterateBaseCellIndexesAtRes(int res, void (*callback)(H3Index),
|
|
|
207
325
|
H3_EXPORT(uncompact)(&bc, 1, children, childrenSz, res);
|
|
208
326
|
|
|
209
327
|
for (int j = 0; j < childrenSz; j++) {
|
|
210
|
-
if (children[j] ==
|
|
328
|
+
if (children[j] == H3_NULL) {
|
|
211
329
|
continue;
|
|
212
330
|
}
|
|
213
331
|
|
|
@@ -233,3 +351,16 @@ void randomGeo(GeoCoord* g) {
|
|
|
233
351
|
(((float)rand() / (float)(RAND_MAX)) * 180.0) - 90.0);
|
|
234
352
|
g->lon = H3_EXPORT(degsToRads)((float)rand() / (float)(RAND_MAX)) * 360.0;
|
|
235
353
|
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Returns the number of non-invalid indexes in the array.
|
|
357
|
+
*/
|
|
358
|
+
int countActualHexagons(H3Index* hexagons, int numHexagons) {
|
|
359
|
+
int actualNumHexagons = 0;
|
|
360
|
+
for (int i = 0; i < numHexagons; i++) {
|
|
361
|
+
if (hexagons[i] != H3_NULL) {
|
|
362
|
+
actualNumHexagons++;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return actualNumHexagons;
|
|
366
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2020 Uber Technologies, Inc.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,19 +13,22 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
#include "benchmark.h"
|
|
17
|
+
#include "geoCoord.h"
|
|
18
|
+
#include "h3api.h"
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
// Fixtures (arbitrary res 9 hexagon)
|
|
21
|
+
H3Index edges[6] = {0};
|
|
22
|
+
H3Index hex = 0x89283080ddbffff;
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
BEGIN_BENCHMARKS();
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
content: 'A hexagonal hierarchical geospatial indexing system'
|
|
24
|
-
}],
|
|
26
|
+
GeoBoundary outBoundary;
|
|
27
|
+
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(hex, edges);
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
BENCHMARK(getH3UnidirectionalEdgeBoundary, 10000, {
|
|
30
|
+
for (int i = 0; i < 6; i++)
|
|
31
|
+
H3_EXPORT(getH3UnidirectionalEdgeBoundary)(edges[i], &outBoundary);
|
|
32
|
+
});
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
END_BENCHMARKS();
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 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 generatePentagonDirectionFaces.c
|
|
17
|
+
* @brief Generates the pentagonDirectionFaces table
|
|
18
|
+
*
|
|
19
|
+
* usage: `generatePentagonDirectionFaces`
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include <stdlib.h>
|
|
23
|
+
|
|
24
|
+
#include "algos.h"
|
|
25
|
+
#include "baseCells.h"
|
|
26
|
+
#include "h3Index.h"
|
|
27
|
+
|
|
28
|
+
static void generate() {
|
|
29
|
+
H3Index pentagons[NUM_PENTAGONS] = {0};
|
|
30
|
+
// Get the res 2 pentagons, whose neighbors have the same base cell
|
|
31
|
+
// and are unambiguously on the correct faces
|
|
32
|
+
H3_EXPORT(getPentagonIndexes)(2, pentagons);
|
|
33
|
+
|
|
34
|
+
printf(
|
|
35
|
+
"static const PentagonDirectionFaces "
|
|
36
|
+
"pentagonDirectionFaces[NUM_PENTAGONS] = "
|
|
37
|
+
"{\n");
|
|
38
|
+
|
|
39
|
+
for (int i = 0; i < NUM_PENTAGONS; i++) {
|
|
40
|
+
H3Index pentagon = pentagons[i];
|
|
41
|
+
int baseCell = H3_EXPORT(h3GetBaseCell)(pentagon);
|
|
42
|
+
printf(" {%d, {", baseCell);
|
|
43
|
+
// Get the neighbors in each direction, in order
|
|
44
|
+
FaceIJK fijk;
|
|
45
|
+
for (Direction dir = J_AXES_DIGIT; dir < NUM_DIGITS; dir++) {
|
|
46
|
+
int r = 0;
|
|
47
|
+
H3Index neighbor = h3NeighborRotations(pentagon, dir, &r);
|
|
48
|
+
_h3ToFaceIjk(neighbor, &fijk);
|
|
49
|
+
|
|
50
|
+
if (dir > J_AXES_DIGIT) printf(", ");
|
|
51
|
+
printf("%d", fijk.face);
|
|
52
|
+
}
|
|
53
|
+
printf("}},\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
printf("};\n");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
int main(int argc, char* argv[]) {
|
|
60
|
+
// check command line args
|
|
61
|
+
if (argc > 1) {
|
|
62
|
+
fprintf(stderr, "usage: %s\n", argv[0]);
|
|
63
|
+
exit(1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
generate();
|
|
67
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright 2017-
|
|
2
|
+
* Copyright 2017-2020 Uber Technologies, Inc.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
#include <stdlib.h>
|
|
18
|
+
#include "baseCells.h"
|
|
18
19
|
#include "h3api.h"
|
|
19
20
|
#include "test.h"
|
|
20
21
|
|
|
@@ -27,4 +28,17 @@ SUITE(baseCells) {
|
|
|
27
28
|
t_assert(indexes[121] == 0x80f3fffffffffff, "correct last basecell");
|
|
28
29
|
free(indexes);
|
|
29
30
|
}
|
|
31
|
+
|
|
32
|
+
TEST(baseCellToCCWrot60) {
|
|
33
|
+
// a few random spot-checks
|
|
34
|
+
t_assert(_baseCellToCCWrot60(16, 0) == 0, "got expected rotation");
|
|
35
|
+
t_assert(_baseCellToCCWrot60(32, 0) == 3, "got expected rotation");
|
|
36
|
+
t_assert(_baseCellToCCWrot60(7, 3) == 1, "got expected rotation");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
TEST(baseCellToCCWrot60_invalid) {
|
|
40
|
+
t_assert(_baseCellToCCWrot60(16, 42) == INVALID_ROTATIONS, "should return invalid rotation for invalid face");
|
|
41
|
+
t_assert(_baseCellToCCWrot60(16, -1) == INVALID_ROTATIONS, "should return invalid rotation for invalid face (negative)");
|
|
42
|
+
t_assert(_baseCellToCCWrot60(1, 0) == INVALID_ROTATIONS, "should return invalid rotation for base cell not appearing on face");
|
|
43
|
+
}
|
|
30
44
|
}
|