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
@@ -0,0 +1,68 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2019 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
|
+
|
17
|
+
#include <inttypes.h>
|
18
|
+
#include <stdlib.h>
|
19
|
+
|
20
|
+
#include "h3Index.h"
|
21
|
+
#include "test.h"
|
22
|
+
|
23
|
+
SUITE(h3ToCenterChild) {
|
24
|
+
H3Index baseHex;
|
25
|
+
GeoCoord baseCentroid;
|
26
|
+
setH3Index(&baseHex, 8, 4, 2);
|
27
|
+
H3_EXPORT(h3ToGeo)(baseHex, &baseCentroid);
|
28
|
+
|
29
|
+
TEST(propertyTests) {
|
30
|
+
for (int res = 0; res <= MAX_H3_RES - 1; res++) {
|
31
|
+
for (int childRes = res + 1; childRes <= MAX_H3_RES; childRes++) {
|
32
|
+
GeoCoord centroid;
|
33
|
+
H3Index h3Index = H3_EXPORT(geoToH3)(&baseCentroid, res);
|
34
|
+
H3_EXPORT(h3ToGeo)(h3Index, ¢roid);
|
35
|
+
|
36
|
+
H3Index geoChild = H3_EXPORT(geoToH3)(¢roid, childRes);
|
37
|
+
H3Index centerChild =
|
38
|
+
H3_EXPORT(h3ToCenterChild)(h3Index, childRes);
|
39
|
+
|
40
|
+
t_assert(
|
41
|
+
centerChild == geoChild,
|
42
|
+
"center child should be same as indexed centroid at child "
|
43
|
+
"resolution");
|
44
|
+
t_assert(H3_EXPORT(h3GetResolution)(centerChild) == childRes,
|
45
|
+
"center child should have correct resolution");
|
46
|
+
t_assert(
|
47
|
+
H3_EXPORT(h3ToParent)(centerChild, res) == h3Index,
|
48
|
+
"parent at original resolution should be initial index");
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
TEST(sameRes) {
|
54
|
+
int res = H3_EXPORT(h3GetResolution)(baseHex);
|
55
|
+
t_assert(H3_EXPORT(h3ToCenterChild)(baseHex, res) == baseHex,
|
56
|
+
"center child at same resolution should return self");
|
57
|
+
}
|
58
|
+
|
59
|
+
TEST(invalidInputs) {
|
60
|
+
int res = H3_EXPORT(h3GetResolution)(baseHex);
|
61
|
+
t_assert(H3_EXPORT(h3ToCenterChild)(baseHex, res - 1) == 0,
|
62
|
+
"should fail at coarser resolution");
|
63
|
+
t_assert(H3_EXPORT(h3ToCenterChild)(baseHex, -1) == 0,
|
64
|
+
"should fail for negative resolution");
|
65
|
+
t_assert(H3_EXPORT(h3ToCenterChild)(baseHex, MAX_H3_RES + 1) == 0,
|
66
|
+
"should fail beyond finest resolution");
|
67
|
+
}
|
68
|
+
}
|
@@ -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 "h3Index.h"
|
19
20
|
#include "test.h"
|
20
21
|
|
@@ -109,7 +110,7 @@ SUITE(h3ToChildren) {
|
|
109
110
|
free(children);
|
110
111
|
}
|
111
112
|
|
112
|
-
TEST(
|
113
|
+
TEST(childResTooCoarse) {
|
113
114
|
const int expectedCount = 0;
|
114
115
|
const int paddedCount = 7;
|
115
116
|
|
@@ -120,6 +121,18 @@ SUITE(h3ToChildren) {
|
|
120
121
|
free(children);
|
121
122
|
}
|
122
123
|
|
124
|
+
TEST(childResTooFine) {
|
125
|
+
const int expectedCount = 0;
|
126
|
+
const int paddedCount = 7;
|
127
|
+
H3Index sfHexMax = H3_EXPORT(geoToH3)(&sf, MAX_H3_RES);
|
128
|
+
|
129
|
+
H3Index* children = calloc(paddedCount, sizeof(H3Index));
|
130
|
+
H3_EXPORT(h3ToChildren)(sfHexMax, MAX_H3_RES + 1, children);
|
131
|
+
|
132
|
+
verifyCountAndUniqueness(children, paddedCount, expectedCount);
|
133
|
+
free(children);
|
134
|
+
}
|
135
|
+
|
123
136
|
TEST(pentagonChildren) {
|
124
137
|
H3Index pentagon;
|
125
138
|
setH3Index(&pentagon, 1, 4, 0);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright 2018 Uber Technologies, Inc.
|
2
|
+
* Copyright 2018-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.
|
@@ -23,6 +23,7 @@
|
|
23
23
|
#include <stdio.h>
|
24
24
|
#include <stdlib.h>
|
25
25
|
#include <string.h>
|
26
|
+
|
26
27
|
#include "algos.h"
|
27
28
|
#include "baseCells.h"
|
28
29
|
#include "constants.h"
|
@@ -32,198 +33,6 @@
|
|
32
33
|
#include "test.h"
|
33
34
|
#include "utility.h"
|
34
35
|
|
35
|
-
static const int MAX_DISTANCES[] = {1, 2, 5, 12, 19, 26};
|
36
|
-
|
37
|
-
// The same traversal constants from algos.c (for hexRange) here reused as local
|
38
|
-
// IJ vectors.
|
39
|
-
static const CoordIJ DIRECTIONS[6] = {{0, 1}, {-1, 0}, {-1, -1},
|
40
|
-
{0, -1}, {1, 0}, {1, 1}};
|
41
|
-
|
42
|
-
static const CoordIJ NEXT_RING_DIRECTION = {1, 0};
|
43
|
-
|
44
|
-
/**
|
45
|
-
* Test that the local coordinates for an index map to itself.
|
46
|
-
*/
|
47
|
-
void localIjToH3_identity_assertions(H3Index h3) {
|
48
|
-
CoordIJ ij;
|
49
|
-
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
|
50
|
-
"able to setup localIjToH3 test");
|
51
|
-
|
52
|
-
H3Index retrieved;
|
53
|
-
t_assert(H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &retrieved) == 0,
|
54
|
-
"got an index back from localIjTOh3");
|
55
|
-
t_assert(h3 == retrieved, "round trip through local IJ space works");
|
56
|
-
}
|
57
|
-
|
58
|
-
/**
|
59
|
-
* Test that coordinates for an index match some simple rules about index
|
60
|
-
* digits, when using the index as its own origin. That is, that the IJ
|
61
|
-
* coordinates are in the coordinate space of the origin's base cell.
|
62
|
-
*/
|
63
|
-
void h3ToLocalIj_coordinates_assertions(H3Index h3) {
|
64
|
-
int r = H3_GET_RESOLUTION(h3);
|
65
|
-
|
66
|
-
CoordIJ ij;
|
67
|
-
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
|
68
|
-
"get ij for origin");
|
69
|
-
CoordIJK ijk;
|
70
|
-
ijToIjk(&ij, &ijk);
|
71
|
-
if (r == 0) {
|
72
|
-
t_assert(_ijkMatches(&ijk, &UNIT_VECS[0]) == 1, "res 0 cell at 0,0,0");
|
73
|
-
} else if (r == 1) {
|
74
|
-
t_assert(_ijkMatches(&ijk, &UNIT_VECS[H3_GET_INDEX_DIGIT(h3, 1)]) == 1,
|
75
|
-
"res 1 cell at expected coordinates");
|
76
|
-
} else if (r == 2) {
|
77
|
-
CoordIJK expected = UNIT_VECS[H3_GET_INDEX_DIGIT(h3, 1)];
|
78
|
-
_downAp7r(&expected);
|
79
|
-
_neighbor(&expected, H3_GET_INDEX_DIGIT(h3, 2));
|
80
|
-
t_assert(_ijkMatches(&ijk, &expected) == 1,
|
81
|
-
"res 2 cell at expected coordinates");
|
82
|
-
} else {
|
83
|
-
t_assert(0, "resolution supported by test function (coordinates)");
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
/**
|
88
|
-
* Test the the immediate neighbors of an index are at the expected locations in
|
89
|
-
* the local IJ coordinate space.
|
90
|
-
*/
|
91
|
-
void h3ToLocalIj_neighbors_assertions(H3Index h3) {
|
92
|
-
CoordIJ origin = {0};
|
93
|
-
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &origin) == 0,
|
94
|
-
"got ij for origin");
|
95
|
-
CoordIJK originIjk;
|
96
|
-
ijToIjk(&origin, &originIjk);
|
97
|
-
|
98
|
-
for (Direction d = K_AXES_DIGIT; d < INVALID_DIGIT; d++) {
|
99
|
-
if (d == K_AXES_DIGIT && H3_EXPORT(h3IsPentagon)(h3)) {
|
100
|
-
continue;
|
101
|
-
}
|
102
|
-
|
103
|
-
int rotations = 0;
|
104
|
-
H3Index offset = h3NeighborRotations(h3, d, &rotations);
|
105
|
-
|
106
|
-
CoordIJ ij = {0};
|
107
|
-
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, offset, &ij) == 0,
|
108
|
-
"got ij for destination");
|
109
|
-
CoordIJK ijk;
|
110
|
-
ijToIjk(&ij, &ijk);
|
111
|
-
CoordIJK invertedIjk = {0};
|
112
|
-
_neighbor(&invertedIjk, d);
|
113
|
-
for (int i = 0; i < 3; i++) {
|
114
|
-
_ijkRotate60ccw(&invertedIjk);
|
115
|
-
}
|
116
|
-
_ijkAdd(&invertedIjk, &ijk, &ijk);
|
117
|
-
_ijkNormalize(&ijk);
|
118
|
-
|
119
|
-
t_assert(_ijkMatches(&ijk, &originIjk), "back to origin");
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
/**
|
124
|
-
* Test that the neighbors (k-ring), if they can be found in the local IJ
|
125
|
-
* coordinate space, can be converted back to indexes.
|
126
|
-
*/
|
127
|
-
void localIjToH3_kRing_assertions(H3Index h3) {
|
128
|
-
int r = H3_GET_RESOLUTION(h3);
|
129
|
-
t_assert(r <= 5, "resolution supported by test function (kRing)");
|
130
|
-
int maxK = MAX_DISTANCES[r];
|
131
|
-
|
132
|
-
int sz = H3_EXPORT(maxKringSize)(maxK);
|
133
|
-
H3Index *neighbors = calloc(sz, sizeof(H3Index));
|
134
|
-
int *distances = calloc(sz, sizeof(int));
|
135
|
-
|
136
|
-
H3_EXPORT(kRingDistances)(h3, maxK, neighbors, distances);
|
137
|
-
|
138
|
-
for (int i = 0; i < sz; i++) {
|
139
|
-
if (neighbors[i] == 0) {
|
140
|
-
continue;
|
141
|
-
}
|
142
|
-
|
143
|
-
CoordIJ ij;
|
144
|
-
// Don't consider indexes which we can't unfold in the first place
|
145
|
-
if (H3_EXPORT(experimentalH3ToLocalIj)(h3, neighbors[i], &ij) == 0) {
|
146
|
-
H3Index retrieved;
|
147
|
-
t_assert(
|
148
|
-
H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &retrieved) == 0,
|
149
|
-
"retrieved index for unfolded coordinates");
|
150
|
-
t_assert(retrieved == neighbors[i],
|
151
|
-
"round trip neighboring index matches expected");
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
free(distances);
|
156
|
-
free(neighbors);
|
157
|
-
}
|
158
|
-
|
159
|
-
void localIjToH3_traverse_assertions(H3Index h3) {
|
160
|
-
int r = H3_GET_RESOLUTION(h3);
|
161
|
-
t_assert(r <= 5, "resolution supported by test function (traverse)");
|
162
|
-
int k = MAX_DISTANCES[r];
|
163
|
-
|
164
|
-
CoordIJ ij;
|
165
|
-
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
|
166
|
-
"Got origin coordinates");
|
167
|
-
|
168
|
-
// This logic is from hexRangeDistances.
|
169
|
-
// 0 < ring <= k, current ring
|
170
|
-
int ring = 1;
|
171
|
-
// 0 <= direction < 6, current side of the ring
|
172
|
-
int direction = 0;
|
173
|
-
// 0 <= i < ring, current position on the side of the ring
|
174
|
-
int i = 0;
|
175
|
-
|
176
|
-
while (ring <= k) {
|
177
|
-
if (direction == 0 && i == 0) {
|
178
|
-
ij.i += NEXT_RING_DIRECTION.i;
|
179
|
-
ij.j += NEXT_RING_DIRECTION.j;
|
180
|
-
}
|
181
|
-
|
182
|
-
ij.i += DIRECTIONS[direction].i;
|
183
|
-
ij.j += DIRECTIONS[direction].j;
|
184
|
-
|
185
|
-
H3Index testH3;
|
186
|
-
|
187
|
-
int failed = H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &testH3);
|
188
|
-
if (!failed) {
|
189
|
-
t_assert(H3_EXPORT(h3IsValid)(testH3),
|
190
|
-
"test coordinates result in valid index");
|
191
|
-
|
192
|
-
CoordIJ expectedIj;
|
193
|
-
int reverseFailed =
|
194
|
-
H3_EXPORT(experimentalH3ToLocalIj)(h3, testH3, &expectedIj);
|
195
|
-
// If it doesn't give a coordinate for this origin,index pair that's
|
196
|
-
// OK.
|
197
|
-
if (!reverseFailed) {
|
198
|
-
if (expectedIj.i != ij.i || expectedIj.j != ij.j) {
|
199
|
-
// Multiple coordinates for the same index can happen due to
|
200
|
-
// pentagon distortion. In that case, the other coordinates
|
201
|
-
// should also belong to the same index.
|
202
|
-
H3Index testTestH3;
|
203
|
-
t_assert(H3_EXPORT(experimentalLocalIjToH3)(
|
204
|
-
h3, &expectedIj, &testTestH3) == 0,
|
205
|
-
"converted coordinates again");
|
206
|
-
t_assert(testH3 == testTestH3,
|
207
|
-
"index has normalizable coordinates in "
|
208
|
-
"local IJ");
|
209
|
-
}
|
210
|
-
}
|
211
|
-
}
|
212
|
-
|
213
|
-
i++;
|
214
|
-
// Check if end of this side of the k-ring
|
215
|
-
if (i == ring) {
|
216
|
-
i = 0;
|
217
|
-
direction++;
|
218
|
-
// Check if end of this ring.
|
219
|
-
if (direction == 6) {
|
220
|
-
direction = 0;
|
221
|
-
ring++;
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
225
|
-
}
|
226
|
-
|
227
36
|
SUITE(h3ToLocalIj) {
|
228
37
|
// Some indexes that represent base cells. Base cells
|
229
38
|
// are hexagons except for `pent1`.
|
@@ -239,42 +48,6 @@ SUITE(h3ToLocalIj) {
|
|
239
48
|
H3Index pent1 = H3_INIT;
|
240
49
|
setH3Index(&pent1, 0, 4, 0);
|
241
50
|
|
242
|
-
TEST(localIjToH3_identity) {
|
243
|
-
iterateAllIndexesAtRes(0, localIjToH3_identity_assertions);
|
244
|
-
iterateAllIndexesAtRes(1, localIjToH3_identity_assertions);
|
245
|
-
iterateAllIndexesAtRes(2, localIjToH3_identity_assertions);
|
246
|
-
}
|
247
|
-
|
248
|
-
TEST(h3ToLocalIj_coordinates) {
|
249
|
-
iterateAllIndexesAtRes(0, h3ToLocalIj_coordinates_assertions);
|
250
|
-
iterateAllIndexesAtRes(1, h3ToLocalIj_coordinates_assertions);
|
251
|
-
iterateAllIndexesAtRes(2, h3ToLocalIj_coordinates_assertions);
|
252
|
-
}
|
253
|
-
|
254
|
-
TEST(h3ToLocalIj_neighbors) {
|
255
|
-
iterateAllIndexesAtRes(0, h3ToLocalIj_neighbors_assertions);
|
256
|
-
iterateAllIndexesAtRes(1, h3ToLocalIj_neighbors_assertions);
|
257
|
-
iterateAllIndexesAtRes(2, h3ToLocalIj_neighbors_assertions);
|
258
|
-
}
|
259
|
-
|
260
|
-
TEST(localIjToH3_kRing) {
|
261
|
-
iterateAllIndexesAtRes(0, localIjToH3_kRing_assertions);
|
262
|
-
iterateAllIndexesAtRes(1, localIjToH3_kRing_assertions);
|
263
|
-
iterateAllIndexesAtRes(2, localIjToH3_kRing_assertions);
|
264
|
-
// Don't iterate all of res 3, to save time
|
265
|
-
iterateAllIndexesAtResPartial(3, localIjToH3_kRing_assertions, 27);
|
266
|
-
// Further resolutions aren't tested to save time.
|
267
|
-
}
|
268
|
-
|
269
|
-
TEST(localIjToH3_traverse) {
|
270
|
-
iterateAllIndexesAtRes(0, localIjToH3_traverse_assertions);
|
271
|
-
iterateAllIndexesAtRes(1, localIjToH3_traverse_assertions);
|
272
|
-
iterateAllIndexesAtRes(2, localIjToH3_traverse_assertions);
|
273
|
-
// Don't iterate all of res 3, to save time
|
274
|
-
iterateAllIndexesAtResPartial(3, localIjToH3_traverse_assertions, 27);
|
275
|
-
// Further resolutions aren't tested to save time.
|
276
|
-
}
|
277
|
-
|
278
51
|
TEST(ijkBaseCells) {
|
279
52
|
CoordIJK ijk;
|
280
53
|
t_assert(h3ToLocalIjk(pent1, bc1, &ijk) == 0,
|
@@ -300,21 +73,36 @@ SUITE(h3ToLocalIj) {
|
|
300
73
|
ij.i = 2;
|
301
74
|
t_assert(
|
302
75
|
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) != 0,
|
303
|
-
"out of range base cell");
|
76
|
+
"out of range base cell (1)");
|
77
|
+
ij.i = 0;
|
78
|
+
ij.j = 2;
|
79
|
+
t_assert(
|
80
|
+
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) != 0,
|
81
|
+
"out of range base cell (2)");
|
82
|
+
ij.i = -2;
|
83
|
+
ij.j = -2;
|
84
|
+
t_assert(
|
85
|
+
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) != 0,
|
86
|
+
"out of range base cell (3)");
|
304
87
|
}
|
305
88
|
|
306
89
|
TEST(ijOutOfRange) {
|
307
|
-
const int numCoords =
|
308
|
-
const CoordIJ coords[] = {{0, 0}, {1, 0},
|
309
|
-
|
310
|
-
|
311
|
-
|
90
|
+
const int numCoords = 7;
|
91
|
+
const CoordIJ coords[] = {{0, 0}, {1, 0}, {2, 0}, {3, 0},
|
92
|
+
{4, 0}, {-4, 0}, {0, 4}};
|
93
|
+
const H3Index expected[] = {0x81283ffffffffff,
|
94
|
+
0x81293ffffffffff,
|
95
|
+
0x8150bffffffffff,
|
96
|
+
0x8151bffffffffff,
|
97
|
+
H3_NULL,
|
98
|
+
H3_NULL,
|
99
|
+
H3_NULL};
|
312
100
|
|
313
101
|
for (int i = 0; i < numCoords; i++) {
|
314
102
|
H3Index result;
|
315
103
|
const int err = H3_EXPORT(experimentalLocalIjToH3)(
|
316
104
|
expected[0], &coords[i], &result);
|
317
|
-
if (expected[i] ==
|
105
|
+
if (expected[i] == H3_NULL) {
|
318
106
|
t_assert(err != 0, "coordinates out of range");
|
319
107
|
} else {
|
320
108
|
t_assert(err == 0, "coordinates in range");
|