Changeset 98
- Timestamp:
- 11/09/07 02:45:49 (4 years ago)
- Location:
- hw/hw4/library
- Files:
-
- 2 modified
-
app/controllers/librarymaps_controller.rb (modified) (4 diffs)
-
test/functional/librarymaps_controller_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
hw/hw4/library/app/controllers/librarymaps_controller.rb
r97 r98 36 36 if geoloc.status != Geocoding::GEO_SUCCESS 37 37 err = 'Library Coordinates Not Found' 38 r eturnerr38 raise err 39 39 end 40 40 liblatlon = geoloc[0].latlon … … 117 117 # formula = options[:formula] || GeoKit::default_formula 118 118 units = :miles 119 formula = :sphere120 case formula121 when :sphere119 # formula = :sphere 120 # case formula 121 # when :sphere 122 122 units_sphere_multiplier(units) * 123 123 Math.acos( Math.sin(deg2rad(from[0])) * Math.sin(deg2rad(to[0])) + 124 124 Math.cos(deg2rad(from[0])) * Math.cos(deg2rad(to[0])) * 125 125 Math.cos(deg2rad(to[1]) - deg2rad(from[1]))) 126 when :flat127 Math.sqrt((units_per_latitude_degree(units)*(from[0]-to[0]))**2 +128 (units_per_longitude_degree(from[0], units)*(from[1]-to[1]))**2)129 end126 # when :flat 127 # Math.sqrt((units_per_latitude_degree(units)*(from[0]-to[0]))**2 + 128 # (units_per_longitude_degree(from[0], units)*(from[1]-to[1]))**2) 129 # end 130 130 end 131 131 … … 134 134 end 135 135 136 def rad2deg(rad)137 rad.to_f * 180.0 / Math::PI138 end136 # def rad2deg(rad) 137 # rad.to_f * 180.0 / Math::PI 138 # end 139 139 140 def to_heading(rad)141 (rad2deg(rad)+360)%360142 end140 # def to_heading(rad) 141 # (rad2deg(rad)+360)%360 142 # end 143 143 144 144 # Returns the multiplier used to obtain the correct distance units. … … 148 148 149 149 # Returns the number of units per latitude degree. 150 def units_per_latitude_degree(units)151 units == :miles ? MILES_PER_LATITUDE_DEGREE : KMS_PER_LATITUDE_DEGREE152 end150 # def units_per_latitude_degree(units) 151 # units == :miles ? MILES_PER_LATITUDE_DEGREE : KMS_PER_LATITUDE_DEGREE 152 # end 153 153 154 154 # Returns the number units per longitude degree. 155 def units_per_longitude_degree(lat, units)156 miles_per_longitude_degree = (LATITUDE_DEGREES * Math.cos(lat * PI_DIV_RAD)).abs157 units == :miles ? miles_per_longitude_degree : miles_per_longitude_degree * KMS_PER_MILE158 end155 # def units_per_longitude_degree(lat, units) 156 # miles_per_longitude_degree = (LATITUDE_DEGREES * Math.cos(lat * PI_DIV_RAD)).abs 157 # units == :miles ? miles_per_longitude_degree : miles_per_longitude_degree * KMS_PER_MILE 158 # end -
hw/hw4/library/test/functional/librarymaps_controller_test.rb
r88 r98 13 13 14 14 # Replace this with your real tests. 15 def test_truth 16 assert true 15 def test_index 16 get :index, :changelibrary => {:newlibrary=>'Gustav Library'} 17 assert_response :success 18 end 19 20 def test_bad_geoloc 21 l = Library.new 22 l.city = "Hellerstein" 23 l.lname = "Nothing Library" 24 l.save 25 assert_raises(RuntimeError) do 26 get :index, :changelibrary => {:newlibrary=>'Nothing Library'} 27 end 17 28 end 18 29 end
