Class S2Cell

An S2Cell is an S2Region object that represents a cell.

class S2Cell
  : S2Region ;

Unlike S2CellIds, it supports efficient containment and intersection tests. However, it is also a more expensive representation (currently 48 bytes rather than 8).

This class is intended to be copied by value as desired. It uses the default copy constructor and assignment operator, however it is not a "plain old datatype" (POD) because it has virtual functions.

Constructors

NameDescription
this () The default constructor is required in order to use freelists. Cells should otherwise always be constructed explicitly.
this (id) An S2Cell always corresponds to a particular S2CellId. The other constructors are just convenience methods.
this (p) Convenience constructors. The S2LatLng must be normalized.

Methods

NameDescription
approxArea () Returns the approximate area of this cell in steradians. This method is accurate to within 3% percent for all cell sizes and accurate to within 0.1% for cells at level 5 or higher (i.e. squares 350km to a side or smaller on the Earth's surface). It is moderately cheap to compute.
averageArea (level) Returns the average area for cells at the given level.
averageArea () Returns the average area of cells at this level in steradians. This is accurate to within a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to compute.
clone ()
contains (p) Returns true if the cell contains the given point "p". Note that unlike S2Loop/S2Polygon, S2Cells are considered to be closed sets. This means that points along an S2Cell edge (or at a vertex) belong to the adjacent cell(s) as well.
decode (decoder) Decodes an S2Cell encoded with Encode(). Returns true on success.
encode (encoder) Appends a serialized representation of the S2Cell to "encoder".
exactArea () Returns the area of this cell as accurately as possible. This method is more expensive but it is accurate to 6 digits of precision even for leaf cells (whose area is approximately 1e-18).
fromFace (face) Returns the cell corresponding to the given S2 cube face.
fromFacePosLevel (face, pos, level) Returns a cell given its face (range 0..5), Hilbert curve position within that face (an unsigned integer with S2CellId::kPosBits bits), and level (range 0..kMaxLevel). The given position will be modified to correspond to the Hilbert curve position at the center of the returned cell. This is a static function rather than a constructor in order to indicate what the arguments represent.
getBoundaryDistance (target) Returns the distance from the cell boundary to the given point.
getBoundUV () Returns the bounds of this cell in (u,v)-space.
getCenter () Returns the direction vector corresponding to the center in (s,t)-space of the given cell. This is the point at which the cell is divided into four subcells; it is not necessarily the centroid of the cell in (u,v)-space or (x,y,z)-space. The point returned by GetCenterRaw is not necessarily unit length.
getDistance (target) Returns the distance from the cell to the given point. Returns zero if the point is inside the cell.
getDistance (a, b) Returns the minimum distance from the cell to the given edge AB. Returns zero if the edge intersects the cell interior.
getDistance (target) Returns the distance from the cell to the given cell. Returns zero if one cell contains the other.
getEdge (k) Returns the inward-facing normal of the great circle passing through the edge from vertex k to vertex k+1 (mod 4). The normals returned by GetEdgeRaw are not necessarily unit length. For convenience, the argument is reduced modulo 4 to the range [0..3].
getMaxDistance (target) Returns the maximum distance from the cell (including its interior) to the given point.
getMaxDistance (a, b) Returns the maximum distance from the cell (including its interior) to the given edge AB.
getMaxDistance (target) Returns the maximum distance from the cell (including its interior) to the given target cell.
getSizeIJ () These are equivalent to the S2CellId methods, but have a more efficient implementation since the level has been precomputed.
getVertex (k) Returns the k-th vertex of the cell (k = 0,1,2,3). Vertices are returned in CCW order (lower left, lower right, upper right, upper left in the UV plane). The points returned by GetVertexRaw are not normalized. For convenience, the argument is reduced modulo 4 to the range [0..3].
opEquals (y)
subdivide (children) Divides the S2Cell into its four children.
clone () Returns a deep copy of the region.
contains (p) Returns true if and only if the given point is contained by the region. The point 'p' is generally required to be unit length, although some subtypes may relax this restriction.
contains (cell) Returns true if the region completely contains the given cell, otherwise returns false.
getCapBound () Returns a bounding spherical cap that contains the region. The bound may not be tight.
getCellUnionBound (cellIds) Returns a small collection of S2CellIds whose union covers the region. The cells are not sorted, may have redundancies (such as cells that contain other cells), and may cover much more area than necessary.
getRectBound () Returns a bounding latitude-longitude rectangle that contains the region. The bound may not be tight.
mayIntersect (cell) If this method returns false, the region does not intersect the given cell. Otherwise, either region intersects the cell, or the intersection relationship could not be determined.