h3 3.6.2 → 3.7.1
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 +5 -5
- data/CHANGELOG.md +23 -0
- data/Gemfile.lock +6 -6
- data/README.md +1 -1
- 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 +16 -46
- data/ext/h3/src/CHANGELOG.md +43 -0
- data/ext/h3/src/CMakeLists.txt +133 -33
- data/ext/h3/src/CONTRIBUTING.md +1 -1
- data/ext/h3/src/README.md +60 -10
- 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 +7 -1
- 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 +75 -0
- data/ext/h3/src/src/apps/testapps/testCoordIj.c +1 -0
- data/ext/h3/src/src/apps/testapps/testGeoCoord.c +40 -13
- 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 +9 -5
- 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 +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 +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 +1 -0
- 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 +300 -75
- data/ext/h3/src/src/h3lib/lib/baseCells.c +26 -4
- data/ext/h3/src/src/h3lib/lib/bbox.c +56 -31
- 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 +81 -43
- 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/lib/h3/bindings/private.rb +3 -0
- data/lib/h3/miscellaneous.rb +123 -0
- data/lib/h3/version.rb +1 -1
- data/spec/miscellaneous_spec.rb +117 -0
- data/spec/regions_spec.rb +1 -1
- metadata +35 -14
- data/ext/h3/src/.ycm_extra_conf.py +0 -92
- data/ext/h3/src/appveyor.yml +0 -50
- data/ext/h3/src/src/apps/testapps/testPolyfill_GH136.c +0 -58
- 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
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017-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 <stdlib.h>
|
|
18
|
+
|
|
19
|
+
#include "algos.h"
|
|
20
|
+
#include "constants.h"
|
|
21
|
+
#include "geoCoord.h"
|
|
22
|
+
#include "h3Index.h"
|
|
23
|
+
#include "test.h"
|
|
24
|
+
#include "utility.h"
|
|
25
|
+
|
|
26
|
+
// Tests for specific polyfill examples
|
|
27
|
+
|
|
28
|
+
SUITE(polyfill_reported) {
|
|
29
|
+
// https://github.com/uber/h3-js/issues/76#issuecomment-561204505
|
|
30
|
+
TEST(entireWorld) {
|
|
31
|
+
// TODO: Fails for a single worldwide polygon
|
|
32
|
+
GeoCoord worldVerts[] = {
|
|
33
|
+
{-M_PI_2, -M_PI}, {M_PI_2, -M_PI}, {M_PI_2, 0}, {-M_PI_2, 0}};
|
|
34
|
+
Geofence worldGeofence = {.numVerts = 4, .verts = worldVerts};
|
|
35
|
+
GeoPolygon worldGeoPolygon = {.geofence = worldGeofence, .numHoles = 0};
|
|
36
|
+
GeoCoord worldVerts2[] = {
|
|
37
|
+
{-M_PI_2, 0}, {M_PI_2, 0}, {M_PI_2, M_PI}, {-M_PI_2, M_PI}};
|
|
38
|
+
Geofence worldGeofence2 = {.numVerts = 4, .verts = worldVerts2};
|
|
39
|
+
GeoPolygon worldGeoPolygon2 = {.geofence = worldGeofence2,
|
|
40
|
+
.numHoles = 0};
|
|
41
|
+
|
|
42
|
+
for (int res = 0; res < 3; res++) {
|
|
43
|
+
int polyfillSize =
|
|
44
|
+
H3_EXPORT(maxPolyfillSize)(&worldGeoPolygon, res);
|
|
45
|
+
H3Index* polyfillOut = calloc(polyfillSize, sizeof(H3Index));
|
|
46
|
+
|
|
47
|
+
H3_EXPORT(polyfill)(&worldGeoPolygon, res, polyfillOut);
|
|
48
|
+
int actualNumHexagons =
|
|
49
|
+
countActualHexagons(polyfillOut, polyfillSize);
|
|
50
|
+
|
|
51
|
+
int polyfillSize2 =
|
|
52
|
+
H3_EXPORT(maxPolyfillSize)(&worldGeoPolygon2, res);
|
|
53
|
+
H3Index* polyfillOut2 = calloc(polyfillSize2, sizeof(H3Index));
|
|
54
|
+
|
|
55
|
+
H3_EXPORT(polyfill)(&worldGeoPolygon2, res, polyfillOut2);
|
|
56
|
+
int actualNumHexagons2 =
|
|
57
|
+
countActualHexagons(polyfillOut2, polyfillSize2);
|
|
58
|
+
|
|
59
|
+
t_assert(actualNumHexagons + actualNumHexagons2 ==
|
|
60
|
+
H3_EXPORT(numHexagons)(res),
|
|
61
|
+
"got expected polyfill size (entire world)");
|
|
62
|
+
|
|
63
|
+
// Sets should be disjoint
|
|
64
|
+
for (int i = 0; i < polyfillSize; i++) {
|
|
65
|
+
if (polyfillOut[i] == 0) continue;
|
|
66
|
+
|
|
67
|
+
bool found = false;
|
|
68
|
+
for (int j = 0; j < polyfillSize2; j++) {
|
|
69
|
+
if (polyfillOut[i] == polyfillOut2[j]) {
|
|
70
|
+
found = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
t_assert(!found,
|
|
75
|
+
"Index found more than once when polyfilling the "
|
|
76
|
+
"entire world");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
free(polyfillOut);
|
|
80
|
+
free(polyfillOut2);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// https://github.com/uber/h3-js/issues/67
|
|
85
|
+
TEST(h3js_67) {
|
|
86
|
+
double east = H3_EXPORT(degsToRads)(-56.25);
|
|
87
|
+
double north = H3_EXPORT(degsToRads)(-33.13755119234615);
|
|
88
|
+
double south = H3_EXPORT(degsToRads)(-34.30714385628804);
|
|
89
|
+
double west = H3_EXPORT(degsToRads)(-57.65625);
|
|
90
|
+
|
|
91
|
+
GeoCoord testVerts[] = {
|
|
92
|
+
{north, east}, {south, east}, {south, west}, {north, west}};
|
|
93
|
+
Geofence testGeofence = {.numVerts = 4, .verts = testVerts};
|
|
94
|
+
GeoPolygon testPolygon;
|
|
95
|
+
testPolygon.geofence = testGeofence;
|
|
96
|
+
testPolygon.numHoles = 0;
|
|
97
|
+
|
|
98
|
+
int res = 7;
|
|
99
|
+
int numHexagons = H3_EXPORT(maxPolyfillSize)(&testPolygon, res);
|
|
100
|
+
H3Index* hexagons = calloc(numHexagons, sizeof(H3Index));
|
|
101
|
+
|
|
102
|
+
H3_EXPORT(polyfill)(&testPolygon, res, hexagons);
|
|
103
|
+
int actualNumHexagons = countActualHexagons(hexagons, numHexagons);
|
|
104
|
+
|
|
105
|
+
t_assert(actualNumHexagons == 4499,
|
|
106
|
+
"got expected polyfill size (h3-js#67)");
|
|
107
|
+
free(hexagons);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 2nd test case from h3-js#67
|
|
111
|
+
TEST(h3js_67_2nd) {
|
|
112
|
+
double east = H3_EXPORT(degsToRads)(-57.65625);
|
|
113
|
+
double north = H3_EXPORT(degsToRads)(-34.30714385628804);
|
|
114
|
+
double south = H3_EXPORT(degsToRads)(-35.4606699514953);
|
|
115
|
+
double west = H3_EXPORT(degsToRads)(-59.0625);
|
|
116
|
+
|
|
117
|
+
GeoCoord testVerts[] = {
|
|
118
|
+
{north, east}, {south, east}, {south, west}, {north, west}};
|
|
119
|
+
Geofence testGeofence = {.numVerts = 4, .verts = testVerts};
|
|
120
|
+
GeoPolygon testPolygon;
|
|
121
|
+
testPolygon.geofence = testGeofence;
|
|
122
|
+
testPolygon.numHoles = 0;
|
|
123
|
+
|
|
124
|
+
int res = 7;
|
|
125
|
+
int numHexagons = H3_EXPORT(maxPolyfillSize)(&testPolygon, res);
|
|
126
|
+
H3Index* hexagons = calloc(numHexagons, sizeof(H3Index));
|
|
127
|
+
|
|
128
|
+
H3_EXPORT(polyfill)(&testPolygon, res, hexagons);
|
|
129
|
+
int actualNumHexagons = countActualHexagons(hexagons, numHexagons);
|
|
130
|
+
|
|
131
|
+
t_assert(actualNumHexagons == 4609,
|
|
132
|
+
"got expected polyfill size (h3-js#67, 2nd case)");
|
|
133
|
+
free(hexagons);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// https://github.com/uber/h3/issues/136
|
|
137
|
+
TEST(h3_136) {
|
|
138
|
+
GeoCoord testVerts[] = {{0.10068990369902957, 0.8920772174196191},
|
|
139
|
+
{0.10032914690616246, 0.8915914753447348},
|
|
140
|
+
{0.10033349237998787, 0.8915860128746426},
|
|
141
|
+
{0.10069496685903621, 0.8920742194546231}};
|
|
142
|
+
Geofence testGeofence = {.numVerts = 4, .verts = testVerts};
|
|
143
|
+
GeoPolygon testPolygon;
|
|
144
|
+
testPolygon.geofence = testGeofence;
|
|
145
|
+
testPolygon.numHoles = 0;
|
|
146
|
+
|
|
147
|
+
int res = 13;
|
|
148
|
+
int numHexagons = H3_EXPORT(maxPolyfillSize)(&testPolygon, res);
|
|
149
|
+
H3Index* hexagons = calloc(numHexagons, sizeof(H3Index));
|
|
150
|
+
|
|
151
|
+
H3_EXPORT(polyfill)(&testPolygon, res, hexagons);
|
|
152
|
+
int actualNumHexagons = countActualHexagons(hexagons, numHexagons);
|
|
153
|
+
|
|
154
|
+
t_assert(actualNumHexagons == 4353, "got expected polyfill size");
|
|
155
|
+
free(hexagons);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 vertex functions.
|
|
18
|
+
*
|
|
19
|
+
* usage: `testVertex`
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "test.h"
|
|
23
|
+
#include "utility.h"
|
|
24
|
+
#include "vertex.h"
|
|
25
|
+
|
|
26
|
+
SUITE(Vertex) {
|
|
27
|
+
TEST(vertexNumForDirection_hex) {
|
|
28
|
+
H3Index origin = 0x823d6ffffffffff;
|
|
29
|
+
int vertexNums[NUM_HEX_VERTS] = {0};
|
|
30
|
+
for (Direction dir = K_AXES_DIGIT; dir < NUM_DIGITS; dir++) {
|
|
31
|
+
int vertexNum = vertexNumForDirection(origin, dir);
|
|
32
|
+
t_assert(vertexNum >= 0 && vertexNum < NUM_HEX_VERTS,
|
|
33
|
+
"vertex number appears valid");
|
|
34
|
+
t_assert(!vertexNums[vertexNum], "vertex number appears only once");
|
|
35
|
+
vertexNums[vertexNum] = 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
TEST(vertexNumForDirection_pent) {
|
|
40
|
+
H3Index pentagon = 0x823007fffffffff;
|
|
41
|
+
int vertexNums[NUM_PENT_VERTS] = {0};
|
|
42
|
+
for (Direction dir = J_AXES_DIGIT; dir < NUM_DIGITS; dir++) {
|
|
43
|
+
int vertexNum = vertexNumForDirection(pentagon, dir);
|
|
44
|
+
t_assert(vertexNum >= 0 && vertexNum < NUM_PENT_VERTS,
|
|
45
|
+
"vertex number appears valid");
|
|
46
|
+
t_assert(!vertexNums[vertexNum], "vertex number appears only once");
|
|
47
|
+
vertexNums[vertexNum] = 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
TEST(vertexNumForDirection_badDirections) {
|
|
52
|
+
H3Index origin = 0x823007fffffffff;
|
|
53
|
+
|
|
54
|
+
t_assert(
|
|
55
|
+
vertexNumForDirection(origin, CENTER_DIGIT) == INVALID_VERTEX_NUM,
|
|
56
|
+
"center digit should return invalid vertex");
|
|
57
|
+
t_assert(
|
|
58
|
+
vertexNumForDirection(origin, INVALID_DIGIT) == INVALID_VERTEX_NUM,
|
|
59
|
+
"invalid digit should return invalid vertex");
|
|
60
|
+
|
|
61
|
+
H3Index pentagon = 0x823007fffffffff;
|
|
62
|
+
t_assert(
|
|
63
|
+
vertexNumForDirection(pentagon, K_AXES_DIGIT) == INVALID_VERTEX_NUM,
|
|
64
|
+
"K direction on pentagon should return invalid vertex");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -40,4 +40,12 @@ void h3SetToVertexGraph(const H3Index* h3Set, const int numHexes,
|
|
|
40
40
|
// Create a LinkedGeoPolygon from a vertex graph
|
|
41
41
|
void _vertexGraphToLinkedGeo(VertexGraph* graph, LinkedGeoPolygon* out);
|
|
42
42
|
|
|
43
|
+
// Internal function for polyfill that traces a geofence with hexagons of a
|
|
44
|
+
// specific size
|
|
45
|
+
int _getEdgeHexagons(const Geofence* geofence, int numHexagons, int res,
|
|
46
|
+
int* numSearchHexes, H3Index* search, H3Index* found);
|
|
47
|
+
|
|
48
|
+
// The polyfill algorithm. Separated out because it can theoretically fail
|
|
49
|
+
int _polyfillInternal(const GeoPolygon* geoPolygon, int res, H3Index* out);
|
|
50
|
+
|
|
43
51
|
#endif
|
|
@@ -0,0 +1,40 @@
|
|
|
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 alloc.h
|
|
17
|
+
* @brief Memory management functions
|
|
18
|
+
*
|
|
19
|
+
* This file contains macros and the necessary declarations to be able
|
|
20
|
+
* to point H3 at different memory management functions than the standard
|
|
21
|
+
* malloc/free/etc functions.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#ifndef ALLOC_H
|
|
25
|
+
#define ALLOC_H
|
|
26
|
+
|
|
27
|
+
#include "h3api.h" // for TJOIN
|
|
28
|
+
|
|
29
|
+
#ifdef H3_ALLOC_PREFIX
|
|
30
|
+
#define H3_MEMORY(name) TJOIN(H3_ALLOC_PREFIX, name)
|
|
31
|
+
|
|
32
|
+
void* H3_MEMORY(malloc)(size_t size);
|
|
33
|
+
void* H3_MEMORY(calloc)(size_t num, size_t size);
|
|
34
|
+
void* H3_MEMORY(realloc)(void* ptr, size_t size);
|
|
35
|
+
void H3_MEMORY(free)(void* ptr);
|
|
36
|
+
#else
|
|
37
|
+
#define H3_MEMORY(name) name
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#endif
|
|
@@ -45,11 +45,15 @@ extern const BaseCellData baseCellData[NUM_BASE_CELLS];
|
|
|
45
45
|
/** Maximum input for any component to face-to-base-cell lookup functions */
|
|
46
46
|
#define MAX_FACE_COORD 2
|
|
47
47
|
|
|
48
|
+
/** Invalid number of rotations */
|
|
49
|
+
#define INVALID_ROTATIONS -1
|
|
50
|
+
|
|
48
51
|
// Internal functions
|
|
49
52
|
int _isBaseCellPentagon(int baseCell);
|
|
50
53
|
bool _isBaseCellPolarPentagon(int baseCell);
|
|
51
54
|
int _faceIjkToBaseCell(const FaceIJK* h);
|
|
52
55
|
int _faceIjkToBaseCellCCWrot60(const FaceIJK* h);
|
|
56
|
+
int _baseCellToCCWrot60(int baseCell, int face);
|
|
53
57
|
void _baseCellToFaceIjk(int baseCell, FaceIJK* h);
|
|
54
58
|
bool _baseCellIsCwOffset(int baseCell, int testFace);
|
|
55
59
|
int _getBaseCellNeighbor(int baseCell, Direction dir);
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
#define BBOX_H
|
|
22
22
|
|
|
23
23
|
#include <stdbool.h>
|
|
24
|
+
|
|
24
25
|
#include "geoCoord.h"
|
|
25
26
|
|
|
26
27
|
/** @struct BBox
|
|
@@ -37,6 +38,8 @@ bool bboxIsTransmeridian(const BBox* bbox);
|
|
|
37
38
|
void bboxCenter(const BBox* bbox, GeoCoord* center);
|
|
38
39
|
bool bboxContains(const BBox* bbox, const GeoCoord* point);
|
|
39
40
|
bool bboxEquals(const BBox* b1, const BBox* b2);
|
|
40
|
-
int
|
|
41
|
+
int bboxHexEstimate(const BBox* bbox, int res);
|
|
42
|
+
int lineHexEstimate(const GeoCoord* origin, const GeoCoord* destination,
|
|
43
|
+
int res);
|
|
41
44
|
|
|
42
45
|
#endif
|
|
@@ -75,9 +75,10 @@ typedef enum {
|
|
|
75
75
|
void _geoToFaceIjk(const GeoCoord* g, int res, FaceIJK* h);
|
|
76
76
|
void _geoToHex2d(const GeoCoord* g, int res, int* face, Vec2d* v);
|
|
77
77
|
void _faceIjkToGeo(const FaceIJK* h, int res, GeoCoord* g);
|
|
78
|
-
void _faceIjkToGeoBoundary(const FaceIJK* h, int res, int
|
|
78
|
+
void _faceIjkToGeoBoundary(const FaceIJK* h, int res, int start, int length,
|
|
79
79
|
GeoBoundary* g);
|
|
80
|
-
void _faceIjkPentToGeoBoundary(const FaceIJK* h, int res,
|
|
80
|
+
void _faceIjkPentToGeoBoundary(const FaceIJK* h, int res, int start, int length,
|
|
81
|
+
GeoBoundary* g);
|
|
81
82
|
void _faceIjkToVerts(FaceIJK* fijk, int* res, FaceIJK* fijkVerts);
|
|
82
83
|
void _faceIjkPentToVerts(FaceIJK* fijk, int* res, FaceIJK* fijkVerts);
|
|
83
84
|
void _hex2dToGeo(const Vec2d* v, int face, int res, int substrate, GeoCoord* g);
|
|
@@ -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.
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
#include <stdbool.h>
|
|
24
24
|
#include <stdint.h>
|
|
25
25
|
#include <stdio.h>
|
|
26
|
+
|
|
26
27
|
#include "constants.h"
|
|
27
28
|
#include "h3api.h"
|
|
28
29
|
|
|
@@ -43,8 +44,6 @@ bool geoAlmostEqualThreshold(const GeoCoord* p1, const GeoCoord* p2,
|
|
|
43
44
|
|
|
44
45
|
double _posAngleRads(double rads);
|
|
45
46
|
void _setGeoRads(GeoCoord* p, double latRads, double lonRads);
|
|
46
|
-
double _geoDistRads(const GeoCoord* p1, const GeoCoord* p2);
|
|
47
|
-
double _geoDistKm(const GeoCoord* p1, const GeoCoord* p2);
|
|
48
47
|
double _geoAzimuthRads(const GeoCoord* p1, const GeoCoord* p2);
|
|
49
48
|
void _geoAzDistanceRads(const GeoCoord* p1, double az, double distance,
|
|
50
49
|
GeoCoord* p2);
|
|
@@ -46,6 +46,12 @@
|
|
|
46
46
|
/** The number of bits in a single H3 resolution digit. */
|
|
47
47
|
#define H3_PER_DIGIT_OFFSET 3
|
|
48
48
|
|
|
49
|
+
/** 1 in the highest bit, 0's everywhere else. */
|
|
50
|
+
#define H3_HIGH_BIT_MASK ((uint64_t)(1) << H3_MAX_OFFSET)
|
|
51
|
+
|
|
52
|
+
/** 0 in the highest bit, 1's everywhere else. */
|
|
53
|
+
#define H3_HIGH_BIT_MASK_NEGATIVE (~H3_HIGH_BIT_MASK)
|
|
54
|
+
|
|
49
55
|
/** 1's in the 4 mode bits, 0's everywhere else. */
|
|
50
56
|
#define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
|
|
51
57
|
|
|
@@ -74,11 +80,27 @@
|
|
|
74
80
|
#define H3_DIGIT_MASK ((uint64_t)(7))
|
|
75
81
|
|
|
76
82
|
/** 0's in the 7 base cell bits, 1's everywhere else. */
|
|
77
|
-
#define H3_DIGIT_MASK_NEGATIVE (~
|
|
83
|
+
#define H3_DIGIT_MASK_NEGATIVE (~H3_DIGIT_MASK)
|
|
78
84
|
|
|
79
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* H3 index with mode 0, res 0, base cell 0, and 7 for all index digits.
|
|
87
|
+
* Typically used to initialize the creation of an H3 cell index, which
|
|
88
|
+
* expects all direction digits to be 7 beyond the cell's resolution.
|
|
89
|
+
*/
|
|
80
90
|
#define H3_INIT (UINT64_C(35184372088831))
|
|
81
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Gets the highest bit of the H3 index.
|
|
94
|
+
*/
|
|
95
|
+
#define H3_GET_HIGH_BIT(h3) ((int)((((h3)&H3_HIGH_BIT_MASK) >> H3_MAX_OFFSET)))
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sets the highest bit of the h3 to v.
|
|
99
|
+
*/
|
|
100
|
+
#define H3_SET_HIGH_BIT(h3, v) \
|
|
101
|
+
(h3) = (((h3)&H3_HIGH_BIT_MASK_NEGATIVE) | \
|
|
102
|
+
(((uint64_t)(v)) << H3_MAX_OFFSET))
|
|
103
|
+
|
|
82
104
|
/**
|
|
83
105
|
* Gets the integer mode of h3.
|
|
84
106
|
*/
|
|
@@ -143,9 +165,19 @@
|
|
|
143
165
|
<< ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
|
|
144
166
|
|
|
145
167
|
/**
|
|
146
|
-
* Invalid index used to indicate an error from geoToH3 and related functions
|
|
168
|
+
* Invalid index used to indicate an error from geoToH3 and related functions
|
|
169
|
+
* or missing data in arrays of h3 indices. Analogous to NaN in floating point.
|
|
147
170
|
*/
|
|
148
|
-
#define
|
|
171
|
+
#define H3_NULL 0
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
* Return codes for compact
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
#define COMPACT_SUCCESS 0
|
|
178
|
+
#define COMPACT_LOOP_EXCEEDED -1
|
|
179
|
+
#define COMPACT_DUPLICATE -2
|
|
180
|
+
#define COMPACT_ALLOC_FAILED -3
|
|
149
181
|
|
|
150
182
|
void setH3Index(H3Index* h, int res, int baseCell, Direction initDigit);
|
|
151
183
|
int isResClassIII(int res);
|
|
@@ -153,6 +185,7 @@ int isResClassIII(int res);
|
|
|
153
185
|
// Internal functions
|
|
154
186
|
|
|
155
187
|
int _h3ToFaceIjkWithInitializedFijk(H3Index h, FaceIJK* fijk);
|
|
188
|
+
void _h3ToFaceIjk(H3Index h, FaceIJK* fijk);
|
|
156
189
|
H3Index _faceIjkToH3(const FaceIJK* fijk, int res);
|
|
157
190
|
Direction _h3LeadingNonZeroDigit(H3Index h);
|
|
158
191
|
H3Index _h3RotatePent60ccw(H3Index h);
|