Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better vector functionality

  • Loading branch information...
commit 147b7539fe1bab04177450c9181addcfa0f3f3f2 1 parent 6356861
@kristianmandrup authored
View
15 lib/geo_magic/point.rb
@@ -57,15 +57,28 @@ def self.create_from *args
new latitude, longitude
end
- def move dlat, dlong
+ def move! dlat, dlong
@latitude += dlat
@longitude += dlong
+ self
+ end
+
+ def move dlat, dlong
+ cloned = self.dup
+ cloned.latitude += dlat
+ cloned.longitude += dlong
+ cloned
end
def move_vector vector
+ raise ArgumentError, "Argument must be a GeoMagic::Vector, was #{vector}" if !vector.kind_of? GeoMagic::Vector
move vector.lat_distance, vector.long_distance
end
+ def move_vector! vector
+ raise ArgumentError, "Argument must be a GeoMagic::Vector, was #{vector}" if !vector.kind_of? GeoMagic::Vector
+ move! vector.lat_distance, vector.long_distance
+ end
def to_point_hash mode= :long
case mode
View
12 lib/geo_magic/vector.rb
@@ -8,8 +8,8 @@ def initialize p0, p1
@p1 = p1
end
- def create_at center, vector
- new center, center.move(vector)
+ def self.create_at center, vector
+ new center, center.move_vector(vector)
end
def length type = nil
@@ -28,6 +28,14 @@ def length type = nil
d
end
+ def lat_distance
+ length(:latitude).in_radians
+ end
+
+ def long_distance
+ length(:longitude).in_radians
+ end
+
def vector_distance
GeoMagic::Distance::Vector.new length(:latitude), length(:longitude), :lat_factor => lat_factor
end
View
29 spec/geo_magic/vector_spec.rb
@@ -16,6 +16,15 @@
end
end
+ describe 'class methods' do
+ describe '#create_at' do
+ it "should create a vector from a point and another vector" do
+ v2 = GeoMagic::Vector.create_at @a, @vector
+ v2.should be_a(GeoMagic::Vector)
+ end
+ end
+ end
+
describe '#distance' do
it "is has a distance" do
@vector.distance.should be_a(GeoMagic::Distance)
@@ -23,6 +32,26 @@
end
end
+ describe '#lat_factor' do
+ it "is has a lat_factor of 2" do
+ @vector.lat_factor.should >= 2
+ end
+ end
+
+ describe '#length' do
+ describe ':latitude' do
+ it "is has a latitude length of ..." do
+ @vector.length(:latitude).in_km.should >= 0.5
+ end
+ end
+
+ describe ':longitude' do
+ it "is has a longitude length of ..." do
+ @vector.length(:longitude).in_km.should >= 0.5
+ end
+ end
+ end
+
describe '#vector_distance' do
it "is has a vector_distance" do
@vector.vector_distance.should be_a(GeoMagic::Distance::Vector)
Please sign in to comment.
Something went wrong with that request. Please try again.