h3 3.5.0 → 3.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +45 -0
- data/Gemfile.lock +9 -7
- data/README.md +8 -8
- 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 +21 -32
- data/ext/h3/src/CHANGELOG.md +60 -0
- data/ext/h3/src/CMakeLists.txt +150 -33
- data/ext/h3/src/CONTRIBUTING.md +1 -1
- data/ext/h3/src/README.md +65 -16
- 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/hierarchy.md +8 -0
- data/ext/h3/src/docs/api/misc.md +94 -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 +8 -4
- 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/generateBaseCellNeighbors.c +2 -2
- data/ext/h3/src/src/apps/miscapps/generateFaceCenterPoint.c +1 -0
- data/ext/h3/src/src/apps/miscapps/generateNumHexagons.c +1 -2
- 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 +121 -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 +2 -50
- data/ext/h3/src/src/apps/testapps/testH3DistanceExhaustive.c +84 -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 +2 -84
- data/ext/h3/src/src/apps/testapps/testH3LineExhaustive.c +115 -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 +68 -0
- data/ext/h3/src/src/apps/testapps/testH3ToChildren.c +15 -2
- 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 +24 -236
- data/ext/h3/src/src/apps/testapps/testH3ToLocalIjExhaustive.c +265 -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 +1 -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 +58 -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/constants.h +2 -0
- 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 +85 -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 +305 -80
- 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 +35 -24
- data/ext/h3/src/src/h3lib/lib/geoCoord.c +162 -44
- data/ext/h3/src/src/h3lib/lib/h3Index.c +150 -46
- 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 +5 -5
- data/ext/h3/src/src/h3lib/lib/polygon.c +3 -2
- 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 +1 -0
- data/lib/h3.rb +8 -23
- data/lib/h3/bindings/base.rb +15 -4
- data/lib/h3/bindings/private.rb +13 -9
- data/lib/h3/geo_json.rb +1 -1
- data/lib/h3/hierarchy.rb +24 -9
- data/lib/h3/indexing.rb +7 -7
- data/lib/h3/inspection.rb +22 -26
- data/lib/h3/miscellaneous.rb +157 -9
- data/lib/h3/regions.rb +3 -0
- data/lib/h3/traversal.rb +9 -9
- data/lib/h3/unidirectional_edges.rb +18 -18
- data/lib/h3/version.rb +1 -1
- data/spec/geo_json_spec.rb +8 -0
- data/spec/hierarchy_spec.rb +23 -13
- data/spec/indexing_spec.rb +15 -15
- data/spec/inspection_spec.rb +17 -17
- data/spec/miscellaneous_spec.rb +151 -6
- data/spec/{region_spec.rb → regions_spec.rb} +1 -1
- data/spec/traversal_spec.rb +6 -6
- data/spec/unidirectional_edges_spec.rb +18 -18
- metadata +55 -15
- 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
- data/lib/h3/bindings.rb +0 -12
@@ -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();
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright 2016-
|
2
|
+
* Copyright 2016-2019 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.
|
@@ -87,7 +87,7 @@ static void generate() {
|
|
87
87
|
|
88
88
|
for (int i = 0; i < NUM_BASE_CELLS; i++) {
|
89
89
|
if (!_isBaseCellPentagon(i)) {
|
90
|
-
for (int dir =
|
90
|
+
for (int dir = CENTER_DIGIT; dir <= NUM_DIRS; dir++) {
|
91
91
|
FaceIJK fijk;
|
92
92
|
_baseCellToFaceIjk(i, &fijk);
|
93
93
|
_neighbor(&fijk.coord, dir);
|
@@ -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
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright 2017-
|
2
|
+
* Copyright 2017-2019 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
|
+
|
18
19
|
#include "constants.h"
|
19
20
|
#include "h3Index.h"
|
20
21
|
#include "test.h"
|
@@ -152,6 +153,105 @@ SUITE(compact) {
|
|
152
153
|
"compact fails on duplicate input");
|
153
154
|
}
|
154
155
|
|
156
|
+
TEST(compact_duplicateMinimum) {
|
157
|
+
// Test that the minimum number of duplicate hexagons causes failure
|
158
|
+
H3Index h3;
|
159
|
+
int res = 10;
|
160
|
+
// Arbitrary index
|
161
|
+
setH3Index(&h3, res, 0, 2);
|
162
|
+
|
163
|
+
int arrSize = H3_EXPORT(maxH3ToChildrenSize)(h3, res + 1) + 1;
|
164
|
+
H3Index* children = calloc(arrSize, sizeof(H3Index));
|
165
|
+
|
166
|
+
H3_EXPORT(h3ToChildren)(h3, res + 1, children);
|
167
|
+
// duplicate one index
|
168
|
+
children[arrSize - 1] = children[0];
|
169
|
+
|
170
|
+
H3Index* output = calloc(arrSize, sizeof(H3Index));
|
171
|
+
|
172
|
+
int compactResult = H3_EXPORT(compact)(children, output, arrSize);
|
173
|
+
t_assert(compactResult == COMPACT_DUPLICATE,
|
174
|
+
"compact fails on duplicate input (single duplicate)");
|
175
|
+
|
176
|
+
free(output);
|
177
|
+
free(children);
|
178
|
+
}
|
179
|
+
|
180
|
+
TEST(compact_duplicatePentagonLimit) {
|
181
|
+
// Test that the minimum number of duplicate hexagons causes failure
|
182
|
+
H3Index h3;
|
183
|
+
int res = 10;
|
184
|
+
// Arbitrary pentagon parent cell
|
185
|
+
setH3Index(&h3, res, 4, 0);
|
186
|
+
|
187
|
+
int arrSize = H3_EXPORT(maxH3ToChildrenSize)(h3, res + 1) + 1;
|
188
|
+
H3Index* children = calloc(arrSize, sizeof(H3Index));
|
189
|
+
|
190
|
+
H3_EXPORT(h3ToChildren)(h3, res + 1, children);
|
191
|
+
// duplicate one index
|
192
|
+
children[arrSize - 1] = H3_EXPORT(h3ToCenterChild)(h3, res + 1);
|
193
|
+
|
194
|
+
H3Index* output = calloc(arrSize, sizeof(H3Index));
|
195
|
+
|
196
|
+
int compactResult = H3_EXPORT(compact)(children, output, arrSize);
|
197
|
+
t_assert(compactResult == COMPACT_DUPLICATE,
|
198
|
+
"compact fails on duplicate input (pentagon parent)");
|
199
|
+
|
200
|
+
free(output);
|
201
|
+
free(children);
|
202
|
+
}
|
203
|
+
|
204
|
+
TEST(compact_duplicateIgnored) {
|
205
|
+
// Test that duplicated cells are not rejected by compact.
|
206
|
+
// This is not necessarily desired - just asserting the
|
207
|
+
// existing behavior.
|
208
|
+
H3Index h3;
|
209
|
+
int res = 10;
|
210
|
+
// Arbitrary index
|
211
|
+
setH3Index(&h3, res, 0, 2);
|
212
|
+
|
213
|
+
int arrSize = H3_EXPORT(maxH3ToChildrenSize)(h3, res + 1);
|
214
|
+
H3Index* children = calloc(arrSize, sizeof(H3Index));
|
215
|
+
|
216
|
+
H3_EXPORT(h3ToChildren)(h3, res + 1, children);
|
217
|
+
// duplicate one index
|
218
|
+
children[arrSize - 1] = children[0];
|
219
|
+
|
220
|
+
H3Index* output = calloc(arrSize, sizeof(H3Index));
|
221
|
+
|
222
|
+
int compactResult = H3_EXPORT(compact)(children, output, arrSize);
|
223
|
+
t_assert(compactResult == COMPACT_SUCCESS,
|
224
|
+
"compact succeeds on duplicate input (correct count)");
|
225
|
+
|
226
|
+
free(output);
|
227
|
+
free(children);
|
228
|
+
}
|
229
|
+
|
230
|
+
TEST(compact_empty) {
|
231
|
+
t_assert(H3_EXPORT(compact)(NULL, NULL, 0) == 0,
|
232
|
+
"compact succeeds on empty input");
|
233
|
+
}
|
234
|
+
|
235
|
+
TEST(compact_disparate) {
|
236
|
+
// Exercises a case where compaction needs to be tested but none is
|
237
|
+
// possible
|
238
|
+
const int numHex = 7;
|
239
|
+
H3Index disparate[] = {0, 0, 0, 0, 0, 0, 0};
|
240
|
+
for (int i = 0; i < numHex; i++) {
|
241
|
+
setH3Index(&disparate[i], 1, i, CENTER_DIGIT);
|
242
|
+
}
|
243
|
+
H3Index output[] = {0, 0, 0, 0, 0, 0, 0};
|
244
|
+
|
245
|
+
t_assert(H3_EXPORT(compact)(disparate, output, numHex) == 0,
|
246
|
+
"compact succeeds on disparate input");
|
247
|
+
|
248
|
+
// Assumes that `output` is an exact copy of `disparate`, including
|
249
|
+
// the ordering (which may not necessarily be the case)
|
250
|
+
for (int i = 0; i < numHex; i++) {
|
251
|
+
t_assert(disparate[i] == output[i], "output set equals input set");
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
155
255
|
TEST(uncompact_wrongRes) {
|
156
256
|
int numHex = 3;
|
157
257
|
H3Index someHexagons[] = {0, 0, 0};
|
@@ -165,6 +265,10 @@ SUITE(compact) {
|
|
165
265
|
sizeResult = H3_EXPORT(maxUncompactSize)(someHexagons, numHex, -1);
|
166
266
|
t_assert(sizeResult < 0,
|
167
267
|
"maxUncompactSize fails when given illegal resolutions");
|
268
|
+
sizeResult =
|
269
|
+
H3_EXPORT(maxUncompactSize)(someHexagons, numHex, MAX_H3_RES + 1);
|
270
|
+
t_assert(sizeResult < 0,
|
271
|
+
"maxUncompactSize fails when given resolutions beyond max");
|
168
272
|
|
169
273
|
H3Index uncompressed[] = {0, 0, 0};
|
170
274
|
int uncompactResult =
|
@@ -180,6 +284,14 @@ SUITE(compact) {
|
|
180
284
|
t_assert(
|
181
285
|
uncompactResult != 0,
|
182
286
|
"uncompact fails when given too little buffer (same resolution)");
|
287
|
+
|
288
|
+
for (int i = 0; i < numHex; i++) {
|
289
|
+
setH3Index(&someHexagons[i], MAX_H3_RES, i, 0);
|
290
|
+
}
|
291
|
+
uncompactResult = H3_EXPORT(uncompact)(
|
292
|
+
someHexagons, numHex, uncompressed, numHex * 7, MAX_H3_RES + 1);
|
293
|
+
t_assert(uncompactResult != 0,
|
294
|
+
"uncompact fails when given resolutions beyond max");
|
183
295
|
}
|
184
296
|
|
185
297
|
TEST(someHexagon) {
|
@@ -209,6 +321,13 @@ SUITE(compact) {
|
|
209
321
|
free(result);
|
210
322
|
}
|
211
323
|
|
324
|
+
TEST(uncompact_empty) {
|
325
|
+
int uncompactSz = H3_EXPORT(maxUncompactSize)(NULL, 0, 0);
|
326
|
+
t_assert(uncompactSz == 0, "maxUncompactSize accepts empty input");
|
327
|
+
t_assert(H3_EXPORT(uncompact)(NULL, 0, NULL, 0, 0) == 0,
|
328
|
+
"uncompact accepts empty input");
|
329
|
+
}
|
330
|
+
|
212
331
|
TEST(uncompact_onlyZero) {
|
213
332
|
// maxUncompactSize and uncompact both permit 0 indexes
|
214
333
|
// in the input array, and skip them. When only a zero is
|
@@ -225,7 +344,7 @@ SUITE(compact) {
|
|
225
344
|
free(children);
|
226
345
|
}
|
227
346
|
|
228
|
-
TEST(
|
347
|
+
TEST(uncompact_withZero) {
|
229
348
|
// maxUncompactSize and uncompact both permit 0 indexes
|
230
349
|
// in the input array, and skip them.
|
231
350
|
|