Class: GeoDistance::DistanceFormula

Inherits:
Object
  • Object
show all
Extended by:
GeoUnits, Math
Defined in:
lib/geo-distance/formula.rb

Direct Known Subclasses

Flat, Haversine, NVector, Spherical, Vincenty

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDistanceFormula

Returns a new instance of DistanceFormula.

Raises:

  • (NotImplementedError)


8
9
10
# File 'lib/geo-distance/formula.rb', line 8

def initialize
  raise NotImplementedError
end

Class Method Details

.geo_distance(*args) ⇒ Object

use underlying distance formula



13
14
15
# File 'lib/geo-distance/formula.rb', line 13

def self.geo_distance *args
  GeoDistance.new distance(args), get_units(args.last_option)
end

.get_points(*args) ⇒ Object

used to convert various argument types into GeoPoints



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/geo-distance/formula.rb', line 18

def self.get_points(*args)
  args.flatten!
  options = args.delete(args.last_option) || {}
  units = options[:units] || GeoDistance.default_units

  case args.size
  when 2
    [GeoPoint.new(args.first), GeoPoint.new(args.last), units]
  when 4
    [GeoPoint.new(args[0..1]), GeoPoint.new(args[2..3]), units]        
  else
    raise "Distance from point A to B, must be given either as 4 arguments (lat1, lng1, lat2, lng2) or 2 arguments: (pointA, pointB), was: #{args}"
  end
end

.get_units(options = {}) ⇒ Object

used to get the units for how to calculate the distance



34
35
36
# File 'lib/geo-distance/formula.rb', line 34

def self.get_units options = {}
  GeoUnits.key(options[:units] || :kms)
end