diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 232c8ac394bd278725de00d5473b9016141fc85d..f3cfc0dd57d9345e94ea6e802d476ba7245507bf 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -176,6 +176,26 @@ class GeocoderTest < Test::Unit::TestCase assert_equal [0.0, 0.5], Geocoder::Calculations.geographic_center([p1, p2]) end + def test_bounding_box_calculation_in_miles + center = [51, 7] # Cologne, DE + radius = 10 # miles + dlon = radius / Geocoder::Calculations.latitude_degree_distance + dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0]) + corners = [50.86, 6.77, 51.14, 7.23] + assert_equal corners.map{ |i| (i * 100).round }, + Geocoder::Calculations.bounding_box(center[0], center[1], radius).map{ |i| (i * 100).round } + end + + def test_bounding_box_calculation_in_kilometers + center = [51, 7] # Cologne, DE + radius = 111 # kilometers (= 1 degree latitude) + dlon = radius / Geocoder::Calculations.latitude_degree_distance(:km) + dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0], :km) + corners = [50, 5.41, 52, 8.59] + assert_equal corners.map{ |i| (i * 100).round }, + Geocoder::Calculations.bounding_box(center[0], center[1], radius, :units => :km).map{ |i| (i * 100).round } + end + # --- bearing ---