S2Cap

S2Cap represents a disc-shaped region defined by a center and radius. Technically this shape is called a "spherical cap" (rather than disc) because it is not planar; the cap represents a portion of the sphere that has been cut off by a plane. The boundary of the cap is the circle defined by the intersection of the sphere and the plane. For containment purposes, the cap is a closed set, i.e. it contains its boundary.

For the most part, you can use a spherical cap wherever you would use a disc in planar geometry. The radius of the cap is measured along the surface of the sphere (rather than the straight-line distance through the interior). Thus a cap of radius Pi/2 is a hemisphere, and a cap of radius Pi covers the entire sphere.

A cap can also be defined by its center point and height. The height is simply the distance from the center point to the cutoff plane. There is also support for "empty" and "full" caps, which contain no points and all points respectively.

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 returns an empty S2Cap.

this
this(S2Cap o)
Undocumented in source.
this
this(S2Point center, S1Angle radius)

Constructs a cap with the given center and radius. A negative radius yields an empty cap; a radius of 180 degrees or more yields a full cap (containing the entire sphere). "center" should be unit length.

this
this(S2Point center, S1ChordAngle radius)

Constructs a cap where the angle is expressed as an S1ChordAngle. This constructor is more efficient than the one above.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

addCap
void addCap(S2Cap other)

Increases the cap height if necessary to include "other". If the current cap is empty it is set to the given other cap.

addPoint
void addPoint(S2Point p)

Increase the cap height if necessary to include the given point. If the cap is empty then the center is set to the given point, but otherwise the center is not changed. "p" should be a unit-length vector.

approxEquals
bool approxEquals(S2Cap other, S1Angle max_error_angle)

Returns true if the cap center and height differ by at most "max_error" from the given cap "other".

clone
S2Cap clone()

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

complement
S2Cap complement()

Returns the complement of the interior of the cap. A cap and its complement have the same boundary but do not share any interior points. The complement operator is not a bijection because the complement of a singleton cap (containing a single point) is the same as the complement of an empty cap.

contains
bool contains(S2Cap other)

Returns true if and only if this cap contains the given other cap (in a set containment sense, e.g. every cap contains the empty cap).

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)

The point "p" should be a unit-length vector.

decode
bool decode(Decoder!IRangeT decoder)

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

encode
void encode(Encoder!ORangeT encoder)

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

expanded
S2Cap expanded(S1Angle distance)

Returns a cap that contains all points within a given distance of this cap. Note that any expansion of the empty cap is still empty.

getArea
double getArea()

Returns the area of the cap.

getCapBound
S2Cap getCapBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getCellUnionBound
void getCellUnionBound(S2CellId[] cell_ids)

Computes a covering of the S2Cap. In general the covering consists of at most 4 cells except for very large caps, which may need up to 6 cells. The output is not sorted.

getCentroid
S2Point getCentroid()

Returns the true centroid of the cap multiplied by its surface area (see s2centroids.h for details on centroids). The result lies on the ray from the origin through the cap's center, but it is not unit length. Note that if you just want the "surface centroid", i.e. the normalized result, then it is much simpler just to call center().

getRadius
S1Angle getRadius()

Returns the cap radius as an S1Angle. (Note that the cap angle is stored internally as an S1ChordAngle, so this method requires a trigonometric operation and may yield a slightly different result than the value passed to the (S2Point, S1Angle) constructor.)

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

Returns the height of the cap, i.e. the distance from the center point to the cutoff plane.

interiorContains
bool interiorContains(S2Point p)

Returns true if and only if the given point is contained in the interior of the cap (i.e. the cap excluding its boundary). "p" should be be a unit-length vector.

interiorIntersects
bool interiorIntersects(S2Cap other)

Returns true if and only if the interior of this cap intersects the given other cap. (This relationship is not symmetric, since only the interior of this cap is used.)

intersects
bool intersects(S2Cap other)

Returns true if and only if this cap intersects the given other cap, i.e. whether they have any points in common.

isEmpty
bool isEmpty()

Returns true if the cap is empty, i.e. it contains no points.

isFull
bool isFull()

Returns true if the cap is full, i.e. it contains all points.

isValid
bool isValid()

We allow negative heights (to represent empty caps) but heights are normalized so that they do not exceed 2.

mayIntersect
bool mayIntersect(S2Cell cell)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object o)

//////////////////////////////////////////////////////////////////// Returns true if two caps are identical.

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

Properties

center
S2Point center [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
radius
S1ChordAngle radius [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

empty
S2Cap empty()

Returns an empty cap, i.e. a cap that contains no points.

fromCenterArea
S2Cap fromCenterArea(S2Point center, double area)

Returns a cap with the given center and surface area. Note that the area can also be interpreted as the solid angle subtended by the cap (because the sphere has unit radius). A negative area yields an empty cap; an area of 4*Pi or more yields a full cap. "center" should be unit length.

fromCenterHeight
S2Cap fromCenterHeight(S2Point center, double height)

Returns a cap with the given center and height (see comments above). A negative height yields an empty cap; a height of 2 or more yields a full cap. "center" should be unit length.

fromPoint
S2Cap fromPoint(S2Point center)

Convenience function that creates a cap containing a single point. This method is more efficient that the S2Cap(center, radius) constructor.

full
S2Cap full()

Returns a full cap, i.e. a cap that contains all points.

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