Permalink
Browse files

more radius specs

  • Loading branch information...
kristianmandrup committed Feb 10, 2011
1 parent 42f6ff3 commit 43626d2b325cc0a5e7d1d5fa22a06c75612def68
View
@@ -17,7 +17,7 @@ def initialize *args
when 2
args
when 1
- to_point args
+ to_point args.first
else
raise ArgumentError, "Must be array of numbers or Hash of latitude, longitude"
end
@@ -14,6 +14,8 @@ def to_vector
def to_point
case self
+ when GeoMagic::Point
+ return [self.latitude, self.longitude]
when Hash
return [self[:lat], (self[:lng] || self[:long])] if self[:lat]
return [self[:latitude], self[:longitude]] if self[:latitude]
View
@@ -19,6 +19,10 @@ def create_#{name} center, distance
}
end
+ def center
+ GeoMagic::Point.new latitude, longitude
+ end
+
def double
multiply 2
end
@@ -27,7 +31,7 @@ def double!
multiply! 2
end
- def halve!
+ def halve
multiply 0.5
end
@@ -9,7 +9,8 @@ def initialize center, distance
end
def multiply arg
- self.clone.multiply! arg
+ circle = GeoMagic::CircularRadius.new center, distance.clone
+ circle.multiply! arg
end
def multiply! arg
@@ -4,31 +4,95 @@
let(:center) do
{:lat => 40, :long => 11}
end
+
let(:distance) { 3.2.km }
+ let(:center_point) do
+ GeoMagic::Point.new :lat => 40, :long => 11
+ end
+
+
describe '#new' do
+ it "should create a new circular radius from an array" do
+ circle = GeoMagic::CircularRadius.new [30, 10], distance
+ puts circle.inspect
+ end
+
it "should create a new circular radius" do
circle = GeoMagic::CircularRadius.new center, distance
puts circle.inspect
end
+
+ it "should create a new circular radius from a point" do
+ circle = GeoMagic::CircularRadius.new center_point, distance
+ puts circle.inspect
+ end
end
+
+ describe '#multiply!' do
+ let (:circle) do
+ GeoMagic::CircularRadius.new center, distance
+ end
+
+ it "should multiply the radius distance" do
+ circle.multiply!(5)
+ puts circle.inspect
+ end
+ end
+
+ describe '#multiply' do
+ let (:circle) do
+ GeoMagic::CircularRadius.new center, distance
+ end
+
+ it "should multiply the radius distance and return new circle" do
+ other_circle = circle.multiply(5)
+ other_circle.distance.should_not == circle.distance
+ puts circle.inspect
+ end
+ end
+
describe '#double' do
let (:circle) do
GeoMagic::CircularRadius.new center, distance
end
+ it "should double the radius distance and return new circle" do
+ other_circle = circle.double
+ other_circle.distance.should_not == circle.distance
+ puts circle.inspect
+ end
+ end
+
+ describe '#double!' do
+ let (:circle) do
+ GeoMagic::CircularRadius.new center, distance
+ end
+
it "should double the radius distance" do
circle.double!
puts circle.inspect
end
end
-
+
describe '#halve' do
let (:circle) do
GeoMagic::CircularRadius.new center, distance
end
+ it "should halve the radius distance and return new circle" do
+ other_circle = circle.halve
+ other_circle.distance.should_not == circle.distance
+ puts circle.inspect
+ end
+ end
+
+ describe '#halve!' do
+ let (:circle) do
+ GeoMagic::CircularRadius.new center, distance
+ end
+
it "should halve the radius distance" do
circle.halve!
puts circle.inspect

0 comments on commit 43626d2

Please sign in to comment.