class CartesianForGeo::Point

Class for one Point

Attributes

coords[R]
lat[RW]
lng[RW]
order[R]
to_a[R]

Public Class Methods

new(*coords) click to toggle source
# File lib/cartesian_for_geo.rb, line 38
def initialize(*coords)
        @coords = coords.flatten
        @lat, @lng = @coords
        @order = :lat_lng
end
parse(coords_text) click to toggle source
# File lib/cartesian_for_geo.rb, line 33
def parse(coords_text)
        new *coords_text.gsub(/[()\s]/, '').split(',').map(&:to_f)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/cartesian_for_geo.rb, line 80
def <=>(other)
        [
                to_a,
                other.to_a.public_send(order == other.order ? :itself : :reverse)
        ].map { |cord| cord.map { |f| f.round 9 } }.reduce(:<=>)
end
==(other) click to toggle source
Calls superclass method
# File lib/cartesian_for_geo.rb, line 76
def ==(other)
        super if other.is_a?(Point)
end
empty?() click to toggle source
# File lib/cartesian_for_geo.rb, line 48
def empty?
        (lat && lng).nil?
end
lat_lng!() click to toggle source
# File lib/cartesian_for_geo.rb, line 66
def lat_lng!
        @order = :lat_lng
        @coords = [@lat, @lng]
        self
end
lng_from_edge() click to toggle source
# File lib/cartesian_for_geo.rb, line 52
def lng_from_edge
        180 - lng.abs
end
lng_lat!() click to toggle source
# File lib/cartesian_for_geo.rb, line 60
def lng_lat!
        @order = :lng_lat
        @coords = [@lng, @lat]
        self
end
side() click to toggle source
# File lib/cartesian_for_geo.rb, line 44
def side
        lng.negative? ? -1 : 1
end
to_json(*) click to toggle source
# File lib/cartesian_for_geo.rb, line 72
def to_json(*)
        JSON.generate(lat: lat, lng: lng)
end
to_s() click to toggle source
# File lib/cartesian_for_geo.rb, line 56
def to_s
        empty? ? '' : "(#{coords.join(',')})"
end