Class S2LatLngRect.Builder

java.lang.Object
com.google.common.geometry.S2LatLngRectBase
com.google.common.geometry.S2LatLngRect.Builder
All Implemented Interfaces:
S2Region, Serializable
Enclosing class:
S2LatLngRect

public static final class S2LatLngRect.Builder extends S2LatLngRectBase
This class is a builder for S2LatLngRect instances. This is much more efficient when creating the bounds from numerous operations, as it ensures that the S2LatLngRect is only created once.

Example usage:

S2LatLngRect union(List<S2LatLng> points) { S2LatLngRect.Builder builder = new S2LatLngRect.Builder(); for (S2LatLng point : points) { builder.addPoint(point); } return builder.build(); }

See Also:
  • Constructor Details

  • Method Details

    • lat

      public final R1Interval lat()
      Description copied from class: S2LatLngRectBase
      Returns the latitude range of this rectangle.
      Specified by:
      lat in class S2LatLngRectBase
    • lng

      public final S1Interval lng()
      Description copied from class: S2LatLngRectBase
      Returns the longitude range of this rectangle.
      Specified by:
      lng in class S2LatLngRectBase
    • build

      public S2LatLngRect build()
      Returns a new immutable S2LatLngRect copied from the current state of this builder.
    • empty

      public static S2LatLngRect.Builder empty()
      A builder initialized to be empty (such that it doesn't contain anything).
    • setFull

      public S2LatLngRect.Builder setFull()
      Sets the rectangle to the full rectangle.
    • addPoint

      public S2LatLngRect.Builder addPoint(S2Point p)
    • addPoint

      public S2LatLngRect.Builder addPoint(S2LatLng ll)
      Increases the size of the bounding rectangle to include the given point. The rectangle is expanded by the minimum amount possible.
    • expanded

      public S2LatLngRect.Builder expanded(S2LatLng margin)
      Mutates the rectangle to contain all points whose latitude distance from this rectangle is at most margin.lat(), and whose longitude distance from this rectangle is at most margin.lng(). In particular, latitudes are clamped while longitudes are wrapped. Note that any expansion of an empty interval remains empty, and both components of the given margin must be non-negative.

      NOTE: If you are trying to grow a rectangle by a certain *distance* on the sphere (e.g. 5km), use the convolveWithCap() method instead.

    • polarClosure

      public S2LatLngRect.Builder polarClosure()
      If the rectangle does not include either pole, leave it unmodified. Otherwise expand the longitude range to full() so that the rectangle contains all possible representations of the contained pole(s).
    • union

      public S2LatLngRect.Builder union(S2LatLngRect other)
      Mutates this rectangle to be the smallest rectangle containing the union of the current and given rectangles.
    • intersection

      public S2LatLngRect.Builder intersection(S2LatLngRect other)
      Mutates this rectangle to be the smallest rectangle containing the intersection of the current and given rectangles. Note that the region of intersection may consist of two disjoint rectangles, in which case we set the rectangle to be a single rectangle spanning both of them.
    • convolveWithCap

      public S2LatLngRect.Builder convolveWithCap(S1Angle angle)
      Mutates the current rectangle to contain the convolution of this rectangle with a cap of the given angle. This expands the rectangle by a fixed distance (as opposed to growing the rectangle in latitude-longitude space). The new rectangle includes all points whose minimum distance to the original rectangle is at most the given angle.
    • clone

      public S2Region clone()
      Overrides:
      clone in class Object
    • getRectBound

      public S2LatLngRect getRectBound()
      Description copied from interface: S2Region
      Return a bounding latitude-longitude rectangle.