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.



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

#fromObject

Returns the value of attribute from.



79
80
81
# File 'lib/cartesian_for_geo.rb', line 79

def from
  @from
end

#pointsObject (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

#toObject

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

Returns:

  • (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

#splitObject



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