S2LatLngRect

An S2LatLngRect represents a closed latitude-longitude rectangle. It is capable of representing the empty and full rectangles as well as single points. Note that the latitude-longitude space is considered to have a *cylindrical* topology rather than a spherical one, i.e. the poles have multiple lat/lng representations. An S2LatLngRect may be defined so that includes some representations of a pole but not others. Use the PolarClosure() method if you want to expand a rectangle so that it contains all possible representations of any contained poles.

Because S2LatLngRect uses S1Interval to store the longitude range, longitudes of -180 degrees are treated specially. Except for empty and full longitude spans, -180 degree longitudes will turn into +180 degrees. This sign flip causes lng_lo() to be greater than lng_hi(), indicating that the rectangle will wrap around through -180 instead of through +179. Thus the math is consistent within the library, but the sign flip can be surprising, especially when working with map projections where -180 and +180 are at opposite ends of the flattened map. See the comments on S1Interval for more details.

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.

class S2LatLngRect : S2Region {}

Constructors

this
this(S2LatLng lo, S2LatLng hi)
Undocumented in source.
this
this(R1Interval lat, S1Interval lng)
Undocumented in source.
this
this(S2LatLngRect rect)
Undocumented in source.
this
this()
Undocumented in source.

Members

Functions

addPoint
void addPoint(S2Point p)

Increase the size of the bounding rectangle to include the given point. The rectangle is expanded by the minimum amount possible. The S2LatLng argument must be normalized.

addPoint
void addPoint(S2LatLng ll)
Undocumented in source. Be warned that the author may not have intended to support it.
approxEquals
bool approxEquals(S2LatLngRect other, S1Angle max_error)
Undocumented in source. Be warned that the author may not have intended to support it.
approxEquals
bool approxEquals(S2LatLngRect other, S2LatLng max_error)
Undocumented in source. Be warned that the author may not have intended to support it.
area
double area()
Undocumented in source. Be warned that the author may not have intended to support it.
boundaryIntersects
bool boundaryIntersects(S2Point v0, S2Point v1)
Undocumented in source. Be warned that the author may not have intended to support it.
clone
S2LatLngRect clone()

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

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

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

encode
void encode(Encoder!ORangeT encoder)

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

expanded
S2LatLngRect expanded(S2LatLng margin)

Returns a rectangle that has been expanded by margin.lat() on each side in the latitude direction, and by margin.lng() on each side in the longitude direction. If either margin is negative, then shrinks the rectangle on the corresponding sides instead. The resulting rectangle may be empty.

expandedByDistance
S2LatLngRect expandedByDistance(S1Angle distance)

Expands this rectangle so that it contains all points within the given distance of the boundary, and return the smallest such rectangle. If the distance is negative, then instead shrinks this rectangle so that it excludes all points within the given absolute distance of the boundary, and returns the largest such rectangle.

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
S2LatLng getCenter()
Undocumented in source. Be warned that the author may not have intended to support it.
getCentroid
S2Point getCentroid()

Returns the true centroid of the rectangle multiplied by its surface area (see s2centroids.h for details on centroids). The result is not unit length, so you may want to normalize it. Note that in general the centroid is *not* at the center of the rectangle, and in fact it may not even be contained by the rectangle. (It is the "center of mass" of the rectangle viewed as subset of the unit sphere, i.e. it is the point in space about which this curved shape would rotate.)

getDirectedHausdorffDistance
S1Angle getDirectedHausdorffDistance(S2LatLngRect other)
Undocumented in source. Be warned that the author may not have intended to support it.
getDistance
S1Angle getDistance(S2LatLngRect other)
Undocumented in source.
getDistance
S1Angle getDistance(S2LatLng p)
Undocumented in source. Be warned that the author may not have intended to support it.
getHausdorffDistance
S1Angle getHausdorffDistance(S2LatLngRect other)
Undocumented in source. Be warned that the author may not have intended to support it.
getRectBound
S2LatLngRect getRectBound()
Undocumented in source. Be warned that the author may not have intended to support it.
getSize
S2LatLng getSize()
Undocumented in source. Be warned that the author may not have intended to support it.
getVertex
S2LatLng getVertex(int k)
Undocumented in source. Be warned that the author may not have intended to support it.
hi
S2LatLng hi()
Undocumented in source. Be warned that the author may not have intended to support it.
interiorContains
bool interiorContains(S2Point p)
Undocumented in source. Be warned that the author may not have intended to support it.
interiorContains
bool interiorContains(S2LatLng ll)
Undocumented in source. Be warned that the author may not have intended to support it.
interiorContains
bool interiorContains(S2LatLngRect other)
Undocumented in source. Be warned that the author may not have intended to support it.
interiorIntersects
bool interiorIntersects(S2LatLngRect other)
Undocumented in source. Be warned that the author may not have intended to support it.
intersection
S2LatLngRect intersection(S2LatLngRect other)

Returns the smallest rectangle containing the intersection of this rectangle and the given rectangle. Note that the region of intersection may consist of two disjoint rectangles, in which case a single rectangle spanning both of them is returned.

intersects
bool intersects(S2LatLngRect other)
Undocumented in source. Be warned that the author may not have intended to support it.
intersects
bool intersects(S2Cell cell)
Undocumented in source. Be warned that the author may not have intended to support it.
isEmpty
bool isEmpty()
Undocumented in source. Be warned that the author may not have intended to support it.
isFull
bool isFull()
Undocumented in source. Be warned that the author may not have intended to support it.
isInverted
bool isInverted()
Undocumented in source. Be warned that the author may not have intended to support it.
isPoint
bool isPoint()
Undocumented in source. Be warned that the author may not have intended to support it.
isValid
bool isValid()
Undocumented in source. Be warned that the author may not have intended to support it.
lo
S2LatLng lo()
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.
mutableLat
R1Interval mutableLat()
Undocumented in source. Be warned that the author may not have intended to support it.
mutableLng
S1Interval mutableLng()
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Object o)
Undocumented in source. Be warned that the author may not have intended to support it.
polarClosure
S2LatLngRect polarClosure()

If the rectangle does not include either pole, returns it unmodified. Otherwise expands the longitude range to Full() so that the rectangle contains all possible representations of the contained pole(s).

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

Returns the smallest rectangle containing the union of this rectangle and the given rectangle.

Properties

lat
R1Interval lat [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
latHi
S1Angle latHi [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
latLo
S1Angle latLo [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
lng
S1Interval lng [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
lngHi
S1Angle lngHi [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
lngLo
S1Angle lngLo [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

empty
S2LatLngRect empty()
Undocumented in source. Be warned that the author may not have intended to support it.
fromCenterSize
S2LatLngRect fromCenterSize(S2LatLng center, S2LatLng size)
Undocumented in source. Be warned that the author may not have intended to support it.
fromPoint
S2LatLngRect fromPoint(S2LatLng p)
Undocumented in source. Be warned that the author may not have intended to support it.
fromPointPair
S2LatLngRect fromPointPair(S2LatLng p1, S2LatLng p2)
Undocumented in source. Be warned that the author may not have intended to support it.
full
S2LatLngRect full()
Undocumented in source. Be warned that the author may not have intended to support it.
fullLat
R1Interval fullLat()
Undocumented in source. Be warned that the author may not have intended to support it.
fullLng
S1Interval fullLng()
Undocumented in source. Be warned that the author may not have intended to support it.
intersectsLatEdge
bool intersectsLatEdge(S2Point a, S2Point b, double lat, S1Interval lng)

Returns true if the edge AB intersects the given edge of constant latitude. Requires the vectors to have unit length.

intersectsLngEdge
bool intersectsLngEdge(S2Point a, S2Point b, R1Interval lat, double lng)

Returns true if the edge AB intersects the given edge of constant longitude.

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