h3 3.4.4 → 3.5.0

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 +10 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +2 -1
  5. data/ext/h3/Makefile +1 -1
  6. data/ext/h3/src/.gitignore +2 -1
  7. data/ext/h3/src/CHANGELOG.md +9 -0
  8. data/ext/h3/src/CMakeLists.txt +72 -45
  9. data/ext/h3/src/RELEASE.md +2 -1
  10. data/ext/h3/src/VERSION +1 -1
  11. data/ext/h3/src/docs/api/hierarchy.md +2 -0
  12. data/ext/h3/src/docs/api/indexing.md +3 -1
  13. data/ext/h3/src/docs/api/inspection.md +20 -0
  14. data/ext/h3/src/docs/api/misc.md +2 -0
  15. data/ext/h3/src/docs/api/regions.md +2 -0
  16. data/ext/h3/src/docs/api/traversal.md +2 -0
  17. data/ext/h3/src/docs/api/uniedge.md +2 -0
  18. data/ext/h3/src/docs/community/bindings.md +4 -0
  19. data/ext/h3/src/docs/community/tutorials.md +12 -0
  20. data/ext/h3/src/scripts/update_version.sh +50 -0
  21. data/ext/h3/src/src/apps/applib/include/args.h +122 -0
  22. data/ext/h3/src/src/apps/applib/include/utility.h +5 -62
  23. data/ext/h3/src/src/apps/applib/lib/args.c +216 -0
  24. data/ext/h3/src/src/apps/applib/lib/utility.c +40 -206
  25. data/ext/h3/src/src/apps/filters/geoToH3.c +7 -9
  26. data/ext/h3/src/src/apps/filters/h3ToComponents.c +50 -47
  27. data/ext/h3/src/src/apps/filters/h3ToGeo.c +7 -30
  28. data/ext/h3/src/src/apps/filters/h3ToGeoBoundary.c +7 -27
  29. data/ext/h3/src/src/apps/filters/h3ToLocalIj.c +42 -25
  30. data/ext/h3/src/src/apps/filters/hexRange.c +43 -24
  31. data/ext/h3/src/src/apps/filters/kRing.c +4 -4
  32. data/ext/h3/src/src/apps/filters/localIjToH3.c +63 -21
  33. data/ext/h3/src/src/apps/miscapps/h3ToGeoBoundaryHier.c +68 -44
  34. data/ext/h3/src/src/apps/miscapps/h3ToGeoHier.c +68 -43
  35. data/ext/h3/src/src/apps/miscapps/h3ToHier.c +48 -37
  36. data/ext/h3/src/src/apps/testapps/mkRandGeo.c +32 -27
  37. data/ext/h3/src/src/apps/testapps/mkRandGeoBoundary.c +33 -28
  38. data/ext/h3/src/src/apps/testapps/testH3GetFaces.c +136 -0
  39. data/ext/h3/src/src/h3lib/include/faceijk.h +19 -7
  40. data/ext/h3/src/src/h3lib/include/h3api.h.in +12 -1
  41. data/ext/h3/src/src/h3lib/lib/algos.c +7 -2
  42. data/ext/h3/src/src/h3lib/lib/faceijk.c +135 -103
  43. data/ext/h3/src/src/h3lib/lib/h3Index.c +86 -5
  44. data/lib/h3/bindings/private.rb +1 -0
  45. data/lib/h3/inspection.rb +34 -0
  46. data/lib/h3/version.rb +1 -1
  47. data/spec/inspection_spec.rb +33 -1
  48. metadata +6 -2
@@ -17,7 +17,7 @@
17
17
  * @brief stdin/stdout filter that converts from lat/lon coordinates to integer
18
18
  * H3 indexes
19
19
  *
20
- * usage: `geoToH3 --resolution res [--latitude lat --longitude lon]`
20
+ * See `geoToH3 --help` for usage.
21
21
  *
22
22
  * The program reads lat/lon pairs from stdin until EOF is encountered. For
23
23
  * each lat/lon the program outputs to stdout the integer H3 index of the
@@ -32,8 +32,7 @@
32
32
  * latN lonN
33
33
  */
34
34
 
35
- #include <stdio.h>
36
- #include <stdlib.h>
35
+ #include "args.h"
37
36
  #include "h3Index.h"
38
37
  #include "utility.h"
39
38
 
@@ -58,8 +57,7 @@ int main(int argc, char* argv[]) {
58
57
  double lat = 0;
59
58
  double lon = 0;
60
59
 
61
- Arg helpArg = {.names = {"-h", "--help"},
62
- .helpText = "Show this help message."};
60
+ Arg helpArg = ARG_HELP;
63
61
  Arg resArg = {.names = {"-r", "--resolution"},
64
62
  .required = true,
65
63
  .scanFormat = "%d",
@@ -72,7 +70,7 @@ int main(int argc, char* argv[]) {
72
70
  .value = &lat,
73
71
  .helpText =
74
72
  "Latitude in degrees. If not specified, \"latitude "
75
- "longitude\" pairs will be read from stdin."};
73
+ "longitude\" pairs will be read from standard input."};
76
74
  Arg lonArg = {.names = {"--lon", "--longitude"},
77
75
  .scanFormat = "%lf",
78
76
  .valueName = "lon",
@@ -80,17 +78,17 @@ int main(int argc, char* argv[]) {
80
78
  .helpText = "Longitude in degrees."};
81
79
 
82
80
  Arg* args[] = {&helpArg, &resArg, &latArg, &lonArg};
83
-
81
+ const int numArgs = 4;
84
82
  const char* helpText =
85
83
  "Convert degrees latitude/longitude coordinates to H3 indexes.";
86
84
 
87
- if (parseArgs(argc, argv, 4, args, &helpArg, helpText)) {
85
+ if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
88
86
  return helpArg.found ? 0 : 1;
89
87
  }
90
88
 
91
89
  if (latArg.found != lonArg.found) {
92
90
  // One is found but the other is not.
93
- printHelp(stderr, argv[0], helpText, 4, args,
91
+ printHelp(stderr, argv[0], helpText, numArgs, args,
94
92
  "Latitude and longitude must both be specified.", NULL);
95
93
  return 1;
96
94
  }
@@ -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,16 +17,14 @@
17
17
  * @brief stdin/stdout filter that converts from integer H3 indexes to
18
18
  * components.
19
19
  *
20
- * usage: `h3ToComponents`
20
+ * See `h3ToComponents --help` for usage.
21
21
  *
22
22
  * The program reads H3 indexes from stdin until EOF and outputs the
23
23
  * corresponding component strings to stdout.
24
24
  */
25
25
 
26
- #include <stdio.h>
27
- #include <stdlib.h>
28
- #include <string.h>
29
- #include "baseCells.h"
26
+ #include <inttypes.h>
27
+ #include "args.h"
30
28
  #include "h3Index.h"
31
29
  #include "utility.h"
32
30
 
@@ -44,29 +42,12 @@ char resDigitToChar(int d) {
44
42
  return '0' + d;
45
43
  }
46
44
 
47
- void doCell(H3Index h, int verboseMode) {
45
+ void doCell(H3Index h, bool verboseMode) {
48
46
  int h3Mode = H3_GET_MODE(h);
49
47
  int h3Res = H3_GET_RESOLUTION(h);
50
48
  int h3BaseCell = H3_GET_BASE_CELL(h);
51
- if (verboseMode == 0) {
52
- if (h3Mode == H3_HEXAGON_MODE) {
53
- printf("%d:%d:%d:", h3Mode, h3Res, h3BaseCell);
54
- for (int i = 1; i <= h3Res; i++) {
55
- printf("%c", resDigitToChar(H3_GET_INDEX_DIGIT(h, i)));
56
- }
57
- printf("\n");
58
- } else if (h3Mode == H3_UNIEDGE_MODE) {
59
- printf("%d:%d:%d:%d:", h3Mode, H3_GET_RESERVED_BITS(h), h3Res,
60
- h3BaseCell);
61
- for (int i = 1; i <= h3Res; i++) {
62
- printf("%c", resDigitToChar(H3_GET_INDEX_DIGIT(h, i)));
63
- }
64
- printf("\n");
65
- } else {
66
- printf("INVALID INDEX\n");
67
- }
68
- } else {
69
- char* modes[] = {
49
+ if (verboseMode) {
50
+ const char* modes[] = {
70
51
  "RESERVED", // 0
71
52
  "Hexagon", // 1
72
53
  "Unidirectional Edge", // 2
@@ -100,33 +81,55 @@ void doCell(H3Index h, int verboseMode) {
100
81
  resDigitToChar(H3_GET_INDEX_DIGIT(h, i)));
101
82
  }
102
83
  printf("╚════════════╝\n\n");
84
+ } else {
85
+ if (h3Mode == H3_HEXAGON_MODE) {
86
+ printf("%d:%d:%d:", h3Mode, h3Res, h3BaseCell);
87
+ for (int i = 1; i <= h3Res; i++) {
88
+ printf("%c", resDigitToChar(H3_GET_INDEX_DIGIT(h, i)));
89
+ }
90
+ printf("\n");
91
+ } else if (h3Mode == H3_UNIEDGE_MODE) {
92
+ printf("%d:%d:%d:%d:", h3Mode, H3_GET_RESERVED_BITS(h), h3Res,
93
+ h3BaseCell);
94
+ for (int i = 1; i <= h3Res; i++) {
95
+ printf("%c", resDigitToChar(H3_GET_INDEX_DIGIT(h, i)));
96
+ }
97
+ printf("\n");
98
+ } else {
99
+ printf("INVALID INDEX\n");
100
+ }
103
101
  }
104
102
  }
105
103
 
106
104
  int main(int argc, char* argv[]) {
107
- // check command line args
108
- int verboseMode = 0;
109
- if (argc > 1) {
110
- if (strncmp("--verbose", argv[1], 9) == 0) {
111
- verboseMode = 1;
112
- } else {
113
- fprintf(stderr, "usage: %s [--verbose]\n", argv[0]);
114
- exit(1);
115
- }
105
+ Arg helpArg = ARG_HELP;
106
+ Arg verboseArg = {.names = {"-v", "--verbose"},
107
+ .helpText = "Verbose output mode."};
108
+ DEFINE_INDEX_ARG(index, indexArg);
109
+ const int numArgs = 3;
110
+ Arg* args[] = {&helpArg, &verboseArg, &indexArg};
111
+
112
+ if (parseArgs(argc, argv, numArgs, args, &helpArg,
113
+ "Converts H3 indexes to component parts")) {
114
+ return helpArg.found ? 0 : 1;
116
115
  }
117
116
 
118
- // process the indexes on stdin
119
- char buff[BUFF_SIZE];
120
- while (1) {
121
- // get an index from stdin
122
- if (!fgets(buff, BUFF_SIZE, stdin)) {
123
- if (feof(stdin))
124
- break;
125
- else
126
- error("reading H3 index from stdin");
127
- }
117
+ if (indexArg.found) {
118
+ doCell(index, verboseArg.found);
119
+ } else {
120
+ // process the indexes on stdin
121
+ char buff[BUFF_SIZE];
122
+ while (1) {
123
+ // get an index from stdin
124
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
125
+ if (feof(stdin))
126
+ break;
127
+ else
128
+ error("reading H3 index from stdin");
129
+ }
128
130
 
129
- H3Index h3 = H3_EXPORT(stringToH3)(buff);
130
- doCell(h3, verboseMode);
131
+ H3Index h3 = H3_EXPORT(stringToH3)(buff);
132
+ doCell(h3, verboseArg.found);
133
+ }
131
134
  }
132
135
  }
@@ -17,8 +17,7 @@
17
17
  * @brief stdin/stdout filter that converts from integer H3 indexes to lat/lon
18
18
  * cell center point
19
19
  *
20
- * usage: `h3ToGeo [--index index] [--kml [--kml-name name] [--kml-description
21
- * desc]]`
20
+ * See `h3ToGeo --help` for usage.
22
21
  *
23
22
  * The program reads H3 indexes from stdin and outputs the corresponding
24
23
  * cell center points to stdout, until EOF is encountered. The H3 indexes
@@ -42,9 +41,7 @@
42
41
  */
43
42
 
44
43
  #include <inttypes.h>
45
- #include <stdio.h>
46
- #include <stdlib.h>
47
- #include <string.h>
44
+ #include "args.h"
48
45
  #include "h3api.h"
49
46
  #include "kml.h"
50
47
  #include "utility.h"
@@ -66,31 +63,11 @@ void doCell(H3Index h, int isKmlOut) {
66
63
  }
67
64
 
68
65
  int main(int argc, char *argv[]) {
69
- H3Index index = 0;
70
- char userKmlName[BUFF_SIZE] = {0};
71
- char userKmlDesc[BUFF_SIZE] = {0};
72
-
73
- Arg helpArg = {.names = {"-h", "--help"},
74
- .helpText = "Show this help message."};
75
- Arg indexArg = {
76
- .names = {"-i", "--index"},
77
- .scanFormat = "%" PRIx64,
78
- .valueName = "index",
79
- .value = &index,
80
- .helpText =
81
- "Index, or not specified to read indexes from standard in."};
82
- Arg kmlArg = {.names = {"-k", "--kml"},
83
- .helpText = "Print output in KML format."};
84
- Arg kmlNameArg = {.names = {"--kn", "--kml-name"},
85
- .scanFormat = "%255c", // BUFF_SIZE - 1
86
- .valueName = "name",
87
- .value = &userKmlName,
88
- .helpText = "Text for the KML name tag."};
89
- Arg kmlDescArg = {.names = {"--kd", "--kml-description"},
90
- .scanFormat = "%255c", // BUFF_SIZE - 1
91
- .valueName = "description",
92
- .value = &userKmlDesc,
93
- .helpText = "Text for the KML description tag."};
66
+ Arg helpArg = ARG_HELP;
67
+ DEFINE_INDEX_ARG(index, indexArg);
68
+ Arg kmlArg = ARG_KML;
69
+ DEFINE_KML_NAME_ARG(userKmlName, kmlNameArg);
70
+ DEFINE_KML_DESC_ARG(userKmlDesc, kmlDescArg);
94
71
 
95
72
  Arg *args[] = {&helpArg, &indexArg, &kmlArg, &kmlNameArg, &kmlDescArg};
96
73
 
@@ -17,8 +17,7 @@
17
17
  * @brief stdin/stdout filter that converts from integer H3 indexes to lat/lon
18
18
  * cell boundaries
19
19
  *
20
- * usage: `h3ToGeoBoundary [--index index] [--kml [--kml-name name]
21
- * [--kml-description desc]]`
20
+ * See `h3ToGeoBoundary --help` for usage.
22
21
  *
23
22
  * The program reads H3 indexes from stdin and outputs the corresponding
24
23
  * cell boundaries to stdout, until EOF is encountered.
@@ -44,6 +43,7 @@
44
43
  #include <stdio.h>
45
44
  #include <stdlib.h>
46
45
  #include <string.h>
46
+ #include "args.h"
47
47
  #include "h3api.h"
48
48
  #include "kml.h"
49
49
  #include "utility.h"
@@ -64,31 +64,11 @@ void doCell(H3Index h, int isKmlOut) {
64
64
  }
65
65
 
66
66
  int main(int argc, char *argv[]) {
67
- H3Index index = 0;
68
- char userKmlName[BUFF_SIZE] = {0};
69
- char userKmlDesc[BUFF_SIZE] = {0};
70
-
71
- Arg helpArg = {.names = {"-h", "--help"},
72
- .helpText = "Show this help message."};
73
- Arg indexArg = {
74
- .names = {"-i", "--index"},
75
- .scanFormat = "%" PRIx64,
76
- .valueName = "index",
77
- .value = &index,
78
- .helpText =
79
- "Index, or not specified to read indexes from standard in."};
80
- Arg kmlArg = {.names = {"-k", "--kml"},
81
- .helpText = "Print output in KML format."};
82
- Arg kmlNameArg = {.names = {"--kn", "--kml-name"},
83
- .scanFormat = "%255c", // BUFF_SIZE - 1
84
- .valueName = "name",
85
- .value = &userKmlName,
86
- .helpText = "Text for the KML name tag."};
87
- Arg kmlDescArg = {.names = {"--kd", "--kml-description"},
88
- .scanFormat = "%255c", // BUFF_SIZE - 1
89
- .valueName = "description",
90
- .value = &userKmlDesc,
91
- .helpText = "Text for the KML description tag."};
67
+ Arg helpArg = ARG_HELP;
68
+ DEFINE_INDEX_ARG(index, indexArg);
69
+ Arg kmlArg = ARG_KML;
70
+ DEFINE_KML_NAME_ARG(userKmlName, kmlNameArg);
71
+ DEFINE_KML_DESC_ARG(userKmlDesc, kmlDescArg);
92
72
 
93
73
  Arg *args[] = {&helpArg, &indexArg, &kmlArg, &kmlNameArg, &kmlDescArg};
94
74
 
@@ -17,7 +17,7 @@
17
17
  * @brief stdin/stdout filter that converts from H3 indexes to local IJ
18
18
  * coordinates. This is experimental.
19
19
  *
20
- * usage: `h3ToLocalIj [origin]`
20
+ * See `h3ToLocalIj --help` for usage.
21
21
  *
22
22
  * The program reads H3 indexes from stdin and outputs the corresponding
23
23
  * IJ coordinates to stdout, until EOF is encountered. `NA` is printed if the
@@ -33,8 +33,7 @@
33
33
  #include <inttypes.h>
34
34
  #include <stdio.h>
35
35
  #include <stdlib.h>
36
- #include "coordijk.h"
37
- #include "h3Index.h"
36
+ #include "args.h"
38
37
  #include "h3api.h"
39
38
  #include "utility.h"
40
39
 
@@ -47,32 +46,50 @@ void doCell(H3Index h, H3Index origin) {
47
46
  }
48
47
  }
49
48
 
50
- int main(int argc, char *argv[]) {
51
- // check command line args
52
- if (argc != 2) {
53
- fprintf(stderr, "usage: %s [origin]\n", argv[0]);
54
- exit(1);
55
- }
49
+ int main(int argc, char* argv[]) {
50
+ H3Index origin = 0;
56
51
 
57
- H3Index origin;
52
+ Arg helpArg = ARG_HELP;
53
+ Arg originArg = {
54
+ .names = {"-o", "--origin"},
55
+ .scanFormat = "%" PRIx64,
56
+ .valueName = "origin",
57
+ .value = &origin,
58
+ .required = true,
59
+ .helpText =
60
+ "Origin (anchoring index) for the local coordinate system."};
61
+ DEFINE_INDEX_ARG(index, indexArg);
58
62
 
59
- if (!sscanf(argv[1], "%" PRIx64, &origin))
60
- error("origin could not be read");
63
+ Arg* args[] = {&helpArg, &originArg, &indexArg};
64
+ const int numArgs = 3;
65
+ const char* helpText = "Converts H3 indexes to local IJ coordinates";
61
66
 
62
- if (!H3_EXPORT(h3IsValid)(origin)) error("origin is invalid");
67
+ if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
68
+ return helpArg.found ? 0 : 1;
69
+ }
63
70
 
64
- // process the indexes on stdin
65
- char buff[BUFF_SIZE];
66
- while (1) {
67
- // get an index from stdin
68
- if (!fgets(buff, BUFF_SIZE, stdin)) {
69
- if (feof(stdin))
70
- break;
71
- else
72
- error("reading H3 index from stdin");
73
- }
71
+ if (!H3_EXPORT(h3IsValid)(origin)) {
72
+ printHelp(stderr, argv[0], helpText, numArgs, args,
73
+ "Origin is invalid.", NULL);
74
+ return 1;
75
+ }
74
76
 
75
- H3Index h3 = H3_EXPORT(stringToH3)(buff);
76
- doCell(h3, origin);
77
+ if (indexArg.found) {
78
+ doCell(index, origin);
79
+ } else {
80
+ // process the indexes on stdin
81
+ char buff[BUFF_SIZE];
82
+ while (1) {
83
+ // get an index from stdin
84
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
85
+ if (feof(stdin))
86
+ break;
87
+ else
88
+ error("reading H3 index from stdin");
89
+ }
90
+
91
+ H3Index h3 = H3_EXPORT(stringToH3)(buff);
92
+ doCell(h3, origin);
93
+ }
77
94
  }
78
95
  }
@@ -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,7 +17,7 @@
17
17
  * @brief stdin/stdout filter that converts from integer H3 indexes to
18
18
  * k-rings
19
19
  *
20
- * usage: `hexRange [k]`
20
+ * See `hexRange --help` for usage.
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. Requires all indexes
@@ -28,10 +28,11 @@
28
28
  * as the only output.
29
29
  */
30
30
 
31
+ #include <inttypes.h>
31
32
  #include <stdio.h>
32
33
  #include <stdlib.h>
33
- #include "algos.h"
34
- #include "h3Index.h"
34
+ #include "args.h"
35
+ #include "h3api.h"
35
36
  #include "utility.h"
36
37
 
37
38
  void doCell(H3Index h, int k) {
@@ -50,29 +51,47 @@ void doCell(H3Index h, int k) {
50
51
  }
51
52
 
52
53
  int main(int argc, char* argv[]) {
53
- // check command line args
54
- if (argc != 2) {
55
- fprintf(stderr, "usage: %s [k]\n", argv[0]);
56
- exit(1);
57
- }
58
-
59
54
  int k = 0;
60
- if (argc > 1) {
61
- if (!sscanf(argv[1], "%d", &k)) error("k must be an integer");
55
+ H3Index origin = 0;
56
+
57
+ Arg helpArg = ARG_HELP;
58
+ Arg kArg = {.names = {"-k", NULL},
59
+ .required = true,
60
+ .scanFormat = "%d",
61
+ .valueName = "k",
62
+ .value = &k,
63
+ .helpText = "Radius in hexagons."};
64
+ Arg originArg = {
65
+ .names = {"-o", "--origin"},
66
+ .scanFormat = "%" PRIx64,
67
+ .valueName = "origin",
68
+ .value = &origin,
69
+ .helpText =
70
+ "Origin, or not specified to read origins from standard input."};
71
+ const int numArgs = 3;
72
+ Arg* args[] = {&helpArg, &kArg, &originArg};
73
+
74
+ if (parseArgs(argc, argv, numArgs, args, &helpArg,
75
+ "Print indexes k distance away from the origin")) {
76
+ return helpArg.found ? 0 : 1;
62
77
  }
63
78
 
64
- // process the indexes on stdin
65
- char buff[BUFF_SIZE];
66
- while (1) {
67
- // get an index from stdin
68
- if (!fgets(buff, BUFF_SIZE, stdin)) {
69
- if (feof(stdin))
70
- break;
71
- else
72
- error("reading H3 index from stdin");
73
- }
79
+ if (originArg.found) {
80
+ doCell(origin, k);
81
+ } else {
82
+ // process the indexes on stdin
83
+ char buff[BUFF_SIZE];
84
+ while (1) {
85
+ // get an index from stdin
86
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
87
+ if (feof(stdin))
88
+ break;
89
+ else
90
+ error("reading H3 index from stdin");
91
+ }
74
92
 
75
- H3Index h3 = H3_EXPORT(stringToH3)(buff);
76
- doCell(h3, k);
93
+ H3Index h3 = H3_EXPORT(stringToH3)(buff);
94
+ doCell(h3, k);
95
+ }
77
96
  }
78
97
  }