Class: Poke::API::Geometry::S2CellId

Inherits:
Object
  • Object
show all
Includes:
S2Base
Defined in:
lib/poke-api/geometry/s2_cell_id.rb

Constant Summary

Constants included from S2Base

Poke::API::Geometry::S2Base::INVERT_MASK, Poke::API::Geometry::S2Base::LINEAR_PROJECTION, Poke::API::Geometry::S2Base::LOOKUP_BITS, Poke::API::Geometry::S2Base::LOOKUP_IJ, Poke::API::Geometry::S2Base::LOOKUP_POS, Poke::API::Geometry::S2Base::MAX_LEVEL, Poke::API::Geometry::S2Base::MAX_SIZE, Poke::API::Geometry::S2Base::NUM_FACES, Poke::API::Geometry::S2Base::POS_BITS, Poke::API::Geometry::S2Base::POS_TO_IJ, Poke::API::Geometry::S2Base::POS_TO_OR, Poke::API::Geometry::S2Base::QUADRATIC_PROJECTION, Poke::API::Geometry::S2Base::SWAP_MASK, Poke::API::Geometry::S2Base::TAN_PROJECTION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from S2Base

lookup_bits, lookup_cells

Constructor Details

#initialize(id) ⇒ S2CellId

Returns a new instance of S2CellId.



8
9
10
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 8

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 6

def id
  @id
end

Class Method Details

.from_point(p) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 49

def self.from_point(p)
  face, u, v = xyz_to_face_uv(p)
  i = st_to_ij(uv_to_st(u))
  j = st_to_ij(uv_to_st(v))

  S2CellId.new(from_face_ij(face, i, j))
end

Instance Method Details

#levelObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 28

def level
  return MAX_LEVEL if leaf?

  x = (@id & 0xffffffff)
  level = -1

  if x != 0
    level += 16
  else
    x = ((@id >> 32) & 0xffffffff)
  end

  x &= -x

  level += 8 unless (x & 0x00005555).zero?
  level += 4 unless (x & 0x00550055).zero?
  level += 2 unless (x & 0x05050505).zero?
  level += 1 unless (x & 0x11111111).zero?
  level
end

#nextObject



24
25
26
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 24

def next
  S2CellId.new(@id + (lsb << 1))
end

#parent(level) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 12

def parent(level)
  new_lsb = lsb_for_level(level)
  s2 = S2CellId.new((@id & -new_lsb) | new_lsb)

  raise Errors::InvalidLevel, level unless valid?(s2.id)
  s2
end

#prevObject



20
21
22
# File 'lib/poke-api/geometry/s2_cell_id.rb', line 20

def prev
  S2CellId.new(@id - (lsb << 1))
end