class Tsuga::Model::Tile
Constants
- WIGGLE_FACTOR
Attributes
depth[R]
level in the tile tree, also number of relevant high bits in the geohash.
northeast[R]
corner points
prefix[R]
geohash prefix
southwest[R]
corner points
Private Class Methods
new(prefix:nil)
click to toggle source
# File lib/tsuga/model/tile.rb, line 18 def initialize(prefix:nil) raise ArgumentError, 'bad prefix' if prefix !~ /^[0-3]{1,32}$/ @prefix = prefix @depth = prefix.length @southwest = Point.new(geohash: prefix.ljust(32, '0')) @northeast = Point.new(geohash: prefix.ljust(32, '3')) end
Private Instance Methods
children()
click to toggle source
return the 4 children of this tile
# File lib/tsuga/model/tile.rb, line 39 def children %w(0 1 2 3).map { |quadrant| self.class.new(prefix: @prefix + quadrant) } end
contains?(point)
click to toggle source
# File lib/tsuga/model/tile.rb, line 26 def contains?(point) point.geohash.start_with?(@prefix) end
dlat(count = 1)
click to toggle source
# File lib/tsuga/model/tile.rb, line 30 def dlat(count = 1) (northeast.lat - southwest.lat) * (count + WIGGLE_FACTOR) end
dlng(count = 1)
click to toggle source
# File lib/tsuga/model/tile.rb, line 34 def dlng(count = 1) (northeast.lng - southwest.lng) * (count + WIGGLE_FACTOR) end
inspect()
click to toggle source
# File lib/tsuga/model/tile.rb, line 66 def inspect "<%s depth:%d prefix:%s>" % [ (self.class.name || 'Tile'), depth, prefix ] end
neighbour(lat:0, lng:0)
click to toggle source
return a neighouring tile offset in tile increments TODO: this could be implemented using bit logic
# File lib/tsuga/model/tile.rb, line 47 def neighbour(lat:0, lng:0) new_point = Point.new( lat: southwest.lat + dlat(lat), lng: southwest.lng + dlng(lng)) Tile.including(new_point, depth: depth) end
neighbours()
click to toggle source
return neighbouring tiles to the north, northeast, and east
# File lib/tsuga/model/tile.rb, line 55 def neighbours offsets = (-1..1).to_a.product((-1..1).to_a) offsets.map do |lat, lng| begin neighbour(lat:lat, lng:lng) rescue ArgumentError nil # occurs on world boundaries end end.compact end