Module: S2Cells::S2Base

Included in:
S2CellId
Defined in:
lib/s2_cells/s2_cell_base.rb

Constant Summary collapse

LINEAR_PROJECTION =
0
TAN_PROJECTION =
1
QUADRATIC_PROJECTION =
2
MAX_LEVEL =
30
NUM_FACES =
6
POS_BITS =
2 * MAX_LEVEL + 1
MAX_SIZE =
1 << MAX_LEVEL
SWAP_MASK =
0x01
INVERT_MASK =
0x02
LOOKUP_BITS =
4
POS_TO_OR =
[SWAP_MASK, 0, 0, INVERT_MASK | SWAP_MASK].freeze
POS_TO_IJ =
[[0, 1, 3, 2],
[0, 2, 3, 1],
[3, 2, 0, 1],
[3, 1, 0, 2]].freeze
LOOKUP_POS =
[nil] * (1 << (2 * LOOKUP_BITS + 2))
LOOKUP_IJ =
[nil] * (1 << (2 * LOOKUP_BITS + 2))

Class Method Summary collapse

Class Method Details

.lookup_bits(i, j, orig_orientation, pos, orientation) ⇒ Object



37
38
39
40
41
# File 'lib/s2_cells/s2_cell_base.rb', line 37

def self.lookup_bits(i, j, orig_orientation, pos, orientation)
  ij = (i << LOOKUP_BITS) + j
  LOOKUP_POS[(ij << 2) + orig_orientation] = (pos << 2) + orientation
  LOOKUP_IJ[(pos << 2) + orig_orientation] = (ij << 2) + orientation
end

.lookup_cells(level, i, j, orig_orientation, pos, orientation) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/s2_cells/s2_cell_base.rb', line 25

def self.lookup_cells(level, i, j, orig_orientation, pos, orientation)
  return lookup_bits(i, j, orig_orientation, pos, orientation) if level == LOOKUP_BITS

  r = POS_TO_IJ[orientation]
  4.times do |index|
    lookup_cells(
      level + 1, (i << 1) + (r[index] >> 1), (j << 1) + (r[index] & 1),
      orig_orientation, (pos << 2) + index, orientation ^ POS_TO_OR[index]
    )
  end
end