Skip to content

Commit

Permalink
Refactor CircularRadius#random_points_within
Browse files Browse the repository at this point in the history
  • Loading branch information
dburt committed Jun 2, 2011
1 parent ef7f084 commit 94389dd
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions lib/geo_magic/radius/circular.rb
Expand Up @@ -28,7 +28,7 @@ def to_s

# Factory
def random_point_within
max_radius_rad = dist.distance
max_radius_rad = distance.distance
range = normalize max_radius_rad

q = rand(range) * PI_2
Expand All @@ -40,25 +40,7 @@ def random_point_within
end

def random_points_within number
conversion = GeoMagic::Distance.radians_ratio(distance.unit)

max_radius_rad = distance.distance
range = normalize max_radius_rad

max_radius_rad = distance.distance
range = normalize max_radius_rad

number.times.inject([]) do |res, n|
q = rand(range) * PI_2
r = Math.sqrt(rand(range))

dlong = denormalize range * r * Math.cos(q)
dlat = denormalize range * r * Math.sin(q)

point = GeoMagic::Point.new @center.latitude + dlat, @center.longitude + dlong
res << point
res
end
Array.new(number) { random_point_within }
end
end
end

0 comments on commit 94389dd

Please sign in to comment.