h3 3.5.0 → 3.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,18 +70,24 @@ module H3
70
70
  # @return [Float] Average hexagon area in square metres.
71
71
  attach_function :hex_area_m2, :hexAreaM2, [Resolution], :double
72
72
 
73
- # @!method num_hexagons(resolution)
73
+ # @!method hexagon_count(resolution)
74
74
  #
75
75
  # Number of unique H3 indexes at the given resolution.
76
76
  #
77
77
  # @param [Integer] resolution Resolution.
78
78
  #
79
79
  # @example Find number of hexagons at resolution 6
80
- # H3.num_hexagons(6)
80
+ # H3.hexagon_count(6)
81
81
  # 14117882
82
82
  #
83
83
  # @return [Integer] Number of unique hexagons
84
- attach_function :num_hexagons, :numHexagons, [Resolution], :ulong_long
84
+ attach_function :hexagon_count, :numHexagons, [Resolution], :ulong_long
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
85
91
 
86
92
  # @!method rads_to_degs(rads)
87
93
  #
@@ -96,28 +102,40 @@ module H3
96
102
  # @return [Float] Value expressed in degrees.
97
103
  attach_function :rads_to_degs, :radsToDegs, %i[double], :double
98
104
 
99
- # @!method res_0_index_count
105
+ # @!method base_cell_count
100
106
  #
101
107
  # Returns the number of resolution 0 hexagons (base cells).
102
108
  #
103
109
  # @example Return the number of base cells
104
- # H3.res_0_index_count
110
+ # H3.base_cell_count
105
111
  # 122
106
112
  #
107
113
  # @return [Integer] The number of resolution 0 hexagons (base cells).
108
- attach_function :res_0_index_count, :res0IndexCount, [], :int
114
+ attach_function :base_cell_count, :res0IndexCount, [], :int
115
+
116
+ # @deprecated Please use {#base_cell_count} instead.
117
+ def res_0_index_count
118
+ base_cell_count
119
+ end
120
+ deprecate :res_0_index_count, :base_cell_count, 2020, 1
109
121
 
110
122
  # Returns all resolution 0 hexagons (base cells).
111
123
  #
112
124
  # @example Return all base cells.
113
- # H3.res_0_indexes
125
+ # H3.base_cells
114
126
  # [576495936675512319, 576531121047601151, ..., 580753245698260991]
115
127
  #
116
128
  # @return [Array<Integer>] All resolution 0 hexagons (base cells).
117
- def res_0_indexes
118
- out = H3Indexes.of_size(res_0_index_count)
129
+ def base_cells
130
+ out = H3Indexes.of_size(base_cell_count)
119
131
  Bindings::Private.res_0_indexes(out)
120
132
  out.read
121
133
  end
134
+
135
+ # @deprecated Please use {#base_cells} instead.
136
+ def res_0_indexes
137
+ base_cells
138
+ end
139
+ deprecate :res_0_indexes, :base_cells, 2020, 1
122
140
  end
123
141
  end
data/lib/h3/traversal.rb CHANGED
@@ -18,7 +18,7 @@ module H3
18
18
  # @return [Integer] Maximum k-ring size.
19
19
  attach_function :max_kring_size, :maxKringSize, %i[k_distance], :int
20
20
 
21
- # @!method h3_distance(origin, h3_index)
21
+ # @!method distance(origin, h3_index)
22
22
  #
23
23
  # Derive the distance between two H3 indexes.
24
24
  #
@@ -26,13 +26,19 @@ module H3
26
26
  # @param [Integer] h3_index H3 index
27
27
  #
28
28
  # @example Derive the distance between two H3 indexes.
29
- # H3.h3_distance(617700169983721471, 617700169959866367)
29
+ # H3.distance(617700169983721471, 617700169959866367)
30
30
  # 5
31
31
  #
32
32
  # @return [Integer] Distance between indexes.
33
- attach_function :h3_distance, :h3Distance, %i[h3_index h3_index], :k_distance
33
+ attach_function :distance, :h3Distance, %i[h3_index h3_index], :k_distance
34
34
 
35
- # @!method h3_line_size(origin, destination)
35
+ # @deprecated Please use {#distance} instead.
36
+ def h3_distance(origin, destination)
37
+ distance(origin, destination)
38
+ end
39
+ deprecate :h3_distance, :distance, 2020, 1
40
+
41
+ # @!method line_size(origin, destination)
36
42
  #
37
43
  # Derive the number of hexagons present in a line between two H3 indexes.
38
44
  #
@@ -45,11 +51,17 @@ module H3
45
51
  # @param [Integer] destination H3 index
46
52
  #
47
53
  # @example Derive the number of hexagons present in a line between two H3 indexes.
48
- # H3.h3_line_size(617700169983721471, 617700169959866367)
54
+ # H3.line_size(617700169983721471, 617700169959866367)
49
55
  # 6
50
56
  #
51
57
  # @return [Integer] Number of hexagons found between indexes.
52
- attach_function :h3_line_size, :h3LineSize, %i[h3_index h3_index], :int
58
+ attach_function :line_size, :h3LineSize, %i[h3_index h3_index], :int
59
+
60
+ # @deprecated Please use {#line_size} instead.
61
+ def h3_line_size(origin, destination)
62
+ line_size(origin, destination)
63
+ end
64
+ deprecate :h3_line_size, :line_size, 2020, 1
53
65
 
54
66
  # Derives H3 indexes within k distance of the origin H3 index.
55
67
  #
@@ -288,7 +300,7 @@ module H3
288
300
  # @param [Integer] destination Destination H3 index.
289
301
  #
290
302
  # @example Derive the indexes found in a line.
291
- # H3.h3_line(617700169983721471, 617700169959866367)
303
+ # H3.line(617700169983721471, 617700169959866367)
292
304
  # [
293
305
  # 617700169983721471, 617700169984245759, 617700169988177919,
294
306
  # 617700169986867199, 617700169987391487, 617700169959866367
@@ -297,14 +309,20 @@ module H3
297
309
  # @raise [ArgumentError] Could not compute line
298
310
  #
299
311
  # @return [Array<Integer>] H3 indexes
300
- def h3_line(origin, destination)
301
- max_hexagons = h3_line_size(origin, destination)
312
+ def line(origin, destination)
313
+ max_hexagons = line_size(origin, destination)
302
314
  hexagons = H3Indexes.of_size(max_hexagons)
303
315
  res = Bindings::Private.h3_line(origin, destination, hexagons)
304
316
  raise(ArgumentError, "Could not compute line") if res.negative?
305
317
  hexagons.read
306
318
  end
307
319
 
320
+ # @deprecated Please use {#line} instead.
321
+ def h3_line(origin, destination)
322
+ line(origin, destination)
323
+ end
324
+ deprecate :h3_line, :line, 2020, 1
325
+
308
326
  private
309
327
 
310
328
  def k_rings_for_hex_range(indexes, k)
@@ -5,7 +5,7 @@ module H3
5
5
  module UnidirectionalEdges
6
6
  extend H3::Bindings::Base
7
7
 
8
- # @!method h3_indexes_neighbors?(origin, destination)
8
+ # @!method neighbors?(origin, destination)
9
9
  #
10
10
  # Determine whether two H3 indexes are neighbors.
11
11
  #
@@ -13,29 +13,47 @@ module H3
13
13
  # @param [Integer] destination Destination H3 index
14
14
  #
15
15
  # @example Check two H3 indexes
16
- # H3.h3_indexes_neighbors?(617700169958293503, 617700169958031359)
16
+ # H3.neighbors?(617700169958293503, 617700169958031359)
17
17
  # true
18
18
  #
19
19
  # @return [Boolean] True if indexes are neighbors
20
- attach_function :h3_indexes_neighbors, :h3IndexesAreNeighbors, %i[h3_index h3_index], :bool
20
+ attach_function :neighbors, :h3IndexesAreNeighbors, %i[h3_index h3_index], :bool
21
+ alias_method :neighbors?, :neighbors
22
+ undef_method :neighbors
21
23
 
22
- # @!method h3_unidirectional_edge_valid?(h3_index)
24
+ # @deprecated Please use {#neighbors?} instead.
25
+ def h3_indexes_neighbors?(origin, destination)
26
+ neighbors?(origin, destination)
27
+ end
28
+
29
+ deprecate :h3_indexes_neighbors?, :neighbors?, 2020, 1
30
+
31
+ # @!method unidirectional_edge_valid?(h3_index)
23
32
  #
24
33
  # Determine whether the given H3 index represents an edge.
25
34
  #
26
35
  # @param [Integer] h3_index H3 index
27
36
  #
28
37
  # @example Check if H3 index is a valid unidirectional edge.
29
- # H3.h3_unidirectional_edge_valid?(1266218516299644927)
38
+ # H3.unidirectional_edge_valid?(1266218516299644927)
30
39
  # true
31
40
  #
32
41
  # @return [Boolean] True if H3 index is a valid unidirectional edge
33
- attach_function :h3_unidirectional_edge_valid,
42
+ attach_function :unidirectional_edge_valid,
34
43
  :h3UnidirectionalEdgeIsValid,
35
44
  %i[h3_index],
36
45
  :bool
46
+ alias_method :unidirectional_edge_valid?, :unidirectional_edge_valid
47
+ undef_method :unidirectional_edge_valid
48
+
49
+ # @deprecated Please use {#unidirectional_edge_valid?} instead.
50
+ def h3_unidirectional_edge_valid?(h3_index)
51
+ unidirectional_edge_valid?(h3_index)
52
+ end
53
+
54
+ deprecate :h3_unidirectional_edge_valid?, :unidirectional_edge_valid?, 2020, 1
37
55
 
38
- # @!method h3_unidirectional_edge(origin, destination)
56
+ # @!method unidirectional_edge(origin, destination)
39
57
  #
40
58
  # Derives the H3 index of the edge from the given H3 indexes.
41
59
  #
@@ -43,15 +61,22 @@ module H3
43
61
  # @param [Integer] destination H3 index
44
62
  #
45
63
  # @example Derive the H3 edge index between two H3 indexes
46
- # H3.h3_unidirectional_edge(617700169958293503, 617700169958031359)
64
+ # H3.unidirectional_edge(617700169958293503, 617700169958031359)
47
65
  # 1626506486489284607
48
66
  #
49
67
  # @return [Integer] H3 edge index
50
- attach_function :h3_unidirectional_edge,
68
+ attach_function :unidirectional_edge,
51
69
  :getH3UnidirectionalEdge,
52
70
  %i[h3_index h3_index],
53
71
  :h3_index
54
72
 
73
+ # @deprecated Please use {#unidirectional_edge} instead.
74
+ def h3_unidirectional_edge(origin, destination)
75
+ unidirectional_edge(origin, destination)
76
+ end
77
+
78
+ deprecate :h3_unidirectional_edge, :unidirectional_edge, 2020, 1
79
+
55
80
  # @!method destination_from_unidirectional_edge(edge)
56
81
  #
57
82
  # Derive destination H3 index from edge.
@@ -93,42 +118,62 @@ module H3
93
118
  # @param [Integer] edge H3 edge index
94
119
  #
95
120
  # @example Get origin and destination indexes from edge
96
- # H3.h3_indexes_from_unidirectional_edge(1266218516299644927)
121
+ # H3.origin_and_destination_from_unidirectional_edge(1266218516299644927)
97
122
  # [617700169958293503, 617700169961177087]
98
123
  #
99
124
  # @return [Array<Integer>] H3 index array.
100
- def h3_indexes_from_unidirectional_edge(edge)
125
+ def origin_and_destination_from_unidirectional_edge(edge)
101
126
  max_hexagons = 2
102
127
  out = H3Indexes.of_size(max_hexagons)
103
128
  Bindings::Private.h3_indexes_from_unidirectional_edge(edge, out)
104
129
  out.read
105
130
  end
106
131
 
132
+ # @deprecated Please use {#origin_and_destination_from_unidirectional_edge} instead.
133
+ def h3_indexes_from_unidirectional_edge(edge)
134
+ origin_and_destination_from_unidirectional_edge(edge)
135
+ end
136
+
137
+ deprecate :h3_indexes_from_unidirectional_edge,
138
+ :origin_and_destination_from_unidirectional_edge,
139
+ 2020,
140
+ 1
141
+
107
142
  # Derive unidirectional edges for a H3 index.
108
143
  #
109
144
  # @param [Integer] origin H3 index
110
145
  #
111
146
  # @example Get unidirectional indexes from hexagon
112
- # H3.h3_unidirectional_edges_from_hexagon(612933930963697663)
147
+ # H3.unidirectional_edges_from_hexagon(612933930963697663)
113
148
  # [
114
149
  # 1261452277305049087, 1333509871342977023, 1405567465380904959,
115
150
  # 1477625059418832895, 1549682653456760831, 1621740247494688767
116
151
  # ]
117
152
  #
118
153
  # @return [Array<Integer>] H3 index array.
119
- def h3_unidirectional_edges_from_hexagon(origin)
154
+ def unidirectional_edges_from_hexagon(origin)
120
155
  max_edges = 6
121
156
  out = H3Indexes.of_size(max_edges)
122
157
  Bindings::Private.h3_unidirectional_edges_from_hexagon(origin, out)
123
158
  out.read
124
159
  end
125
160
 
161
+ # @deprecated Please use {#unidirectional_edges_from_hexagon} instead.
162
+ def h3_unidirectional_edges_from_hexagon(origin)
163
+ unidirectional_edges_from_hexagon(origin)
164
+ end
165
+
166
+ deprecate :h3_unidirectional_edges_from_hexagon,
167
+ :unidirectional_edges_from_hexagon,
168
+ 2020,
169
+ 1
170
+
126
171
  # Derive coordinates for edge boundary.
127
172
  #
128
173
  # @param [Integer] edge H3 edge index
129
174
  #
130
175
  # @example
131
- # H3.h3_unidirectional_edge_boundary(612933930963697663)
176
+ # H3.unidirectional_edge_boundary(612933930963697663)
132
177
  # [
133
178
  # [68.92995788193981, 31.831280499087402], [69.39359648991828, 62.345344956509784],
134
179
  # [76.163042830191, 94.14309010184775], [87.36469532319619, 145.5581976913368],
@@ -136,12 +181,22 @@ module H3
136
181
  # ]
137
182
  #
138
183
  # @return [Array<Array<Float>>] Edge boundary coordinates for a hexagon
139
- def h3_unidirectional_edge_boundary(edge)
184
+ def unidirectional_edge_boundary(edge)
140
185
  geo_boundary = GeoBoundary.new
141
186
  Bindings::Private.h3_unidirectional_edge_boundary(edge, geo_boundary)
142
187
  geo_boundary[:verts].take(geo_boundary[:num_verts]).map do |d|
143
188
  [rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
144
189
  end
145
190
  end
191
+
192
+ # @deprecated Please use {#unidirectional_edge_boundary} instead.
193
+ def h3_unidirectional_edge_boundary(edge)
194
+ unidirectional_edge_boundary(edge)
195
+ end
196
+
197
+ deprecate :h3_unidirectional_edge_boundary,
198
+ :unidirectional_edge_boundary,
199
+ 2020,
200
+ 1
146
201
  end
147
202
  end
data/lib/h3/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module H3
2
- VERSION = "3.5.0".freeze
2
+ VERSION = "3.5.1".freeze
3
3
  end
@@ -1,27 +1,27 @@
1
1
  RSpec.describe H3 do
2
2
  include_context "constants"
3
3
 
4
- describe ".h3_to_parent" do
4
+ describe ".parent" do
5
5
  let(:h3_index) { "89283082993ffff".to_i(16) }
6
6
  let(:parent_resolution) { 8 }
7
7
  let(:result) { "8828308299fffff".to_i(16) }
8
8
 
9
- subject(:h3_to_parent) { H3.h3_to_parent(h3_index, parent_resolution) }
9
+ subject(:parent) { H3.parent(h3_index, parent_resolution) }
10
10
 
11
11
  it { is_expected.to eq(result) }
12
12
  end
13
13
 
14
- describe ".h3_to_children" do
14
+ describe ".children" do
15
15
  let(:h3_index) { "8928308280fffff".to_i(16) }
16
16
 
17
- subject(:h3_to_children) { H3.h3_to_children(h3_index, child_resolution) }
17
+ subject(:children) { H3.children(h3_index, child_resolution) }
18
18
 
19
19
  context "when resolution is 3" do
20
20
  let(:child_resolution) { 3 }
21
21
  let(:count) { 0 }
22
22
 
23
23
  it "has 0 children" do
24
- expect(h3_to_children.count).to eq count
24
+ expect(children.count).to eq count
25
25
  end
26
26
  end
27
27
 
@@ -31,11 +31,11 @@ RSpec.describe H3 do
31
31
  let(:expected) { "8928308280fffff".to_i(16) }
32
32
 
33
33
  it "has 1 child" do
34
- expect(h3_to_children.count).to eq count
34
+ expect(children.count).to eq count
35
35
  end
36
36
 
37
37
  it "is the expected value" do
38
- expect(h3_to_children.first).to eq expected
38
+ expect(children.first).to eq expected
39
39
  end
40
40
  end
41
41
 
@@ -44,7 +44,7 @@ RSpec.describe H3 do
44
44
  let(:count) { 7 }
45
45
 
46
46
  it "has 7 children" do
47
- expect(h3_to_children.count).to eq count
47
+ expect(children.count).to eq count
48
48
  end
49
49
  end
50
50
 
@@ -53,7 +53,7 @@ RSpec.describe H3 do
53
53
  let(:count) { 117649 }
54
54
 
55
55
  it "has 117649 children" do
56
- expect(h3_to_children.count).to eq count
56
+ expect(children.count).to eq count
57
57
  end
58
58
  end
59
59
 
@@ -61,7 +61,7 @@ RSpec.describe H3 do
61
61
  let(:child_resolution) { -1 }
62
62
 
63
63
  it "raises an error" do
64
- expect { h3_to_children }.to raise_error(ArgumentError)
64
+ expect { children }.to raise_error(ArgumentError)
65
65
  end
66
66
  end
67
67
 
@@ -69,15 +69,15 @@ RSpec.describe H3 do
69
69
  let(:child_resolution) { 16 }
70
70
 
71
71
  it "raises an error" do
72
- expect { h3_to_children }.to raise_error(ArgumentError)
72
+ expect { children }.to raise_error(ArgumentError)
73
73
  end
74
74
  end
75
75
  end
76
76
 
77
- describe ".max_h3_to_children_size" do
77
+ describe ".max_children" do
78
78
  let(:h3_index) { "8928308280fffff".to_i(16) }
79
79
 
80
- subject(:h3_to_children) { H3.max_h3_to_children_size(h3_index, child_resolution) }
80
+ subject(:max_children) { H3.max_children(h3_index, child_resolution) }
81
81
 
82
82
  context "when resolution is 3" do
83
83
  let(:child_resolution) { 3 }
@@ -1,12 +1,12 @@
1
1
  RSpec.describe H3 do
2
2
  include_context "constants"
3
3
 
4
- describe ".geo_to_h3" do
4
+ describe ".from_geo_coordinates" do
5
5
  let(:resolution) { 8 }
6
6
  let(:coords) { [53.959130, -1.079230]}
7
7
  let(:result) { valid_h3_index }
8
8
 
9
- subject(:geo_to_h3) { H3.geo_to_h3(coords, resolution) }
9
+ subject(:from_geo_coordinates) { H3.from_geo_coordinates(coords, resolution) }
10
10
 
11
11
  it { is_expected.to eq(result) }
12
12
 
@@ -14,7 +14,7 @@ RSpec.describe H3 do
14
14
  let(:coords) { [1, 2, 3] }
15
15
 
16
16
  it "raises an error" do
17
- expect { geo_to_h3 }.to raise_error(ArgumentError)
17
+ expect { from_geo_coordinates }.to raise_error(ArgumentError)
18
18
  end
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ RSpec.describe H3 do
22
22
  let(:coords) { "boom" }
23
23
 
24
24
  it "raises an error" do
25
- expect { geo_to_h3 }.to raise_error(ArgumentError)
25
+ expect { from_geo_coordinates }.to raise_error(ArgumentError)
26
26
  end
27
27
  end
28
28
 
@@ -30,31 +30,31 @@ RSpec.describe H3 do
30
30
  let(:coords) { [-1.1323222, 190.1020102] }
31
31
 
32
32
  it "raises an error" do
33
- expect { geo_to_h3 }.to raise_error(ArgumentError)
33
+ expect { from_geo_coordinates }.to raise_error(ArgumentError)
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
- describe ".h3_to_geo" do
38
+ describe ".to_geo_coordinates" do
39
39
  let(:h3_index) { valid_h3_index }
40
40
  let(:expected_lat) { 53.95860421941 }
41
41
  let(:expected_lon) { -1.08119564709 }
42
42
 
43
- subject(:h3_to_geo) { H3.h3_to_geo(h3_index) }
43
+ subject(:to_geo_coordinates) { H3.to_geo_coordinates(h3_index) }
44
44
 
45
45
  it "should return the expected latitude" do
46
- expect(h3_to_geo[0]).to be_within(0.000001).of(expected_lat)
46
+ expect(to_geo_coordinates[0]).to be_within(0.000001).of(expected_lat)
47
47
  end
48
48
 
49
49
  it "should return the expected longitude" do
50
- expect(h3_to_geo[1]).to be_within(0.000001).of(expected_lon)
50
+ expect(to_geo_coordinates[1]).to be_within(0.000001).of(expected_lon)
51
51
  end
52
52
 
53
53
  context "when given an invalid h3_index" do
54
54
  let(:h3_index) { "boom" }
55
55
 
56
56
  it "raises an error" do
57
- expect { h3_to_geo }.to raise_error(TypeError)
57
+ expect { to_geo_coordinates }.to raise_error(TypeError)
58
58
  end
59
59
  end
60
60
 
@@ -62,12 +62,12 @@ RSpec.describe H3 do
62
62
  let(:h3_index) { too_long_number }
63
63
 
64
64
  it "raises an error" do
65
- expect { h3_to_geo }.to raise_error(RangeError)
65
+ expect { to_geo_coordinates }.to raise_error(RangeError)
66
66
  end
67
67
  end
68
68
  end
69
69
 
70
- describe ".h3_to_geo_boundary" do
70
+ describe ".to_boundary" do
71
71
  let(:h3_index) { "85283473fffffff".to_i(16) }
72
72
  let(:expected) do
73
73
  [
@@ -80,13 +80,13 @@ RSpec.describe H3 do
80
80
  ]
81
81
  end
82
82
 
83
- subject(:h3_to_geo_boundary) { H3.h3_to_geo_boundary(h3_index) }
83
+ subject(:to_boundary) { H3.to_boundary(h3_index) }
84
84
 
85
85
  it "matches expected boundary coordinates" do
86
- h3_to_geo_boundary.zip(expected) do |(lat, lon), (exp_lat, exp_lon)|
86
+ to_boundary.zip(expected) do |(lat, lon), (exp_lat, exp_lon)|
87
87
  expect(lat).to be_within(0.000001).of(exp_lat)
88
88
  expect(lon).to be_within(0.000001).of(exp_lon)
89
89
  end
90
90
  end
91
91
  end
92
- end
92
+ end