h3 3.5.1 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +3 -3
  4. data/ext/h3/src/.travis.yml +15 -4
  5. data/ext/h3/src/CHANGELOG.md +7 -0
  6. data/ext/h3/src/CMakeLists.txt +15 -0
  7. data/ext/h3/src/README.md +5 -6
  8. data/ext/h3/src/VERSION +1 -1
  9. data/ext/h3/src/docs/api/hierarchy.md +8 -0
  10. data/ext/h3/src/docs/api/misc.md +18 -0
  11. data/ext/h3/src/scripts/coverage.sh.in +7 -3
  12. data/ext/h3/src/src/apps/miscapps/generateBaseCellNeighbors.c +2 -2
  13. data/ext/h3/src/src/apps/miscapps/generateNumHexagons.c +0 -2
  14. data/ext/h3/src/src/apps/testapps/testCompact.c +12 -0
  15. data/ext/h3/src/src/apps/testapps/testH3Distance.c +1 -50
  16. data/ext/h3/src/src/apps/testapps/testH3DistanceExhaustive.c +83 -0
  17. data/ext/h3/src/src/apps/testapps/testH3Line.c +1 -84
  18. data/ext/h3/src/src/apps/testapps/testH3LineExhaustive.c +114 -0
  19. data/ext/h3/src/src/apps/testapps/testH3ToCenterChild.c +67 -0
  20. data/ext/h3/src/src/apps/testapps/testH3ToChildren.c +14 -2
  21. data/ext/h3/src/src/apps/testapps/testH3ToLocalIj.c +12 -230
  22. data/ext/h3/src/src/apps/testapps/testH3ToLocalIjExhaustive.c +264 -0
  23. data/ext/h3/src/src/apps/testapps/testPentagonIndexes.c +57 -0
  24. data/ext/h3/src/src/h3lib/include/constants.h +2 -0
  25. data/ext/h3/src/src/h3lib/include/h3api.h.in +20 -0
  26. data/ext/h3/src/src/h3lib/lib/algos.c +5 -5
  27. data/ext/h3/src/src/h3lib/lib/faceijk.c +3 -3
  28. data/ext/h3/src/src/h3lib/lib/h3Index.c +69 -6
  29. data/ext/h3/src/src/h3lib/lib/localij.c +4 -4
  30. data/ext/h3/src/src/h3lib/lib/polygon.c +1 -2
  31. data/h3.gemspec +1 -1
  32. data/lib/h3/bindings/private.rb +1 -0
  33. data/lib/h3/hierarchy.rb +15 -0
  34. data/lib/h3/miscellaneous.rb +25 -0
  35. data/lib/h3/version.rb +1 -1
  36. data/spec/hierarchy_spec.rb +10 -0
  37. data/spec/miscellaneous_spec.rb +28 -0
  38. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcd6c37e501f228912e6a851ff799d38cefd458b424e9c19ed5fc8a635feda9f
4
- data.tar.gz: 9e969c1a07735bed4b498ecdb066f9dde27b5f1d27843f2c48636a8ee6f6fb46
3
+ metadata.gz: 4344398c78a4d188c270838673195d9e16e1a400ab157ec34fa45a006fc17c2b
4
+ data.tar.gz: 0ee405d8aefdb3fa062079903ae586da85598b2a12e87c4b029c11aa3d1c73f2
5
5
  SHA512:
6
- metadata.gz: 33281c3298ba50a851674f6f1523a55c5683bddcfe32772cd7d95a6bf529db6690d20f47c1e9f9b4ff473f5f42283801b403b2620c14241a4e5d005b248dae86
7
- data.tar.gz: cb3677482d3cd5f6cfb0bc63f2d9ebe7bc1c0a9409a354f6917f21fed6044e6b42e2ee2694208873fccef7be498d4034d992bc38d5a339f2691c5af99273f763
6
+ metadata.gz: c385c0805d7b8e59c2610048ff71aacaf9e4b5a8aae21385a36ae42d47f036eab812296752ff108146655ed2fc1b87800246889d3393bf1a6940dfce43e34a4e
7
+ data.tar.gz: f8aeaf98281a57718266fb5eb259d269e1dbf4804c02fb0af25327c39594084eba87fbdb504446066330b5c57368aaedab856c45bf0a437726fd6d95d7b159b0
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
7
  We track the MAJOR and MINOR version levels of Uber's H3 project (https://github.com/uber/h3) but maintain independent patch levels so we can make small fixes and non breaking changes.
8
8
 
9
+ ## [3.6.0] - 2019-8-14
10
+ ### Added
11
+ - `center_child` method to find center child at given resolution (#62).
12
+ - `pentagons` (and `pentagon_count`) method to find pentagons at given resolution (#62).
13
+
9
14
  ## [3.5.1] - 2019-8-5
10
15
  ### Changed
11
16
  - Renamed 26 methods to be more idiomatic with Ruby conventions. The old names are deprecated until 2020 when they will be removed (#59).
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- h3 (3.5.1)
4
+ h3 (3.6.0)
5
5
  ffi (~> 1.9)
6
6
  rgeo-geojson (~> 2.1)
7
- zeitwerk (~> 2.1.9)
7
+ zeitwerk (~> 2.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -20,7 +20,7 @@ GEM
20
20
  ffi (1.11.1)
21
21
  json (2.1.0)
22
22
  rake (12.3.2)
23
- rgeo (2.0.1)
23
+ rgeo (2.1.0)
24
24
  rgeo-geojson (2.1.1)
25
25
  rgeo (>= 1.0.0)
26
26
  rspec (3.8.0)
@@ -1,4 +1,4 @@
1
- # Copyright 2018 Uber Technologies, Inc.
1
+ # Copyright 2018-2019 Uber Technologies, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  language: c
16
16
 
17
17
  os: linux
18
- dist: trusty
18
+ dist: xenial
19
19
 
20
20
  compiler:
21
21
  - gcc
@@ -48,13 +48,24 @@ matrix:
48
48
  packages:
49
49
  - lcov
50
50
  install:
51
- - pip install --user cpp-coveralls
51
+ - gem install coveralls-lcov
52
52
  before_script:
53
53
  - cmake -DCMAKE_BUILD_TYPE=Debug -DWARNINGS_AS_ERRORS=ON -DH3_PREFIX=testprefix_ .
54
54
  script:
55
55
  - make && make coverage
56
56
  after_success:
57
- - coveralls --lcov-file coverage.cleaned.info --verbose
57
+ - coveralls-lcov coverage.cleaned.info
58
+ - env: NAME="Valgrind test"
59
+ compiler: gcc
60
+ addons:
61
+ apt:
62
+ packages:
63
+ - valgrind
64
+ before_script:
65
+ - cmake -DCMAKE_BUILD_TYPE=Debug -DWRAP_VALGRIND=ON .
66
+ script:
67
+ - make
68
+ - CTEST_OUTPUT_ON_FAILURE=1 make test-fast
58
69
  - env: NAME="Mac OSX (Xcode 8)"
59
70
  os: osx
60
71
  - env: NAME="binding-functions target"
@@ -7,6 +7,13 @@ The public API of this library consists of the functions declared in file
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.6.0] - 2019-08-12
11
+ ### Added
12
+ - `h3ToCenterChild` function to find center child at given resolution (#267)
13
+ - `getPentagonIndexes` (and `pentagonIndexCount`) function to find pentagons at given resolution (#267)
14
+ ### Fixed
15
+ - Fix bounds check for local IJ coordinates (#271)
16
+
10
17
  ## [3.5.0] - 2019-07-22
11
18
  ### Added
12
19
  - CMake options for excluding filter applications or benchmarks from the build. (#247)
@@ -143,6 +143,7 @@ set(OTHER_SOURCE_FILES
143
143
  src/apps/testapps/testVertexGraph.c
144
144
  src/apps/testapps/testCompact.c
145
145
  src/apps/testapps/testPolyfill.c
146
+ src/apps/testapps/testPentagonIndexes.c
146
147
  src/apps/testapps/testKRing.c
147
148
  src/apps/testapps/testH3ToGeoBoundary.c
148
149
  src/apps/testapps/testH3ToParent.c
@@ -153,6 +154,7 @@ set(OTHER_SOURCE_FILES
153
154
  src/apps/testapps/testMaxH3ToChildrenSize.c
154
155
  src/apps/testapps/testHexRanges.c
155
156
  src/apps/testapps/testH3ToGeo.c
157
+ src/apps/testapps/testH3ToCenterChild.c
156
158
  src/apps/testapps/testH3ToChildren.c
157
159
  src/apps/testapps/testH3GetFaces.c
158
160
  src/apps/testapps/testGeoCoord.c
@@ -168,8 +170,11 @@ set(OTHER_SOURCE_FILES
168
170
  src/apps/testapps/testH3Api.c
169
171
  src/apps/testapps/testH3SetToLinkedGeo.c
170
172
  src/apps/testapps/testH3ToLocalIj.c
173
+ src/apps/testapps/testH3ToLocalIjExhaustive.c
171
174
  src/apps/testapps/testH3Distance.c
175
+ src/apps/testapps/testH3DistanceExhaustive.c
172
176
  src/apps/testapps/testH3Line.c
177
+ src/apps/testapps/testH3LineExhaustive.c
173
178
  src/apps/testapps/testCoordIj.c
174
179
  src/apps/testapps/testCoordIjk.c
175
180
  src/apps/miscapps/h3ToGeoBoundaryHier.c
@@ -491,6 +496,7 @@ if(BUILD_TESTING)
491
496
  add_h3_test(testHexRing src/apps/testapps/testHexRing.c)
492
497
  add_h3_test(testHexRanges src/apps/testapps/testHexRanges.c)
493
498
  add_h3_test(testH3ToParent src/apps/testapps/testH3ToParent.c)
499
+ add_h3_test(testH3ToCenterChild src/apps/testapps/testH3ToCenterChild.c)
494
500
  add_h3_test(testH3ToChildren src/apps/testapps/testH3ToChildren.c)
495
501
  add_h3_test(testH3GetFaces src/apps/testapps/testH3GetFaces.c)
496
502
  add_h3_test(testMaxH3ToChildrenSize src/apps/testapps/testMaxH3ToChildrenSize.c)
@@ -513,10 +519,19 @@ if(BUILD_TESTING)
513
519
  add_h3_test(testCoordIj src/apps/testapps/testCoordIj.c)
514
520
  add_h3_test(testCoordIjk src/apps/testapps/testCoordIjk.c)
515
521
  add_h3_test(testBaseCells src/apps/testapps/testBaseCells.c)
522
+ add_h3_test(testPentagonIndexes src/apps/testapps/testPentagonIndexes.c)
516
523
 
517
524
  add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 0)
518
525
  add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 1)
519
526
  add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 2)
527
+
528
+ # The "Exhaustive" part of the test name is used by the test-fast to exclude these files.
529
+ # test-fast exists so that Travis CI can run Valgrind on tests without taking a very long time.
530
+ add_h3_test(testH3ToLocalIjExhaustive src/apps/testapps/testH3ToLocalIjExhaustive.c)
531
+ add_h3_test(testH3LineExhaustive src/apps/testapps/testH3LineExhaustive.c)
532
+ add_h3_test(testH3DistanceExhaustive src/apps/testapps/testH3DistanceExhaustive.c)
533
+
534
+ add_custom_target(test-fast COMMAND ctest -E Exhaustive)
520
535
  endif()
521
536
 
522
537
  if(BUILD_BENCHMARKS)
data/ext/h3/src/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <img align="right" src="https://uber.github.io/res/h3Logo-color.svg" alt="H3 Logo" width="200">
2
+
1
3
  # H3: A Hexagonal Hierarchical Geospatial Indexing System
2
4
 
3
5
  [![Build Status](https://travis-ci.com/uber/h3.svg?branch=master)](https://travis-ci.com/uber/h3)
@@ -92,8 +94,7 @@ To build the documentation website, see the [website/](./website/) directory.
92
94
  To get the H3 index for some location:
93
95
 
94
96
  ```
95
- ./bin/geoToH3 10
96
- 40.689167 -74.044444
97
+ ./bin/geoToH3 --resolution 10 --latitude 40.689167 --longitude -74.044444
97
98
  ```
98
99
 
99
100
  10 is the H3 resolution, between 0 (coarsest) and 15 (finest). The coordinates entered are the latitude and longitude, in degrees, you want the index for (these coordinates are the Statue of Liberty). You should get an H3 index as output, like `8a2a1072b59ffff`.
@@ -101,8 +102,7 @@ To get the H3 index for some location:
101
102
  You can then take this index and get some information about it, for example:
102
103
 
103
104
  ```
104
- ./bin/h3ToGeoBoundary
105
- 8a2a1072b59ffff
105
+ ./bin/h3ToGeoBoundary --index 8a2a1072b59ffff
106
106
  ```
107
107
 
108
108
  This will produce the vertices of the hexagon at this location:
@@ -122,8 +122,7 @@ This will produce the vertices of the hexagon at this location:
122
122
  You can get the center coordinate of the hexagon like so:
123
123
 
124
124
  ```
125
- ./bin/h3ToGeo
126
- 8a2a1072b59ffff
125
+ ./bin/h3ToGeo --index 8a2a1072b59ffff
127
126
  ```
128
127
 
129
128
  This will produce some coordinate:
data/ext/h3/src/VERSION CHANGED
@@ -1 +1 @@
1
- 3.5.0
1
+ 3.6.0
@@ -26,6 +26,14 @@ int maxH3ToChildrenSize(H3Index h, int childRes);
26
26
 
27
27
  Returns the size of the array needed by `h3ToChildren` for these inputs.
28
28
 
29
+ ## h3ToCenterChild
30
+
31
+ ```
32
+ H3Index h3ToCenterChild(H3Index h, int childRes);
33
+ ```
34
+
35
+ Returns the center child (finer) index contained by `h` at resolution `childRes`.
36
+
29
37
  ## compact
30
38
 
31
39
  ```
@@ -65,6 +65,7 @@ void getRes0Indexes(H3Index *out);
65
65
  ```
66
66
 
67
67
  All the resolution 0 **H3** indexes.
68
+ `out` must be an array of at least size `res0IndexCount()`.
68
69
 
69
70
  ## res0IndexCount
70
71
 
@@ -73,3 +74,20 @@ int res0IndexCount();
73
74
  ```
74
75
 
75
76
  Number of resolution 0 **H3** indexes.
77
+
78
+ ## getPentagonIndexes
79
+
80
+ ```
81
+ void getPentagonIndexes(int res, H3Index *out);
82
+ ```
83
+
84
+ All the pentagon **H3** indexes at the specified resolution.
85
+ `out` must be an array of at least size `pentagonIndexCount()`.
86
+
87
+ ## pentagonIndexCount
88
+
89
+ ```
90
+ int pentagonIndexCount();
91
+ ```
92
+
93
+ Number of pentagon **H3** indexes per resolution. This is always 12, but provided as a convenience.
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- # Copyright 2018 Uber Technologies, Inc.
3
+ # Copyright 2018-2019 Uber Technologies, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -44,7 +44,11 @@ fi
44
44
  src_dir=${1:-"Missing source directory"}
45
45
  binary_dir=${2:-"Missing binary directory"}
46
46
 
47
+ # Exclude the usual LCOV exclusion comment, and also
48
+ # do not require branch coverage for assertions.
49
+ br_exclusion='LCOV_EXCL_BR_LINE|assert\('
50
+
47
51
  cd "${binary_dir}"
48
- lcov --rc lcov_branch_coverage=1 --directory . --capture --output-file coverage.info
49
- lcov --rc lcov_branch_coverage=1 --extract coverage.info "${src_dir}/src/h3lib/*" --output-file coverage.cleaned.info
52
+ lcov --rc lcov_branch_coverage=1 --rc "lcov_excl_br_line=$br_exclusion" --directory . --capture --output-file coverage.info
53
+ lcov --rc lcov_branch_coverage=1 --rc "lcov_excl_br_line=$br_exclusion" --extract coverage.info "${src_dir}/src/h3lib/*" --output-file coverage.cleaned.info
50
54
  genhtml --branch-coverage -o coverage coverage.cleaned.info --title 'h3 coverage'
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2016-2018 Uber Technologies, Inc.
2
+ * Copyright 2016-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.
@@ -87,7 +87,7 @@ static void generate() {
87
87
 
88
88
  for (int i = 0; i < NUM_BASE_CELLS; i++) {
89
89
  if (!_isBaseCellPentagon(i)) {
90
- for (int dir = 0; dir <= NUM_DIRS; dir++) {
90
+ for (int dir = CENTER_DIGIT; dir <= NUM_DIRS; dir++) {
91
91
  FaceIJK fijk;
92
92
  _baseCellToFaceIjk(i, &fijk);
93
93
  _neighbor(&fijk.coord, dir);
@@ -28,8 +28,6 @@
28
28
  #include <stdlib.h>
29
29
  #include "constants.h"
30
30
 
31
- #define NUM_PENTAGONS 12
32
-
33
31
  /**
34
32
  * Generates and prints the numHexagons table.
35
33
  */
@@ -165,6 +165,10 @@ SUITE(compact) {
165
165
  sizeResult = H3_EXPORT(maxUncompactSize)(someHexagons, numHex, -1);
166
166
  t_assert(sizeResult < 0,
167
167
  "maxUncompactSize fails when given illegal resolutions");
168
+ sizeResult =
169
+ H3_EXPORT(maxUncompactSize)(someHexagons, numHex, MAX_H3_RES + 1);
170
+ t_assert(sizeResult < 0,
171
+ "maxUncompactSize fails when given resolutions beyond max");
168
172
 
169
173
  H3Index uncompressed[] = {0, 0, 0};
170
174
  int uncompactResult =
@@ -180,6 +184,14 @@ SUITE(compact) {
180
184
  t_assert(
181
185
  uncompactResult != 0,
182
186
  "uncompact fails when given too little buffer (same resolution)");
187
+
188
+ for (int i = 0; i < numHex; i++) {
189
+ setH3Index(&someHexagons[i], MAX_H3_RES, i, 0);
190
+ }
191
+ uncompactResult = H3_EXPORT(uncompact)(
192
+ someHexagons, numHex, uncompressed, numHex * 7, MAX_H3_RES + 1);
193
+ t_assert(uncompactResult != 0,
194
+ "uncompact fails when given resolutions beyond max");
183
195
  }
184
196
 
185
197
  TEST(someHexagon) {
@@ -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.
@@ -31,40 +31,6 @@
31
31
  #include "test.h"
32
32
  #include "utility.h"
33
33
 
34
- static const int MAX_DISTANCES[] = {1, 2, 5, 12, 19, 26};
35
-
36
- static void h3Distance_identity_assertions(H3Index h3) {
37
- t_assert(H3_EXPORT(h3Distance)(h3, h3) == 0, "distance to self is 0");
38
- }
39
-
40
- static void h3Distance_kRing_assertions(H3Index h3) {
41
- int r = H3_GET_RESOLUTION(h3);
42
- t_assert(r <= 5, "resolution supported by test function (kRing)");
43
- int maxK = MAX_DISTANCES[r];
44
-
45
- int sz = H3_EXPORT(maxKringSize)(maxK);
46
- H3Index *neighbors = calloc(sz, sizeof(H3Index));
47
- int *distances = calloc(sz, sizeof(int));
48
-
49
- H3_EXPORT(kRingDistances)(h3, maxK, neighbors, distances);
50
-
51
- for (int i = 0; i < sz; i++) {
52
- if (neighbors[i] == 0) {
53
- continue;
54
- }
55
-
56
- int calculatedDistance = H3_EXPORT(h3Distance)(h3, neighbors[i]);
57
-
58
- // Don't consider indexes where h3Distance reports failure to
59
- // generate
60
- t_assert(calculatedDistance == distances[i] || calculatedDistance == -1,
61
- "kRingDistances matches h3Distance");
62
- }
63
-
64
- free(distances);
65
- free(neighbors);
66
- }
67
-
68
34
  SUITE(h3Distance) {
69
35
  // Some indexes that represent base cells. Base cells
70
36
  // are hexagons except for `pent1`.
@@ -118,21 +84,6 @@ SUITE(h3Distance) {
118
84
  "distance in res 2 across pentagon (reversed)");
119
85
  }
120
86
 
121
- TEST(h3Distance_identity) {
122
- iterateAllIndexesAtRes(0, h3Distance_identity_assertions);
123
- iterateAllIndexesAtRes(1, h3Distance_identity_assertions);
124
- iterateAllIndexesAtRes(2, h3Distance_identity_assertions);
125
- }
126
-
127
- TEST(h3Distance_kRing) {
128
- iterateAllIndexesAtRes(0, h3Distance_kRing_assertions);
129
- iterateAllIndexesAtRes(1, h3Distance_kRing_assertions);
130
- iterateAllIndexesAtRes(2, h3Distance_kRing_assertions);
131
- // Don't iterate all of res 3, to save time
132
- iterateAllIndexesAtResPartial(3, h3Distance_kRing_assertions, 27);
133
- // Further resolutions aren't tested to save time.
134
- }
135
-
136
87
  TEST(h3DistanceBaseCells) {
137
88
  t_assert(H3_EXPORT(h3Distance)(bc1, pent1) == 1,
138
89
  "distance to neighbor is 1 (15, 4)");
@@ -0,0 +1,83 @@
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 distance function using tests over a large number of indexes.
18
+ *
19
+ * usage: `testH3DistanceExhaustive`
20
+ */
21
+
22
+ #include <stdio.h>
23
+ #include <stdlib.h>
24
+ #include <string.h>
25
+ #include "algos.h"
26
+ #include "baseCells.h"
27
+ #include "constants.h"
28
+ #include "h3Index.h"
29
+ #include "h3api.h"
30
+ #include "localij.h"
31
+ #include "test.h"
32
+ #include "utility.h"
33
+
34
+ static const int MAX_DISTANCES[] = {1, 2, 5, 12, 19, 26};
35
+
36
+ static void h3Distance_identity_assertions(H3Index h3) {
37
+ t_assert(H3_EXPORT(h3Distance)(h3, h3) == 0, "distance to self is 0");
38
+ }
39
+
40
+ static void h3Distance_kRing_assertions(H3Index h3) {
41
+ int r = H3_GET_RESOLUTION(h3);
42
+ t_assert(r <= 5, "resolution supported by test function (kRing)");
43
+ int maxK = MAX_DISTANCES[r];
44
+
45
+ int sz = H3_EXPORT(maxKringSize)(maxK);
46
+ H3Index *neighbors = calloc(sz, sizeof(H3Index));
47
+ int *distances = calloc(sz, sizeof(int));
48
+
49
+ H3_EXPORT(kRingDistances)(h3, maxK, neighbors, distances);
50
+
51
+ for (int i = 0; i < sz; i++) {
52
+ if (neighbors[i] == 0) {
53
+ continue;
54
+ }
55
+
56
+ int calculatedDistance = H3_EXPORT(h3Distance)(h3, neighbors[i]);
57
+
58
+ // Don't consider indexes where h3Distance reports failure to
59
+ // generate
60
+ t_assert(calculatedDistance == distances[i] || calculatedDistance == -1,
61
+ "kRingDistances matches h3Distance");
62
+ }
63
+
64
+ free(distances);
65
+ free(neighbors);
66
+ }
67
+
68
+ SUITE(h3Distance) {
69
+ TEST(h3Distance_identity) {
70
+ iterateAllIndexesAtRes(0, h3Distance_identity_assertions);
71
+ iterateAllIndexesAtRes(1, h3Distance_identity_assertions);
72
+ iterateAllIndexesAtRes(2, h3Distance_identity_assertions);
73
+ }
74
+
75
+ TEST(h3Distance_kRing) {
76
+ iterateAllIndexesAtRes(0, h3Distance_kRing_assertions);
77
+ iterateAllIndexesAtRes(1, h3Distance_kRing_assertions);
78
+ iterateAllIndexesAtRes(2, h3Distance_kRing_assertions);
79
+ // Don't iterate all of res 3, to save time
80
+ iterateAllIndexesAtResPartial(3, h3Distance_kRing_assertions, 27);
81
+ // Further resolutions aren't tested to save time.
82
+ }
83
+ }