Class: S2Cells::S2CellId
- Inherits:
-
Object
show all
- Includes:
- S2Base
- Defined in:
- lib/s2_cells/s2_cell_id.rb
Constant Summary
collapse
- SIGNED_CONST =
2**64
Constants included
from S2Base
S2Cells::S2Base::INVERT_MASK, S2Cells::S2Base::LINEAR_PROJECTION, S2Cells::S2Base::LOOKUP_BITS, S2Cells::S2Base::LOOKUP_IJ, S2Cells::S2Base::LOOKUP_POS, S2Cells::S2Base::MAX_LEVEL, S2Cells::S2Base::MAX_SIZE, S2Cells::S2Base::NUM_FACES, S2Cells::S2Base::POS_BITS, S2Cells::S2Base::POS_TO_IJ, S2Cells::S2Base::POS_TO_OR, S2Cells::S2Base::QUADRATIC_PROJECTION, S2Cells::S2Base::SWAP_MASK, S2Cells::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.
10
11
12
|
# File 'lib/s2_cells/s2_cell_id.rb', line 10
def initialize(id)
@id = id
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6
7
8
|
# File 'lib/s2_cells/s2_cell_id.rb', line 6
def id
@id
end
|
Class Method Details
.from_point(p) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/s2_cells/s2_cell_id.rb', line 55
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
#level ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/s2_cells/s2_cell_id.rb', line 34
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
|
#next ⇒ Object
30
31
32
|
# File 'lib/s2_cells/s2_cell_id.rb', line 30
def next
S2CellId.new(@id + (lsb << 1))
end
|
#parent(level) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/s2_cells/s2_cell_id.rb', line 18
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
|
#prev ⇒ Object
26
27
28
|
# File 'lib/s2_cells/s2_cell_id.rb', line 26
def prev
S2CellId.new(@id - (lsb << 1))
end
|
#signed_id ⇒ Object
14
15
16
|
# File 'lib/s2_cells/s2_cell_id.rb', line 14
def signed_id
@id - SIGNED_CONST
end
|