Module: PointVector::VectorOps

Included in:
PointVector
Defined in:
lib/geo_vectors/point_vector/vector_ops.rb

Instance Method Summary collapse

Instance Method Details

#add(*args) ⇒ Object Also known as: <<, +



11
12
13
# File 'lib/geo_vectors/point_vector/vector_ops.rb', line 11

def add *args
  self.dup.add! *args 
end

#add!(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/geo_vectors/point_vector/vector_ops.rb', line 17

def add! *args
  vector = GeoVector::Parser.create_vector *args
  case vector
  when PointVector
    v2 = add_to_point vector
    self.point = v2.to_a
    self      
  else
    GeoVectors.new self, vector
  end
end

#random_vectorObject



3
4
5
6
7
8
9
# File 'lib/geo_vectors/point_vector/vector_ops.rb', line 3

def random_vector                             
  lat_max = point.lat.abs
  lng_max = point.lng.abs    
  rand_lat = rand(lat_max * 2) - lat_max
  rand_lng = rand(lng_max * 2) - lng_max
  PointVector.new [rand_lat, rand_lng]
end

#sub(*args) ⇒ Object



29
30
31
# File 'lib/geo_vectors/point_vector/vector_ops.rb', line 29

def sub *args
  self.dup.sub! *args
end

#sub!(*args) ⇒ Object



33
34
35
36
# File 'lib/geo_vectors/point_vector/vector_ops.rb', line 33

def sub! *args
  vector = GeoVector::Parser.create_vector *args
  add! vector.reverse
end