Package com.google.common.geometry
Class S2LatLngRect.Builder
- java.lang.Object
-
- com.google.common.geometry.S2LatLngRectBase
-
- com.google.common.geometry.S2LatLngRect.Builder
-
- All Implemented Interfaces:
S2Region
,java.io.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:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.google.common.geometry.S2LatLngRectBase
lat, lng
-
-
Constructor Summary
Constructors Constructor Description Builder(R1Interval lat, S1Interval lng)
Builder(S2LatLng lo, S2LatLng hi)
Builder(S2LatLngRectBase b)
Creates a new S2LatLngRect.Builder as a copy ofb
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description S2LatLngRect.Builder
addPoint(S2LatLng ll)
Increases the size of the bounding rectangle to include the given point.S2LatLngRect.Builder
addPoint(S2Point p)
S2LatLngRect
build()
Returns a new immutable S2LatLngRect copied from the current state of this builder.S2Region
clone()
S2LatLngRect.Builder
convolveWithCap(S1Angle angle)
Mutates the current rectangle to contain the convolution of this rectangle with a cap of the given angle.static S2LatLngRect.Builder
empty()
A builder initialized to be empty (such that it doesn't contain anything).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().S2LatLngRect
getRectBound()
Return a bounding latitude-longitude rectangle.S2LatLngRect.Builder
intersection(S2LatLngRect other)
Mutates this rectangle to be the smallest rectangle containing the intersection of the current and given rectangles.R1Interval
lat()
Returns the latitude range of this rectangle.S1Interval
lng()
Returns the longitude range of this rectangle.S2LatLngRect.Builder
polarClosure()
If the rectangle does not include either pole, leave it unmodified.S2LatLngRect.Builder
setFull()
Sets the rectangle to the full rectangle.S2LatLngRect.Builder
union(S2LatLngRect other)
Mutates this rectangle to be the smallest rectangle containing the union of the current and given rectangles.-
Methods inherited from class com.google.common.geometry.S2LatLngRectBase
approxEquals, approxEquals, approxEquals, area, boundaryIntersects, contains, contains, contains, contains, equals, getCapBound, getCenter, getCentroid, getDirectedHausdorffDistance, getDistance, getDistance, getHausdorffDistance, getSize, getVertex, hashCode, hi, interiorContains, interiorContains, interiorContains, interiorIntersects, intersects, intersects, intersectsLatEdge, intersectsLngEdge, isEmpty, isFull, isInverted, isPoint, isValid, latHi, latLo, lngHi, lngLo, lo, mayIntersect, toString, toStringDegrees
-
-
-
-
Constructor Detail
-
Builder
public Builder(R1Interval lat, S1Interval lng)
-
Builder
public Builder(S2LatLngRectBase b)
Creates a new S2LatLngRect.Builder as a copy ofb
.
-
-
Method Detail
-
lat
public final R1Interval lat()
Description copied from class:S2LatLngRectBase
Returns the latitude range of this rectangle.- Specified by:
lat
in classS2LatLngRectBase
-
lng
public final S1Interval lng()
Description copied from class:S2LatLngRectBase
Returns the longitude range of this rectangle.- Specified by:
lng
in classS2LatLngRectBase
-
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 classjava.lang.Object
-
getRectBound
public S2LatLngRect getRectBound()
Description copied from interface:S2Region
Return a bounding latitude-longitude rectangle.
-
-