Module: FastHaversine

Defined in:
lib/fast_haversine.rb,
lib/fast_haversine/version.rb,
ext/fast_haversine/fast_haversine.c

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.distance_between(point_a, point_b, units) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fast_haversine.rb', line 5

def self.distance_between(point_a, point_b, units)
  case units
  when :km
    return distance_in_km(point_a[0], point_a[1], point_b[0], point_b[1])
  when :mi
    return distance_in_mi(point_a[0], point_a[1], point_b[0], point_b[1])
  end
end

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



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'ext/fast_haversine/fast_haversine.c', line 38

static VALUE rb_distance_in_km(
      VALUE self,
      VALUE lat1,
      VALUE lon1,
      VALUE lat2,
      VALUE lon2) {
  double c = haversine_c(
      NUM2DBL(lat1),
      NUM2DBL(lon1),
      NUM2DBL(lat2),
      NUM2DBL(lon2));
  return rb_float_new(c * EARTH_RADIUS_IN_KM);
}

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



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/fast_haversine/fast_haversine.c', line 24

static VALUE rb_distance_in_mi(
      VALUE self,
      VALUE lat1,
      VALUE lon1,
      VALUE lat2,
      VALUE lon2) {
  double c = haversine_c(
      NUM2DBL(lat1),
      NUM2DBL(lon1),
      NUM2DBL(lat2),
      NUM2DBL(lon2));
  return rb_float_new(c * EARTH_RADIUS_IN_MI);
}