Class: GeoDelta::Packer32

Inherits:
Object
  • Object
show all
Defined in:
lib/geodelta/packer32.rb

Instance Method Summary collapse

Instance Method Details

#pack(ids) ⇒ Object



29
30
31
32
33
34
# File 'lib/geodelta/packer32.rb', line 29

def pack(ids)
  wid   = self.pack_world_delta(ids[0])
  sids  = ids[1..-1].each_with_index.map { |id, i| self.pack_sub_delta(i + 2, id) }.inject(0, &:+)
  level = self.pack_level(ids.size)
  return wid + sids + level
end

#pack_level(level) ⇒ Object



21
22
23
# File 'lib/geodelta/packer32.rb', line 21

def pack_level(level)
  return level
end

#pack_sub_delta(level, id) ⇒ Object



13
14
15
# File 'lib/geodelta/packer32.rb', line 13

def pack_sub_delta(level, id)
  return id << (26 - ((level - 2) * 2))
end

#pack_world_delta(id) ⇒ Object



5
6
7
# File 'lib/geodelta/packer32.rb', line 5

def pack_world_delta(id)
  return id << 28
end

#unpack(value) ⇒ Object



36
37
38
39
40
41
# File 'lib/geodelta/packer32.rb', line 36

def unpack(value)
  level = self.unpack_level(value)
  wid   = self.unpack_world_delta(value)
  sids  = (level - 1).times.map { |i| self.unpack_sub_delta(i + 2, value) }
  return [wid] + sids
end

#unpack_level(value) ⇒ Object



25
26
27
# File 'lib/geodelta/packer32.rb', line 25

def unpack_level(value)
  return value & 0b1111
end

#unpack_sub_delta(level, value) ⇒ Object



17
18
19
# File 'lib/geodelta/packer32.rb', line 17

def unpack_sub_delta(level, value)
  return (value >> (26 - ((level - 2) * 2))) & 0b11
end

#unpack_world_delta(value) ⇒ Object



9
10
11
# File 'lib/geodelta/packer32.rb', line 9

def unpack_world_delta(value)
  return (value >> 28) & 0b111
end