[][src]Struct s2::cellid::CellID

pub struct CellID(pub u64);

CellID uniquely identifies a cell in the S2 cell decomposition. The most significant 3 bits encode the face number (0-5). The remaining 61 bits encode the position of the center of this cell along the Hilbert curve on that face. The zero value and the value (1<<64)-1 are invalid cell IDs. The first compares less than any valid cell ID, the second as greater than any valid cell ID.

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 * (maxLevel - 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 type provides methods for converting directly between these two representations. For cells that represent 2D regions rather than discrete point, it is better to use Cells.

Methods

impl CellID[src]

pub fn from_face_pos_level(face: u64, pos: u64, level: u64) -> Self[src]

from_pos_level returns a cell given its face in the range [0,5], the 61-bit Hilbert curve position pos within that face, and the level in the range [0,maxLevel]. The position in the cell ID will be truncated to correspond to the Hilbert curve position at the center of the returned cell.

pub fn from_face(face: u64) -> Self[src]

from_face returns the cell corresponding to a given S2 cube face.

pub fn from_face_ij(f: u8, i: i32, j: i32) -> Self[src]

pub fn from_token(s: &str) -> CellID[src]

from_token returns a cell given a hex-encoded string of its uint64 ID.

pub fn to_token(&self) -> String[src]

to_token returns a hex-encoded string of the uint64 cell id, with leading zeros included but trailing zeros stripped.

pub fn is_valid(&self) -> bool[src]

is_valid reports whether ci represents a valid cell.

pub fn face(&self) -> u8[src]

face returns the cube face for this cell ID, in the range [0,5].

pub fn pos(&self) -> u64[src]

pos returns the position along the Hilbert curve of this cell ID, in the range [0,2^posBits-1].

pub fn level(&self) -> u64[src]

level returns the subdivision level of this cell ID, in the range [0, maxLevel].

pub fn is_leaf(&self) -> bool[src]

is_leaf returns whether this cell ID is at the deepest level; that is, the level at which the cells are smallest.

pub fn child_position(&self, level: u64) -> u64[src]

child_position returns the child position (0..3) of this cell's ancestor at the given level, relative to its parent. The argument should be in the range 1..kMaxLevel. For example, ChildPosition(1) returns the position of this cell's level-1 ancestor within its top-level face cell.

pub fn parent(&self, level: u64) -> Self[src]

parent returns the cell at the given level, which must be no greater than the current level.

pub fn immediate_parent(&self) -> Self[src]

immediate_parent is cheaper than Parent, but assumes !ci.isFace().

pub fn is_face(&self) -> bool[src]

is_face returns whether this is a top-level (face) cell.

pub fn lsb(&self) -> u64[src]

lsb returns the least significant bit that is set.

pub fn children(&self) -> [CellID; 4][src]

children returns the four immediate children of this cell. If ci is a leaf cell, it returns four identical cells that are not the children.

pub fn face_ij_orientation(&self) -> (u8, i32, i32, u8)[src]

face_ij_orientation uses the global lookupIJ table to unfiddle the bits of ci.

pub fn edge_neighbors(&self) -> [CellID; 4][src]

edge_neighbors returns the four cells that are adjacent across the cell's four edges. Edges 0, 1, 2, 3 are in the down, right, up, left directions in the face space. All neighbors are guaranteed to be distinct.

pub fn vertex_neighbors(&self, level: u64) -> Vec<CellID>[src]

vertex_neighbors returns the neighboring cellIDs with vertex closest to this cell at the given level. (Normally there are four neighbors, but the closest vertex may only have three neighbors if it is one of the 8 cube vertices.)

pub fn all_neighbors(&self, level: u64) -> Vec<CellID>[src]

all_neighbors returns all neighbors of this cell at the given level. Two cells X and Y are neighbors if their boundaries intersect but their interiors do not. In particular, two cells that intersect at a single point are neighbors. Note that for cells adjacent to a face vertex, the same neighbor may be returned more than once. There could be up to eight neighbors including the diagonal ones that share the vertex.

This requires level >= ci.Level().

pub fn range_min(&self) -> Self[src]

range_min returns the minimum CellID that is contained within this cell.

pub fn range_max(&self) -> Self[src]

range_max returns the maximum CellID that is contained within this cell.

pub fn contains(&self, other: &CellID) -> bool[src]

contains returns true iff the CellID contains oci.

pub fn intersects(&self, other: &CellID) -> bool[src]

intersects returns true iff the CellID intersects oci.

pub fn raw_point(&self) -> Vector[src]

pub fn child_begin(&self) -> Self[src]

child_begin returns the first child in a traversal of the children of this cell, in Hilbert curve order.

pub fn child_begin_at_level(&self, level: u64) -> Self[src]

child_begin_at_level returns the first cell in a traversal of children a given level deeper than this cell, in Hilbert curve order. The given level must be no smaller than the cell's level. See ChildBegin for example use.

pub fn child_end(&self) -> Self[src]

child_end returns the first cell after a traversal of the children of this cell in Hilbert curve order. The returned cell may be invalid.

pub fn child_end_at_level(&self, level: u64) -> Self[src]

child_end_at_level returns the first cell after the last child in a traversal of children a given level deeper than this cell, in Hilbert curve order. The given level must be no smaller than the cell's level. The returned cell may be invalid.

pub fn next(&self) -> Self[src]

next returns the next cell along the Hilbert curve. This is expected to be used with child_begin and child_end, or child_begin_at_level and child_end_at_level.

pub fn prev(&self) -> Self[src]

prev returns the previous cell along the Hilbert curve.

pub fn next_wrap(&self) -> Self[src]

next_wrap returns the next cell along the Hilbert curve, wrapping from last to first as necessary. This should not be used with ChildBegin and ChildEnd.

pub fn prev_wrap(&self) -> Self[src]

prev_wrap returns the previous cell along the Hilbert curve, wrapping around from first to last as necessary. This should not be used with ChildBegin and ChildEnd.

pub fn advance_wrap(&self, steps: i64) -> Self[src]

advance_wrap advances or retreats the indicated number of steps along the Hilbert curve at the current level and returns the new position. The position wraps between the first and last faces as necessary.

pub fn distance_from_begin(&self) -> i64[src]

distance_from_begin returns the number of steps that this cell is from the first node in the S2 heirarchy at our level. (i.e., FromFace(0).ChildBeginAtLevel(ci.Level())). The return value is always non-negative.

pub fn common_ancestor_level(&self, other: &Self) -> Option<u64>[src]

common_ancestor_level returns the level of the common ancestor of the two S2 CellIDs.

pub fn advance(&self, steps: i64) -> Self[src]

advance advances or retreats the indicated number of steps along the Hilbert curve at the current level, and returns the new position. The position is never advanced past End() or before Begin().

pub fn bound_st(&self) -> Rect[src]

bound_st returns the bound of this CellID in (s,t)-space.

pub fn center_uv(&self) -> Point[src]

center_uv returns the center of this CellID in (u,v)-space. Note that the center of the cell is defined as the point at which it is recursively subdivided into four children; in general, it is not at the midpoint of the (u,v) rectangle covered by the cell.

pub fn bound_uv(&self) -> Rect[src]

bound_uv returns the bound of this CellID in (u,v)-space.

pub fn max_tile(&self, limit: &Self) -> Self[src]

max_tile returns the largest cell with the same range_min such that range_max < limit.range_min. It returns limit if no such cell exists. This method can be used to generate a small set of CellIDs that covers a given range (a tiling). This example shows how to generate a tiling for a semi-open range of leaf cells [start, limit):

for id := start.MaxTile(limit); id != limit; id = id.Next().MaxTile(limit)) { ... }

Note that in general the cells in the tiling will be of different sizes; they gradually get larger (near the middle of the range) and then gradually get smaller as limit is approached.

pub fn center_face_siti(&self) -> (u8, i32, i32)[src]

center_face_siti returns 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.

impl CellID[src]

Important traits for Iter
pub fn child_iter(&self) -> Iter[src]

Important traits for Iter
pub fn child_iter_at_level(&self, level: u64) -> Iter[src]

Trait Implementations

impl Ord for CellID[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl Clone for CellID[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Eq for CellID[src]

impl<'a> From<&'a CellID> for Cell[src]

impl From<CellID> for Cell[src]

impl<'a> From<&'a Cell> for CellID[src]

impl From<Cell> for CellID[src]

impl From<CellID> for Point[src]

fn from(id: CellID) -> Self[src]

returns the center of the s2 cell on the sphere as a Point. The maximum directional error in Point (compared to the exact mathematical result) is 1.5 * dblEpsilon radians, and the maximum length error is 2 * dblEpsilon (the same as Normalize).

impl<'a> From<&'a CellID> for Point[src]

fn from(id: &'a CellID) -> Self[src]

cellIDFromPoint returns a leaf cell containing 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 s2.CellIDs are considered to be closed sets. The returned cell will always contain the given point, i.e.

Cell::from(&p).contains_point(&p)

is always true.

impl From<CellID> for LatLng[src]

fn from(id: CellID) -> Self[src]

returns the center of the s2 cell on the sphere as a LatLng.

impl<'a> From<&'a CellID> for LatLng[src]

impl From<LatLng> for CellID[src]

impl<'a> From<&'a LatLng> for CellID[src]

impl<'a> From<&'a Point> for CellID[src]

impl From<Point> for CellID[src]

impl Copy for CellID[src]

impl PartialEq<CellID> for CellID[src]

impl PartialOrd<CellID> for CellID[src]

impl Hash for CellID[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for CellID[src]

Auto Trait Implementations

impl Sync for CellID

impl Unpin for CellID

impl Send for CellID

impl RefUnwindSafe for CellID

impl UnwindSafe for CellID

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]