Skip to content

Commit 0c9afc2

Browse files
authored
Release v3.6.0 (#62)
### Added - `center_child` method to find center child at given resolution (#62). - `pentagons` (and `pentagon_count`) method to find pentagons at given resolution (#62).
1 parent 12efefd commit 0c9afc2

10 files changed

+90
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66

77
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.
88

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+
914
## [3.5.1] - 2019-8-5
1015
### Changed
1116
- Renamed 26 methods to be more idiomatic with Ruby conventions. The old names are deprecated until 2020 when they will be removed (#59).

Gemfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PATH
22
remote: .
33
specs:
4-
h3 (3.5.1)
4+
h3 (3.6.0)
55
ffi (~> 1.9)
66
rgeo-geojson (~> 2.1)
7-
zeitwerk (~> 2.1.9)
7+
zeitwerk (~> 2.1)
88

99
GEM
1010
remote: https://rubygems.org/
@@ -20,7 +20,7 @@ GEM
2020
ffi (1.11.1)
2121
json (2.1.0)
2222
rake (12.3.2)
23-
rgeo (2.0.1)
23+
rgeo (2.1.0)
2424
rgeo-geojson (2.1.1)
2525
rgeo (>= 1.0.0)
2626
rspec (3.8.0)

h3.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
1414

1515
spec.add_runtime_dependency "ffi", "~> 1.9"
1616
spec.add_runtime_dependency "rgeo-geojson", "~> 2.1"
17-
spec.add_runtime_dependency "zeitwerk", "~> 2.1.9"
17+
spec.add_runtime_dependency "zeitwerk", "~> 2.1"
1818

1919
spec.add_development_dependency "coveralls", "~> 0.8"
2020
spec.add_development_dependency "rake", "~> 12.3"

lib/h3/bindings/private.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Private
1010
attach_function :compact, [H3IndexesIn, H3IndexesOut, :size], :bool
1111
attach_function :destroy_linked_polygon, :destroyLinkedPolygon, [LinkedGeoPolygon], :void
1212
attach_function :geo_to_h3, :geoToH3, [GeoCoord, Resolution], :h3_index
13+
attach_function :get_pentagon_indexes, :getPentagonIndexes, [:int, H3IndexesOut], :void
1314
attach_function :h3_faces, :h3GetFaces, %i[h3_index output_buffer], :void
1415
attach_function :h3_indexes_from_unidirectional_edge,
1516
:getH3IndexesFromUnidirectionalEdge,

lib/h3/hierarchy.rb

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ def h3_to_parent(h3_index, resolution)
3939
# @return [Integer] Maximum number of child hexagons possible at given resolution.
4040
attach_function :max_children, :maxH3ToChildrenSize, [:h3_index, Resolution], :int
4141

42+
# @!method center_child(h3_index, child_resolution)
43+
#
44+
# Returns the center child (finer) index contained by the given index
45+
# at the given resolution.
46+
#
47+
# @param [Integer] h3_index A valid H3 index.
48+
# @param [Integer] child_resoluton The desired resolution of the center child hexagon.
49+
#
50+
# @example Find center child hexagon.
51+
# H3.center_child(613196570357137407, 10)
52+
# 622203769609814015
53+
#
54+
# @return [Integer] H3 index of center child hexagon.
55+
attach_function :center_child, :h3ToCenterChild, [:h3_index, Resolution], :h3_index
56+
4257
# @deprecated Please use {#max_children} instead.
4358
def max_h3_to_children_size(h3_index, resolution)
4459
max_children(h3_index, resolution)

lib/h3/miscellaneous.rb

+25
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ def num_hexagons(resolution)
113113
# @return [Integer] The number of resolution 0 hexagons (base cells).
114114
attach_function :base_cell_count, :res0IndexCount, [], :int
115115

116+
# @!method pentagon_count
117+
#
118+
# Number of pentagon H3 indexes per resolution.
119+
# This is always 12, but provided as a convenience.
120+
#
121+
# @example Return the number of pentagons
122+
# H3.pentagon_count
123+
# 12
124+
#
125+
# @return [Integer] The number of pentagons per resolution.
126+
attach_function :pentagon_count, :pentagonIndexCount, [], :int
127+
116128
# @deprecated Please use {#base_cell_count} instead.
117129
def res_0_index_count
118130
base_cell_count
@@ -132,6 +144,19 @@ def base_cells
132144
out.read
133145
end
134146

147+
# Returns all pentagon indexes at the given resolution.
148+
#
149+
# @example Return all pentagons at resolution 4.
150+
# H3.pentagons(4)
151+
# [594615896891195391, 594967740612083711, ..., 598591730937233407]
152+
#
153+
# @return [Array<Integer>] All pentagon indexes at the given resolution.
154+
def pentagons(resolution)
155+
out = H3Indexes.of_size(pentagon_count)
156+
Bindings::Private.get_pentagon_indexes(resolution, out)
157+
out.read
158+
end
159+
135160
# @deprecated Please use {#base_cells} instead.
136161
def res_0_indexes
137162
base_cells

lib/h3/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module H3
2-
VERSION = "3.5.1".freeze
2+
VERSION = "3.6.0".freeze
33
end

spec/hierarchy_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,14 @@
172172
end
173173
end
174174
end
175+
176+
describe ".center_child" do
177+
let(:h3_index) { "8828308299fffff".to_i(16) }
178+
let(:resolution) { 10 }
179+
let(:result) { "8a2830829807fff".to_i(16) }
180+
181+
subject(:center_child) { H3.center_child(h3_index, resolution) }
182+
183+
it { is_expected.to eq result }
184+
end
175185
end

spec/miscellaneous_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,32 @@
8181
expect(base_cells.count).to eq(count)
8282
end
8383
end
84+
85+
describe ".pentagon_count" do
86+
let(:count) { 12 }
87+
subject(:pentagon_count) { H3.pentagon_count }
88+
89+
it "has 12 pentagons per resolution" do
90+
expect(pentagon_count).to eq(count)
91+
end
92+
end
93+
94+
describe ".pentagons" do
95+
let(:resolution) { 4 }
96+
let(:expected) do
97+
[
98+
594615896891195391, 594967740612083711,
99+
595319584332972031, 595812165542215679,
100+
596199193635192831, 596515852983992319,
101+
596691774844436479, 597008434193235967,
102+
597395462286213119, 597888043495456767,
103+
598239887216345087, 598591730937233407
104+
]
105+
end
106+
subject(:pentagons) { H3.pentagons(resolution) }
107+
108+
it "returns pentagons at the given resolution" do
109+
expect(pentagons).to eq(expected)
110+
end
111+
end
84112
end

0 commit comments

Comments
 (0)