Package com.google.common.geometry
Class S2EdgeUtil.RectBounder
java.lang.Object
com.google.common.geometry.S2EdgeUtil.RectBounder
- Enclosing class:
S2EdgeUtil
This class computes a bounding rectangle that contains all edges defined by a vertex chain v0,
v1, v2, ... All vertices must be unit length. Note that the bounding rectangle of an edge can
be larger than the bounding rectangle of its endpoints, e.g. consider an edge that passes
through the north pole.
The bounds are calculated conservatively to account for numerical errors when S2Points are converted to S2LatLngs. For example, this class guarantees that if L is a closed edge chain (a loop) such that the interior of the loop does not contain either pole, and P is any point such that L contains P, then the RectBounder of all edges in L will contain S2LatLng(P).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate S2Point
The previous vertex in the chain.private S2LatLng
The corresponding latitude-longitude.private S2LatLngRect.Builder
The accumulated bounds, initially empty.private final R1Interval
Temporary storage for the latitude range spanned by AB.private final S1Interval
Temporary storage for the longitude range spanned by AB. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method is called to add each vertex to the chain.void
This method is called to add each vertex to the chain.private void
Internal implementation of addPoint that takes both the point and latLng representation, by whichever path provided them, and expands the bounds accordingly.(package private) static S2LatLngRect
expandForSubregions
(S2LatLngRect bound) Expand a bound returned by getBound() so that it is guaranteed to contain the bounds of any subregion whose bounds are computed using this class.getBound()
Returns the bounding rectangle of the edge chain that connects the vertices defined so far.(package private) static S2LatLng
Returns the maximum error in getBound() provided that the result does not include either pole.
-
Field Details
-
builder
The accumulated bounds, initially empty. -
a
The previous vertex in the chain. -
aLatLng
The corresponding latitude-longitude. -
lngAB
Temporary storage for the longitude range spanned by AB. -
latAB
Temporary storage for the latitude range spanned by AB.
-
-
Constructor Details
-
RectBounder
public RectBounder()
-
-
Method Details
-
addPoint
This method is called to add each vertex to the chain. This method is much faster thanaddPoint(S2Point)
, since converting S2LatLng to an S2Point is much faster than the other way around.. -
addPoint
This method is called to add each vertex to the chain. Prefer callingaddPoint(S2LatLng)
if you have that type available. The point must be unit length. -
addPoint
Internal implementation of addPoint that takes both the point and latLng representation, by whichever path provided them, and expands the bounds accordingly. -
getBound
Returns the bounding rectangle of the edge chain that connects the vertices defined so far. This bound satisfies the guarantee made above, i.e. if the edge chain defines a loop, then the bound contains the S2LatLng coordinates of all S2Points contained by the loop. -
maxErrorForTests
Returns the maximum error in getBound() provided that the result does not include either pole. It is only to be used for testing purposes (e.g., by passing it toS2LatLngRectBase.approxEquals(com.google.common.geometry.S2LatLngRectBase, double)
). -
expandForSubregions
Expand a bound returned by getBound() so that it is guaranteed to contain the bounds of any subregion whose bounds are computed using this class. For example, consider a loop L that defines a square. GetBound() ensures that if a point P is contained by this square, then S2LatLng(P) is contained by the bound. But now consider a diamond shaped loop S contained by L. It is possible that GetBound() returns a larger* bound for S than it does for L, due to rounding errors. This method expands the bound for L so that it is guaranteed to contain the bounds of any subregion S.More precisely, if L is a loop that does not contain either pole, and S is a loop such that
L.contains(S)
, thenexpandForSubregions(RectBound(L)).contains(RectBound(S))
.
-