class GeoTreeModule::Loc

Represents an x,y location. Each coordinate is stored internally as an integer, but may be referred to as a latitude and longitude as well.

Attributes

x[RW]
y[RW]

Public Class Methods

cvt_latlong_to_int(n) click to toggle source
# File lib/geotree/loc.rb, line 25
def self.cvt_latlong_to_int(n)
  m = (n / LAT_LONG_FACTOR_ + 0.5).to_i
  raise ArgumentError,"Converting lat/long #{n} is out of range" if m < LOC_MIN || m > LOC_MAX
  m
end
new(x = 0, y = 0) click to toggle source

Construct a point. If x is a Float, it assumes that x and y are longitude and latitude respectively, and converts them to integer values.

# File lib/geotree/loc.rb, line 36
def initialize(x = 0, y = 0)
  if x.is_a? Float
    x = Loc.cvt_latlong_to_int(x)
    y = Loc.cvt_latlong_to_int(y)
  end          
  @x = x
  @y = y
end

Public Instance Methods

flip() click to toggle source

Return a version of the point with the coordinates exchanged

# File lib/geotree/loc.rb, line 72
def flip
  Loc.new(@y,@x)
end
inspect() click to toggle source
# File lib/geotree/loc.rb, line 61
def inspect
  to_s
end
latit() click to toggle source

Get y as a latitudinal coordinate

# File lib/geotree/loc.rb, line 53
def latit
  @y * LAT_LONG_FACTOR_
end
longit() click to toggle source

Get x as a longitudinal coordinate

# File lib/geotree/loc.rb, line 47
def longit 
  @x * LAT_LONG_FACTOR_
end
set_to(src) click to toggle source
# File lib/geotree/loc.rb, line 65
def set_to(src)
  @x = src.x
  @y = src.y
end
to_s() click to toggle source
# File lib/geotree/loc.rb, line 57
def to_s
  "(#{x},#{y})"
end