h3 3.4.0 → 3.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/ext/h3/src/.travis.yml +5 -0
  4. data/ext/h3/src/CHANGELOG.md +25 -0
  5. data/ext/h3/src/CMakeLists.txt +5 -8
  6. data/ext/h3/src/CONTRIBUTING.md +2 -0
  7. data/ext/h3/src/README.md +6 -2
  8. data/ext/h3/src/VERSION +1 -1
  9. data/ext/h3/src/appveyor.yml +6 -1
  10. data/ext/h3/src/docs/api/misc.md +16 -0
  11. data/ext/h3/src/docs/community/bindings.md +9 -0
  12. data/ext/h3/src/docs/community/tutorials.md +4 -0
  13. data/ext/h3/src/scripts/binding_functions.ps1 +1 -2
  14. data/ext/h3/src/scripts/binding_functions.sh +3 -2
  15. data/ext/h3/src/scripts/coverage.sh.in +3 -3
  16. data/ext/h3/src/src/apps/applib/include/utility.h +60 -0
  17. data/ext/h3/src/src/apps/applib/lib/utility.c +196 -2
  18. data/ext/h3/src/src/apps/benchmarks/benchmarkPolyfill.c +7 -4
  19. data/ext/h3/src/src/apps/filters/geoToH3.c +73 -27
  20. data/ext/h3/src/src/apps/filters/h3ToGeo.c +63 -47
  21. data/ext/h3/src/src/apps/filters/h3ToGeoBoundary.c +64 -48
  22. data/ext/h3/src/src/apps/filters/h3ToLocalIj.c +4 -5
  23. data/ext/h3/src/src/apps/filters/hexRange.c +0 -1
  24. data/ext/h3/src/src/apps/filters/kRing.c +60 -28
  25. data/ext/h3/src/src/apps/filters/localIjToH3.c +75 -0
  26. data/ext/h3/src/src/apps/miscapps/generateBaseCellNeighbors.c +2 -2
  27. data/ext/h3/src/src/apps/testapps/testBBox.c +18 -0
  28. data/ext/h3/src/src/apps/testapps/testCompact.c +41 -0
  29. data/ext/h3/src/src/apps/testapps/testCoordIj.c +0 -1
  30. data/ext/h3/src/src/apps/testapps/testCoordIjk.c +53 -0
  31. data/ext/h3/src/src/apps/testapps/testH3Api.c +20 -0
  32. data/ext/h3/src/src/apps/testapps/testH3Distance.c +5 -3
  33. data/ext/h3/src/src/apps/testapps/testH3Line.c +18 -6
  34. data/ext/h3/src/src/apps/testapps/testH3ToLocalIj.c +75 -3
  35. data/ext/h3/src/src/apps/testapps/testH3UniEdge.c +17 -11
  36. data/ext/h3/src/src/apps/testapps/testHexRanges.c +10 -0
  37. data/ext/h3/src/src/apps/testapps/testKRing.c +11 -7
  38. data/ext/h3/src/src/h3lib/lib/algos.c +2 -1
  39. data/ext/h3/src/src/h3lib/lib/geoCoord.c +10 -10
  40. data/ext/h3/src/src/h3lib/lib/h3Index.c +1 -2
  41. data/ext/h3/src/src/h3lib/lib/localij.c +32 -36
  42. data/lib/h3/version.rb +1 -1
  43. metadata +4 -7
  44. data/ext/h3/src/cmake/CheckAlloca.cmake +0 -33
  45. data/ext/h3/src/cmake/CheckVLA.cmake +0 -33
  46. data/ext/h3/src/cmake/alloca_test.c +0 -29
  47. data/ext/h3/src/cmake/vla_test.c +0 -26
  48. data/ext/h3/src/src/h3lib/include/stackAlloc.h +0 -64
@@ -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.
@@ -20,15 +20,14 @@
20
20
  * usage: `h3ToLocalIj [origin]`
21
21
  *
22
22
  * The program reads H3 indexes from stdin and outputs the corresponding
23
- * IJ coordinates to stdout, until EOF is encountered. The H3 indexes
24
- * should be in integer form. `NA` is printed if the IJ coordinates
25
- * could not be obtained.
23
+ * IJ coordinates to stdout, until EOF is encountered. `NA` is printed if the
24
+ * IJ coordinates could not be obtained.
26
25
  *
27
26
  * `origin` indicates the origin (or anchoring) index for the IJ coordinate
28
27
  * space.
29
28
  *
30
29
  * This program has the same limitations as the `experimentalH3ToLocalIj`
31
- * function.
30
+ * function.
32
31
  */
33
32
 
34
33
  #include <inttypes.h>
@@ -32,7 +32,6 @@
32
32
  #include <stdlib.h>
33
33
  #include "algos.h"
34
34
  #include "h3Index.h"
35
- #include "stackAlloc.h"
36
35
  #include "utility.h"
37
36
 
38
37
  void doCell(H3Index h, int k) {
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2016-2017 Uber Technologies, Inc.
2
+ * Copyright 2016-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.
@@ -17,57 +17,89 @@
17
17
  * @brief stdin/stdout filter that converts from integer H3 indexes to
18
18
  * k-rings
19
19
  *
20
- * usage: `kRing [k]`
20
+ * usage: `kRing -k <k> [--print-distances] [--origin origin]`
21
21
  *
22
22
  * The program reads H3 indexes from stdin until EOF and outputs
23
23
  * the H3 indexes within k-ring `k` to stdout.
24
+ *
25
+ * --print-distances may be specified to also print the grid distance
26
+ * from the origin index.
24
27
  */
25
28
 
29
+ #include <inttypes.h>
30
+ #include <stdbool.h>
26
31
  #include <stdio.h>
27
32
  #include <stdlib.h>
28
- #include "algos.h"
29
- #include "h3Index.h"
30
- #include "stackAlloc.h"
33
+ #include "h3api.h"
31
34
  #include "utility.h"
32
35
 
33
- void doCell(H3Index h, int k) {
36
+ void doCell(H3Index h, int k, int printDistances) {
34
37
  int maxSize = H3_EXPORT(maxKringSize)(k);
35
38
  H3Index* rings = calloc(maxSize, sizeof(H3Index));
36
- H3_EXPORT(kRing)(h, k, rings);
39
+ int* distances = calloc(maxSize, sizeof(int));
40
+ H3_EXPORT(kRingDistances)(h, k, rings, distances);
37
41
 
38
42
  for (int i = 0; i < maxSize; i++) {
39
43
  if (rings[i] != 0) {
40
- h3Println(rings[i]);
44
+ h3Print(rings[i]);
45
+ if (printDistances) {
46
+ printf(" %d\n", distances[i]);
47
+ } else {
48
+ printf("\n");
49
+ }
41
50
  }
42
51
  }
43
52
 
53
+ free(distances);
44
54
  free(rings);
45
55
  }
46
56
 
47
57
  int main(int argc, char* argv[]) {
48
- // check command line args
49
- if (argc != 2) {
50
- fprintf(stderr, "usage: %s [k]\n", argv[0]);
51
- exit(1);
52
- }
53
-
54
58
  int k = 0;
55
- if (argc > 1) {
56
- if (!sscanf(argv[1], "%d", &k)) error("k must be an integer");
59
+ H3Index origin = 0;
60
+
61
+ Arg helpArg = {.names = {"-h", "--help"},
62
+ .helpText = "Show this help message."};
63
+ Arg kArg = {.names = {"-k", NULL},
64
+ .required = true,
65
+ .scanFormat = "%d",
66
+ .valueName = "k",
67
+ .value = &k,
68
+ .helpText = "Radius in hexagons."};
69
+ Arg printDistancesArg = {
70
+ .names = {"-d", "--print-distances"},
71
+ .helpText = "Print distance from origin after each index."};
72
+ Arg originArg = {
73
+ .names = {"-o", "--origin"},
74
+ .scanFormat = "%" PRIx64,
75
+ .valueName = "origin",
76
+ .value = &origin,
77
+ .helpText =
78
+ "Origin, or not specified to read origins from standard in."};
79
+
80
+ Arg* args[] = {&helpArg, &kArg, &printDistancesArg, &originArg};
81
+
82
+ if (parseArgs(argc, argv, 4, args, &helpArg,
83
+ "Print indexes k distance away from the origin")) {
84
+ return helpArg.found ? 0 : 1;
57
85
  }
58
86
 
59
- // process the indexes on stdin
60
- char buff[BUFF_SIZE];
61
- while (1) {
62
- // get an index from stdin
63
- if (!fgets(buff, BUFF_SIZE, stdin)) {
64
- if (feof(stdin))
65
- break;
66
- else
67
- error("reading H3 index from stdin");
68
- }
87
+ if (originArg.found) {
88
+ doCell(origin, k, printDistancesArg.found);
89
+ } else {
90
+ // process the indexes on stdin
91
+ char buff[BUFF_SIZE];
92
+ while (1) {
93
+ // get an index from stdin
94
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
95
+ if (feof(stdin))
96
+ break;
97
+ else
98
+ error("reading H3 index from stdin");
99
+ }
69
100
 
70
- H3Index h3 = H3_EXPORT(stringToH3)(buff);
71
- doCell(h3, k);
101
+ H3Index h3 = H3_EXPORT(stringToH3)(buff);
102
+ doCell(h3, k, printDistancesArg.found);
103
+ }
72
104
  }
73
105
  }
@@ -0,0 +1,75 @@
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 stdin/stdout filter that converts from local IJ coordinates to
18
+ * H3 indexes. This is experimental.
19
+ *
20
+ * usage: `localIjToH3 [origin]`
21
+ *
22
+ * The program reads IJ coordinates (in the format `i j` separated by newlines)
23
+ * from stdin and outputs the corresponding H3 indexes to stdout, until EOF is
24
+ * encountered. `NA` is printed if the H3 index could not be obtained.
25
+ *
26
+ * `origin` indicates the origin (or anchoring) index for the IJ coordinate
27
+ * space.
28
+ *
29
+ * This program has the same limitations as the `experimentalLocalIjToH3`
30
+ * function.
31
+ */
32
+
33
+ #include <inttypes.h>
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include "h3api.h"
37
+ #include "utility.h"
38
+
39
+ void doCell(const CoordIJ *ij, H3Index origin) {
40
+ H3Index h;
41
+ if (H3_EXPORT(experimentalLocalIjToH3)(origin, ij, &h)) {
42
+ printf("NA\n");
43
+ } else {
44
+ h3Println(h);
45
+ }
46
+ }
47
+
48
+ int main(int argc, char *argv[]) {
49
+ // check command line args
50
+ if (argc != 2) {
51
+ fprintf(stderr, "usage: %s [origin]\n", argv[0]);
52
+ exit(1);
53
+ }
54
+
55
+ H3Index origin = H3_EXPORT(stringToH3(argv[1]));
56
+ if (!H3_EXPORT(h3IsValid)(origin)) error("origin is invalid");
57
+
58
+ // process the coordinates on stdin
59
+ char buff[BUFF_SIZE];
60
+ while (1) {
61
+ // get coordinates from stdin
62
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
63
+ if (feof(stdin))
64
+ break;
65
+ else
66
+ error("reading IJ coordinates from stdin");
67
+ }
68
+
69
+ CoordIJ ij;
70
+ if (!sscanf(buff, "%d %d", &ij.i, &ij.j))
71
+ error("Parsing IJ coordinates. Expected `i j`.");
72
+
73
+ doCell(&ij, origin);
74
+ }
75
+ }
@@ -161,7 +161,7 @@ static void generate() {
161
161
  if (dir == K_AXES_DIGIT) {
162
162
  // 4 and 117 are 'polar' type pentagons, which have
163
163
  // some different behavior.
164
- if (i == 4 || i == 117) {
164
+ if (_isBaseCellPentagon(i)) {
165
165
  _ijkRotate60cw(&ijk);
166
166
  _ijkRotate60cw(&ijk);
167
167
  } else {
@@ -172,7 +172,7 @@ static void generate() {
172
172
 
173
173
  // Adjust for the deleted k-subsequence distortion
174
174
  int rotAdj = 0;
175
- if (i == 4 || i == 117) {
175
+ if (_isBaseCellPolarPentagon(i)) {
176
176
  // 'polar' type pentagon with all faces pointing
177
177
  // towards i
178
178
  if (dir == IK_AXES_DIGIT) {
@@ -219,4 +219,22 @@ SUITE(BBox) {
219
219
  t_assert(bboxIsTransmeridian(&bboxTransmeridian),
220
220
  "Transmeridian bbox is transmeridian");
221
221
  }
222
+
223
+ TEST(bboxEquals) {
224
+ BBox bbox = {1.0, 0.0, 1.0, 0.0};
225
+ BBox north = bbox;
226
+ north.north += 0.1;
227
+ BBox south = bbox;
228
+ south.south += 0.1;
229
+ BBox east = bbox;
230
+ east.east += 0.1;
231
+ BBox west = bbox;
232
+ west.west += 0.1;
233
+
234
+ t_assert(bboxEquals(&bbox, &bbox), "Equals self");
235
+ t_assert(!bboxEquals(&bbox, &north), "Not equals different north");
236
+ t_assert(!bboxEquals(&bbox, &south), "Not equals different south");
237
+ t_assert(!bboxEquals(&bbox, &east), "Not equals different east");
238
+ t_assert(!bboxEquals(&bbox, &west), "Not equals different west");
239
+ }
222
240
  }
@@ -23,6 +23,8 @@ H3Index sunnyvale = 0x89283470c27ffff;
23
23
 
24
24
  H3Index uncompactable[] = {0x89283470803ffff, 0x8928347081bffff,
25
25
  0x8928347080bffff};
26
+ H3Index uncompactableWithZero[] = {0x89283470803ffff, 0x8928347081bffff, 0,
27
+ 0x8928347080bffff};
26
28
 
27
29
  SUITE(compact) {
28
30
  TEST(roundtrip) {
@@ -207,6 +209,45 @@ SUITE(compact) {
207
209
  free(result);
208
210
  }
209
211
 
212
+ TEST(uncompact_onlyZero) {
213
+ // maxUncompactSize and uncompact both permit 0 indexes
214
+ // in the input array, and skip them. When only a zero is
215
+ // given, it's a no-op.
216
+
217
+ H3Index origin = 0;
218
+
219
+ int childrenSz = H3_EXPORT(maxUncompactSize)(&origin, 1, 2);
220
+ H3Index* children = calloc(childrenSz, sizeof(H3Index));
221
+ int uncompactResult =
222
+ H3_EXPORT(uncompact)(&origin, 1, children, childrenSz, 2);
223
+ t_assert(uncompactResult == 0, "uncompact only zero success");
224
+
225
+ free(children);
226
+ }
227
+
228
+ TEST(uncompactZero) {
229
+ // maxUncompactSize and uncompact both permit 0 indexes
230
+ // in the input array, and skip them.
231
+
232
+ int childrenSz =
233
+ H3_EXPORT(maxUncompactSize)(uncompactableWithZero, 4, 10);
234
+ H3Index* children = calloc(childrenSz, sizeof(H3Index));
235
+ int uncompactResult = H3_EXPORT(uncompact)(uncompactableWithZero, 4,
236
+ children, childrenSz, 10);
237
+ t_assert(uncompactResult == 0, "uncompact with zero succeeds");
238
+
239
+ int found = 0;
240
+ for (int i = 0; i < childrenSz; i++) {
241
+ if (children[i] != 0) {
242
+ found++;
243
+ }
244
+ }
245
+ t_assert(found == childrenSz,
246
+ "uncompacted with zero to expected number of hexagons");
247
+
248
+ free(children);
249
+ }
250
+
210
251
  TEST(pentagon) {
211
252
  H3Index pentagon;
212
253
  setH3Index(&pentagon, 1, 4, 0);
@@ -28,7 +28,6 @@
28
28
  #include "h3Index.h"
29
29
  #include "h3api.h"
30
30
  #include "localij.h"
31
- #include "stackAlloc.h"
32
31
  #include "test.h"
33
32
  #include "utility.h"
34
33
 
@@ -0,0 +1,53 @@
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 IJK grid functions
18
+ *
19
+ * usage: `testCoordIjk`
20
+ */
21
+
22
+ #include "coordijk.h"
23
+ #include "test.h"
24
+
25
+ SUITE(coordIjk) {
26
+ TEST(_unitIjkToDigit) {
27
+ CoordIJK zero = {0};
28
+ CoordIJK i = {1, 0, 0};
29
+ CoordIJK outOfRange = {2, 0, 0};
30
+ CoordIJK unnormalizedZero = {2, 2, 2};
31
+
32
+ t_assert(_unitIjkToDigit(&zero) == CENTER_DIGIT, "Unit IJK to zero");
33
+ t_assert(_unitIjkToDigit(&i) == I_AXES_DIGIT, "Unit IJK to I axis");
34
+ t_assert(_unitIjkToDigit(&outOfRange) == INVALID_DIGIT,
35
+ "Unit IJK out of range");
36
+ t_assert(_unitIjkToDigit(&unnormalizedZero) == CENTER_DIGIT,
37
+ "Unnormalized unit IJK to zero");
38
+ }
39
+
40
+ TEST(_neighbor) {
41
+ CoordIJK ijk = {0};
42
+
43
+ CoordIJK zero = {0};
44
+ CoordIJK i = {1, 0, 0};
45
+
46
+ _neighbor(&ijk, CENTER_DIGIT);
47
+ t_assert(_ijkMatches(&ijk, &zero), "Center neighbor is self");
48
+ _neighbor(&ijk, I_AXES_DIGIT);
49
+ t_assert(_ijkMatches(&ijk, &i), "I neighbor as expected");
50
+ _neighbor(&ijk, INVALID_DIGIT);
51
+ t_assert(_ijkMatches(&ijk, &i), "Invalid neighbor is self");
52
+ }
53
+ }
@@ -79,6 +79,26 @@ SUITE(h3Api) {
79
79
  t_assertBoundary(h3, &boundary);
80
80
  }
81
81
 
82
+ TEST(h3ToGeoBoundary_coslonConstrain) {
83
+ // Bug test for https://github.com/uber/h3/issues/212
84
+ H3Index h3 = 0x87dc6d364ffffffL;
85
+ GeoBoundary boundary;
86
+ boundary.numVerts = 6;
87
+ setGeoDegs(&boundary.verts[0], -52.0130533678236091,
88
+ -34.6232931343713091);
89
+ setGeoDegs(&boundary.verts[1], -52.0041156384652012,
90
+ -34.6096733160584549);
91
+ setGeoDegs(&boundary.verts[2], -51.9929610229502472,
92
+ -34.6165157145896387);
93
+ setGeoDegs(&boundary.verts[3], -51.9907410568096608,
94
+ -34.6369680004259877);
95
+ setGeoDegs(&boundary.verts[4], -51.9996738734672377,
96
+ -34.6505896528323660);
97
+ setGeoDegs(&boundary.verts[5], -52.0108315681413629,
98
+ -34.6437571897165668);
99
+ t_assertBoundary(h3, &boundary);
100
+ }
101
+
82
102
  TEST(version) {
83
103
  t_assert(H3_VERSION_MAJOR >= 0, "major version is set");
84
104
  t_assert(H3_VERSION_MINOR >= 0, "minor version is set");
@@ -28,7 +28,6 @@
28
28
  #include "h3Index.h"
29
29
  #include "h3api.h"
30
30
  #include "localij.h"
31
- #include "stackAlloc.h"
32
31
  #include "test.h"
33
32
  #include "utility.h"
34
33
 
@@ -44,8 +43,8 @@ static void h3Distance_kRing_assertions(H3Index h3) {
44
43
  int maxK = MAX_DISTANCES[r];
45
44
 
46
45
  int sz = H3_EXPORT(maxKringSize)(maxK);
47
- STACK_ARRAY_CALLOC(H3Index, neighbors, sz);
48
- STACK_ARRAY_CALLOC(int, distances, sz);
46
+ H3Index *neighbors = calloc(sz, sizeof(H3Index));
47
+ int *distances = calloc(sz, sizeof(int));
49
48
 
50
49
  H3_EXPORT(kRingDistances)(h3, maxK, neighbors, distances);
51
50
 
@@ -61,6 +60,9 @@ static void h3Distance_kRing_assertions(H3Index h3) {
61
60
  t_assert(calculatedDistance == distances[i] || calculatedDistance == -1,
62
61
  "kRingDistances matches h3Distance");
63
62
  }
63
+
64
+ free(distances);
65
+ free(neighbors);
64
66
  }
65
67
 
66
68
  SUITE(h3Distance) {