X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ef7f3d800cbdd49b692df10d312e5fd880e2e938..4e64291839d45a0c660fc84f11a6c4c811cf8f21:/lib/short_link.rb diff --git a/lib/short_link.rb b/lib/short_link.rb index 0d8f21cad..ddf37b67a 100644 --- a/lib/short_link.rb +++ b/lib/short_link.rb @@ -8,7 +8,7 @@ module ShortLink # array of 64 chars to encode 6 bits. this is almost like base64 encoding, but # the symbolic chars are different, as base64's + and / aren't very # URL-friendly. - ARRAY = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['_', '~'] + ARRAY = ("A".."Z").to_a + ("a".."z").to_a + ("0".."9").to_a + ["_", "~"] ## # Given a string encoding a location, returns the [lon, lat, z] tuple of that @@ -30,8 +30,13 @@ module ShortLink z_offset -= 1 else 3.times do - x <<= 1; x |= 1 unless (t & 32).zero?; t <<= 1 - y <<= 1; y |= 1 unless (t & 32).zero?; t <<= 1 + x <<= 1 + x |= 1 unless (t & 32).zero? + t <<= 1 + + y <<= 1 + y |= 1 unless (t & 32).zero? + t <<= 1 end z += 3 end @@ -50,7 +55,7 @@ module ShortLink # given a location and zoom, return a short string representing it. def self.encode(lon, lat, z) code = interleave_bits(((lon + 180.0) * 2**32 / 360.0).to_i, - ((lat + 90.0) * 2**32 / 180.0).to_i) + ((lat + 90.0) * 2**32 / 180.0).to_i) str = "" # add eight to the zoom level, which approximates an accuracy of # one pixel in a tile.