Class S2EdgeUtil.RectBounder

  • Enclosing class:
    S2EdgeUtil

    public static class S2EdgeUtil.RectBounder
    extends java.lang.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 a
      The previous vertex in the chain.
      private S2LatLng aLatLng
      The corresponding latitude-longitude.
      private S2LatLngRect.Builder builder
      The accumulated bounds, initially empty.
      private R1Interval latAB
      Temporary storage for the latitude range spanned by AB.
      private S1Interval lngAB
      Temporary storage for the longitude range spanned by AB.
    • Constructor Summary

      Constructors 
      Constructor Description
      RectBounder()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPoint​(S2LatLng b)
      This method is called to add each vertex to the chain.
      void addPoint​(S2Point b)
      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 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.
      S2LatLngRect getBound()
      Returns the bounding rectangle of the edge chain that connects the vertices defined so far.
      (package private) static S2LatLng maxErrorForTests()
      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 Detail

      • 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 Detail

      • RectBounder

        public RectBounder()
    • Method Detail

      • 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.
      • 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)).