Module: HaversineFast

Defined in:
lib/haversine_fast.rb,
lib/haversine_fast/version.rb,
ext/calc_haversine/calc_haversine.c

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.calc_distance(lat1, lon1, lat2, lon2) ⇒ Object



6
7
8
# File 'lib/haversine_fast.rb', line 6

def calc_distance(lat1, lon1, lat2, lon2)
  calculate_distance_by_haversine(lat1, lon1, lat2, lon2)
end

.calculate_distance_by_haversine(lat1, lon1, lat2, lon2) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'ext/calc_haversine/calc_haversine.c', line 20

static VALUE calculate_distance_by_haversine(VALUE self, VALUE lat1, VALUE lon1, VALUE lat2, VALUE lon2){
  
  double  dLat1 = NUM2RADDBL(lat1),
          dLon1 = NUM2RADDBL(lon1),
          dLat2 = NUM2RADDBL(lat2),
          dLon2 = NUM2RADDBL(lon2),
          result;

  result = 2.0 * RADIUS_OF_EARTH *
  asin(sqrt(
    (1-cos(dLat2-dLat1))/2 + 
    cos(dLat1)*cos(dLat2) * (1-cos(dLon2-dLon1))/2
    ));

  return rb_float_new(result);
}