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,265 @@
|
|
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
|
+
/** @file
|
17
|
+
* @brief tests H3 index to local IJ and IJK+ grid functions using
|
18
|
+
* tests over a large number of indexes.
|
19
|
+
*
|
20
|
+
* usage: `testH3ToLocalIjExhaustive`
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include <h3api.h>
|
24
|
+
#include <stdio.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
#include <string.h>
|
27
|
+
|
28
|
+
#include "algos.h"
|
29
|
+
#include "baseCells.h"
|
30
|
+
#include "constants.h"
|
31
|
+
#include "h3Index.h"
|
32
|
+
#include "h3api.h"
|
33
|
+
#include "localij.h"
|
34
|
+
#include "test.h"
|
35
|
+
#include "utility.h"
|
36
|
+
|
37
|
+
static const int MAX_DISTANCES[] = {1, 2, 5, 12, 19, 26};
|
38
|
+
|
39
|
+
// The same traversal constants from algos.c (for hexRange) here reused as local
|
40
|
+
// IJ vectors.
|
41
|
+
static const CoordIJ DIRECTIONS[6] = {{0, 1}, {-1, 0}, {-1, -1},
|
42
|
+
{0, -1}, {1, 0}, {1, 1}};
|
43
|
+
|
44
|
+
static const CoordIJ NEXT_RING_DIRECTION = {1, 0};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Test that the local coordinates for an index map to itself.
|
48
|
+
*/
|
49
|
+
void localIjToH3_identity_assertions(H3Index h3) {
|
50
|
+
CoordIJ ij;
|
51
|
+
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
|
52
|
+
"able to setup localIjToH3 test");
|
53
|
+
|
54
|
+
H3Index retrieved;
|
55
|
+
t_assert(H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &retrieved) == 0,
|
56
|
+
"got an index back from localIjTOh3");
|
57
|
+
t_assert(h3 == retrieved, "round trip through local IJ space works");
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Test that coordinates for an index match some simple rules about index
|
62
|
+
* digits, when using the index as its own origin. That is, that the IJ
|
63
|
+
* coordinates are in the coordinate space of the origin's base cell.
|
64
|
+
*/
|
65
|
+
void h3ToLocalIj_coordinates_assertions(H3Index h3) {
|
66
|
+
int r = H3_GET_RESOLUTION(h3);
|
67
|
+
|
68
|
+
CoordIJ ij;
|
69
|
+
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
|
70
|
+
"get ij for origin");
|
71
|
+
CoordIJK ijk;
|
72
|
+
ijToIjk(&ij, &ijk);
|
73
|
+
if (r == 0) {
|
74
|
+
t_assert(_ijkMatches(&ijk, &UNIT_VECS[0]) == 1, "res 0 cell at 0,0,0");
|
75
|
+
} else if (r == 1) {
|
76
|
+
t_assert(_ijkMatches(&ijk, &UNIT_VECS[H3_GET_INDEX_DIGIT(h3, 1)]) == 1,
|
77
|
+
"res 1 cell at expected coordinates");
|
78
|
+
} else if (r == 2) {
|
79
|
+
CoordIJK expected = UNIT_VECS[H3_GET_INDEX_DIGIT(h3, 1)];
|
80
|
+
_downAp7r(&expected);
|
81
|
+
_neighbor(&expected, H3_GET_INDEX_DIGIT(h3, 2));
|
82
|
+
t_assert(_ijkMatches(&ijk, &expected) == 1,
|
83
|
+
"res 2 cell at expected coordinates");
|
84
|
+
} else {
|
85
|
+
t_assert(0, "resolution supported by test function (coordinates)");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Test the the immediate neighbors of an index are at the expected locations in
|
91
|
+
* the local IJ coordinate space.
|
92
|
+
*/
|
93
|
+
void h3ToLocalIj_neighbors_assertions(H3Index h3) {
|
94
|
+
CoordIJ origin = {0};
|
95
|
+
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &origin) == 0,
|
96
|
+
"got ij for origin");
|
97
|
+
CoordIJK originIjk;
|
98
|
+
ijToIjk(&origin, &originIjk);
|
99
|
+
|
100
|
+
for (Direction d = K_AXES_DIGIT; d < INVALID_DIGIT; d++) {
|
101
|
+
if (d == K_AXES_DIGIT && H3_EXPORT(h3IsPentagon)(h3)) {
|
102
|
+
continue;
|
103
|
+
}
|
104
|
+
|
105
|
+
int rotations = 0;
|
106
|
+
H3Index offset = h3NeighborRotations(h3, d, &rotations);
|
107
|
+
|
108
|
+
CoordIJ ij = {0};
|
109
|
+
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, offset, &ij) == 0,
|
110
|
+
"got ij for destination");
|
111
|
+
CoordIJK ijk;
|
112
|
+
ijToIjk(&ij, &ijk);
|
113
|
+
CoordIJK invertedIjk = {0};
|
114
|
+
_neighbor(&invertedIjk, d);
|
115
|
+
for (int i = 0; i < 3; i++) {
|
116
|
+
_ijkRotate60ccw(&invertedIjk);
|
117
|
+
}
|
118
|
+
_ijkAdd(&invertedIjk, &ijk, &ijk);
|
119
|
+
_ijkNormalize(&ijk);
|
120
|
+
|
121
|
+
t_assert(_ijkMatches(&ijk, &originIjk), "back to origin");
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Test that the neighbors (k-ring), if they can be found in the local IJ
|
127
|
+
* coordinate space, can be converted back to indexes.
|
128
|
+
*/
|
129
|
+
void localIjToH3_kRing_assertions(H3Index h3) {
|
130
|
+
int r = H3_GET_RESOLUTION(h3);
|
131
|
+
t_assert(r <= 5, "resolution supported by test function (kRing)");
|
132
|
+
int maxK = MAX_DISTANCES[r];
|
133
|
+
|
134
|
+
int sz = H3_EXPORT(maxKringSize)(maxK);
|
135
|
+
H3Index *neighbors = calloc(sz, sizeof(H3Index));
|
136
|
+
int *distances = calloc(sz, sizeof(int));
|
137
|
+
|
138
|
+
H3_EXPORT(kRingDistances)(h3, maxK, neighbors, distances);
|
139
|
+
|
140
|
+
for (int i = 0; i < sz; i++) {
|
141
|
+
if (neighbors[i] == 0) {
|
142
|
+
continue;
|
143
|
+
}
|
144
|
+
|
145
|
+
CoordIJ ij;
|
146
|
+
// Don't consider indexes which we can't unfold in the first place
|
147
|
+
if (H3_EXPORT(experimentalH3ToLocalIj)(h3, neighbors[i], &ij) == 0) {
|
148
|
+
H3Index retrieved;
|
149
|
+
t_assert(
|
150
|
+
H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &retrieved) == 0,
|
151
|
+
"retrieved index for unfolded coordinates");
|
152
|
+
t_assert(retrieved == neighbors[i],
|
153
|
+
"round trip neighboring index matches expected");
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
free(distances);
|
158
|
+
free(neighbors);
|
159
|
+
}
|
160
|
+
|
161
|
+
void localIjToH3_traverse_assertions(H3Index h3) {
|
162
|
+
int r = H3_GET_RESOLUTION(h3);
|
163
|
+
t_assert(r <= 5, "resolution supported by test function (traverse)");
|
164
|
+
int k = MAX_DISTANCES[r];
|
165
|
+
|
166
|
+
CoordIJ ij;
|
167
|
+
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(h3, h3, &ij) == 0,
|
168
|
+
"Got origin coordinates");
|
169
|
+
|
170
|
+
// This logic is from hexRangeDistances.
|
171
|
+
// 0 < ring <= k, current ring
|
172
|
+
int ring = 1;
|
173
|
+
// 0 <= direction < 6, current side of the ring
|
174
|
+
int direction = 0;
|
175
|
+
// 0 <= i < ring, current position on the side of the ring
|
176
|
+
int i = 0;
|
177
|
+
|
178
|
+
while (ring <= k) {
|
179
|
+
if (direction == 0 && i == 0) {
|
180
|
+
ij.i += NEXT_RING_DIRECTION.i;
|
181
|
+
ij.j += NEXT_RING_DIRECTION.j;
|
182
|
+
}
|
183
|
+
|
184
|
+
ij.i += DIRECTIONS[direction].i;
|
185
|
+
ij.j += DIRECTIONS[direction].j;
|
186
|
+
|
187
|
+
H3Index testH3;
|
188
|
+
|
189
|
+
int failed = H3_EXPORT(experimentalLocalIjToH3)(h3, &ij, &testH3);
|
190
|
+
if (!failed) {
|
191
|
+
t_assert(H3_EXPORT(h3IsValid)(testH3),
|
192
|
+
"test coordinates result in valid index");
|
193
|
+
|
194
|
+
CoordIJ expectedIj;
|
195
|
+
int reverseFailed =
|
196
|
+
H3_EXPORT(experimentalH3ToLocalIj)(h3, testH3, &expectedIj);
|
197
|
+
// If it doesn't give a coordinate for this origin,index pair that's
|
198
|
+
// OK.
|
199
|
+
if (!reverseFailed) {
|
200
|
+
if (expectedIj.i != ij.i || expectedIj.j != ij.j) {
|
201
|
+
// Multiple coordinates for the same index can happen due to
|
202
|
+
// pentagon distortion. In that case, the other coordinates
|
203
|
+
// should also belong to the same index.
|
204
|
+
H3Index testTestH3;
|
205
|
+
t_assert(H3_EXPORT(experimentalLocalIjToH3)(
|
206
|
+
h3, &expectedIj, &testTestH3) == 0,
|
207
|
+
"converted coordinates again");
|
208
|
+
t_assert(testH3 == testTestH3,
|
209
|
+
"index has normalizable coordinates in "
|
210
|
+
"local IJ");
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
i++;
|
216
|
+
// Check if end of this side of the k-ring
|
217
|
+
if (i == ring) {
|
218
|
+
i = 0;
|
219
|
+
direction++;
|
220
|
+
// Check if end of this ring.
|
221
|
+
if (direction == 6) {
|
222
|
+
direction = 0;
|
223
|
+
ring++;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
SUITE(h3ToLocalIj) {
|
230
|
+
TEST(localIjToH3_identity) {
|
231
|
+
iterateAllIndexesAtRes(0, localIjToH3_identity_assertions);
|
232
|
+
iterateAllIndexesAtRes(1, localIjToH3_identity_assertions);
|
233
|
+
iterateAllIndexesAtRes(2, localIjToH3_identity_assertions);
|
234
|
+
}
|
235
|
+
|
236
|
+
TEST(h3ToLocalIj_coordinates) {
|
237
|
+
iterateAllIndexesAtRes(0, h3ToLocalIj_coordinates_assertions);
|
238
|
+
iterateAllIndexesAtRes(1, h3ToLocalIj_coordinates_assertions);
|
239
|
+
iterateAllIndexesAtRes(2, h3ToLocalIj_coordinates_assertions);
|
240
|
+
}
|
241
|
+
|
242
|
+
TEST(h3ToLocalIj_neighbors) {
|
243
|
+
iterateAllIndexesAtRes(0, h3ToLocalIj_neighbors_assertions);
|
244
|
+
iterateAllIndexesAtRes(1, h3ToLocalIj_neighbors_assertions);
|
245
|
+
iterateAllIndexesAtRes(2, h3ToLocalIj_neighbors_assertions);
|
246
|
+
}
|
247
|
+
|
248
|
+
TEST(localIjToH3_kRing) {
|
249
|
+
iterateAllIndexesAtRes(0, localIjToH3_kRing_assertions);
|
250
|
+
iterateAllIndexesAtRes(1, localIjToH3_kRing_assertions);
|
251
|
+
iterateAllIndexesAtRes(2, localIjToH3_kRing_assertions);
|
252
|
+
// Don't iterate all of res 3, to save time
|
253
|
+
iterateAllIndexesAtResPartial(3, localIjToH3_kRing_assertions, 27);
|
254
|
+
// Further resolutions aren't tested to save time.
|
255
|
+
}
|
256
|
+
|
257
|
+
TEST(localIjToH3_traverse) {
|
258
|
+
iterateAllIndexesAtRes(0, localIjToH3_traverse_assertions);
|
259
|
+
iterateAllIndexesAtRes(1, localIjToH3_traverse_assertions);
|
260
|
+
iterateAllIndexesAtRes(2, localIjToH3_traverse_assertions);
|
261
|
+
// Don't iterate all of res 3, to save time
|
262
|
+
iterateAllIndexesAtResPartial(3, localIjToH3_traverse_assertions, 27);
|
263
|
+
// Further resolutions aren't tested to save time.
|
264
|
+
}
|
265
|
+
}
|
@@ -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.
|
@@ -20,10 +20,12 @@
|
|
20
20
|
*/
|
21
21
|
|
22
22
|
#include <stdlib.h>
|
23
|
+
|
23
24
|
#include "constants.h"
|
24
25
|
#include "geoCoord.h"
|
25
26
|
#include "h3Index.h"
|
26
27
|
#include "test.h"
|
28
|
+
#include "utility.h"
|
27
29
|
|
28
30
|
// Fixtures
|
29
31
|
static GeoCoord sfGeo = {0.659966917655, -2.1364398519396};
|
@@ -123,13 +125,31 @@ SUITE(h3UniEdge) {
|
|
123
125
|
}
|
124
126
|
|
125
127
|
TEST(getH3UnidirectionalEdgeFromPentagon) {
|
128
|
+
H3Index pentagons[NUM_PENTAGONS] = {0};
|
129
|
+
H3Index ring[7] = {0};
|
126
130
|
H3Index pentagon;
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
H3Index edge;
|
132
|
+
|
133
|
+
for (int res = 0; res < MAX_H3_RES; res++) {
|
134
|
+
H3_EXPORT(getPentagonIndexes)(res, pentagons);
|
135
|
+
for (int p = 0; p < NUM_PENTAGONS; p++) {
|
136
|
+
pentagon = pentagons[p];
|
137
|
+
H3_EXPORT(kRing)(pentagon, 1, ring);
|
138
|
+
|
139
|
+
for (int i = 0; i < 7; i++) {
|
140
|
+
H3Index neighbor = ring[i];
|
141
|
+
if (neighbor == pentagon || neighbor == H3_NULL) continue;
|
142
|
+
edge =
|
143
|
+
H3_EXPORT(getH3UnidirectionalEdge)(pentagon, neighbor);
|
144
|
+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edge),
|
145
|
+
"pentagon-to-neighbor is a valid edge");
|
146
|
+
edge =
|
147
|
+
H3_EXPORT(getH3UnidirectionalEdge)(neighbor, pentagon);
|
148
|
+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edge),
|
149
|
+
"neighbor-to-pentagon is a valid edge");
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
133
153
|
}
|
134
154
|
|
135
155
|
TEST(h3UnidirectionalEdgeIsValid) {
|
@@ -166,6 +186,11 @@ SUITE(h3UniEdge) {
|
|
166
186
|
H3_SET_RESERVED_BITS(badPentagonalEdge, 1);
|
167
187
|
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(badPentagonalEdge) == 0,
|
168
188
|
"missing pentagonal edge does not validate");
|
189
|
+
|
190
|
+
H3Index highBitEdge = edge;
|
191
|
+
H3_SET_HIGH_BIT(highBitEdge, 1);
|
192
|
+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(highBitEdge) == 0,
|
193
|
+
"high bit set edge does not validate");
|
169
194
|
}
|
170
195
|
|
171
196
|
TEST(getH3UnidirectionalEdgesFromHexagon) {
|
@@ -222,9 +247,7 @@ SUITE(h3UniEdge) {
|
|
222
247
|
const int expectedVertices[][2] = {{3, 4}, {1, 2}, {2, 3},
|
223
248
|
{5, 0}, {4, 5}, {0, 1}};
|
224
249
|
|
225
|
-
|
226
|
-
// fails on resolutions finer than 12
|
227
|
-
for (int res = 0; res < 13; res++) {
|
250
|
+
for (int res = 0; res < MAX_H3_RES; res++) {
|
228
251
|
sf = H3_EXPORT(geoToH3)(&sfGeo, res);
|
229
252
|
H3_EXPORT(h3ToGeoBoundary)(sf, &boundary);
|
230
253
|
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(sf, edges);
|
@@ -253,9 +276,7 @@ SUITE(h3UniEdge) {
|
|
253
276
|
const int expectedVertices[][3] = {{-1, -1, -1}, {2, 3, 4}, {4, 5, 6},
|
254
277
|
{8, 9, 0}, {6, 7, 8}, {0, 1, 2}};
|
255
278
|
|
256
|
-
|
257
|
-
// fails on resolutions finer than 12
|
258
|
-
for (int res = 1; res < 13; res += 2) {
|
279
|
+
for (int res = 1; res < MAX_H3_RES; res += 2) {
|
259
280
|
setH3Index(&pentagon, res, 24, 0);
|
260
281
|
H3_EXPORT(h3ToGeoBoundary)(pentagon, &boundary);
|
261
282
|
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(pentagon, edges);
|
@@ -293,9 +314,7 @@ SUITE(h3UniEdge) {
|
|
293
314
|
const int expectedVertices[][3] = {{-1, -1}, {1, 2}, {2, 3},
|
294
315
|
{4, 0}, {3, 4}, {0, 1}};
|
295
316
|
|
296
|
-
|
297
|
-
// fails on resolutions finer than 12
|
298
|
-
for (int res = 0; res < 12; res += 2) {
|
317
|
+
for (int res = 0; res < MAX_H3_RES; res += 2) {
|
299
318
|
setH3Index(&pentagon, res, 24, 0);
|
300
319
|
H3_EXPORT(h3ToGeoBoundary)(pentagon, &boundary);
|
301
320
|
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(pentagon, edges);
|
@@ -323,4 +342,14 @@ SUITE(h3UniEdge) {
|
|
323
342
|
"Only one edge was deleted for the pentagon");
|
324
343
|
}
|
325
344
|
}
|
345
|
+
|
346
|
+
TEST(exactEdgeLength_invalid) {
|
347
|
+
// Test that invalid inputs do not cause crashes.
|
348
|
+
t_assert(H3_EXPORT(exactEdgeLengthRads)(0) == 0,
|
349
|
+
"Invalid edge has zero length");
|
350
|
+
GeoCoord zero = {0, 0};
|
351
|
+
H3Index h3 = H3_EXPORT(geoToH3)(&zero, 0);
|
352
|
+
t_assert(H3_EXPORT(exactEdgeLengthRads)(h3) == 0,
|
353
|
+
"Non-edge (cell) has zero edge length");
|
354
|
+
}
|
326
355
|
}
|
@@ -0,0 +1,111 @@
|
|
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
|
17
|
+
* @brief tests H3 unidirectional edge functions using tests over a large number
|
18
|
+
* of indexes.
|
19
|
+
*
|
20
|
+
* usage: `testH3UniEdgeExhaustive`
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include <stdio.h>
|
24
|
+
#include <stdlib.h>
|
25
|
+
#include <string.h>
|
26
|
+
|
27
|
+
#include "baseCells.h"
|
28
|
+
#include "constants.h"
|
29
|
+
#include "geoCoord.h"
|
30
|
+
#include "h3Index.h"
|
31
|
+
#include "test.h"
|
32
|
+
#include "utility.h"
|
33
|
+
|
34
|
+
static void h3UniEdge_correctness_assertions(H3Index h3) {
|
35
|
+
H3Index edges[6] = {H3_NULL};
|
36
|
+
int isPentagon = H3_EXPORT(h3IsPentagon)(h3);
|
37
|
+
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(h3, edges);
|
38
|
+
H3Index destination;
|
39
|
+
|
40
|
+
for (int i = 0; i < 6; i++) {
|
41
|
+
if (isPentagon && i == 0) {
|
42
|
+
t_assert(edges[i] == H3_NULL, "last pentagon edge is empty");
|
43
|
+
continue;
|
44
|
+
}
|
45
|
+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edges[i]) == 1,
|
46
|
+
"edge is an edge");
|
47
|
+
t_assert(
|
48
|
+
H3_EXPORT(getOriginH3IndexFromUnidirectionalEdge)(edges[i]) == h3,
|
49
|
+
"origin matches input origin");
|
50
|
+
|
51
|
+
destination =
|
52
|
+
H3_EXPORT(getDestinationH3IndexFromUnidirectionalEdge)(edges[i]);
|
53
|
+
t_assert(H3_EXPORT(h3IndexesAreNeighbors)(h3, destination),
|
54
|
+
"destination is a neighbor");
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
static void h3UniEdge_boundary_assertions(H3Index h3) {
|
59
|
+
H3Index edges[6] = {H3_NULL};
|
60
|
+
H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(h3, edges);
|
61
|
+
H3Index destination;
|
62
|
+
H3Index revEdge;
|
63
|
+
GeoBoundary edgeBoundary;
|
64
|
+
GeoBoundary revEdgeBoundary;
|
65
|
+
|
66
|
+
for (int i = 0; i < 6; i++) {
|
67
|
+
if (edges[i] == H3_NULL) continue;
|
68
|
+
H3_EXPORT(getH3UnidirectionalEdgeBoundary)(edges[i], &edgeBoundary);
|
69
|
+
destination =
|
70
|
+
H3_EXPORT(getDestinationH3IndexFromUnidirectionalEdge)(edges[i]);
|
71
|
+
revEdge = H3_EXPORT(getH3UnidirectionalEdge)(destination, h3);
|
72
|
+
H3_EXPORT(getH3UnidirectionalEdgeBoundary)(revEdge, &revEdgeBoundary);
|
73
|
+
|
74
|
+
t_assert(edgeBoundary.numVerts == revEdgeBoundary.numVerts,
|
75
|
+
"numVerts is equal for edge and reverse");
|
76
|
+
|
77
|
+
for (int j = 0; j < edgeBoundary.numVerts; j++) {
|
78
|
+
int almostEqual = geoAlmostEqualThreshold(
|
79
|
+
&edgeBoundary.verts[j],
|
80
|
+
&revEdgeBoundary.verts[revEdgeBoundary.numVerts - 1 - j],
|
81
|
+
0.000001);
|
82
|
+
t_assert(almostEqual, "Got expected vertex");
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
SUITE(h3UniEdge) {
|
88
|
+
TEST(h3UniEdge_correctness) {
|
89
|
+
iterateAllIndexesAtRes(0, h3UniEdge_correctness_assertions);
|
90
|
+
iterateAllIndexesAtRes(1, h3UniEdge_correctness_assertions);
|
91
|
+
iterateAllIndexesAtRes(2, h3UniEdge_correctness_assertions);
|
92
|
+
iterateAllIndexesAtRes(3, h3UniEdge_correctness_assertions);
|
93
|
+
iterateAllIndexesAtRes(4, h3UniEdge_correctness_assertions);
|
94
|
+
}
|
95
|
+
|
96
|
+
TEST(h3UniEdge_boundary) {
|
97
|
+
iterateAllIndexesAtRes(0, h3UniEdge_boundary_assertions);
|
98
|
+
iterateAllIndexesAtRes(1, h3UniEdge_boundary_assertions);
|
99
|
+
iterateAllIndexesAtRes(2, h3UniEdge_boundary_assertions);
|
100
|
+
iterateAllIndexesAtRes(3, h3UniEdge_boundary_assertions);
|
101
|
+
iterateAllIndexesAtRes(4, h3UniEdge_boundary_assertions);
|
102
|
+
// Res 5: normal base cell
|
103
|
+
iterateBaseCellIndexesAtRes(5, h3UniEdge_boundary_assertions, 0);
|
104
|
+
// Res 5: pentagon base cell
|
105
|
+
iterateBaseCellIndexesAtRes(5, h3UniEdge_boundary_assertions, 14);
|
106
|
+
// Res 5: polar pentagon base cell
|
107
|
+
iterateBaseCellIndexesAtRes(5, h3UniEdge_boundary_assertions, 117);
|
108
|
+
// Res 6: Test one pentagon just to check for new edge cases
|
109
|
+
iterateBaseCellIndexesAtRes(6, h3UniEdge_boundary_assertions, 14);
|
110
|
+
}
|
111
|
+
}
|