Skip to content

Commit ce6d486

Browse files
seanhandleyfxn
andauthored
Support for h3 3.5.0 (#56)
* Update h3 to 3.5.0 Includes new `h3_faces` and `h3_max_count` methods. Behind the scenes, `cmake` is given a couple of extra build options to prevent it from building unnecessary filter binaries and benchmarks. * Update CHANGELOG.md Co-Authored-By: Xavier Noria <fxn@hashref.com> * Update lib/h3/inspection.rb Co-Authored-By: Xavier Noria <fxn@hashref.com>
1 parent 2d1a968 commit ce6d486

File tree

8 files changed

+78
-5
lines changed

8 files changed

+78
-5
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ 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.5.0] - 2019-7-25
10+
### Added
11+
- `h3_faces` and `max_face_count` support (#56)
12+
### Changed
13+
- New CMake options to prevent unnecessary building of filter apps and benchmarks.
14+
915
## [3.4.4] - 2019-6-4
1016
### Changed
1117
- Internal h3 bugfixes.

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
h3 (3.4.0)
4+
h3 (3.5.0)
55
ffi (~> 1.9)
66
rgeo-geojson (~> 2.1)
77

ext/h3/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
make:
2-
cd src; cmake . -DBUILD_SHARED_LIBS=true; make
2+
cd src; cmake . -DBUILD_SHARED_LIBS=true -DBUILD_FILTERS=OFF -DBUILD_BENCHMARKS=OFF; make
33
install:
44
: # do nothing, we'll load the lib directly
55
clean:

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 :h3_faces, :h3GetFaces, %i[h3_index output_buffer], :void
1314
attach_function :h3_indexes_from_unidirectional_edge,
1415
:getH3IndexesFromUnidirectionalEdge,
1516
[:h3_index, H3IndexesOut], :void

lib/h3/inspection.rb

+34
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,39 @@ def h3_to_string(h3_index)
101101
Bindings::Private.h3_to_string(h3_index, h3_str, H3_TO_STR_BUF_SIZE)
102102
h3_str.read_string
103103
end
104+
105+
# @!method max_face_count(h3_index)
106+
#
107+
# Returns the maximum number of icosahedron faces the given H3 index may intersect.
108+
#
109+
# @param [Integer] h3_index A H3 index.
110+
#
111+
# @example Check maximum faces
112+
# H3.max_face_count(585961082523222015)
113+
# 5
114+
#
115+
# @return [Integer] Maximum possible number of faces
116+
attach_function :max_face_count, :maxFaceCount, %i[h3_index], :int
117+
118+
# void h3GetFaces(H3Index h, int* out);
119+
120+
# @!method h3_faces(h3_index)
121+
#
122+
# Find all icosahedron faces intersected by a given H3 index.
123+
#
124+
# @param [Integer] h3_index A H3 index.
125+
#
126+
# @example Find icosahedron faces for given index
127+
# H3.h3_faces(585961082523222015)
128+
# [1, 2, 6, 7, 11]
129+
#
130+
# @return [Array<Integer>] Faces. Faces are represented as integers from 0-19, inclusive.
131+
def h3_faces(h3_index)
132+
max_faces = max_face_count(h3_index)
133+
out = FFI::MemoryPointer.new(:int, max_faces)
134+
Bindings::Private.h3_faces(h3_index, out)
135+
# The C function returns a sparse array whose holes are represented by -1.
136+
out.read_array_of_int(max_faces).reject(&:negative?).sort
137+
end
104138
end
105139
end

lib/h3/version.rb

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

spec/inspection_spec.rb

+33-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,36 @@
8787
it { is_expected.to eq(result) }
8888
end
8989
end
90-
end
90+
91+
describe ".max_face_count" do
92+
let(:h3_index) { "8928308280fffff".to_i(16) }
93+
let(:result) { 2 }
94+
95+
subject(:max_face_count) { H3.max_face_count(h3_index) }
96+
97+
it { is_expected.to eq(result) }
98+
99+
context "when the h3 index is a pentagon" do
100+
let(:h3_index) { "821c07fffffffff".to_i(16) }
101+
let(:result) { 5 }
102+
103+
it { is_expected.to eq(result) }
104+
end
105+
end
106+
107+
describe ".h3_faces" do
108+
let(:h3_index) { "8928308280fffff".to_i(16) }
109+
let(:result) { [7] }
110+
111+
subject(:max_face_count) { H3.h3_faces(h3_index) }
112+
113+
it { is_expected.to eq(result) }
114+
115+
context "when the h3 index is a pentagon" do
116+
let(:h3_index) { "821c07fffffffff".to_i(16) }
117+
let(:result) { [1, 2, 6, 7, 11] }
118+
119+
it { is_expected.to eq(result) }
120+
end
121+
end
122+
end

0 commit comments

Comments
 (0)