S2Cell

An S2Cell is an S2Region object that represents a cell.

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

this
this()

The default constructor is required in order to use freelists. Cells should otherwise always be constructed explicitly.

this
this(S2CellId id)

An S2Cell always corresponds to a particular S2CellId. The other constructors are just convenience methods.

this
this(S2Cell cell)
Undocumented in source.
this
this(S2Point p)

Convenience constructors. The S2LatLng must be normalized.

this
this(S2LatLng ll)
Undocumented in source.

Members

Functions

approxArea
double 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
double 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
S2Region clone()

/////////////////////////////////////////////////////////////////////

contains
bool contains(S2Cell cell)
Undocumented in source. Be warned that the author may not have intended to support it.
contains
bool contains(S2Point 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
bool decode(Decoder!IRangeT decoder)

Decodes an S2Cell encoded with Encode(). Returns true on success.

encode
void encode(Encoder!ORangeT encoder)

Appends a serialized representation of the S2Cell to "encoder".

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

face
int face()
Undocumented in source. Be warned that the author may not have intended to support it.
getBoundUV
R2Rect getBoundUV()

Returns the bounds of this cell in (u,v)-space.

getBoundaryDistance
S1ChordAngle getBoundaryDistance(S2Point target)

Returns the distance from the cell boundary to the given point.

getCapBound
S2Cap getCapBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getCellUnionBound
void getCellUnionBound(S2CellId[] cellIds)
Undocumented in source. Be warned that the author may not have intended to support it.
getCenter
S2Point 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.

getCenterRaw
S2Point getCenterRaw()
Undocumented in source. Be warned that the author may not have intended to support it.
getDistance
S1ChordAngle getDistance(S2Point target)

Returns the distance from the cell to the given point. Returns zero if the point is inside the cell.

getDistance
S1ChordAngle getDistance(S2Point a, S2Point b)

Returns the minimum distance from the cell to the given edge AB. Returns zero if the edge intersects the cell interior.

getDistance
S1ChordAngle getDistance(S2Cell target)

Returns the distance from the cell to the given cell. Returns zero if one cell contains the other.

getEdge
S2Point getEdge(int 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].

getEdgeRaw
S2Point getEdgeRaw(int k)
Undocumented in source. Be warned that the author may not have intended to support it.
getMaxDistance
S1ChordAngle getMaxDistance(S2Point target)

Returns the maximum distance from the cell (including its interior) to the given point.

getMaxDistance
S1ChordAngle getMaxDistance(S2Point a, S2Point b)

Returns the maximum distance from the cell (including its interior) to the given edge AB.

getMaxDistance
S1ChordAngle getMaxDistance(S2Cell target)

Returns the maximum distance from the cell (including its interior) to the given target cell.

getRectBound
S2LatLngRect getRectBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getSizeIJ
int getSizeIJ()

These are equivalent to the S2CellId methods, but have a more efficient implementation since the level has been precomputed.

getSizeST
double getSizeST()
Undocumented in source. Be warned that the author may not have intended to support it.
getVertex
S2Point getVertex(int 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].

getVertexRaw
S2Point getVertexRaw(int k)
Undocumented in source. Be warned that the author may not have intended to support it.
id
S2CellId id()
Undocumented in source. Be warned that the author may not have intended to support it.
initFromS2CellId
void initFromS2CellId(S2CellId id)
Undocumented in source. Be warned that the author may not have intended to support it.
isLeaf
bool isLeaf()
Undocumented in source. Be warned that the author may not have intended to support it.
level
int level()
Undocumented in source. Be warned that the author may not have intended to support it.
mayIntersect
bool mayIntersect(S2Cell cell)
Undocumented in source. Be warned that the author may not have intended to support it.
opCmp
int opCmp(Object y)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object y)

/////////////////////////////////////////////////////////////////////

orientation
int orientation()
Undocumented in source. Be warned that the author may not have intended to support it.
subdivide
bool subdivide(S2Cell[4] children)

Divides the S2Cell into its four children.

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

averageArea
double averageArea(int level)

Returns the average area for cells at the given level.

fromFace
S2Cell fromFace(int face)

Returns the cell corresponding to the given S2 cube face.

fromFacePosLevel
S2Cell fromFacePosLevel(int face, ulong pos, int 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.

Inherited Members

From S2Region

clone
S2Region clone()

Returns a deep copy of the region.

getCapBound
S2Cap getCapBound()

Returns a bounding spherical cap that contains the region. The bound may not be tight.

getRectBound
S2LatLngRect getRectBound()

Returns a bounding latitude-longitude rectangle that contains the region. The bound may not be tight.

getCellUnionBound
void getCellUnionBound(S2CellId[] 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.

contains
bool contains(S2Cell cell)

Returns true if the region completely contains the given cell, otherwise returns false.

mayIntersect
bool mayIntersect(S2Cell 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.

contains
bool contains(S2Point 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.

Meta