C0 code coverage information
Generated on Wed Sep 10 17:14:43 +0200 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
| Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
| lib/algebra.rb
|
52
|
40
|
|
|
1 module Algebra
2 include Math
3
4 RADIUS_EARTH = 6372.796924
5
6 def midpoint(coords_a, coords_b)
7 lat_a = coords_a[0].to_f
8 lon_a = coords_a[1].to_f
9
10 lat_b = coords_b[0].to_f
11 lon_b = coords_b[1].to_f
12
13 [((lat_a + lat_b) / 2).to_s, ((lon_a + lon_b) / 2).to_s]
14 end
15
16 def random_points_into_a_circumference(coordinates, radius, points = 10)
17 center_latitude = deg2rad(coordinates[0].to_f)
18 center_longitude = deg2rad(coordinates[1].to_f)
19
20 max_distance = radius / RADIUS_EARTH
21 cos_dif = cos(max_distance) - 1
22 sin_lat = sin(center_latitude)
23 cos_lat = cos(center_latitude)
24
25 (1..points).map {
26 dist = acos(rand() * cos_dif + 1)
27 bearing = 2 * PI * rand()
28 lat = asin(sin_lat * cos(dist) + cos_lat * sin(dist) * cos(bearing))
29 lon = center_longitude + atan2(sin(bearing) * sin(dist) * cos_lat, cos(dist) - sin_lat * sin(lat))
30
31 [rad2deg(lat), rad2deg(normalize(lon))]
32 }
33 end
34
35 def rad2deg(rad)
36 (rad * 180) / Math::PI
37 end
38
39 def deg2rad(dgr)
40 (dgr * Math::PI) / 180
41 end
42
43 def normalize(lon)
44 if (lon > Math::PI)
45 lon = lon - 2 * Math::PI
46 elsif (lon < -Math::PI)
47 lon = lon + 2 * Math::PI
48 end
49 lon
50 end
51
52 end
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.1.2.