Class: CartesianForGeo::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/cartesian_for_geo.rb

Overview

Class for Vector (of two Points)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*points) ⇒ Vector

Returns a new instance of Vector.



98
99
100
101
# File 'lib/cartesian_for_geo.rb', line 98

def initialize(*points)
	@points = points.flatten
	@from, @to = @points
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



90
91
92
# File 'lib/cartesian_for_geo.rb', line 90

def from
  @from
end

#pointsObject (readonly) Also known as: to_a

Returns the value of attribute points.



91
92
93
# File 'lib/cartesian_for_geo.rb', line 91

def points
  @points
end

#toObject

Returns the value of attribute to.



90
91
92
# File 'lib/cartesian_for_geo.rb', line 90

def to
  @to
end

Instance Method Details

#crossing?Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/cartesian_for_geo.rb', line 109

def crossing?
	delta = points.map(&:lng).reduce(:-).abs
	delta > 180 && delta < 360
end

#splitObject



103
104
105
106
107
# File 'lib/cartesian_for_geo.rb', line 103

def split
	@split ||= [
		[from, point_at_edge(from.side)], [point_at_edge(to.side), to]
	].map(&Vector.method(:[]))
end