Class: CartesianForGeo::Vector
- Inherits:
-
Object
- Object
- CartesianForGeo::Vector
- Defined in:
- lib/cartesian_for_geo.rb
Overview
Class for Vector (of two Points)
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#points ⇒ Object
(also: #to_a)
readonly
Returns the value of attribute points.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #crossing? ⇒ Boolean
-
#initialize(*points) ⇒ Vector
constructor
A new instance of Vector.
- #split ⇒ Object
Constructor Details
#initialize(*points) ⇒ Vector
Returns a new instance of Vector.
87 88 89 90 |
# File 'lib/cartesian_for_geo.rb', line 87 def initialize(*points) @points = points.flatten @from, @to = @points end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
79 80 81 |
# File 'lib/cartesian_for_geo.rb', line 79 def from @from end |
#points ⇒ Object (readonly) Also known as: to_a
Returns the value of attribute points.
80 81 82 |
# File 'lib/cartesian_for_geo.rb', line 80 def points @points end |
#to ⇒ Object
Returns the value of attribute to.
79 80 81 |
# File 'lib/cartesian_for_geo.rb', line 79 def to @to end |
Instance Method Details
#crossing? ⇒ Boolean
98 99 100 101 |
# File 'lib/cartesian_for_geo.rb', line 98 def crossing? delta = points.map(&:lng).reduce(:-).abs delta > 180 && delta < 360 end |
#split ⇒ Object
92 93 94 95 96 |
# File 'lib/cartesian_for_geo.rb', line 92 def split @split ||= [ [from, point_at_edge(from.side)], [point_at_edge(to.side), to] ].map(&Vector.method(:[])) end |