Struct S2CellId

Source
#[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

Source

pub fn new(id: u64) -> Self

Construct a cell id from the given 64-bit integer.

Source

pub fn none() -> Self

Returns an empty cell id.

Source

pub fn sentinel() -> Self

Returns an invalid cell id guaranteed to be larger than any valid cell id. Useful for creating indexes.

Source

pub fn from_face(face: u8) -> S2CellId

Return the cell corresponding to a given S2 cube face.

Source

pub fn from_lon_lat(ll: &LonLat) -> S2CellId

Construct a leaf cell containing the given normalized S2LatLng.

Source

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).

Source

pub fn from_face_uv(face: u8, u: f64, v: f64) -> Self

Construct a leaf cell given its face and (u,v) coordinates.

Source

pub fn from_face_st(face: u8, s: f64, t: f64) -> Self

Construct a leaf cell given its face and (s,t) coordinates.

Source

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).

Source

pub fn from_distance(distance: u64, level: Option<u8>) -> S2CellId

Given a distance and optional zoom level, construct a cell ID at that distance

Source

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

Source

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)

Source

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)

Source

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).

Source

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().

Source

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.

Source

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.

Source

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.

Source

pub fn face(&self) -> u8

Which cube face this cell belongs to, in the range 0..5.

Source

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).

Source

pub fn level(&self) -> u8

Return the subdivision level of the cell (range 0..K_MAX_LEVEL).

Source

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).

Source

pub fn is_leaf(&self) -> bool

Return true if this is a leaf cell (more efficient than checking whether level() == K_MAX_LEVEL).

Source

pub fn to_point_raw(&self) -> S2Point

Convert an S2CellID to an S2Point

Source

pub fn to_point(&self) -> S2Point

Convert an S2CellID to an S2Point in normalized vector coordinates

Source

pub fn to_st(&self) -> (u8, f64, f64)

Convert an S2CellID to an Face-S-T coordinate Returns (face, s, t)

Source

pub fn to_uv(&self) -> (u8, f64, f64)

Convert an S2CellID to an Face-U-V coordinate Returns (face, u, v)

Source

pub fn is_face(&self) -> bool

Given an S2CellID, check if it is a Face Cell.

Source

pub fn distance(&self, lev: Option<u8>) -> f64

Given an S2CellID, get the distance it spans (or length it covers)

Source

pub fn children(&self, orientation: Option<u8>) -> [S2CellId; 4]

Given an S2CellID, get all the quad children tiles

Source

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

Source

pub fn parent(&self, level: Option<u8>) -> S2CellId

Given an S2CellID, get the parent quad tile

Source

pub fn range(&self) -> (Self, Self)

Given an S2CellID, get the hilbert range it spans returns (min, max)

Source

pub fn contains(&self, other: &S2CellId) -> bool

Check if the first S2CellID contains the second.

Source

pub fn intersects(&self, other: &S2CellId) -> bool

Check if an S2CellID intersects another. This includes edges touching.

Source

pub fn next(&self) -> S2CellId

Get the next S2CellID in the hilbert space

Source

pub fn prev(&self) -> S2CellId

Get the previous S2CellID in the hilbert space

Source

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)

Source

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)

Source

pub fn neighbors(&self) -> [S2CellId; 4]

Given an S2CellID, find the neighboring S2CellIDs returns neighbors: [up, right, down, left]

Source

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]

Source

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

Source

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

Source

pub fn vertex_neighbors(&self, level: Option<u8>) -> Vec<S2CellId>

Given an S2CellID, find it’s nearest neighbors associated with it

Source

pub fn low_bits(&self) -> u32

Return the low 32 bits of the cell id

Source

pub fn high_bits(&self) -> u32

Return the high 32 bits of the cell id

Trait Implementations§

Source§

impl Clone for S2CellId

Source§

fn clone(&self) -> S2CellId

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for S2CellId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&S2CellId> for LonLat

Source§

fn from(c: &S2CellId) -> Self

Converts to this type from the input type.
Source§

impl From<&S2CellId> for S2Point

Source§

fn from(cellid: &S2CellId) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for S2CellId

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<LonLat> for S2CellId

Source§

fn from(value: LonLat) -> Self

Converts to this type from the input type.
Source§

impl From<S2Point> for S2CellId

Source§

fn from(value: S2Point) -> Self

Converts to this type from the input type.
Source§

impl From<String> for S2CellId

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for S2CellId

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl Hash for S2CellId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for S2CellId

Source§

fn cmp(&self, other: &S2CellId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for S2CellId

Source§

fn eq(&self, other: &S2CellId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for S2CellId

Source§

fn partial_cmp(&self, other: &S2CellId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for S2CellId

Source§

impl Eq for S2CellId

Source§

impl StructuralPartialEq for S2CellId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.