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
@@ -1,5 +1,4 @@
1
- Overview of the H3 Geospatial Indexing System
2
- ---
1
+ # Overview of the H3 Geospatial Indexing System
3
2
 
4
3
  The **H3** geospatial indexing system is a discrete global grid system (see [Sahr et al., 2003](http://webpages.sou.edu/~sahrk/sqspc/pubs/gdggs03.pdf)) consisting of a multi-precision hexagonal tiling of the sphere with hierarchical indexes. The hexagonal grid system is created on the planar faces of a sphere-circumscribed icosahedron, and the grid cells are then projected to the surface of the sphere using an inverse face-centered polyhedral gnomonic projection.
5
4
 
@@ -9,6 +8,6 @@ The **H3** grid is constructed on the icosahedron by recursively creating increa
9
8
 
10
9
  The first **H3** resolution (resolution 0) consists of 122 cells (110 hexagons and 12 icosahedron vertex-centered pentagons), referred to as the *base cells*. These were chosen to capture as much of the symmetry of the spherical icosahedron as possible. These base cells are assigned numbers from 0 to 121 based on the latitude of their center points; base cell 0 has the northern most center point, while base cell 121 has the southern most center point.
11
10
 
12
- Each subsequent resolution beyond resolution 0 is created using an aperture 7 resolution spacing (aperture refers to the number of cells in the next finer resolution grid for each cell); as resolution increases the unit length is scaled by \\(\sqrt{7}\\) and each hexagon has \\(1/7th\\) the area of a hexagon at the next coarser resolution (as measured on the icosahedron). **H3** provides 15 finer grid resolutions in addition to the resolution 0 base cells. The finest resolution, resolution 15, has cells with an area of less than 1 \\(m^2\\). A table detailing the average cell area for each H3 resolution is available <a href="#/documentation/core-library/resolution-table">here</a>.
11
+ Each subsequent resolution beyond resolution 0 is created using an aperture 7 resolution spacing (aperture refers to the number of cells in the next finer resolution grid for each cell); as resolution increases the unit length is scaled by $\sqrt{7}$ and each hexagon has $1/7th$ the area of a hexagon at the next coarser resolution (as measured on the icosahedron). **H3** provides 15 finer grid resolutions in addition to the resolution 0 base cells. The finest resolution, resolution 15, has cells with an area of less than $1 m^2$. A table detailing the average cell area for each H3 resolution is available [here](/docs/core-library/restable).
13
12
 
14
13
  *Note:* you can create KML files to visualize the **H3** grids by running the `kml` make target. It will place the files in the `KML` output sub-directory.
@@ -1,5 +1,4 @@
1
- Table of Cell Areas for H3 Resolutions
2
- ---
1
+ # Table of Cell Areas for H3 Resolutions
3
2
 
4
3
  | H3 Resolution | Average Hexagon Area (km<sup>2</sup>) | Average Hexagon Edge Length (km) | Number of unique indexes
5
4
  | ------------- | ------------------------------------: | -------------------------------: | -----------------------:
@@ -1,5 +1,4 @@
1
- How to use H3
2
- ---
1
+ # How to use H3
3
2
 
4
3
  The public API of the **H3 Core Library** is defined in the file h3api.h. The functions defined in h3api.h adhere to [Semantic Versioning](http://semver.org/).
5
4
 
@@ -0,0 +1,47 @@
1
+ {
2
+ "id": "table-of-contents",
3
+ "chapters": [
4
+ {
5
+ "title": "Overview",
6
+ "entries": [
7
+ {"entry": "docs/README"},
8
+ {"entry": "docs/usecases"}
9
+ ]
10
+ },
11
+ {
12
+ "title": "Core Library",
13
+ "entries": [
14
+ {"entry": "docs/core-library/overview"},
15
+ {"entry": "docs/core-library/h3indexing"},
16
+ {"entry": "docs/core-library/coordsystems"},
17
+ {"entry": "docs/core-library/geoToH3desc"},
18
+ {"entry": "docs/core-library/h3ToGeoDesc"},
19
+ {"entry": "docs/core-library/h3ToGeoBoundaryDesc"},
20
+ {"entry": "docs/core-library/filters"},
21
+ {"entry": "docs/core-library/usage"},
22
+ {"entry": "docs/core-library/restable"}
23
+ ]
24
+ },
25
+ {
26
+ "title": "API Reference",
27
+ "entries": [
28
+ {"entry": "docs/api/indexing"},
29
+ {"entry": "docs/api/inspection"},
30
+ {"entry": "docs/api/traversal"},
31
+ {"entry": "docs/api/hierarchy"},
32
+ {"entry": "docs/api/regions"},
33
+ {"entry": "docs/api/uniedge"},
34
+ {"entry": "docs/api/misc"}
35
+ ]
36
+ },
37
+ {
38
+ "title": "Community",
39
+ "entries": [
40
+ {"entry": "docs/community/bindings"},
41
+ {"entry": "docs/community/libraries"},
42
+ {"entry": "docs/community/tutorials"},
43
+ {"entry": "docs/community/applications"}
44
+ ]
45
+ }
46
+ ]
47
+ }
@@ -1,8 +1,4 @@
1
- Why H3
2
- ---
3
-
4
- Use cases
5
- ---
1
+ # Use cases
6
2
 
7
3
  Analysis of data sets of locations, such as locations of cars in a city, may be done by bucketing locations. ([Sahr et al., 2003](http://webpages.sou.edu/~sahrk/sqspc/pubs/gdggs03.pdf)) There are several options for partitioning an area into buckets, such as manually drawing regions using human knowledge, or to partition the surface using a regular grid.
8
4
 
@@ -16,7 +12,7 @@ Using a regular grid can avoid these drawbacks by providing smooth gradients and
16
12
 
17
13
  | Triangle | Square | Hexagon
18
14
  | -------- | ------ | -------
19
- | <img src="images/neighbors-triangle.png" style="width:400px"> | <img src="images/neighbors-square.png" style="width:400px"> | <img src="images/neighbors-hexagon.png" style="width:400px">
15
+ | <img src="/images/neighbors-triangle.png" style="width:400px"> | <img src="/images/neighbors-square.png" style="width:400px"> | <img src="/images/neighbors-hexagon.png" style="width:400px">
20
16
  | Triangles have 12 neighbors | Squares have 8 neighbors | Hexagons have 6 neighbors
21
17
 
22
18
  In addition to indexing locations to cells, **H3** provides a number of algorithms operating on indexes.
@@ -24,14 +20,14 @@ In addition to indexing locations to cells, **H3** provides a number of algorith
24
20
  Hexagons have the property of expanding rings of neighbors (`kRing`) approximating circles:
25
21
 
26
22
  <div align="center">
27
- <img src="images/neighbors.png" style="width:400px"><br>
23
+ <img src="/images/neighbors.png" style="width:400px"><br>
28
24
  <i>All six neighbors of a hexagon (ring 1)</i>
29
25
  </div>
30
26
 
31
27
  Squares cleanly subdivide into four finer squares. Hexagons do not cleanly subdivide into seven finer hexagons. However, by alternating the orientation of grids a subdivision into seven cells (referred to as *aperture 7*) can be approximated. This makes it possible to truncate the precision (within a fixed margin of error) of an **H3** index using a few bitwise operations (`h3ToParent`). It is also possible to determine all the children of a parent **H3** index (`h3ToChildren`). Approximate containment only applies when truncating the precision of an **H3** index. The borders of hexagons indexed at a specific resolution are not approximate.
32
28
 
33
29
  <div align="center">
34
- <img src="images/parent-child.png" style="width:400px"><br>
30
+ <img src="/images/parent-child.png" style="width:400px"><br>
35
31
  <i>A parent hexagon approximately contains seven children</i>
36
32
  </div>
37
33
 
@@ -39,11 +35,10 @@ Hierarchical containment allows for use cases like making contiguous sets of hex
39
35
 
40
36
  | Uncompact (dense) | Compact (sparse)
41
37
  | ----------------- | ----------------
42
- | <img src="images/ca_uncompact_6_10633.png" style="width:500px"> | <img src="images/ca_compact_6_901.png" style="width:500px">
38
+ | <img src="/images/ca_uncompact_6_10633.png" style="width:500px"> | <img src="/images/ca_compact_6_901.png" style="width:500px">
43
39
  | California represented by 10633 uncompact hexagons | California represented by 901 compact hexagons
44
40
 
45
- Comparisons
46
- ---
41
+ ## Comparisons
47
42
 
48
43
  | System | Index representation | Cell shape | Projection system
49
44
  | --------- | -------------------- | ---------- | -----------------
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  # Copyright 2017 Uber Technologies, Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
3
  # Copyright 2018-2019 Uber Technologies, Inc.
4
4
  #
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  # Copyright 2019 Uber Technologies, Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- # This script is used interactively as part of the H3 release process
16
+ # This script is used interactively as part of the H3 release process
17
17
  # (RELEASE.md) to update the version number in the VERSION file. Before
18
18
  # writing the new version to the file, changelog information is presented
19
19
  # for verification. It is invoked by the make target `update-version`.
@@ -23,6 +23,7 @@
23
23
  #include <inttypes.h>
24
24
  #include <stdbool.h>
25
25
  #include <stdio.h>
26
+
26
27
  #include "utility.h"
27
28
 
28
29
  /** Maximum number of names an argument may have. */
@@ -21,6 +21,7 @@
21
21
  #define TEST_H
22
22
 
23
23
  #include <stdio.h>
24
+
24
25
  #include "geoCoord.h"
25
26
  #include "h3api.h"
26
27
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2016-2019 Uber Technologies, Inc.
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.
@@ -21,6 +21,7 @@
21
21
  #define UTILITY_H
22
22
 
23
23
  #include <stdio.h>
24
+
24
25
  #include "coordijk.h"
25
26
  #include "h3api.h"
26
27
 
@@ -54,5 +55,10 @@ void iterateAllIndexesAtResPartial(int res, void (*callback)(H3Index),
54
55
  int maxBaseCell);
55
56
  void iterateBaseCellIndexesAtRes(int res, void (*callback)(H3Index),
56
57
  int baseCell);
58
+ void iterateAllUnidirectionalEdgesAtRes(int res, void (*callback)(H3Index));
59
+ double mapSumAllCells_double(int res, double (*callback)(H3Index));
60
+ size_t packNonzeros(H3Index* a, size_t n);
61
+
62
+ int countActualHexagons(H3Index* hexagons, int numHexagons);
57
63
 
58
64
  #endif
@@ -18,10 +18,12 @@
18
18
  */
19
19
 
20
20
  #include "args.h"
21
+
21
22
  #include <stdbool.h>
22
23
  #include <stdio.h>
23
24
  #include <stdlib.h>
24
25
  #include <string.h>
26
+
25
27
  #include "h3api.h"
26
28
 
27
29
  /*
@@ -18,7 +18,9 @@
18
18
  */
19
19
 
20
20
  #include "kml.h"
21
+
21
22
  #include <stdio.h>
23
+
22
24
  #include "h3api.h"
23
25
 
24
26
  void kmlPtsHeader(const char* name, const char* desc) {
@@ -18,6 +18,7 @@
18
18
  */
19
19
 
20
20
  #include "test.h"
21
+
21
22
  #include <assert.h>
22
23
  #include <stdio.h>
23
24
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2016-2019 Uber Technologies, Inc.
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.
@@ -18,12 +18,14 @@
18
18
  */
19
19
 
20
20
  #include "utility.h"
21
+
21
22
  #include <assert.h>
22
23
  #include <inttypes.h>
23
24
  #include <stdio.h>
24
25
  #include <stdlib.h>
25
26
  #include <string.h>
26
27
  #include <time.h>
28
+
27
29
  #include "coordijk.h"
28
30
  #include "h3Index.h"
29
31
  #include "h3api.h"
@@ -175,6 +177,122 @@ int readBoundary(FILE* f, GeoBoundary* b) {
175
177
  return 0;
176
178
  }
177
179
 
180
+ /**
181
+ * Move nonzero elements to the front of array `a` of length `n`.
182
+ *
183
+ * Loop invariant: Everything *before* `i` or *after* `j` is "done".
184
+ * Move `i` and `j` inwards until they equal, and exit.
185
+ * You can move `i` forward until there's a zero in front of it.
186
+ * You can move `j` backward until there's a nonzero to the left of it.
187
+ * Anything to the right of `j` is "junk" that can be reallocated.
188
+ *
189
+ * Before:
190
+ * | a | b | 0 | c | d | ... |
191
+ * ^ ^
192
+ * i j
193
+ * After:
194
+ * | a | b | d | c | d | ... |
195
+ * ^ ^
196
+ * i j
197
+ *
198
+ * todo: should this function be in the public API?
199
+ * todo: add tests for this function
200
+ *
201
+ * @param a H3Index array to whose elements will be moved
202
+ * @param n length of the input array
203
+ * @return number of nonzero elements (length of new array); can reallocate
204
+ * memory after this point
205
+ */
206
+ size_t packNonzeros(H3Index* a, size_t n) {
207
+ size_t i = 0;
208
+ size_t j = n;
209
+
210
+ while (i < j) {
211
+ // move j to the left until the first nonzero
212
+ if (a[j - 1] == 0) {
213
+ j -= 1;
214
+ continue;
215
+ }
216
+
217
+ // move i to the right until the first zero
218
+ if (a[i] != 0) {
219
+ i += 1;
220
+ continue;
221
+ }
222
+
223
+ // if we get to this point, we know:
224
+ // a[i] == 0
225
+ // a[j-1] != 0
226
+ // i < j
227
+ // so we can swap! (actually, move a[j-1] -> a[i])
228
+ a[i] = a[j - 1];
229
+ j -= 1;
230
+ }
231
+
232
+ return i;
233
+ }
234
+
235
+ /**
236
+ * Array of all cells at a given resolution.
237
+ *
238
+ * @param res resolution
239
+ *
240
+ * @return array of H3 cells at resolution res
241
+ */
242
+ H3Index* getCellsAtRes(int res) {
243
+ int num0 = H3_EXPORT(res0IndexCount)();
244
+ H3Index* cells0 = calloc(num0, sizeof(H3Index));
245
+ H3_EXPORT(getRes0Indexes)(cells0);
246
+
247
+ int numRes = H3_EXPORT(maxUncompactSize)(cells0, num0, res);
248
+
249
+ H3Index* cellsRes = calloc(numRes, sizeof(H3Index));
250
+ H3_EXPORT(uncompact)(cells0, num0, cellsRes, numRes, res);
251
+
252
+ free(cells0);
253
+
254
+ numRes = packNonzeros(cellsRes, numRes);
255
+ cellsRes = realloc(cellsRes, numRes * sizeof(H3Index));
256
+
257
+ return cellsRes;
258
+ }
259
+
260
+ /**
261
+ * Apply callback to every cell for a given resolution, and sum the results.
262
+ */
263
+ double mapSumAllCells_double(int res, double (*callback)(H3Index)) {
264
+ H3Index* cells = getCellsAtRes(res);
265
+ int N = H3_EXPORT(numHexagons)(res);
266
+
267
+ double total = 0.0;
268
+ for (int i = 0; i < N; i++) {
269
+ total += (*callback)(cells[i]);
270
+ }
271
+ free(cells);
272
+
273
+ return total;
274
+ }
275
+
276
+ /**
277
+ * Apply callback for every unidirectional edge at the given resolution.
278
+ */
279
+ void iterateAllUnidirectionalEdgesAtRes(int res, void (*callback)(H3Index)) {
280
+ H3Index* cells = getCellsAtRes(res);
281
+ int N = H3_EXPORT(numHexagons)(res);
282
+
283
+ for (int i = 0; i < N; i++) {
284
+ H3Index edges[6] = {H3_NULL};
285
+ int isPentagon = H3_EXPORT(h3IsPentagon)(cells[i]);
286
+ H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(cells[i], edges);
287
+
288
+ for (int j = 0; j < 6; j++) {
289
+ if (isPentagon && j == 0) continue;
290
+ (*callback)(edges[j]);
291
+ }
292
+ }
293
+ free(cells);
294
+ }
295
+
178
296
  /**
179
297
  * Call the callback for every index at the given resolution.
180
298
  */
@@ -207,7 +325,7 @@ void iterateBaseCellIndexesAtRes(int res, void (*callback)(H3Index),
207
325
  H3_EXPORT(uncompact)(&bc, 1, children, childrenSz, res);
208
326
 
209
327
  for (int j = 0; j < childrenSz; j++) {
210
- if (children[j] == 0) {
328
+ if (children[j] == H3_NULL) {
211
329
  continue;
212
330
  }
213
331
 
@@ -233,3 +351,16 @@ void randomGeo(GeoCoord* g) {
233
351
  (((float)rand() / (float)(RAND_MAX)) * 180.0) - 90.0);
234
352
  g->lon = H3_EXPORT(degsToRads)((float)rand() / (float)(RAND_MAX)) * 360.0;
235
353
  }
354
+
355
+ /**
356
+ * Returns the number of non-invalid indexes in the array.
357
+ */
358
+ int countActualHexagons(H3Index* hexagons, int numHexagons) {
359
+ int actualNumHexagons = 0;
360
+ for (int i = 0; i < numHexagons; i++) {
361
+ if (hexagons[i] != H3_NULL) {
362
+ actualNumHexagons++;
363
+ }
364
+ }
365
+ return actualNumHexagons;
366
+ }
@@ -17,7 +17,7 @@
17
17
  #include "geoCoord.h"
18
18
  #include "h3api.h"
19
19
 
20
- // Fixtures
20
+ // Fixtures (arbitrary res 9 hexagon)
21
21
  GeoCoord coord = {0.659966917655, -2.1364398519396};
22
22
  H3Index hex = 0x89283080ddbffff;
23
23
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2018 Uber Technologies, Inc.
2
+ * Copyright 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.
@@ -13,19 +13,22 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ #include "benchmark.h"
17
+ #include "geoCoord.h"
18
+ #include "h3api.h"
16
19
 
17
- module.exports = {
20
+ // Fixtures (arbitrary res 9 hexagon)
21
+ H3Index edges[6] = {0};
22
+ H3Index hex = 0x89283080ddbffff;
18
23
 
19
- title: 'H3',
24
+ BEGIN_BENCHMARKS();
20
25
 
21
- meta: [{
22
- name: 'description',
23
- content: 'A hexagonal hierarchical geospatial indexing system'
24
- }],
26
+ GeoBoundary outBoundary;
27
+ H3_EXPORT(getH3UnidirectionalEdgesFromHexagon)(hex, edges);
25
28
 
26
- scripts: [
27
- // Adds Mathjax support
28
- 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML'
29
- ]
29
+ BENCHMARK(getH3UnidirectionalEdgeBoundary, 10000, {
30
+ for (int i = 0; i < 6; i++)
31
+ H3_EXPORT(getH3UnidirectionalEdgeBoundary)(edges[i], &outBoundary);
32
+ });
30
33
 
31
- };
34
+ END_BENCHMARKS();