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

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]

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.

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

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

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

is_valid reports whether ci represents a valid cell.

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

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

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

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

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.

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

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

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

lsb returns the least significant bit that is set.

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.

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

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.

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

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

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

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

contains returns true iff the CellID contains oci.

intersects returns true iff the CellID intersects oci.

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

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.

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.

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.

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.

prev returns the previous cell along the Hilbert curve.

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.

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.

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.

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.

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

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

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

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.

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

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.

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

Important traits for Iter

Trait Implementations

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

Performs the conversion.

impl From<CellID> for Cell
[src]

Performs the conversion.

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

Performs the conversion.

impl From<Cell> for CellID
[src]

Performs the conversion.

impl Clone for CellID
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for CellID
[src]

impl PartialEq for CellID
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for CellID
[src]

impl PartialOrd for CellID
[src]

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for CellID
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl Hash for CellID
[src]

Feeds this value into the given [Hasher]. Read more

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

impl Debug for CellID
[src]

Formats the value using the given formatter. Read more

impl From<CellID> for Point
[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]

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]

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

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

Performs the conversion.

impl From<LatLng> for CellID
[src]

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

impl From<Point> for CellID
[src]

Performs the conversion.

Auto Trait Implementations

impl Send for CellID

impl Sync for CellID