class CartesianForGeo::Vector

Class for Vector (of two Points)

Attributes

from[RW]
points[R]
to[RW]
to_a[R]

Public Class Methods

new(*points) click to toggle source
# File lib/cartesian_for_geo.rb, line 98
def initialize(*points)
        @points = points.flatten
        @from, @to = @points
end

Public Instance Methods

crossing?() click to toggle source
# File lib/cartesian_for_geo.rb, line 109
def crossing?
        delta = points.map(&:lng).reduce(:-).abs
        delta > 180 && delta < 360
end
split() click to toggle source
# 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

Private Instance Methods

lat_at_edge() click to toggle source
# File lib/cartesian_for_geo.rb, line 121
def lat_at_edge
        points_by_lat = points.sort_by!(&:lat).reverse!
        lng_dists = points_by_lat.map(&:lng_from_edge)
        lat_diff = points_by_lat.map(&:lat).reduce(:-)
        points_by_lat.first.lat -
                lat_diff * lng_dists.first / lng_dists.reduce(:+)
end
point_at_edge(side) click to toggle source
# File lib/cartesian_for_geo.rb, line 116
def point_at_edge(side)
        @lat_at_edge ||= lat_at_edge
        Point[@lat_at_edge, side * 180]
end