h3 3.6.0 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby_ci.yml +30 -0
  3. data/.rubocop.yml +1 -1
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +39 -0
  6. data/Gemfile.lock +6 -24
  7. data/LICENSE.md +1 -1
  8. data/README.md +2 -3
  9. data/ext/h3/src/.github/workflows/test-linux.yml +118 -0
  10. data/ext/h3/src/.github/workflows/test-macos.yml +42 -0
  11. data/ext/h3/src/.github/workflows/test-website.yml +32 -0
  12. data/ext/h3/src/.github/workflows/test-windows.yml +44 -0
  13. data/ext/h3/src/.gitignore +5 -0
  14. data/ext/h3/src/.travis.yml +20 -42
  15. data/ext/h3/src/CHANGELOG.md +57 -0
  16. data/ext/h3/src/CMakeLists.txt +135 -33
  17. data/ext/h3/src/CONTRIBUTING.md +1 -1
  18. data/ext/h3/src/README.md +61 -11
  19. data/ext/h3/src/RELEASE.md +3 -1
  20. data/ext/h3/src/VERSION +1 -1
  21. data/ext/h3/src/dev-docs/RFCs/rfc-template.md +21 -0
  22. data/ext/h3/src/dev-docs/RFCs/v4.0.0/error-handling-rfc.md +21 -0
  23. data/ext/h3/src/dev-docs/RFCs/v4.0.0/names_for_concepts_types_functions.md +276 -0
  24. data/ext/h3/src/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md +141 -0
  25. data/ext/h3/src/dev-docs/RFCs/v4.0.0/polyfill-modes-rfc.md +21 -0
  26. data/ext/h3/src/dev-docs/RFCs/v4.0.0/vertex-mode-rfc.md +50 -0
  27. data/ext/h3/src/dev-docs/build_windows.md +6 -1
  28. data/ext/h3/src/dev-docs/creating_bindings.md +3 -3
  29. data/ext/h3/src/dev-docs/custom_alloc.md +27 -0
  30. data/ext/h3/src/docs/{overview/mainpage.md → README.md} +2 -3
  31. data/ext/h3/src/docs/api/misc.md +76 -0
  32. data/ext/h3/src/docs/community/applications.md +1 -0
  33. data/ext/h3/src/docs/community/bindings.md +10 -0
  34. data/ext/h3/src/docs/community/tutorials.md +8 -3
  35. data/ext/h3/src/docs/core-library/coordsystems.md +5 -4
  36. data/ext/h3/src/docs/core-library/filters.md +8 -9
  37. data/ext/h3/src/docs/core-library/geoToH3desc.md +2 -3
  38. data/ext/h3/src/docs/core-library/h3ToGeoBoundaryDesc.md +4 -5
  39. data/ext/h3/src/docs/core-library/h3ToGeoDesc.md +3 -4
  40. data/ext/h3/src/docs/core-library/h3indexing.md +26 -17
  41. data/ext/h3/src/docs/core-library/overview.md +2 -3
  42. data/ext/h3/src/docs/core-library/restable.md +1 -2
  43. data/ext/h3/src/docs/core-library/usage.md +1 -2
  44. data/ext/h3/src/docs/table-of-contents.json +47 -0
  45. data/ext/h3/src/docs/{overview/usecases.md → usecases.md} +6 -11
  46. data/ext/h3/src/scripts/binding_functions.sh +1 -1
  47. data/ext/h3/src/scripts/coverage.sh.in +1 -1
  48. data/ext/h3/src/scripts/update_version.sh +2 -2
  49. data/ext/h3/src/src/apps/applib/include/args.h +1 -0
  50. data/ext/h3/src/src/apps/applib/include/test.h +1 -0
  51. data/ext/h3/src/src/apps/applib/include/utility.h +7 -1
  52. data/ext/h3/src/src/apps/applib/lib/args.c +2 -0
  53. data/ext/h3/src/src/apps/applib/lib/kml.c +2 -0
  54. data/ext/h3/src/src/apps/applib/lib/test.c +1 -0
  55. data/ext/h3/src/src/apps/applib/lib/utility.c +133 -2
  56. data/ext/h3/src/src/apps/benchmarks/benchmarkH3Api.c +1 -1
  57. data/ext/h3/src/{website/html.config.js → src/apps/benchmarks/benchmarkH3UniEdge.c} +15 -12
  58. data/ext/h3/src/src/apps/filters/h3ToComponents.c +1 -0
  59. data/ext/h3/src/src/apps/filters/h3ToGeo.c +1 -0
  60. data/ext/h3/src/src/apps/filters/h3ToGeoBoundary.c +1 -0
  61. data/ext/h3/src/src/apps/filters/h3ToLocalIj.c +1 -0
  62. data/ext/h3/src/src/apps/filters/hexRange.c +1 -0
  63. data/ext/h3/src/src/apps/filters/kRing.c +1 -0
  64. data/ext/h3/src/src/apps/filters/localIjToH3.c +1 -0
  65. data/ext/h3/src/src/apps/miscapps/generateFaceCenterPoint.c +1 -0
  66. data/ext/h3/src/src/apps/miscapps/generateNumHexagons.c +1 -0
  67. data/ext/h3/src/src/apps/miscapps/generatePentagonDirectionFaces.c +67 -0
  68. data/ext/h3/src/src/apps/miscapps/h3ToGeoBoundaryHier.c +1 -0
  69. data/ext/h3/src/src/apps/miscapps/h3ToGeoHier.c +1 -0
  70. data/ext/h3/src/src/apps/miscapps/h3ToHier.c +1 -0
  71. data/ext/h3/src/src/apps/testapps/mkRandGeo.c +1 -0
  72. data/ext/h3/src/src/apps/testapps/mkRandGeoBoundary.c +1 -0
  73. data/ext/h3/src/src/apps/testapps/testBBox.c +1 -0
  74. data/ext/h3/src/src/apps/testapps/testBaseCells.c +15 -1
  75. data/ext/h3/src/src/apps/testapps/testCompact.c +109 -2
  76. data/ext/h3/src/src/apps/testapps/testCoordIj.c +1 -0
  77. data/ext/h3/src/src/apps/testapps/testGeoCoord.c +47 -8
  78. data/ext/h3/src/src/apps/testapps/testGeoToH3.c +1 -0
  79. data/ext/h3/src/src/apps/testapps/testH3Api.c +1 -0
  80. data/ext/h3/src/src/apps/testapps/testH3CellArea.c +47 -0
  81. data/ext/h3/src/src/apps/testapps/testH3CellAreaExhaustive.c +180 -0
  82. data/ext/h3/src/src/apps/testapps/testH3Distance.c +1 -0
  83. data/ext/h3/src/src/apps/testapps/testH3DistanceExhaustive.c +1 -0
  84. data/ext/h3/src/src/apps/testapps/testH3GetFaces.c +1 -0
  85. data/ext/h3/src/src/apps/testapps/testH3Index.c +33 -3
  86. data/ext/h3/src/src/apps/testapps/testH3Line.c +1 -0
  87. data/ext/h3/src/src/apps/testapps/testH3LineExhaustive.c +1 -0
  88. data/ext/h3/src/src/apps/testapps/testH3Memory.c +175 -0
  89. data/ext/h3/src/src/apps/testapps/testH3NeighborRotations.c +1 -0
  90. data/ext/h3/src/src/apps/testapps/testH3SetToLinkedGeo.c +1 -0
  91. data/ext/h3/src/src/apps/testapps/testH3SetToVertexGraph.c +1 -0
  92. data/ext/h3/src/src/apps/testapps/testH3ToCenterChild.c +1 -0
  93. data/ext/h3/src/src/apps/testapps/testH3ToChildren.c +1 -0
  94. data/ext/h3/src/src/apps/testapps/testH3ToGeo.c +1 -0
  95. data/ext/h3/src/src/apps/testapps/testH3ToGeoBoundary.c +1 -0
  96. data/ext/h3/src/src/apps/testapps/testH3ToLocalIj.c +12 -6
  97. data/ext/h3/src/src/apps/testapps/testH3ToLocalIjExhaustive.c +1 -0
  98. data/ext/h3/src/src/apps/testapps/testH3ToParent.c +1 -0
  99. data/ext/h3/src/src/apps/testapps/testH3UniEdge.c +45 -16
  100. data/ext/h3/src/src/apps/testapps/testH3UniEdgeExhaustive.c +111 -0
  101. data/ext/h3/src/src/apps/testapps/testHexRanges.c +1 -0
  102. data/ext/h3/src/src/apps/testapps/testHexRing.c +1 -0
  103. data/ext/h3/src/src/apps/testapps/testKRing.c +19 -0
  104. data/ext/h3/src/src/apps/testapps/testLinkedGeo.c +1 -0
  105. data/ext/h3/src/src/apps/testapps/testMaxH3ToChildrenSize.c +1 -0
  106. data/ext/h3/src/src/apps/testapps/testPentagonIndexes.c +1 -0
  107. data/ext/h3/src/src/apps/testapps/testPolyfill.c +72 -9
  108. data/ext/h3/src/src/apps/testapps/testPolyfillReported.c +157 -0
  109. data/ext/h3/src/src/apps/testapps/testPolygon.c +27 -1
  110. data/ext/h3/src/src/apps/testapps/testVec2d.c +1 -0
  111. data/ext/h3/src/src/apps/testapps/testVec3d.c +1 -0
  112. data/ext/h3/src/src/apps/testapps/testVertex.c +66 -0
  113. data/ext/h3/src/src/apps/testapps/testVertexGraph.c +1 -0
  114. data/ext/h3/src/src/h3lib/include/algos.h +8 -0
  115. data/ext/h3/src/src/h3lib/include/alloc.h +40 -0
  116. data/ext/h3/src/src/h3lib/include/baseCells.h +4 -0
  117. data/ext/h3/src/src/h3lib/include/bbox.h +4 -1
  118. data/ext/h3/src/src/h3lib/include/faceijk.h +3 -2
  119. data/ext/h3/src/src/h3lib/include/geoCoord.h +2 -3
  120. data/ext/h3/src/src/h3lib/include/h3Index.h +37 -4
  121. data/ext/h3/src/src/h3lib/include/h3api.h.in +65 -17
  122. data/ext/h3/src/src/h3lib/include/linkedGeo.h +1 -0
  123. data/ext/h3/src/src/h3lib/include/polygon.h +1 -0
  124. data/ext/h3/src/src/h3lib/include/polygonAlgos.h +1 -0
  125. data/ext/h3/src/src/h3lib/include/vertex.h +44 -0
  126. data/ext/h3/src/src/h3lib/include/vertexGraph.h +1 -0
  127. data/ext/h3/src/src/h3lib/lib/algos.c +304 -76
  128. data/ext/h3/src/src/h3lib/lib/baseCells.c +26 -4
  129. data/ext/h3/src/src/h3lib/lib/bbox.c +56 -27
  130. data/ext/h3/src/src/h3lib/lib/coordijk.c +2 -0
  131. data/ext/h3/src/src/h3lib/lib/faceijk.c +32 -21
  132. data/ext/h3/src/src/h3lib/lib/geoCoord.c +162 -44
  133. data/ext/h3/src/src/h3lib/lib/h3Index.c +83 -42
  134. data/ext/h3/src/src/h3lib/lib/h3UniEdge.c +42 -57
  135. data/ext/h3/src/src/h3lib/lib/linkedGeo.c +20 -15
  136. data/ext/h3/src/src/h3lib/lib/localij.c +1 -1
  137. data/ext/h3/src/src/h3lib/lib/polygon.c +2 -0
  138. data/ext/h3/src/src/h3lib/lib/vec2d.c +1 -0
  139. data/ext/h3/src/src/h3lib/lib/vec3d.c +1 -0
  140. data/ext/h3/src/src/h3lib/lib/vertex.c +134 -0
  141. data/ext/h3/src/src/h3lib/lib/vertexGraph.c +8 -5
  142. data/ext/h3/src/website/.eslintignore +2 -0
  143. data/ext/h3/src/website/.gitignore +57 -0
  144. data/ext/h3/src/website/.nvmrc +1 -0
  145. data/ext/h3/src/website/README.md +8 -6
  146. data/ext/h3/src/website/gatsby-config.js +83 -0
  147. data/ext/h3/src/website/package.json +20 -12
  148. data/ext/h3/src/website/scripts/build-to-gh-pages.sh +7 -5
  149. data/ext/h3/src/website/src/.gitkeep +0 -0
  150. data/ext/h3/src/website/templates/documentation.jsx +129 -0
  151. data/ext/h3/src/website/yarn.lock +13723 -0
  152. data/h3.gemspec +2 -2
  153. data/lib/h3/bindings/base.rb +14 -4
  154. data/lib/h3/bindings/private.rb +12 -9
  155. data/lib/h3/hierarchy.rb +0 -18
  156. data/lib/h3/indexing.rb +0 -18
  157. data/lib/h3/inspection.rb +3 -59
  158. data/lib/h3/miscellaneous.rb +119 -14
  159. data/lib/h3/regions.rb +3 -0
  160. data/lib/h3/traversal.rb +0 -18
  161. data/lib/h3/unidirectional_edges.rb +5 -60
  162. data/lib/h3/version.rb +1 -1
  163. data/spec/geo_json_spec.rb +8 -0
  164. data/spec/miscellaneous_spec.rb +117 -0
  165. data/spec/{region_spec.rb → regions_spec.rb} +1 -1
  166. data/spec/spec_helper.rb +2 -2
  167. metadata +44 -36
  168. data/.travis.yml +0 -11
  169. data/ext/h3/src/.ycm_extra_conf.py +0 -92
  170. data/ext/h3/src/appveyor.yml +0 -50
  171. data/ext/h3/src/website/src/config.js +0 -46
  172. data/ext/h3/src/website/src/mdRoutes.js +0 -151
  173. data/ext/h3/src/website/src/styles/_variables.scss +0 -16
  174. data/ext/h3/src/website/src/styles/index.scss +0 -3
  175. data/ext/h3/src/website/static/index.html +0 -15
data/h3.gemspec CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Lachlan Laycock", "Sean Handley"]
10
10
  spec.email = "l.laycock@stuart.com"
11
11
 
12
- spec.required_ruby_version = "> 2.3"
12
+ spec.required_ruby_version = ">= 2.5"
13
13
  spec.files = `git ls-files --recurse-submodules`.split("\n")
14
14
 
15
15
  spec.add_runtime_dependency "ffi", "~> 1.9"
16
16
  spec.add_runtime_dependency "rgeo-geojson", "~> 2.1"
17
17
  spec.add_runtime_dependency "zeitwerk", "~> 2.1"
18
18
 
19
- spec.add_development_dependency "coveralls", "~> 0.8"
19
+ # spec.add_development_dependency "coveralls", "~> 0.8"
20
20
  spec.add_development_dependency "rake", "~> 12.3"
21
21
  spec.add_development_dependency "rspec", "~> 3.8"
22
22
  spec.add_development_dependency "yard", "~> 0.9"
@@ -12,11 +12,21 @@ module H3
12
12
  base.include Types
13
13
  base.ffi_lib ["#{lib_path}/libh3.dylib", "#{lib_path}/libh3.so"]
14
14
  base.typedef :ulong_long, :h3_index
15
- base.typedef :int, :size
16
15
  base.typedef :int, :k_distance
17
- base.typedef :pointer, :h3_set
18
- base.typedef :pointer, :output_buffer
19
- base.const_set("H3_INDEX", :ulong_long)
16
+ end
17
+
18
+ def attach_predicate_function(name, *args)
19
+ stripped_name = name.to_s.gsub("?", "")
20
+ attach_function(stripped_name, *args).tap do
21
+ rename_function stripped_name, name
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def rename_function(from, to)
28
+ alias_method to, from
29
+ undef_method from
20
30
  end
21
31
  end
22
32
  end
@@ -7,11 +7,11 @@ module H3
7
7
  module Private
8
8
  extend H3::Bindings::Base
9
9
 
10
- attach_function :compact, [H3IndexesIn, H3IndexesOut, :size], :bool
10
+ attach_function :compact, [H3IndexesIn, H3IndexesOut, :size_t], :bool
11
11
  attach_function :destroy_linked_polygon, :destroyLinkedPolygon, [LinkedGeoPolygon], :void
12
12
  attach_function :geo_to_h3, :geoToH3, [GeoCoord, Resolution], :h3_index
13
13
  attach_function :get_pentagon_indexes, :getPentagonIndexes, [:int, H3IndexesOut], :void
14
- attach_function :h3_faces, :h3GetFaces, %i[h3_index output_buffer], :void
14
+ attach_function :h3_faces, :h3GetFaces, %i[h3_index buffer_out], :void
15
15
  attach_function :h3_indexes_from_unidirectional_edge,
16
16
  :getH3IndexesFromUnidirectionalEdge,
17
17
  [:h3_index, H3IndexesOut], :void
@@ -21,11 +21,11 @@ module H3
21
21
  [:h3_index, H3IndexesOut], :void
22
22
  attach_function :h3_set_to_linked_geo,
23
23
  :h3SetToLinkedGeo,
24
- [H3IndexesIn, :size, LinkedGeoPolygon],
24
+ [H3IndexesIn, :size_t, LinkedGeoPolygon],
25
25
  :void
26
26
  attach_function :h3_to_children, :h3ToChildren, [:h3_index, Resolution, H3IndexesOut], :void
27
27
  attach_function :h3_to_geo, :h3ToGeo, [:h3_index, GeoCoord], :void
28
- attach_function :h3_to_string, :h3ToString, %i[h3_index output_buffer size], :void
28
+ attach_function :h3_to_string, :h3ToString, %i[h3_index buffer_out size_t], :void
29
29
  attach_function :h3_to_geo_boundary,
30
30
  :h3ToGeoBoundary,
31
31
  [:h3_index, GeoBoundary],
@@ -36,25 +36,28 @@ module H3
36
36
  attach_function :hex_range, :hexRange, [:h3_index, :k_distance, H3IndexesOut], :bool
37
37
  attach_function :hex_range_distances,
38
38
  :hexRangeDistances,
39
- [:h3_index, :k_distance, H3IndexesOut, :output_buffer], :bool
39
+ [:h3_index, :k_distance, H3IndexesOut, :buffer_out], :bool
40
40
  attach_function :hex_ranges,
41
41
  :hexRanges,
42
- [H3IndexesIn, :size, :k_distance, H3IndexesOut],
42
+ [H3IndexesIn, :size_t, :k_distance, H3IndexesOut],
43
43
  :bool
44
44
  attach_function :hex_ring, :hexRing, [:h3_index, :k_distance, H3IndexesOut], :bool
45
45
  attach_function :k_ring, :kRing, [:h3_index, :k_distance, H3IndexesOut], :void
46
46
  attach_function :k_ring_distances,
47
47
  :kRingDistances,
48
- [:h3_index, :k_distance, H3IndexesOut, :output_buffer],
48
+ [:h3_index, :k_distance, H3IndexesOut, :buffer_out],
49
49
  :bool
50
50
  attach_function :max_polyfill_size,
51
51
  :maxPolyfillSize,
52
52
  [GeoPolygon, Resolution],
53
53
  :int
54
- attach_function :max_uncompact_size, :maxUncompactSize, [H3IndexesIn, :size, Resolution], :int
54
+ attach_function :max_uncompact_size, :maxUncompactSize, [H3IndexesIn, :size_t, Resolution], :int
55
+ attach_function :point_distance_rads, :pointDistRads, [GeoCoord, GeoCoord], :double
56
+ attach_function :point_distance_km, :pointDistKm, [GeoCoord, GeoCoord], :double
57
+ attach_function :point_distance_m, :pointDistM, [GeoCoord, GeoCoord], :double
55
58
  attach_function :polyfill, [GeoPolygon, Resolution, H3IndexesOut], :void
56
59
  attach_function :res_0_indexes, :getRes0Indexes, [H3IndexesOut], :void
57
- attach_function :uncompact, [H3IndexesIn, :size, H3IndexesOut, :size, Resolution], :bool
60
+ attach_function :uncompact, [H3IndexesIn, :size_t, H3IndexesOut, :size_t, Resolution], :bool
58
61
  end
59
62
  end
60
63
  end
data/lib/h3/hierarchy.rb CHANGED
@@ -19,12 +19,6 @@ module H3
19
19
  # @return [Integer] H3 index of parent hexagon.
20
20
  attach_function :parent, :h3ToParent, [:h3_index, Resolution], :h3_index
21
21
 
22
- # @deprecated Please use {#parent} instead.
23
- def h3_to_parent(h3_index, resolution)
24
- parent(h3_index, resolution)
25
- end
26
- deprecate :h3_to_parent, :parent, 2020, 1
27
-
28
22
  # @!method max_children(h3_index, child_resolution)
29
23
  #
30
24
  # Derive maximum number of child hexagons possible at given resolution.
@@ -54,12 +48,6 @@ module H3
54
48
  # @return [Integer] H3 index of center child hexagon.
55
49
  attach_function :center_child, :h3ToCenterChild, [:h3_index, Resolution], :h3_index
56
50
 
57
- # @deprecated Please use {#max_children} instead.
58
- def max_h3_to_children_size(h3_index, resolution)
59
- max_children(h3_index, resolution)
60
- end
61
- deprecate :max_h3_to_children_size, :max_children, 2020, 1
62
-
63
51
  # Derive child hexagons contained within the hexagon at the given H3 index.
64
52
  #
65
53
  # @param [Integer] h3_index A valid H3 index.
@@ -80,12 +68,6 @@ module H3
80
68
  out.read
81
69
  end
82
70
 
83
- # @deprecated Please use {#children} instead.
84
- def h3_to_children(h3_index, resolution)
85
- children(h3_index, resolution)
86
- end
87
- deprecate :h3_to_children, :children, 2020, 1
88
-
89
71
  # Find the maximum uncompacted size of the given set of H3 indexes.
90
72
  #
91
73
  # @param [Array<Integer>] compacted_set An array of valid H3 indexes.
data/lib/h3/indexing.rb CHANGED
@@ -35,12 +35,6 @@ module H3
35
35
  Bindings::Private.geo_to_h3(coords, resolution)
36
36
  end
37
37
 
38
- # @deprecated Please use {#from_geo_coordinates} instead.
39
- def geo_to_h3(coords, resolution)
40
- from_geo_coordinates(coords, resolution)
41
- end
42
- deprecate :geo_to_h3, :from_geo_coordinates, 2020, 1
43
-
44
38
  # Derive coordinates for a given H3 index.
45
39
  #
46
40
  # The coordinates map to the centre of the hexagon at the given index.
@@ -58,12 +52,6 @@ module H3
58
52
  [rads_to_degs(coords[:lat]), rads_to_degs(coords[:lon])]
59
53
  end
60
54
 
61
- # @deprecated Please use {#to_geo_coordinates} instead.
62
- def h3_to_geo(h3_index)
63
- to_geo_coordinates(h3_index)
64
- end
65
- deprecate :h3_to_geo, :to_geo_coordinates, 2020, 1
66
-
67
55
  # Derive the geographical boundary as coordinates for a given H3 index.
68
56
  #
69
57
  # This will be a set of 6 coordinate pairs matching the vertexes of the
@@ -89,11 +77,5 @@ module H3
89
77
  [rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
90
78
  end
91
79
  end
92
-
93
- # @deprecated Please use {#to_boundary} instead.
94
- def h3_to_geo_boundary(h3_index)
95
- to_boundary(h3_index)
96
- end
97
- deprecate :h3_to_geo_boundary, :to_boundary, 2020, 1
98
80
  end
99
81
  end
data/lib/h3/inspection.rb CHANGED
@@ -21,12 +21,6 @@ module H3
21
21
  # @return [Integer] Resolution of H3 index
22
22
  attach_function :resolution, :h3GetResolution, %i[h3_index], Resolution
23
23
 
24
- # @deprecated Please use {#resolution} instead.
25
- def h3_resolution(h3_index)
26
- resolution(h3_index)
27
- end
28
- deprecate :h3_resolution, :resolution, 2020, 1
29
-
30
24
  # @!method base_cell(h3_index)
31
25
  #
32
26
  # Derives the base cell number of the given H3 index
@@ -40,12 +34,6 @@ module H3
40
34
  # @return [Integer] Base cell number
41
35
  attach_function :base_cell, :h3GetBaseCell, %i[h3_index], :int
42
36
 
43
- # @deprecated Please use {#base_cell} instead.
44
- def h3_base_cell(h3_index)
45
- base_cell(h3_index)
46
- end
47
- deprecate :h3_base_cell, :base_cell, 2020, 1
48
-
49
37
  # @!method from_string(h3_string)
50
38
  #
51
39
  # Derives the H3 index for a given hexadecimal string representation.
@@ -59,12 +47,6 @@ module H3
59
47
  # @return [Integer] H3 index
60
48
  attach_function :from_string, :stringToH3, %i[string], :h3_index
61
49
 
62
- # @deprecated Please use {#from_string} instead.
63
- def string_to_h3(string)
64
- from_string(string)
65
- end
66
- deprecate :string_to_h3, :from_string, 2020, 1
67
-
68
50
  # @!method pentagon?(h3_index)
69
51
  #
70
52
  # Determine whether the given H3 index is a pentagon.
@@ -76,15 +58,7 @@ module H3
76
58
  # true
77
59
  #
78
60
  # @return [Boolean] True if the H3 index is a pentagon.
79
- attach_function :pentagon, :h3IsPentagon, %i[h3_index], :bool
80
- alias_method :pentagon?, :pentagon
81
- undef_method :pentagon
82
-
83
- # @deprecated Please use {#pentagon?} instead.
84
- def h3_pentagon?(h3_index)
85
- pentagon?(h3_index)
86
- end
87
- deprecate :h3_pentagon?, :pentagon?, 2020, 1
61
+ attach_predicate_function :pentagon?, :h3IsPentagon, %i[h3_index], :bool
88
62
 
89
63
  # @!method class_3_resolution?(h3_index)
90
64
  #
@@ -98,15 +72,7 @@ module H3
98
72
  # true
99
73
  #
100
74
  # @return [Boolean] True if the H3 index has a class III resolution.
101
- attach_function :class_3_resolution, :h3IsResClassIII, %i[h3_index], :bool
102
- alias_method :class_3_resolution?, :class_3_resolution
103
- undef_method :class_3_resolution
104
-
105
- # @deprecated Please use {#class_3_resolution?} instead.
106
- def h3_res_class_3?(h3_index)
107
- class_3_resolution?(h3_index)
108
- end
109
- deprecate :h3_res_class_3?, :class_3_resolution?, 2020, 1
75
+ attach_predicate_function :class_3_resolution?, :h3IsResClassIII, %i[h3_index], :bool
110
76
 
111
77
  # @!method valid?(h3_index)
112
78
  #
@@ -119,15 +85,7 @@ module H3
119
85
  # true
120
86
  #
121
87
  # @return [Boolean] True if the H3 index is valid.
122
- attach_function :valid, :h3IsValid, %i[h3_index], :bool
123
- alias_method :valid?, :valid
124
- undef_method :valid
125
-
126
- # @deprecated Please use {#valid?} instead.
127
- def h3_valid?(h3_index)
128
- valid?(h3_index)
129
- end
130
- deprecate :h3_valid?, :valid?, 2020, 1
88
+ attach_predicate_function :valid?, :h3IsValid, %i[h3_index], :bool
131
89
 
132
90
  # Derives the hexadecimal string representation for a given H3 index.
133
91
  #
@@ -144,12 +102,6 @@ module H3
144
102
  h3_str.read_string
145
103
  end
146
104
 
147
- # @deprecated Please use {#to_string} instead.
148
- def h3_to_string(h3_index)
149
- to_string(h3_index)
150
- end
151
- deprecate :h3_to_string, :to_strings, 2020, 1
152
-
153
105
  # @!method max_face_count(h3_index)
154
106
  #
155
107
  # Returns the maximum number of icosahedron faces the given H3 index may intersect.
@@ -163,8 +115,6 @@ module H3
163
115
  # @return [Integer] Maximum possible number of faces
164
116
  attach_function :max_face_count, :maxFaceCount, %i[h3_index], :int
165
117
 
166
- # @!method faces(h3_index)
167
- #
168
118
  # Find all icosahedron faces intersected by a given H3 index.
169
119
  #
170
120
  # @param [Integer] h3_index A H3 index.
@@ -181,11 +131,5 @@ module H3
181
131
  # The C function returns a sparse array whose holes are represented by -1.
182
132
  out.read_array_of_int(max_faces).reject(&:negative?).sort
183
133
  end
184
-
185
- # @deprecated Please use {#faces} instead.
186
- def h3_faces(h3_index)
187
- faces(h3_index)
188
- end
189
- deprecate :h3_faces, :faces, 2020, 1
190
134
  end
191
135
  end
@@ -83,12 +83,6 @@ module H3
83
83
  # @return [Integer] Number of unique hexagons
84
84
  attach_function :hexagon_count, :numHexagons, [Resolution], :ulong_long
85
85
 
86
- # @deprecated Please use {#hexagon_count} instead.
87
- def num_hexagons(resolution)
88
- hexagon_count(resolution)
89
- end
90
- deprecate :num_hexagons, :hexagon_count, 2020, 1
91
-
92
86
  # @!method rads_to_degs(rads)
93
87
  #
94
88
  # Convert a number expressed in radians to its equivalent in degrees.
@@ -125,11 +119,104 @@ module H3
125
119
  # @return [Integer] The number of pentagons per resolution.
126
120
  attach_function :pentagon_count, :pentagonIndexCount, [], :int
127
121
 
128
- # @deprecated Please use {#base_cell_count} instead.
129
- def res_0_index_count
130
- base_cell_count
122
+ # @!method cell_area_rads2
123
+ #
124
+ # Area of a given cell expressed in radians squared
125
+ #
126
+ # @example Return the area of the cell
127
+ # H3.cell_area_rads2(617700169958293503)
128
+ # 2.6952182709835757e-09
129
+ #
130
+ # @return [Double] Area of cell in rads2
131
+ attach_function :cell_area_rads2, :cellAreaRads2, %i[h3_index], :double
132
+
133
+ # @!method cell_area_km2
134
+ #
135
+ # Area of a given cell expressed in km squared
136
+ #
137
+ # @example Return the area of the cell
138
+ # H3.cell_area_km2(617700169958293503)
139
+ # 0.10939818864648902
140
+ #
141
+ # @return [Double] Area of cell in km2
142
+ attach_function :cell_area_km2, :cellAreaKm2, %i[h3_index], :double
143
+
144
+ # @!method cell_area_m2
145
+ #
146
+ # Area of a given cell expressed in metres squared
147
+ #
148
+ # @example Return the area of the cell
149
+ # H3.cell_area_m2(617700169958293503)
150
+ # 109398.18864648901
151
+ #
152
+ # @return [Double] Area of cell in metres squared
153
+ attach_function :cell_area_m2, :cellAreaM2, %i[h3_index], :double
154
+
155
+ # @!method exact_edge_length_rads
156
+ #
157
+ # Exact length of edge in rads
158
+ #
159
+ # @example Return the edge length
160
+ # H3.exact_edge_length_rads(1266218516299644927)
161
+ # 3.287684056071637e-05
162
+ #
163
+ # @return [Double] Edge length in rads
164
+ attach_function :exact_edge_length_rads, :exactEdgeLengthRads, %i[h3_index], :double
165
+
166
+ # @!method exact_edge_length_km
167
+ #
168
+ # Exact length of edge in kilometres
169
+ #
170
+ # @example Return the edge length
171
+ # H3.exact_edge_length_km(1266218516299644927)
172
+ # 3.287684056071637e-05
173
+ #
174
+ # @return [Double] Edge length in kilometres
175
+ attach_function :exact_edge_length_km, :exactEdgeLengthKm, %i[h3_index], :double
176
+
177
+ # @!method exact_edge_length_m
178
+ #
179
+ # Exact length of edge in metres
180
+ #
181
+ # @example Return the edge length
182
+ # H3.exact_edge_length_m(1266218516299644927)
183
+ # 3.287684056071637e-05
184
+ #
185
+ # @return [Double] Edge length in metres
186
+ attach_function :exact_edge_length_m, :exactEdgeLengthM, %i[h3_index], :double
187
+
188
+ # Returns the radians distance between two points.
189
+ #
190
+ # @example Return radians distance.
191
+ # H3.point_distance_rads([41.3964809, 2.160444], [41.3870609, 2.164917])
192
+ # 0.00017453024784008713
193
+ #
194
+ # @return [Double] Radians distance between two points.
195
+ def point_distance_rads(origin, destination)
196
+ Bindings::Private.point_distance_rads(*build_geocoords(origin, destination))
197
+ end
198
+
199
+ # Returns the kilometres distance between two points.
200
+ #
201
+ # @example Return km distance.
202
+ # H3.point_distance_km([41.3964809, 2.160444], [41.3870609, 2.164917])
203
+ # 1.1119334622766763
204
+ #
205
+ # @return [Double] KM distance between two points.
206
+ def point_distance_km(origin, destination)
207
+ Bindings::Private.point_distance_km(*build_geocoords(origin, destination))
208
+ end
209
+
210
+ # Returns the metre distance between two points.
211
+ #
212
+ # @example Return metre distance.
213
+ # H3.point_distance_m([41.3964809, 2.160444], [41.3870609, 2.164917])
214
+ # 1111.9334622766764
215
+ #
216
+ # @return [Double] Metre distance between two points.
217
+ def point_distance_m(origin, destination)
218
+ Bindings::Private.point_distance_m(*build_geocoords(origin, destination))
131
219
  end
132
- deprecate :res_0_index_count, :base_cell_count, 2020, 1
133
220
 
134
221
  # Returns all resolution 0 hexagons (base cells).
135
222
  #
@@ -157,10 +244,28 @@ module H3
157
244
  out.read
158
245
  end
159
246
 
160
- # @deprecated Please use {#base_cells} instead.
161
- def res_0_indexes
162
- base_cells
247
+ private
248
+
249
+ def build_geocoords(origin, destination)
250
+ [origin, destination].inject([]) do |acc, coords|
251
+ validate_coordinate(coords)
252
+
253
+ geo_coord = GeoCoord.new
254
+ lat, lon = coords
255
+ geo_coord[:lat] = degs_to_rads(lat)
256
+ geo_coord[:lon] = degs_to_rads(lon)
257
+ acc << geo_coord
258
+ end
259
+ end
260
+
261
+ def validate_coordinate(coords)
262
+ raise ArgumentError unless coords.is_a?(Array) && coords.count == 2
263
+
264
+ lat, lon = coords
265
+
266
+ if lat > 90 || lat < -90 || lon > 180 || lon < -180
267
+ raise(ArgumentError, "Invalid coordinates")
268
+ end
163
269
  end
164
- deprecate :res_0_indexes, :base_cells, 2020, 1
165
270
  end
166
271
  end