#[repr(C)]pub struct S2CellId {
pub id: u64,
}
Expand description
An S2CellId is a 64-bit unsigned integer that uniquely identifies a cell in the S2 cell decomposition. It has the following format:
id = [face][face_pos]
face: a 3-bit number (range 0..5) encoding the cube face.
face_pos: a 61-bit number encoding the position of the center of this cell along the Hilbert curve over this face (see the Wiki pages for details).
Sequentially increasing cell ids follow a continuous space-filling curve over the entire sphere. They have the following properties:
-
The id of a cell at level k consists of a 3-bit face number followed by k bit pairs that recursively select one of the four children of each cell. The next bit is always 1, and all other bits are 0. Therefore, the level of a cell is determined by the position of its lowest-numbered bit that is turned on (for a cell at level k, this position is 2 * (K_MAX_LEVEL - k).)
-
The id of a parent cell is at the midpoint of the range of ids spanned by its children (or by its descendants at any level).
Leaf cells are often used to represent points on the unit sphere, and this class provides methods for converting directly between these two representations. For cells that represent 2D regions rather than discrete point, it is better to use the S2Cell class.
This class is intended to be copied by value as desired. It uses the default copy constructor and assignment operator.
Fields§
§id: u64
the id contains the face, s, and t components
Implementations§
Source§impl S2CellId
impl S2CellId
Sourcepub fn sentinel() -> Self
pub fn sentinel() -> Self
Returns an invalid cell id guaranteed to be larger than any valid cell id. Useful for creating indexes.
Sourcepub fn from_lon_lat(ll: &LonLat) -> S2CellId
pub fn from_lon_lat(ll: &LonLat) -> S2CellId
Construct a leaf cell containing the given normalized S2LatLng.
Sourcepub fn from_s2_point(p: &S2Point) -> Self
pub fn from_s2_point(p: &S2Point) -> Self
Construct a leaf cell containing the given point “p”. Usually there is exactly one such cell, but for points along the edge of a cell, any adjacent cell may be (deterministically) chosen. This is because S2CellIds are considered to be closed sets. The returned cell will always contain the given point, i.e.
S2Cell(S2CellId(p)).contains(p)
is always true. The point “p” does not need to be normalized.
If instead you want every point to be contained by exactly one S2Cell, you will need to convert the S2CellIds to S2Loops (which implement point containment this way).
Sourcepub fn from_face_uv(face: u8, u: f64, v: f64) -> Self
pub fn from_face_uv(face: u8, u: f64, v: f64) -> Self
Construct a leaf cell given its face and (u,v) coordinates.
Sourcepub fn from_face_st(face: u8, s: f64, t: f64) -> Self
pub fn from_face_st(face: u8, s: f64, t: f64) -> Self
Construct a leaf cell given its face and (s,t) coordinates.
Sourcepub fn from_face_ij(face: u8, i: u32, j: u32, level: Option<u8>) -> S2CellId
pub fn from_face_ij(face: u8, i: u32, j: u32, level: Option<u8>) -> S2CellId
Return a leaf cell given its cube face (range 0..5) and i- and j-coordinates (see s2coords.h).
Sourcepub fn from_distance(distance: u64, level: Option<u8>) -> S2CellId
pub fn from_distance(distance: u64, level: Option<u8>) -> S2CellId
Given a distance and optional zoom level, construct a cell ID at that distance
Sourcepub fn to_zoom_ij(&self, level: Option<u8>) -> (u8, u32, u32)
pub fn to_zoom_ij(&self, level: Option<u8>) -> (u8, u32, u32)
convert an id to a zoom-i-j after setting it to a new parent zoom
Sourcepub fn to_face_ij_orientation(&self, level: Option<u8>) -> (u8, u32, u32, u8)
pub fn to_face_ij_orientation(&self, level: Option<u8>) -> (u8, u32, u32, u8)
Return the (face, i, j) coordinates for the leaf cell corresponding to this cell id. Since cells are represented by the Hilbert curve position at the center of the cell, the returned (i,j) for non-leaf cells will be a leaf cell adjacent to the cell center. If “orientation” is non-nullptr, also return the Hilbert curve orientation for the current cell. Returns (face, i, j, orientation)
Sourcepub fn get_center_si_ti(&self) -> (u8, u32, u32)
pub fn get_center_si_ti(&self) -> (u8, u32, u32)
Return the (face, si, ti) coordinates of the center of the cell. Note that although (si,ti) coordinates span the range [0,231] in general, the cell center coordinates are always in the range [1,231-1] and therefore can be represented using a signed 32-bit integer. Returns (face, si, ti)
Sourcepub fn display_name(&self) -> String
pub fn display_name(&self) -> String
Creates a human readable debug string. Used for << and available for direct usage as well. The format is “f/dd..d” where “f” is a digit in the range [0-5] representing the S2CellId face, and “dd..d” is a string of digits in the range [0-3] representing each child’s position with respect to its parent. (Note that the latter string may be empty.)
For example “4/” represents S2CellId::from_face(4), and “3/02” represents S2CellId::from_face(3).child(0).child(2).
Sourcepub fn child_position(&self, level: u8) -> u8
pub fn child_position(&self, level: u8) -> u8
Return the child position (0..3) of this cell’s ancestor at the given level within its parent. For example, childPosition(1) returns the position of this cell’s level-1 ancestor within its top-level face cell. REQUIRES: 1 <= level <= this->level().
Sourcepub fn from_string(val: &str) -> S2CellId
pub fn from_string(val: &str) -> S2CellId
Converts a string in the format returned by ToString() to an S2CellId. Returns S2CellId.None() if the string could not be parsed.
The method name includes “Debug” in order to avoid possible confusion with FromToken() above.
Sourcepub fn lsb(&self) -> u64
pub fn lsb(&self) -> u64
Return the lowest-numbered bit that is on for this cell id, which is equal to (uint64{1} << (2 * (K_MAX_LEVEL - level))). So for example, a.lsb() <= b.lsb() if and only if a.level() >= b.level(), but the first test is more efficient.
Sourcepub fn child(&self, position: u8) -> S2CellId
pub fn child(&self, position: u8) -> S2CellId
Return the immediate child of this cell at the given traversal order position (in the range 0 to 3). This cell must not be a leaf cell.
Sourcepub fn pos(&self) -> u64
pub fn pos(&self) -> u64
The position of the cell center along the Hilbert curve over this face, in the range 0..(2**K_POS_BITS-1).
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Return true if id represents a valid cell.
All methods require isValid() to be true unless otherwise specified (although not all methods enforce this).
Sourcepub fn is_leaf(&self) -> bool
pub fn is_leaf(&self) -> bool
Return true if this is a leaf cell (more efficient than checking whether level() == K_MAX_LEVEL).
Sourcepub fn to_point_raw(&self) -> S2Point
pub fn to_point_raw(&self) -> S2Point
Convert an S2CellID to an S2Point
Sourcepub fn to_point(&self) -> S2Point
pub fn to_point(&self) -> S2Point
Convert an S2CellID to an S2Point in normalized vector coordinates
Sourcepub fn to_st(&self) -> (u8, f64, f64)
pub fn to_st(&self) -> (u8, f64, f64)
Convert an S2CellID to an Face-S-T coordinate Returns (face, s, t)
Sourcepub fn to_uv(&self) -> (u8, f64, f64)
pub fn to_uv(&self) -> (u8, f64, f64)
Convert an S2CellID to an Face-U-V coordinate Returns (face, u, v)
Sourcepub fn distance(&self, lev: Option<u8>) -> f64
pub fn distance(&self, lev: Option<u8>) -> f64
Given an S2CellID, get the distance it spans (or length it covers)
Sourcepub fn children(&self, orientation: Option<u8>) -> [S2CellId; 4]
pub fn children(&self, orientation: Option<u8>) -> [S2CellId; 4]
Given an S2CellID, get all the quad children tiles
Sourcepub fn children_ij(&self, face: u8, level: u8, i: u32, j: u32) -> [Self; 4]
pub fn children_ij(&self, face: u8, level: u8, i: u32, j: u32) -> [Self; 4]
Given an S2CellID, get the quad children tiles using a face-zoom-ij input
Sourcepub fn parent(&self, level: Option<u8>) -> S2CellId
pub fn parent(&self, level: Option<u8>) -> S2CellId
Given an S2CellID, get the parent quad tile
Sourcepub fn range(&self) -> (Self, Self)
pub fn range(&self) -> (Self, Self)
Given an S2CellID, get the hilbert range it spans returns (min, max)
Sourcepub fn contains(&self, other: &S2CellId) -> bool
pub fn contains(&self, other: &S2CellId) -> bool
Check if the first S2CellID contains the second.
Sourcepub fn intersects(&self, other: &S2CellId) -> bool
pub fn intersects(&self, other: &S2CellId) -> bool
Check if an S2CellID intersects another. This includes edges touching.
Sourcepub fn center_st(&self) -> (u8, f64, f64)
pub fn center_st(&self) -> (u8, f64, f64)
Given an S2CellID and level (zoom), get the center point of that cell in S-T space returns (face, s, t)
Sourcepub fn bounds_st(&self, level: Option<u8>) -> BBox
pub fn bounds_st(&self, level: Option<u8>) -> BBox
Given an S2CellID and level (zoom), get the S-T bounding range of that cell returns (s_min, t_min, s_max, t_max)
Sourcepub fn neighbors(&self) -> [S2CellId; 4]
pub fn neighbors(&self) -> [S2CellId; 4]
Given an S2CellID, find the neighboring S2CellIDs returns neighbors: [up, right, down, left]
Sourcepub fn neighbors_ij(&self, face: u8, i: u32, j: u32, level: u8) -> [S2CellId; 4]
pub fn neighbors_ij(&self, face: u8, i: u32, j: u32, level: u8) -> [S2CellId; 4]
Given a Face-I-J and a desired level (zoom), find the neighboring S2CellIDs return neighbors: [down, right, up, left]
Sourcepub fn from_ij_same(face: u8, i: u32, j: u32, same_face: bool) -> S2CellId
pub fn from_ij_same(face: u8, i: u32, j: u32, same_face: bool) -> S2CellId
Build an S2CellID given a Face-I-J, but ensure the face is the same if desired
Sourcepub fn from_face_ij_wrap(face: u8, i: u32, j: u32) -> S2CellId
pub fn from_face_ij_wrap(face: u8, i: u32, j: u32) -> S2CellId
Build an S2CellID given a Face-I-J, but ensure it’s a legal value, otherwise wrap before creation