Class S2EdgeUtil.RectBounder

java.lang.Object
com.google.common.geometry.S2EdgeUtil.RectBounder
Enclosing class:
S2EdgeUtil

public static class S2EdgeUtil.RectBounder extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private S2Point
    The previous vertex in the chain.
    private S2LatLng
    The corresponding latitude-longitude.
    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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    addPoint(S2Point b, S2LatLng bLatLng)
    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
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • builder

      private S2LatLngRect.Builder builder
      The accumulated bounds, initially empty.
    • a

      private S2Point a
      The previous vertex in the chain.
    • aLatLng

      private S2LatLng aLatLng
      The corresponding latitude-longitude.
    • lngAB

      private final S1Interval lngAB
      Temporary storage for the longitude range spanned by AB.
    • latAB

      private final R1Interval latAB
      Temporary storage for the latitude range spanned by AB.
  • Constructor Details

    • RectBounder

      public RectBounder()
  • Method Details

    • addPoint

      public void addPoint(S2LatLng b)
      This method is called to add each vertex to the chain. This method is much faster than addPoint(S2Point), since converting S2LatLng to an S2Point is much faster than the other way around..
    • addPoint

      public void addPoint(S2Point b)
      This method is called to add each vertex to the chain. Prefer calling addPoint(S2LatLng) if you have that type available. The point must be unit length.
    • addPoint

      private void addPoint(S2Point b, S2LatLng bLatLng)
      Internal implementation of addPoint that takes both the point and latLng representation, by whichever path provided them, and expands the bounds accordingly.
    • getBound

      public S2LatLngRect 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

      static S2LatLng 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 to S2LatLngRectBase.approxEquals(com.google.common.geometry.S2LatLngRectBase, double)).
    • expandForSubregions

      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. 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), then expandForSubregions(RectBound(L)).contains(RectBound(S)).