Skip to content

Commit 8e06f14

Browse files
authored
Deprecate longwinded method names (#59)
* Rename methods. * Fix deprecation warnings in specs.
1 parent 138e5d6 commit 8e06f14

15 files changed

+336
-170
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Please consult [the H3 documentation](https://uber.github.io/h3/#/documentation/
1111

1212
## Supported H3 Versions
1313

14-
The semantic versioning of this gem matches the versioning of the H3 C library. E.g. version `3.2.x` of this gem is targeted for version `3.2.y` of H3 C lib where `x` and `y` are independent patch levels.
14+
The semantic versioning of this gem matches the versioning of the H3 C library. E.g. version `3.5.x` of this gem is targeted for version `3.5.y` of H3 C lib where `x` and `y` are independent patch levels.
1515

1616
## Naming Conventions
1717

1818
We have changed camel-case method names to snake-case, as per the Ruby convention.
1919

20-
In addition, some methods using the `get` verb have been renamed i.e. `getH3UnidirectionalEdgesFromHexagon` becomes `h3_unidirectional_edges_from_hexagon`.
20+
In addition, some methods using the `get` verb have been renamed i.e. `getH3UnidirectionalEdgesFromHexagon` becomes `unidirectional_edges_from_hexagon`.
2121

22-
We have also suffixed predicate methods with a question mark, as per the Ruby convention, and removed `is` from the name i.e. `h3IsPentagon` becomes `h3_pentagon?`
22+
We have also suffixed predicate methods with a question mark, as per the Ruby convention, and removed `h3Is` from the name i.e. `h3IsPentagon` becomes `pentagon?`
2323

2424
## Getting Started
2525

@@ -53,13 +53,13 @@ require "h3"
5353
Call H3 functions via the `H3` namespace
5454

5555
```ruby
56-
H3.geo_to_h3([53.959130, -1.079230], 8).to_s(16)
56+
H3.from_geo_coordinates([53.959130, -1.079230], 8).to_s(16)
5757
=> "8819429a9dfffff"
58-
H3.h3_valid?("8819429a9dfffff".to_i(16))
58+
H3.valid?("8819429a9dfffff".to_i(16))
5959
=> true
60-
H3.h3_pentagon?("8819429a9dfffff".to_i(16))
60+
H3.pentagon?("8819429a9dfffff".to_i(16))
6161
=> false
62-
H3.h3_to_geo_boundary("8819429a9dfffff".to_i(16))
62+
H3.to_boundary("8819429a9dfffff".to_i(16))
6363
=> [[53.962987505331384, -1.079984346847996], [53.9618315234061, -1.0870313428985856], [53.95744798515881, -1.0882421079017874], [53.95422067486053, -1.082406760751464], [53.955376670617454, -1.0753609232787642], [53.95975996282198, -1.074149274503605]]
6464
```
6565

lib/h3.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@ module H3
1919
extend Traversal
2020
extend UnidirectionalEdges
2121

22-
PREDICATES = %i[h3_indexes_neighbors h3_pentagon h3_res_class_3
23-
h3_unidirectional_edge_valid h3_valid].freeze
24-
private_constant :PREDICATES
25-
26-
class << self
27-
# FFI's attach_function doesn't allow method names ending with a
28-
# question mark. This works around the issue by dynamically
29-
# renaming those methods afterwards.
30-
PREDICATES.each do |predicate|
31-
alias_method "#{predicate}?", predicate
32-
undef_method predicate
33-
end
34-
end
35-
3622
# Internal bindings related modules and classes.
3723
#
3824
# These are intended to be used by the library's public methods

lib/h3/bindings/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Base
77
def self.extended(base)
88
lib_path = File.expand_path(__dir__ + "/../../../ext/h3/src/lib")
99
base.extend FFI::Library
10+
base.extend Gem::Deprecate
1011
base.include Structs
1112
base.include Types
1213
base.ffi_lib ["#{lib_path}/libh3.dylib", "#{lib_path}/libh3.so"]

lib/h3/hierarchy.rb

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,72 @@ module H3
55
module Hierarchy
66
extend H3::Bindings::Base
77

8-
# @!method h3_to_parent(h3_index, parent_resolution)
8+
# @!method parent(h3_index, parent_resolution)
99
#
1010
# Derive the parent hexagon which contains the hexagon at the given H3 index.
1111
#
1212
# @param [Integer] h3_index A valid H3 index.
1313
# @param [Integer] parent_resoluton The desired resolution of the parent hexagon.
1414
#
1515
# @example Find the parent hexagon for a H3 index.
16-
# H3.h3_to_parent(613196570357137407, 6)
16+
# H3.parent(613196570357137407, 6)
1717
# 604189371209351167
1818
#
1919
# @return [Integer] H3 index of parent hexagon.
20-
attach_function :h3_to_parent, :h3ToParent, [:h3_index, Resolution], :h3_index
20+
attach_function :parent, :h3ToParent, [:h3_index, Resolution], :h3_index
2121

22-
# @!method max_h3_to_children_size(h3_index, child_resolution)
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+
# @!method max_children(h3_index, child_resolution)
2329
#
2430
# Derive maximum number of child hexagons possible at given resolution.
2531
#
2632
# @param [Integer] h3_index A valid H3 index.
2733
# @param [Integer] child_resoluton The desired resolution of the child hexagons.
2834
#
2935
# @example Derive maximum number of child hexagons.
30-
# H3.max_h3_to_children_size(613196570357137407, 10)
36+
# H3.max_children(613196570357137407, 10)
3137
# 49
3238
#
3339
# @return [Integer] Maximum number of child hexagons possible at given resolution.
34-
attach_function :max_h3_to_children_size, :maxH3ToChildrenSize, [:h3_index, Resolution], :int
40+
attach_function :max_children, :maxH3ToChildrenSize, [:h3_index, Resolution], :int
41+
42+
# @deprecated Please use {#max_children} instead.
43+
def max_h3_to_children_size(h3_index, resolution)
44+
max_children(h3_index, resolution)
45+
end
46+
deprecate :max_h3_to_children_size, :max_children, 2020, 1
3547

3648
# Derive child hexagons contained within the hexagon at the given H3 index.
3749
#
3850
# @param [Integer] h3_index A valid H3 index.
3951
# @param [Integer] child_resolution The desired resolution of hexagons returned.
4052
#
4153
# @example Find the child hexagons for a H3 index.
42-
# H3.h3_to_children(613196570357137407, 9)
54+
# H3.children(613196570357137407, 9)
4355
# [
4456
# 617700169982672895, 617700169982935039, 617700169983197183, 617700169983459327,
4557
# 617700169983721471, 617700169983983615, 617700169984245759
4658
# ]
4759
#
4860
# @return [Array<Integer>] H3 indexes of child hexagons.
49-
def h3_to_children(h3_index, child_resolution)
50-
max_children = max_h3_to_children_size(h3_index, child_resolution)
61+
def children(h3_index, child_resolution)
62+
max_children = max_children(h3_index, child_resolution)
5163
out = H3Indexes.of_size(max_children)
5264
Bindings::Private.h3_to_children(h3_index, child_resolution, out)
5365
out.read
5466
end
5567

68+
# @deprecated Please use {#children} instead.
69+
def h3_to_children(h3_index, resolution)
70+
children(h3_index, resolution)
71+
end
72+
deprecate :h3_to_children, :children, 2020, 1
73+
5674
# Find the maximum uncompacted size of the given set of H3 indexes.
5775
#
5876
# @param [Array<Integer>] compacted_set An array of valid H3 indexes.

lib/h3/indexing.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ module H3
77
#
88
# @see https://uber.github.io/h3/#/documentation/api-reference/indexing
99
module Indexing
10-
include Bindings::Structs
10+
extend H3::Bindings::Base
1111
# Derive H3 index for the given set of coordinates.
1212
#
1313
# @param [Array<Integer>] coords A coordinate pair.
1414
# @param [Integer] resolution The desired resolution of the H3 index.
1515
#
1616
# @example Derive the H3 index for the given coordinates.
17-
# H3.geo_to_h3([52.24630137198303, -1.7358398437499998], 9)
17+
# H3.from_geo_coordinates([52.24630137198303, -1.7358398437499998], 9)
1818
# 617439284584775679
1919
#
2020
# @raise [ArgumentError] If coordinates are invalid.
2121
#
2222
# @return [Integer] H3 index.
23-
def geo_to_h3(coords, resolution)
23+
def from_geo_coordinates(coords, resolution)
2424
raise ArgumentError unless coords.is_a?(Array) && coords.count == 2
2525

2626
lat, lon = coords
@@ -35,23 +35,35 @@ def geo_to_h3(coords, resolution)
3535
Bindings::Private.geo_to_h3(coords, resolution)
3636
end
3737

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+
3844
# Derive coordinates for a given H3 index.
3945
#
4046
# The coordinates map to the centre of the hexagon at the given index.
4147
#
4248
# @param [Integer] h3_index A valid H3 index.
4349
#
4450
# @example Derive the central coordinates for the given H3 index.
45-
# H3.h3_to_geo(617439284584775679)
51+
# H3.to_geo_coordinates(617439284584775679)
4652
# [52.245519061399506, -1.7363137757391423]
4753
#
4854
# @return [Array<Integer>] A coordinate pair.
49-
def h3_to_geo(h3_index)
55+
def to_geo_coordinates(h3_index)
5056
coords = GeoCoord.new
5157
Bindings::Private.h3_to_geo(h3_index, coords)
5258
[rads_to_degs(coords[:lat]), rads_to_degs(coords[:lon])]
5359
end
5460

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+
5567
# Derive the geographical boundary as coordinates for a given H3 index.
5668
#
5769
# This will be a set of 6 coordinate pairs matching the vertexes of the
@@ -62,20 +74,26 @@ def h3_to_geo(h3_index)
6274
# @param [Integer] h3_index A valid H3 index.
6375
#
6476
# @example Derive the geographical boundary for the given H3 index.
65-
# H3.h3_to_geo_boundary(617439284584775679)
77+
# H3.to_boundary(617439284584775679)
6678
# [
6779
# [52.247260929171055, -1.736809158397472], [52.24625850761068, -1.7389279144996015],
6880
# [52.244516619273476, -1.7384324668792375], [52.243777169245725, -1.7358184256304658],
6981
# [52.24477956752282, -1.7336997597088104], [52.246521439109415, -1.7341950448552204]
7082
# ]
7183
#
7284
# @return [Array<Array<Integer>>] An array of six coordinate pairs.
73-
def h3_to_geo_boundary(h3_index)
85+
def to_boundary(h3_index)
7486
geo_boundary = GeoBoundary.new
7587
Bindings::Private.h3_to_geo_boundary(h3_index, geo_boundary)
7688
geo_boundary[:verts].take(geo_boundary[:num_verts]).map do |d|
7789
[rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
7890
end
7991
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
8098
end
8199
end

0 commit comments

Comments
 (0)