Skip to content
Snippets Groups Projects
Commit 47662822 authored by Alex Reisner's avatar Alex Reisner
Browse files

Shorten method names.

parent 4a2320dd
No related branches found
No related tags found
No related merge requests found
...@@ -22,18 +22,20 @@ module Geocoder ...@@ -22,18 +22,20 @@ module Geocoder
KM_IN_MI = 0.621371192 KM_IN_MI = 0.621371192
## ##
# Calculate the distance between latitude lines in the given units. # Calculate the distance spanned by one
# degree of latitude in the given units.
# #
def distance_between_latitude_lines(units = :mi) def latitude_degree_distance(units = :mi)
2 * Math::PI * earth_radius(units) / 360 2 * Math::PI * earth_radius(units) / 360
end end
## ##
# Calculate the distance between longitude lines at the given latitude. # Calculate the distance spanned by one degree of longitude
# This ranges from around 69 miles at the equator to zero at the poles. # at the given latitude. This ranges from around 69 miles at
# the equator to zero at the poles.
# #
def distance_between_longitude_lines(latitude, units = :mi) def longitude_degree_distance(latitude, units = :mi)
distance_between_latitude_lines(units) * Math.cos(to_radians(latitude)) latitude_degree_distance(units) * Math.cos(to_radians(latitude))
end end
## ##
......
...@@ -154,8 +154,8 @@ module Geocoder::Orm ...@@ -154,8 +154,8 @@ module Geocoder::Orm
bearing = false bearing = false
end end
dx = Geocoder::Calculations.distance_between_longitude_lines(30, options[:units] || :mi) dx = Geocoder::Calculations.longitude_degree_distance(30, options[:units] || :mi)
dy = Geocoder::Calculations.distance_between_latitude_lines(options[:units] || :mi) dy = Geocoder::Calculations.latitude_degree_distance(options[:units] || :mi)
distance = "(#{dy} * ABS(#{lat_attr} - #{latitude}) / 2) + " + distance = "(#{dy} * ABS(#{lat_attr} - #{latitude}) / 2) + " +
"(#{dx} * ABS(#{lon_attr} - #{longitude}) / 2)" "(#{dx} * ABS(#{lon_attr} - #{longitude}) / 2)"
...@@ -196,10 +196,10 @@ module Geocoder::Orm ...@@ -196,10 +196,10 @@ module Geocoder::Orm
def coordinate_bounds(latitude, longitude, radius, units = :mi) def coordinate_bounds(latitude, longitude, radius, units = :mi)
radius = radius.to_f radius = radius.to_f
[ [
latitude - (radius / Geocoder::Calculations.distance_between_latitude_lines(units)), latitude - (radius / Geocoder::Calculations.latitude_degree_distance(units)),
latitude + (radius / Geocoder::Calculations.distance_between_latitude_lines(units)), latitude + (radius / Geocoder::Calculations.latitude_degree_distance(units)),
longitude - (radius / Geocoder::Calculations.distance_between_longitude_lines(latitude, units)), longitude - (radius / Geocoder::Calculations.longitude_degree_distance(latitude, units)),
longitude + (radius / Geocoder::Calculations.distance_between_longitude_lines(latitude, units)) longitude + (radius / Geocoder::Calculations.longitude_degree_distance(latitude, units))
] ]
end end
end end
......
...@@ -139,16 +139,16 @@ class GeocoderTest < Test::Unit::TestCase ...@@ -139,16 +139,16 @@ class GeocoderTest < Test::Unit::TestCase
# --- calcluations --- # --- calcluations ---
def test_distance_between_longitude_lines_at_equator def test_longitude_degree_distance_at_equator
assert_equal 69, Geocoder::Calculations.distance_between_longitude_lines(0).round assert_equal 69, Geocoder::Calculations.longitude_degree_distance(0).round
end end
def test_distance_between_longitude_lines_at_new_york def test_longitude_degree_distance_at_new_york
assert_equal 53, Geocoder::Calculations.distance_between_longitude_lines(40).round assert_equal 53, Geocoder::Calculations.longitude_degree_distance(40).round
end end
def test_distance_between_longitude_lines_at_north_pole def test_longitude_degree_distance_at_north_pole
assert_equal 0, Geocoder::Calculations.distance_between_longitude_lines(89.98).round assert_equal 0, Geocoder::Calculations.longitude_degree_distance(89.98).round
end end
def test_distance_between def test_distance_between
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment