Module: GeoDistance::ClassMethods
- Included in:
- GeoDistance
- Defined in:
- lib/geo-distance/class_methods.rb
Overview
this is global because if computing lots of track point distances, it didn’t make sense to new a Hash each time over potentially 100’s of thousands of points
Instance Method Summary collapse
- #algorithms ⇒ Object
- #all_units ⇒ Object
- #default_algorithm ⇒ Object
- #default_algorithm=(name) ⇒ Object
- #default_units ⇒ Object
- #default_units=(name) ⇒ Object
-
#distance(*args) ⇒ Object
radius of the great circle in miles radius in kilometers…some algorithms use 6367.
- #earth_radius(units) ⇒ Object
- #radians_per_degree ⇒ Object
- #radians_ratio(unit) ⇒ Object
- #units ⇒ Object
Instance Method Details
#algorithms ⇒ Object
65 66 67 |
# File 'lib/geo-distance/class_methods.rb', line 65 def algorithms [:flat, :haversine, :spherical, :vincenty, :nvector] end |
#all_units ⇒ Object
57 58 59 |
# File 'lib/geo-distance/class_methods.rb', line 57 def all_units GeoUnits.all_units end |
#default_algorithm ⇒ Object
41 42 43 |
# File 'lib/geo-distance/class_methods.rb', line 41 def default_algorithm @default_algorithm || :haversine end |
#default_algorithm=(name) ⇒ Object
36 37 38 39 |
# File 'lib/geo-distance/class_methods.rb', line 36 def default_algorithm= name raise ArgumentError, "Not a valid algorithm. Must be one of: #{algorithms}" if !algorithms.include?(name.to_sym) @default_algorithm = name end |
#default_units ⇒ Object
32 33 34 |
# File 'lib/geo-distance/class_methods.rb', line 32 def default_units @default_units || :kms end |
#default_units=(name) ⇒ Object
27 28 29 30 |
# File 'lib/geo-distance/class_methods.rb', line 27 def default_units= name raise ArgumentError, "Not a valid units. Must be one of: #{all_units}" if !all_units.include?(name.to_sym) @default_units = GeoUnits.key(name) end |
#distance(*args) ⇒ Object
radius of the great circle in miles radius in kilometers…some algorithms use 6367
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/geo-distance/class_methods.rb', line 9 def distance(*args) klass = case default_algorithm when :flat GeoDistance::Flat when :haversine GeoDistance::Haversine when :spherical GeoDistance::Spherical when :vincenty GeoDistance::Vincenty when :nvector GeoDistance::NVector else raise ArgumentError, "Not a valid algorithm. Must be one of: #{algorithms}" end klass.distance *args end |
#earth_radius(units) ⇒ Object
45 46 47 |
# File 'lib/geo-distance/class_methods.rb', line 45 def earth_radius units GeoUnits.earth_radius units end |
#radians_per_degree ⇒ Object
49 50 51 |
# File 'lib/geo-distance/class_methods.rb', line 49 def radians_per_degree 0.017453293 # PI/180 end |
#radians_ratio(unit) ⇒ Object
53 54 55 |
# File 'lib/geo-distance/class_methods.rb', line 53 def radians_ratio unit GeoDistance.radians_per_degree * earth_radius[unit] end |
#units ⇒ Object
61 62 63 |
# File 'lib/geo-distance/class_methods.rb', line 61 def units GeoUnits.units end |