class Honua::Coordinate

Attributes

column[RW]
row[RW]
zoom[RW]

Public Class Methods

new(row, column, zoom = 0) click to toggle source
# File lib/honua/coordinate.rb, line 8
def initialize(row, column, zoom = 0)
  @row    = row
  @column = column
  @zoom   = zoom
end

Public Instance Methods

==(other) click to toggle source
# File lib/honua/coordinate.rb, line 53
def ==(other)
  row == other.row &&
    column == other.column &&
    zoom == other.zoom
end
container() click to toggle source

the top left most coordinate within the same tile used to identify the tile within the the tile rid

# File lib/honua/coordinate.rb, line 24
def container
  Coordinate.new(row.to_i, column.to_i, zoom)
end
down(distance = 1) click to toggle source
# File lib/honua/coordinate.rb, line 36
def down(distance = 1)
  Coordinate.new(row + distance, column, zoom)
end
left(distance = 1) click to toggle source
# File lib/honua/coordinate.rb, line 40
def left(distance = 1)
  Coordinate.new(row, column - distance, zoom)
end
right(distance = 1) click to toggle source
# File lib/honua/coordinate.rb, line 32
def right(distance = 1)
  Coordinate.new(row, column + distance, zoom)
end
to_location() click to toggle source
# File lib/honua/coordinate.rb, line 44
def to_location
  n = 2.0**zoom
  lon = column / n * 360.0 - 180
  lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * row / n)))
  lat = rad2deg(lat_rad)

  Location.new(lat, lon)
end
up(distance = 1) click to toggle source
# File lib/honua/coordinate.rb, line 28
def up(distance = 1)
  Coordinate.new(row - distance, column, zoom)
end
zoom_to(zoom_level) click to toggle source
# File lib/honua/coordinate.rb, line 14
def zoom_to(zoom_level)
  Coordinate.new(
    row * (2**(zoom_level - zoom)),
    column * (2**(zoom_level - zoom)),
    zoom_level
  )
end

Private Instance Methods

rad2deg(radians) click to toggle source

radians to degrees

# File lib/honua/coordinate.rb, line 62
def rad2deg(radians)
  radians * (180 / Math::PI)
end