Class: GeoVectors
- Includes:
- Enumerable
- Defined in:
- lib/geo_vectors/geo_vectors.rb
Overview
Operations that apply on a collection of GeoVector
Instance Attribute Summary collapse
-
#vectors ⇒ Object
include GeoVector.
Instance Method Summary collapse
- #/(scalar) ⇒ Object (also: #reduce)
-
#add_to_point(point) ⇒ Object
return new point from adding vector to point.
-
#add_to_point!(point) ⇒ Object
add vector directly to point (destructive update).
-
#directions ⇒ Object
iterate each and call direction.
- #distances ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(*vectors) ⇒ GeoVectors
constructor
A new instance of GeoVectors.
- #reverse_directions ⇒ Object
- #scale(scalar) ⇒ Object (also: #*)
- #scale!(scalar) ⇒ Object
- #sub_from_point(point) ⇒ Object
- #sub_from_point!(point) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Array
Methods included from GeoVector::Macros
Constructor Details
#initialize(*vectors) ⇒ GeoVectors
Returns a new instance of GeoVectors.
7 8 9 |
# File 'lib/geo_vectors/geo_vectors.rb', line 7 def initialize *vectors self.vectors = vectors end |
Instance Attribute Details
#vectors ⇒ Object
include GeoVector
5 6 7 |
# File 'lib/geo_vectors/geo_vectors.rb', line 5 def vectors @vectors end |
Instance Method Details
#/(scalar) ⇒ Object Also known as: reduce
63 64 65 |
# File 'lib/geo_vectors/geo_vectors.rb', line 63 def / scalar scale (1.0 / scalar) end |
#add_to_point(point) ⇒ Object
return new point from adding vector to point
31 32 33 |
# File 'lib/geo_vectors/geo_vectors.rb', line 31 def add_to_point point add_to_point! point.dup end |
#add_to_point!(point) ⇒ Object
add vector directly to point (destructive update)
36 37 38 39 40 41 |
# File 'lib/geo_vectors/geo_vectors.rb', line 36 def add_to_point! point vectors.each do |v| point.add! v end point end |
#directions ⇒ Object
iterate each and call direction
18 19 20 |
# File 'lib/geo_vectors/geo_vectors.rb', line 18 def directions vectors.map {|v| v.direction } end |
#distances ⇒ Object
22 23 24 |
# File 'lib/geo_vectors/geo_vectors.rb', line 22 def distances vectors.map {|v| v.distance } end |
#each(&block) ⇒ Object
26 27 28 |
# File 'lib/geo_vectors/geo_vectors.rb', line 26 def each &block vectors.each { |v| yield v } end |
#reverse_directions ⇒ Object
69 70 71 72 73 74 |
# File 'lib/geo_vectors/geo_vectors.rb', line 69 def reverse_directions vectors.each do |v| v.reverse! end self end |
#scale(scalar) ⇒ Object Also known as: *
56 57 58 |
# File 'lib/geo_vectors/geo_vectors.rb', line 56 def scale scalar self.dup.scale! scalar end |
#scale!(scalar) ⇒ Object
51 52 53 54 |
# File 'lib/geo_vectors/geo_vectors.rb', line 51 def scale! scalar each {|v| v.scale! scalar } self end |
#sub_from_point(point) ⇒ Object
43 44 45 |
# File 'lib/geo_vectors/geo_vectors.rb', line 43 def sub_from_point point reverse_directions.add_to_point point end |
#sub_from_point!(point) ⇒ Object
47 48 49 |
# File 'lib/geo_vectors/geo_vectors.rb', line 47 def sub_from_point! point reverse_directions.add_to_point! point end |
#to_s ⇒ Object
76 77 78 79 80 81 |
# File 'lib/geo_vectors/geo_vectors.rb', line 76 def to_s vectors.inject([]) do |res, v| res << v.to_s res end.join(' ; ') end |