Package com.google.common.geometry
Class S2LatLngRectBase
- java.lang.Object
-
- com.google.common.geometry.S2LatLngRectBase
-
- All Implemented Interfaces:
S2Region
,java.io.Serializable
- Direct Known Subclasses:
S2LatLngRect
,S2LatLngRect.Builder
@GwtCompatible(serializable=false) public abstract class S2LatLngRectBase extends java.lang.Object implements S2Region, java.io.Serializable
Base class for methods shared between the immutableS2LatLngRect
and the mutableS2LatLngRect.Builder
.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected R1Interval
lat
protected S1Interval
lng
private static S2Point
ORTHO_LNG
-
Constructor Summary
Constructors Constructor Description S2LatLngRectBase()
Constructs a rectangle with lat and lng fields set to empty intervals, as defined inR1Interval
andS1Interval
.S2LatLngRectBase(R1Interval lat, S1Interval lng)
Constructs a rectangle from latitude and longitude intervals.S2LatLngRectBase(S2LatLng lo, S2LatLng hi)
Constructs a rectangle from minimum and maximum latitudes and longitudes.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
approxEquals(S2LatLngRectBase other)
Returns true if this rectangle is very nearly identical to the given other rectangle.boolean
approxEquals(S2LatLngRectBase other, double maxError)
Returns true if the latitude and longitude intervals of the two rectangles are the same up to the given tolerance.boolean
approxEquals(S2LatLngRectBase other, S2LatLng maxError)
AsapproxEquals(S2LatLngRectBase, double)
, but with separate tolerances for latitude and longitude.double
area()
Returns the surface area of this rectangle on the unit sphere.boolean
boundaryIntersects(S2Point v0, S2Point v1)
Returns true if the boundary of this rectangle intersects the given geodesic edge (v0, v1).boolean
contains(S2Cell cell)
Returns true if this latitude/longitude region contains the given cell.boolean
contains(S2LatLng ll)
More efficient version of contains() that accepts a S2LatLng rather than an S2Point.boolean
contains(S2LatLngRectBase other)
Returns true if and only if the rectangle contains the given other rectangle.boolean
contains(S2Point p)
The point 'p' does not need to be normalized.boolean
equals(java.lang.Object that)
Returns true if these are the same type of rectangle and contain the same set of points.private static S2Point
getBisectorIntersection(R1Interval lat, double lng)
Return the intersection of longitude 0 with the bisector of an edge on longitude 'lng' and spanning latitude range 'lat'.S2Cap
getCapBound()
Return a bounding spherical cap.S2LatLng
getCenter()
Returns the center of the rectangle in latitude-longitude space (in general this is not the center of the region on the sphere).S2Point
getCentroid()
private static S1Angle
getDirectedHausdorffDistance(double lngDiff, R1Interval a, R1Interval b)
Return the directed Hausdorff distance from one longitudinal edge spanning latitude rangea_lat
to the other longitudinal edge spanning latitude rangeb_lat
, with their longitudinal difference given bylngDiff
.S1Angle
getDirectedHausdorffDistance(S2LatLngRectBase other)
Returns the directed Hausdorff distance (measured along the surface of the sphere) to the given S2LatLngRect.S1Angle
getDistance(S2LatLng p)
Returns the minimum distance (measured along the surface of the sphere) from a given point to the rectangle (both its boundary and its interior).S1Angle
getDistance(S2LatLngRectBase other)
Returns the minimum distance (measured along the surface of the sphere) to the given S2LatLngRectBase.S1Angle
getHausdorffDistance(S2LatLngRectBase other)
Returns the undirected Hausdorff distance (measured along the surface of the sphere) to the given S2LatLngRect.private static S1Angle
getInteriorMaxDistance(R1Interval aLat, S2Point b)
Return max distance from a point b to the segment spanning latitude range aLat on longitude 0, if the max occurs in the interior of aLat.S2LatLng
getSize()
Returns the width and height of this rectangle in latitude-longitude space.S2LatLng
getVertex(int k)
Returns the kth vertex of the rectangle (k = 0,1,2,3) in CCW order (lower-left, lower right, upper right, upper left).int
hashCode()
S2LatLng
hi()
boolean
interiorContains(S2LatLng ll)
More efficient version of interiorContains() that accepts a S2LatLng rather than an S2Point.boolean
interiorContains(S2LatLngRectBase other)
Returns true if and only if the interior of this rectangle contains all points of the given other rectangle (including its boundary).boolean
interiorContains(S2Point p)
Returns true if and only if the given point is contained in the interior of the region (i.e.boolean
interiorIntersects(S2LatLngRectBase other)
Returns true if and only if the interior of this rectangle intersects any point (including the boundary) of the given other rectangle.boolean
intersects(S2Cell cell)
Returns true if this rectangle intersects the given cell.boolean
intersects(S2LatLngRectBase other)
Returns true if this rectangle and the given other rectangle have any points in common.static boolean
intersectsLatEdge(S2Point a, S2Point b, double lat, S1Interval lng)
Returns true if the edge AB intersects the given edge of constant latitude.static boolean
intersectsLngEdge(S2Point a, S2Point b, R1Interval lat, double lng)
Returns true if the edge AB intersects the given edge of constant longitude.boolean
isEmpty()
Returns true if the rectangle is empty, i.e.boolean
isFull()
Returns true if the rectangle is full, i.e.boolean
isInverted()
Returns true if lng_.lo() > lng_.hi(), i.e.boolean
isPoint()
Returns true if the rectangle is a point, i.e.boolean
isValid()
Returns true if the rectangle is valid, which essentially just means that the latitude bounds do not exceed Pi/2 in absolute value and the longitude bounds do not exceed Pi in absolute value.abstract R1Interval
lat()
Returns the latitude range of this rectangle.S1Angle
latHi()
S1Angle
latLo()
abstract S1Interval
lng()
Returns the longitude range of this rectangle.S1Angle
lngHi()
S1Angle
lngLo()
S2LatLng
lo()
boolean
mayIntersect(S2Cell cell)
This test is cheap but is NOT exact.java.lang.String
toString()
java.lang.String
toStringDegrees()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.geometry.S2Region
getRectBound
-
-
-
-
Field Detail
-
lat
protected final R1Interval lat
-
lng
protected final S1Interval lng
-
ORTHO_LNG
private static final S2Point ORTHO_LNG
-
-
Constructor Detail
-
S2LatLngRectBase
S2LatLngRectBase(S2LatLng lo, S2LatLng hi)
Constructs a rectangle from minimum and maximum latitudes and longitudes. If lo.lng() > hi.lng(), the rectangle spans the 180 degree longitude line. Both points must be normalized, with lo.lat() <= hi.lat(). The rectangle contains all the points p such that 'lo' <= p <= 'hi', where '<=' is defined in the obvious way.
-
S2LatLngRectBase
S2LatLngRectBase(R1Interval lat, S1Interval lng)
Constructs a rectangle from latitude and longitude intervals. The two intervals must either be both empty or both non-empty, and the latitude interval must not extend outside [-90, +90] degrees. Note that both intervals (and hence the rectangle) are closed.
-
S2LatLngRectBase
S2LatLngRectBase()
Constructs a rectangle with lat and lng fields set to empty intervals, as defined inR1Interval
andS1Interval
.
-
-
Method Detail
-
isValid
public final boolean isValid()
Returns true if the rectangle is valid, which essentially just means that the latitude bounds do not exceed Pi/2 in absolute value and the longitude bounds do not exceed Pi in absolute value. Also, if either the latitude or longitude bound is empty then both must be.
-
latLo
public final S1Angle latLo()
-
latHi
public final S1Angle latHi()
-
lngLo
public final S1Angle lngLo()
-
lngHi
public final S1Angle lngHi()
-
lat
public abstract R1Interval lat()
Returns the latitude range of this rectangle.
-
lng
public abstract S1Interval lng()
Returns the longitude range of this rectangle.
-
lo
public final S2LatLng lo()
-
hi
public final S2LatLng hi()
-
isEmpty
public final boolean isEmpty()
Returns true if the rectangle is empty, i.e. it contains no points at all.
-
isFull
public final boolean isFull()
Returns true if the rectangle is full, i.e. it contains all points.
-
isPoint
public final boolean isPoint()
Returns true if the rectangle is a point, i.e. lo() == hi()
-
isInverted
public final boolean isInverted()
Returns true if lng_.lo() > lng_.hi(), i.e. the rectangle crosses the 180 degree latitude line.
-
getVertex
public final S2LatLng getVertex(int k)
Returns the kth vertex of the rectangle (k = 0,1,2,3) in CCW order (lower-left, lower right, upper right, upper left).
-
getCenter
public final S2LatLng getCenter()
Returns the center of the rectangle in latitude-longitude space (in general this is not the center of the region on the sphere).
-
getDistance
public final S1Angle getDistance(S2LatLng p)
Returns the minimum distance (measured along the surface of the sphere) from a given point to the rectangle (both its boundary and its interior). The latLng must be valid.
-
getDistance
public final S1Angle getDistance(S2LatLngRectBase other)
Returns the minimum distance (measured along the surface of the sphere) to the given S2LatLngRectBase. Both S2LatLngRectBases must be non-empty.
-
getHausdorffDistance
public final S1Angle getHausdorffDistance(S2LatLngRectBase other)
Returns the undirected Hausdorff distance (measured along the surface of the sphere) to the given S2LatLngRect. The directed Hausdorff distance from rectangle A to rectangle B is given byh(A, B) = max_{p in A} min_{q in B} d(p, q)
. The Hausdorff distance between rectangle A and rectangle B is given byH(A, B) = max{h(A, B), h(B, A)}
.
-
getDirectedHausdorffDistance
public final S1Angle getDirectedHausdorffDistance(S2LatLngRectBase other)
Returns the directed Hausdorff distance (measured along the surface of the sphere) to the given S2LatLngRect. The directed Hausdorff distance from rectangle A to rectangle B is given byh(A, B) = max_{p in A} min_{q in B} d(p, q)
. The Hausdorff distance between rectangle A and rectangle B is given byH(A, B) = max{h(A, B), h(B, A)}
.
-
getDirectedHausdorffDistance
private static S1Angle getDirectedHausdorffDistance(double lngDiff, R1Interval a, R1Interval b)
Return the directed Hausdorff distance from one longitudinal edge spanning latitude rangea_lat
to the other longitudinal edge spanning latitude rangeb_lat
, with their longitudinal difference given bylngDiff
.
-
getBisectorIntersection
private static S2Point getBisectorIntersection(R1Interval lat, double lng)
Return the intersection of longitude 0 with the bisector of an edge on longitude 'lng' and spanning latitude range 'lat'.
-
getInteriorMaxDistance
private static S1Angle getInteriorMaxDistance(R1Interval aLat, S2Point b)
Return max distance from a point b to the segment spanning latitude range aLat on longitude 0, if the max occurs in the interior of aLat. Otherwise return -1.
-
getSize
public final S2LatLng getSize()
Returns the width and height of this rectangle in latitude-longitude space. Empty rectangles have a negative width and height.
-
getCentroid
public final S2Point getCentroid()
-
contains
public final boolean contains(S2LatLng ll)
More efficient version of contains() that accepts a S2LatLng rather than an S2Point.
-
interiorContains
public final boolean interiorContains(S2Point p)
Returns true if and only if the given point is contained in the interior of the region (i.e. the region excluding its boundary). The point 'p' does not need to be normalized.
-
interiorContains
public final boolean interiorContains(S2LatLng ll)
More efficient version of interiorContains() that accepts a S2LatLng rather than an S2Point.
-
contains
public final boolean contains(S2LatLngRectBase other)
Returns true if and only if the rectangle contains the given other rectangle.
-
interiorContains
public final boolean interiorContains(S2LatLngRectBase other)
Returns true if and only if the interior of this rectangle contains all points of the given other rectangle (including its boundary).
-
intersects
public final boolean intersects(S2LatLngRectBase other)
Returns true if this rectangle and the given other rectangle have any points in common.
-
intersects
public final boolean intersects(S2Cell cell)
Returns true if this rectangle intersects the given cell. (This is an exact test and may be fairly expensive, see also MayIntersect below.)
-
interiorIntersects
public final boolean interiorIntersects(S2LatLngRectBase other)
Returns true if and only if the interior of this rectangle intersects any point (including the boundary) of the given other rectangle.
-
boundaryIntersects
public final boolean boundaryIntersects(S2Point v0, S2Point v1)
Returns true if the boundary of this rectangle intersects the given geodesic edge (v0, v1).
-
area
public final double area()
Returns the surface area of this rectangle on the unit sphere.
-
equals
public final boolean equals(java.lang.Object that)
Returns true if these are the same type of rectangle and contain the same set of points.- Overrides:
equals
in classjava.lang.Object
-
approxEquals
public final boolean approxEquals(S2LatLngRectBase other, double maxError)
Returns true if the latitude and longitude intervals of the two rectangles are the same up to the given tolerance. SeeR1Interval
andS1Interval
for details.
-
approxEquals
public final boolean approxEquals(S2LatLngRectBase other)
Returns true if this rectangle is very nearly identical to the given other rectangle.
-
approxEquals
public final boolean approxEquals(S2LatLngRectBase other, S2LatLng maxError)
AsapproxEquals(S2LatLngRectBase, double)
, but with separate tolerances for latitude and longitude.
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getCapBound
public S2Cap getCapBound()
Description copied from interface:S2Region
Return a bounding spherical cap.- Specified by:
getCapBound
in interfaceS2Region
-
contains
public final boolean contains(S2Cell cell)
Returns true if this latitude/longitude region contains the given cell. A latitude-longitude rectangle contains a cell if and only if it contains the cell's bounding rectangle, making this an exact test. Note, however, that the cell must be valid; an error may result if e.g.S2CellId.sentinel()
is passed here.
-
mayIntersect
public final boolean mayIntersect(S2Cell cell)
This test is cheap but is NOT exact. Use Intersects() if you want a more accurate and more expensive test. Note that when this method is used by an S2RegionCoverer, the accuracy isn't all that important since if a cell may intersect the region then it is subdivided, and the accuracy of this method goes up as the cells get smaller.- Specified by:
mayIntersect
in interfaceS2Region
-
contains
public final boolean contains(S2Point p)
The point 'p' does not need to be normalized.
-
intersectsLngEdge
public static final boolean intersectsLngEdge(S2Point a, S2Point b, R1Interval lat, double lng)
Returns true if the edge AB intersects the given edge of constant longitude.
-
intersectsLatEdge
public static final boolean intersectsLatEdge(S2Point a, S2Point b, double lat, S1Interval lng)
Returns true if the edge AB intersects the given edge of constant latitude.
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toStringDegrees
public final java.lang.String toStringDegrees()
-
-