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.
Files changed (161) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +23 -0
  3. data/Gemfile.lock +6 -6
  4. data/README.md +1 -1
  5. data/ext/h3/src/.github/workflows/test-linux.yml +118 -0
  6. data/ext/h3/src/.github/workflows/test-macos.yml +42 -0
  7. data/ext/h3/src/.github/workflows/test-website.yml +32 -0
  8. data/ext/h3/src/.github/workflows/test-windows.yml +44 -0
  9. data/ext/h3/src/.gitignore +5 -0
  10. data/ext/h3/src/.travis.yml +16 -46
  11. data/ext/h3/src/CHANGELOG.md +43 -0
  12. data/ext/h3/src/CMakeLists.txt +133 -33
  13. data/ext/h3/src/CONTRIBUTING.md +1 -1
  14. data/ext/h3/src/README.md +60 -10
  15. data/ext/h3/src/RELEASE.md +3 -1
  16. data/ext/h3/src/VERSION +1 -1
  17. data/ext/h3/src/dev-docs/RFCs/rfc-template.md +21 -0
  18. data/ext/h3/src/dev-docs/RFCs/v4.0.0/error-handling-rfc.md +21 -0
  19. data/ext/h3/src/dev-docs/RFCs/v4.0.0/names_for_concepts_types_functions.md +276 -0
  20. data/ext/h3/src/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md +141 -0
  21. data/ext/h3/src/dev-docs/RFCs/v4.0.0/polyfill-modes-rfc.md +21 -0
  22. data/ext/h3/src/dev-docs/RFCs/v4.0.0/vertex-mode-rfc.md +50 -0
  23. data/ext/h3/src/dev-docs/build_windows.md +6 -1
  24. data/ext/h3/src/dev-docs/creating_bindings.md +3 -3
  25. data/ext/h3/src/dev-docs/custom_alloc.md +27 -0
  26. data/ext/h3/src/docs/{overview/mainpage.md → README.md} +2 -3
  27. data/ext/h3/src/docs/api/misc.md +76 -0
  28. data/ext/h3/src/docs/community/applications.md +1 -0
  29. data/ext/h3/src/docs/community/bindings.md +7 -1
  30. data/ext/h3/src/docs/community/tutorials.md +8 -3
  31. data/ext/h3/src/docs/core-library/coordsystems.md +5 -4
  32. data/ext/h3/src/docs/core-library/filters.md +8 -9
  33. data/ext/h3/src/docs/core-library/geoToH3desc.md +2 -3
  34. data/ext/h3/src/docs/core-library/h3ToGeoBoundaryDesc.md +4 -5
  35. data/ext/h3/src/docs/core-library/h3ToGeoDesc.md +3 -4
  36. data/ext/h3/src/docs/core-library/h3indexing.md +26 -17
  37. data/ext/h3/src/docs/core-library/overview.md +2 -3
  38. data/ext/h3/src/docs/core-library/restable.md +1 -2
  39. data/ext/h3/src/docs/core-library/usage.md +1 -2
  40. data/ext/h3/src/docs/table-of-contents.json +47 -0
  41. data/ext/h3/src/docs/{overview/usecases.md → usecases.md} +6 -11
  42. data/ext/h3/src/scripts/binding_functions.sh +1 -1
  43. data/ext/h3/src/scripts/coverage.sh.in +1 -1
  44. data/ext/h3/src/scripts/update_version.sh +2 -2
  45. data/ext/h3/src/src/apps/applib/include/args.h +1 -0
  46. data/ext/h3/src/src/apps/applib/include/test.h +1 -0
  47. data/ext/h3/src/src/apps/applib/include/utility.h +7 -1
  48. data/ext/h3/src/src/apps/applib/lib/args.c +2 -0
  49. data/ext/h3/src/src/apps/applib/lib/kml.c +2 -0
  50. data/ext/h3/src/src/apps/applib/lib/test.c +1 -0
  51. data/ext/h3/src/src/apps/applib/lib/utility.c +133 -2
  52. data/ext/h3/src/src/apps/benchmarks/benchmarkH3Api.c +1 -1
  53. data/ext/h3/src/{website/html.config.js → src/apps/benchmarks/benchmarkH3UniEdge.c} +15 -12
  54. data/ext/h3/src/src/apps/filters/h3ToComponents.c +1 -0
  55. data/ext/h3/src/src/apps/filters/h3ToGeo.c +1 -0
  56. data/ext/h3/src/src/apps/filters/h3ToGeoBoundary.c +1 -0
  57. data/ext/h3/src/src/apps/filters/h3ToLocalIj.c +1 -0
  58. data/ext/h3/src/src/apps/filters/hexRange.c +1 -0
  59. data/ext/h3/src/src/apps/filters/kRing.c +1 -0
  60. data/ext/h3/src/src/apps/filters/localIjToH3.c +1 -0
  61. data/ext/h3/src/src/apps/miscapps/generateFaceCenterPoint.c +1 -0
  62. data/ext/h3/src/src/apps/miscapps/generateNumHexagons.c +1 -0
  63. data/ext/h3/src/src/apps/miscapps/generatePentagonDirectionFaces.c +67 -0
  64. data/ext/h3/src/src/apps/miscapps/h3ToGeoBoundaryHier.c +1 -0
  65. data/ext/h3/src/src/apps/miscapps/h3ToGeoHier.c +1 -0
  66. data/ext/h3/src/src/apps/miscapps/h3ToHier.c +1 -0
  67. data/ext/h3/src/src/apps/testapps/mkRandGeo.c +1 -0
  68. data/ext/h3/src/src/apps/testapps/mkRandGeoBoundary.c +1 -0
  69. data/ext/h3/src/src/apps/testapps/testBBox.c +1 -0
  70. data/ext/h3/src/src/apps/testapps/testBaseCells.c +15 -1
  71. data/ext/h3/src/src/apps/testapps/testCompact.c +75 -0
  72. data/ext/h3/src/src/apps/testapps/testCoordIj.c +1 -0
  73. data/ext/h3/src/src/apps/testapps/testGeoCoord.c +40 -13
  74. data/ext/h3/src/src/apps/testapps/testGeoToH3.c +1 -0
  75. data/ext/h3/src/src/apps/testapps/testH3Api.c +1 -0
  76. data/ext/h3/src/src/apps/testapps/testH3CellArea.c +47 -0
  77. data/ext/h3/src/src/apps/testapps/testH3CellAreaExhaustive.c +180 -0
  78. data/ext/h3/src/src/apps/testapps/testH3Distance.c +1 -0
  79. data/ext/h3/src/src/apps/testapps/testH3DistanceExhaustive.c +1 -0
  80. data/ext/h3/src/src/apps/testapps/testH3GetFaces.c +1 -0
  81. data/ext/h3/src/src/apps/testapps/testH3Index.c +33 -3
  82. data/ext/h3/src/src/apps/testapps/testH3Line.c +1 -0
  83. data/ext/h3/src/src/apps/testapps/testH3LineExhaustive.c +1 -0
  84. data/ext/h3/src/src/apps/testapps/testH3Memory.c +175 -0
  85. data/ext/h3/src/src/apps/testapps/testH3NeighborRotations.c +1 -0
  86. data/ext/h3/src/src/apps/testapps/testH3SetToLinkedGeo.c +1 -0
  87. data/ext/h3/src/src/apps/testapps/testH3SetToVertexGraph.c +1 -0
  88. data/ext/h3/src/src/apps/testapps/testH3ToCenterChild.c +1 -0
  89. data/ext/h3/src/src/apps/testapps/testH3ToChildren.c +1 -0
  90. data/ext/h3/src/src/apps/testapps/testH3ToGeo.c +1 -0
  91. data/ext/h3/src/src/apps/testapps/testH3ToGeoBoundary.c +1 -0
  92. data/ext/h3/src/src/apps/testapps/testH3ToLocalIj.c +9 -5
  93. data/ext/h3/src/src/apps/testapps/testH3ToLocalIjExhaustive.c +1 -0
  94. data/ext/h3/src/src/apps/testapps/testH3ToParent.c +1 -0
  95. data/ext/h3/src/src/apps/testapps/testH3UniEdge.c +45 -16
  96. data/ext/h3/src/src/apps/testapps/testH3UniEdgeExhaustive.c +111 -0
  97. data/ext/h3/src/src/apps/testapps/testHexRanges.c +1 -0
  98. data/ext/h3/src/src/apps/testapps/testHexRing.c +1 -0
  99. data/ext/h3/src/src/apps/testapps/testKRing.c +1 -0
  100. data/ext/h3/src/src/apps/testapps/testLinkedGeo.c +1 -0
  101. data/ext/h3/src/src/apps/testapps/testMaxH3ToChildrenSize.c +1 -0
  102. data/ext/h3/src/src/apps/testapps/testPentagonIndexes.c +1 -0
  103. data/ext/h3/src/src/apps/testapps/testPolyfill.c +72 -9
  104. data/ext/h3/src/src/apps/testapps/testPolyfillReported.c +157 -0
  105. data/ext/h3/src/src/apps/testapps/testPolygon.c +1 -0
  106. data/ext/h3/src/src/apps/testapps/testVec2d.c +1 -0
  107. data/ext/h3/src/src/apps/testapps/testVec3d.c +1 -0
  108. data/ext/h3/src/src/apps/testapps/testVertex.c +66 -0
  109. data/ext/h3/src/src/apps/testapps/testVertexGraph.c +1 -0
  110. data/ext/h3/src/src/h3lib/include/algos.h +8 -0
  111. data/ext/h3/src/src/h3lib/include/alloc.h +40 -0
  112. data/ext/h3/src/src/h3lib/include/baseCells.h +4 -0
  113. data/ext/h3/src/src/h3lib/include/bbox.h +4 -1
  114. data/ext/h3/src/src/h3lib/include/faceijk.h +3 -2
  115. data/ext/h3/src/src/h3lib/include/geoCoord.h +2 -3
  116. data/ext/h3/src/src/h3lib/include/h3Index.h +37 -4
  117. data/ext/h3/src/src/h3lib/include/h3api.h.in +65 -17
  118. data/ext/h3/src/src/h3lib/include/linkedGeo.h +1 -0
  119. data/ext/h3/src/src/h3lib/include/polygon.h +1 -0
  120. data/ext/h3/src/src/h3lib/include/polygonAlgos.h +1 -0
  121. data/ext/h3/src/src/h3lib/include/vertex.h +44 -0
  122. data/ext/h3/src/src/h3lib/include/vertexGraph.h +1 -0
  123. data/ext/h3/src/src/h3lib/lib/algos.c +300 -75
  124. data/ext/h3/src/src/h3lib/lib/baseCells.c +26 -4
  125. data/ext/h3/src/src/h3lib/lib/bbox.c +56 -31
  126. data/ext/h3/src/src/h3lib/lib/coordijk.c +2 -0
  127. data/ext/h3/src/src/h3lib/lib/faceijk.c +32 -21
  128. data/ext/h3/src/src/h3lib/lib/geoCoord.c +162 -44
  129. data/ext/h3/src/src/h3lib/lib/h3Index.c +81 -43
  130. data/ext/h3/src/src/h3lib/lib/h3UniEdge.c +42 -57
  131. data/ext/h3/src/src/h3lib/lib/linkedGeo.c +20 -15
  132. data/ext/h3/src/src/h3lib/lib/localij.c +1 -1
  133. data/ext/h3/src/src/h3lib/lib/polygon.c +2 -0
  134. data/ext/h3/src/src/h3lib/lib/vec2d.c +1 -0
  135. data/ext/h3/src/src/h3lib/lib/vec3d.c +1 -0
  136. data/ext/h3/src/src/h3lib/lib/vertex.c +134 -0
  137. data/ext/h3/src/src/h3lib/lib/vertexGraph.c +8 -5
  138. data/ext/h3/src/website/.eslintignore +2 -0
  139. data/ext/h3/src/website/.gitignore +57 -0
  140. data/ext/h3/src/website/.nvmrc +1 -0
  141. data/ext/h3/src/website/README.md +8 -6
  142. data/ext/h3/src/website/gatsby-config.js +83 -0
  143. data/ext/h3/src/website/package.json +20 -12
  144. data/ext/h3/src/website/scripts/build-to-gh-pages.sh +7 -5
  145. data/ext/h3/src/website/src/.gitkeep +0 -0
  146. data/ext/h3/src/website/templates/documentation.jsx +129 -0
  147. data/ext/h3/src/website/yarn.lock +13723 -0
  148. data/lib/h3/bindings/private.rb +3 -0
  149. data/lib/h3/miscellaneous.rb +123 -0
  150. data/lib/h3/version.rb +1 -1
  151. data/spec/miscellaneous_spec.rb +117 -0
  152. data/spec/regions_spec.rb +1 -1
  153. metadata +35 -14
  154. data/ext/h3/src/.ycm_extra_conf.py +0 -92
  155. data/ext/h3/src/appveyor.yml +0 -50
  156. data/ext/h3/src/src/apps/testapps/testPolyfill_GH136.c +0 -58
  157. data/ext/h3/src/website/src/config.js +0 -46
  158. data/ext/h3/src/website/src/mdRoutes.js +0 -151
  159. data/ext/h3/src/website/src/styles/_variables.scss +0 -16
  160. data/ext/h3/src/website/src/styles/index.scss +0 -3
  161. data/ext/h3/src/website/static/index.html +0 -15
@@ -24,6 +24,7 @@
24
24
  */
25
25
 
26
26
  #include <inttypes.h>
27
+
27
28
  #include "args.h"
28
29
  #include "h3Index.h"
29
30
  #include "utility.h"
@@ -41,6 +41,7 @@
41
41
  */
42
42
 
43
43
  #include <inttypes.h>
44
+
44
45
  #include "args.h"
45
46
  #include "h3api.h"
46
47
  #include "kml.h"
@@ -43,6 +43,7 @@
43
43
  #include <stdio.h>
44
44
  #include <stdlib.h>
45
45
  #include <string.h>
46
+
46
47
  #include "args.h"
47
48
  #include "h3api.h"
48
49
  #include "kml.h"
@@ -33,6 +33,7 @@
33
33
  #include <inttypes.h>
34
34
  #include <stdio.h>
35
35
  #include <stdlib.h>
36
+
36
37
  #include "args.h"
37
38
  #include "h3api.h"
38
39
  #include "utility.h"
@@ -31,6 +31,7 @@
31
31
  #include <inttypes.h>
32
32
  #include <stdio.h>
33
33
  #include <stdlib.h>
34
+
34
35
  #include "args.h"
35
36
  #include "h3api.h"
36
37
  #include "utility.h"
@@ -30,6 +30,7 @@
30
30
  #include <stdbool.h>
31
31
  #include <stdio.h>
32
32
  #include <stdlib.h>
33
+
33
34
  #include "args.h"
34
35
  #include "h3api.h"
35
36
  #include "utility.h"
@@ -33,6 +33,7 @@
33
33
  #include <inttypes.h>
34
34
  #include <stdio.h>
35
35
  #include <stdlib.h>
36
+
36
37
  #include "args.h"
37
38
  #include "h3api.h"
38
39
  #include "utility.h"
@@ -20,6 +20,7 @@
20
20
  */
21
21
 
22
22
  #include <stdlib.h>
23
+
23
24
  #include "faceijk.h"
24
25
  #include "vec3d.h"
25
26
 
@@ -26,6 +26,7 @@
26
26
  #include <inttypes.h>
27
27
  #include <stdio.h>
28
28
  #include <stdlib.h>
29
+
29
30
  #include "constants.h"
30
31
 
31
32
  /**
@@ -0,0 +1,67 @@
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 generatePentagonDirectionFaces.c
17
+ * @brief Generates the pentagonDirectionFaces table
18
+ *
19
+ * usage: `generatePentagonDirectionFaces`
20
+ */
21
+
22
+ #include <stdlib.h>
23
+
24
+ #include "algos.h"
25
+ #include "baseCells.h"
26
+ #include "h3Index.h"
27
+
28
+ static void generate() {
29
+ H3Index pentagons[NUM_PENTAGONS] = {0};
30
+ // Get the res 2 pentagons, whose neighbors have the same base cell
31
+ // and are unambiguously on the correct faces
32
+ H3_EXPORT(getPentagonIndexes)(2, pentagons);
33
+
34
+ printf(
35
+ "static const PentagonDirectionFaces "
36
+ "pentagonDirectionFaces[NUM_PENTAGONS] = "
37
+ "{\n");
38
+
39
+ for (int i = 0; i < NUM_PENTAGONS; i++) {
40
+ H3Index pentagon = pentagons[i];
41
+ int baseCell = H3_EXPORT(h3GetBaseCell)(pentagon);
42
+ printf(" {%d, {", baseCell);
43
+ // Get the neighbors in each direction, in order
44
+ FaceIJK fijk;
45
+ for (Direction dir = J_AXES_DIGIT; dir < NUM_DIGITS; dir++) {
46
+ int r = 0;
47
+ H3Index neighbor = h3NeighborRotations(pentagon, dir, &r);
48
+ _h3ToFaceIjk(neighbor, &fijk);
49
+
50
+ if (dir > J_AXES_DIGIT) printf(", ");
51
+ printf("%d", fijk.face);
52
+ }
53
+ printf("}},\n");
54
+ }
55
+
56
+ printf("};\n");
57
+ }
58
+
59
+ int main(int argc, char* argv[]) {
60
+ // check command line args
61
+ if (argc > 1) {
62
+ fprintf(stderr, "usage: %s\n", argv[0]);
63
+ exit(1);
64
+ }
65
+
66
+ generate();
67
+ }
@@ -53,6 +53,7 @@
53
53
  #include <stdio.h>
54
54
  #include <stdlib.h>
55
55
  #include <string.h>
56
+
56
57
  #include "args.h"
57
58
  #include "baseCells.h"
58
59
  #include "h3Index.h"
@@ -53,6 +53,7 @@
53
53
  #include <stdio.h>
54
54
  #include <stdlib.h>
55
55
  #include <string.h>
56
+
56
57
  #include "args.h"
57
58
  #include "baseCells.h"
58
59
  #include "h3Index.h"
@@ -32,6 +32,7 @@
32
32
  #include <inttypes.h>
33
33
  #include <stdio.h>
34
34
  #include <stdlib.h>
35
+
35
36
  #include "args.h"
36
37
  #include "baseCells.h"
37
38
  #include "h3Index.h"
@@ -25,6 +25,7 @@
25
25
 
26
26
  #include <stdio.h>
27
27
  #include <stdlib.h>
28
+
28
29
  #include "args.h"
29
30
  #include "utility.h"
30
31
 
@@ -24,6 +24,7 @@
24
24
 
25
25
  #include <stdio.h>
26
26
  #include <stdlib.h>
27
+
27
28
  #include "args.h"
28
29
  #include "utility.h"
29
30
 
@@ -16,6 +16,7 @@
16
16
 
17
17
  #include <math.h>
18
18
  #include <stdlib.h>
19
+
19
20
  #include "bbox.h"
20
21
  #include "constants.h"
21
22
  #include "geoCoord.h"
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2017-2019 Uber Technologies, Inc.
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.
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  #include <stdlib.h>
18
+ #include "baseCells.h"
18
19
  #include "h3api.h"
19
20
  #include "test.h"
20
21
 
@@ -27,4 +28,17 @@ SUITE(baseCells) {
27
28
  t_assert(indexes[121] == 0x80f3fffffffffff, "correct last basecell");
28
29
  free(indexes);
29
30
  }
31
+
32
+ TEST(baseCellToCCWrot60) {
33
+ // a few random spot-checks
34
+ t_assert(_baseCellToCCWrot60(16, 0) == 0, "got expected rotation");
35
+ t_assert(_baseCellToCCWrot60(32, 0) == 3, "got expected rotation");
36
+ t_assert(_baseCellToCCWrot60(7, 3) == 1, "got expected rotation");
37
+ }
38
+
39
+ TEST(baseCellToCCWrot60_invalid) {
40
+ t_assert(_baseCellToCCWrot60(16, 42) == INVALID_ROTATIONS, "should return invalid rotation for invalid face");
41
+ t_assert(_baseCellToCCWrot60(16, -1) == INVALID_ROTATIONS, "should return invalid rotation for invalid face (negative)");
42
+ t_assert(_baseCellToCCWrot60(1, 0) == INVALID_ROTATIONS, "should return invalid rotation for base cell not appearing on face");
43
+ }
30
44
  }
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  #include <stdlib.h>
18
+
18
19
  #include "constants.h"
19
20
  #include "h3Index.h"
20
21
  #include "test.h"
@@ -152,6 +153,80 @@ SUITE(compact) {
152
153
  "compact fails on duplicate input");
153
154
  }
154
155
 
156
+ TEST(compact_duplicateMinimum) {
157
+ // Test that the minimum number of duplicate hexagons causes failure
158
+ H3Index h3;
159
+ int res = 10;
160
+ // Arbitrary index
161
+ setH3Index(&h3, res, 0, 2);
162
+
163
+ int arrSize = H3_EXPORT(maxH3ToChildrenSize)(h3, res + 1) + 1;
164
+ H3Index* children = calloc(arrSize, sizeof(H3Index));
165
+
166
+ H3_EXPORT(h3ToChildren)(h3, res + 1, children);
167
+ // duplicate one index
168
+ children[arrSize - 1] = children[0];
169
+
170
+ H3Index* output = calloc(arrSize, sizeof(H3Index));
171
+
172
+ int compactResult = H3_EXPORT(compact)(children, output, arrSize);
173
+ t_assert(compactResult == COMPACT_DUPLICATE,
174
+ "compact fails on duplicate input (single duplicate)");
175
+
176
+ free(output);
177
+ free(children);
178
+ }
179
+
180
+ TEST(compact_duplicatePentagonLimit) {
181
+ // Test that the minimum number of duplicate hexagons causes failure
182
+ H3Index h3;
183
+ int res = 10;
184
+ // Arbitrary pentagon parent cell
185
+ setH3Index(&h3, res, 4, 0);
186
+
187
+ int arrSize = H3_EXPORT(maxH3ToChildrenSize)(h3, res + 1) + 1;
188
+ H3Index* children = calloc(arrSize, sizeof(H3Index));
189
+
190
+ H3_EXPORT(h3ToChildren)(h3, res + 1, children);
191
+ // duplicate one index
192
+ children[arrSize - 1] = H3_EXPORT(h3ToCenterChild)(h3, res + 1);
193
+
194
+ H3Index* output = calloc(arrSize, sizeof(H3Index));
195
+
196
+ int compactResult = H3_EXPORT(compact)(children, output, arrSize);
197
+ t_assert(compactResult == COMPACT_DUPLICATE,
198
+ "compact fails on duplicate input (pentagon parent)");
199
+
200
+ free(output);
201
+ free(children);
202
+ }
203
+
204
+ TEST(compact_duplicateIgnored) {
205
+ // Test that duplicated cells are not rejected by compact.
206
+ // This is not necessarily desired - just asserting the
207
+ // existing behavior.
208
+ H3Index h3;
209
+ int res = 10;
210
+ // Arbitrary index
211
+ setH3Index(&h3, res, 0, 2);
212
+
213
+ int arrSize = H3_EXPORT(maxH3ToChildrenSize)(h3, res + 1);
214
+ H3Index* children = calloc(arrSize, sizeof(H3Index));
215
+
216
+ H3_EXPORT(h3ToChildren)(h3, res + 1, children);
217
+ // duplicate one index
218
+ children[arrSize - 1] = children[0];
219
+
220
+ H3Index* output = calloc(arrSize, sizeof(H3Index));
221
+
222
+ int compactResult = H3_EXPORT(compact)(children, output, arrSize);
223
+ t_assert(compactResult == COMPACT_SUCCESS,
224
+ "compact succeeds on duplicate input (correct count)");
225
+
226
+ free(output);
227
+ free(children);
228
+ }
229
+
155
230
  TEST(compact_empty) {
156
231
  t_assert(H3_EXPORT(compact)(NULL, NULL, 0) == 0,
157
232
  "compact succeeds on empty input");
@@ -22,6 +22,7 @@
22
22
  #include <stdio.h>
23
23
  #include <stdlib.h>
24
24
  #include <string.h>
25
+
25
26
  #include "algos.h"
26
27
  #include "baseCells.h"
27
28
  #include "constants.h"
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2017-2019 Uber Technologies, Inc.
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.
@@ -19,11 +19,14 @@
19
19
  * usage: `testGeoCoord`
20
20
  */
21
21
 
22
+ #include <float.h>
22
23
  #include <math.h>
24
+
23
25
  #include "constants.h"
24
26
  #include "geoCoord.h"
25
27
  #include "h3api.h"
26
28
  #include "test.h"
29
+ #include "utility.h"
27
30
 
28
31
  /**
29
32
  * Test a function for all resolutions, where the value should be decreasing as
@@ -32,7 +35,8 @@
32
35
  * @param function
33
36
  * @param message
34
37
  */
35
- void testDecreasingFunction(double (*function)(int), const char* message) {
38
+ static void testDecreasingFunction(double (*function)(int),
39
+ const char* message) {
36
40
  double last = 0;
37
41
  double next;
38
42
  for (int i = MAX_H3_RES; i >= 0; i--) {
@@ -51,20 +55,41 @@ SUITE(geoCoord) {
51
55
  "radsToDegs/degsToRads invertible");
52
56
  }
53
57
 
54
- TEST(_geoDistRads) {
58
+ TEST(pointDistRads) {
55
59
  GeoCoord p1;
56
60
  setGeoDegs(&p1, 10, 10);
57
61
  GeoCoord p2;
58
62
  setGeoDegs(&p2, 0, 10);
59
63
 
60
64
  // TODO: Epsilon is relatively large
61
- t_assert(_geoDistRads(&p1, &p1) < EPSILON_RAD * 1000,
65
+ t_assert(H3_EXPORT(pointDistRads)(&p1, &p1) < EPSILON_RAD * 1000,
62
66
  "0 distance as expected");
63
- t_assert(fabs(_geoDistRads(&p1, &p2) - H3_EXPORT(degsToRads)(10)) <
64
- EPSILON_RAD * 1000,
67
+ t_assert(fabs(H3_EXPORT(pointDistRads)(&p1, &p2) -
68
+ H3_EXPORT(degsToRads)(10)) < EPSILON_RAD * 1000,
65
69
  "distance along longitude as expected");
66
70
  }
67
71
 
72
+ TEST(geoAlmostEqualThreshold) {
73
+ GeoCoord a = {15, 10};
74
+ GeoCoord b = {15, 10};
75
+ t_assert(geoAlmostEqualThreshold(&a, &b, DBL_EPSILON), "same point");
76
+
77
+ b.lat = 15.00001;
78
+ b.lon = 10.00002;
79
+ t_assert(geoAlmostEqualThreshold(&a, &b, 0.0001),
80
+ "differences under threshold");
81
+
82
+ b.lat = 15.00001;
83
+ b.lon = 10;
84
+ t_assert(!geoAlmostEqualThreshold(&a, &b, 0.000001),
85
+ "lat over threshold");
86
+
87
+ b.lat = 15;
88
+ b.lon = 10.00001;
89
+ t_assert(!geoAlmostEqualThreshold(&a, &b, 0.000001),
90
+ "lon over threshold");
91
+ }
92
+
68
93
  TEST(constrainLatLng) {
69
94
  t_assert(constrainLat(0) == 0, "lat 0");
70
95
  t_assert(constrainLat(1) == 1, "lat 1");
@@ -159,24 +184,26 @@ SUITE(geoCoord) {
159
184
  double distance = H3_EXPORT(degsToRads)(15);
160
185
 
161
186
  _geoAzDistanceRads(&start, azimuth, distance, &out);
162
- t_assert(fabs(_geoDistRads(&start, &out) - distance) < EPSILON_RAD,
187
+ t_assert(fabs(H3_EXPORT(pointDistRads)(&start, &out) - distance) <
188
+ EPSILON_RAD,
163
189
  "moved distance is as expected");
164
190
 
165
191
  GeoCoord start2 = out;
166
192
  _geoAzDistanceRads(&start2, azimuth + degrees180, distance, &out);
167
193
  // TODO: Epsilon is relatively large
168
- t_assert(_geoDistRads(&start, &out) < 0.01, "moved back to origin");
194
+ t_assert(H3_EXPORT(pointDistRads)(&start, &out) < 0.01,
195
+ "moved back to origin");
169
196
  }
170
197
 
171
- TEST(_geoDistRads_wrappedLongitude) {
198
+ TEST(pointDistRads_wrappedLongitude) {
172
199
  const GeoCoord negativeLongitude = {.lat = 0, .lon = -(M_PI + M_PI_2)};
173
200
  const GeoCoord zero = {.lat = 0, .lon = 0};
174
201
 
175
- t_assert(fabs(M_PI_2 - _geoDistRads(&negativeLongitude, &zero)) <
176
- EPSILON_RAD,
202
+ t_assert(fabs(M_PI_2 - H3_EXPORT(pointDistRads)(&negativeLongitude,
203
+ &zero)) < EPSILON_RAD,
177
204
  "Distance with wrapped longitude");
178
- t_assert(fabs(M_PI_2 - _geoDistRads(&zero, &negativeLongitude)) <
179
- EPSILON_RAD,
205
+ t_assert(fabs(M_PI_2 - H3_EXPORT(pointDistRads)(
206
+ &zero, &negativeLongitude)) < EPSILON_RAD,
180
207
  "Distance with wrapped longitude and swapped arguments");
181
208
  }
182
209
 
@@ -26,6 +26,7 @@
26
26
 
27
27
  #include <stdio.h>
28
28
  #include <stdlib.h>
29
+
29
30
  #include "geoCoord.h"
30
31
  #include "h3Index.h"
31
32
  #include "test.h"