Package com.google.common.geometry
Class S2ShapeIndexRegion
- java.lang.Object
-
- com.google.common.geometry.S2ShapeIndexRegion
-
- All Implemented Interfaces:
S2Region
@GwtCompatible(serializable=false) public class S2ShapeIndexRegion extends java.lang.Object implements S2Region
This class wraps an S2ShapeIndex object with the additional methods needed to implement the S2Region API, in order to allow S2RegionCoverer to compute S2CellId coverings of arbitrary collections of geometry.Example usage:
S2CellUnion getCovering(S2ShapeIndex index) { S2RegionCoverer coverer = new S2RegionCoverer(); coverer.setMaxCells(20); return coverer.getCovering(new S2ShapeIndexRegion(index)); }
This class uses a number of temporary mutable objects to keep allocation down, and so is not thread-safe. To use it in parallel, each thread should construct its own instance (this is not expensive).
-
-
Field Summary
Fields Modifier and Type Field Description private R2Rect
bound
Temporary bound for internal usage.private S2Shape.MutableEdge
edge
Temporary edge for internal usage.private S2Iterator<S2ShapeIndex.Cell>
it
The iterator.private S2ContainsPointQuery.S2VertexModel
model
The vertex model for contains(S2Point) tests.private R2Vector
p0
Temporary R2 point for internal usage.private R2Vector
p1
Temporary R2 point for internal usage.private S2CellUnion
union
Temporary cell union for internal usage.
-
Constructor Summary
Constructors Constructor Description S2ShapeIndexRegion(S2ShapeIndex index)
Creates a new region with the given index, and asemi-open
vertex model.S2ShapeIndexRegion(S2ShapeIndex index, S2ContainsPointQuery.S2VertexModel model)
Creates a new region with the given index, and a givenS2ContainsPointQuery.S2VertexModel
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
anyEdgeIntersects(S2ShapeIndex.S2ClippedShape clipped, S2Cell target)
Returns true if any edge of the indexed shape "clipped" intersects the cell "target".boolean
contains(S2Cell target)
Returns true if 'target' is contained by any single shape.boolean
contains(S2Point p)
Returns true if the given point is contained by any two-dimensional shape (i.e., polygon).private static void
coverRange(S2CellId first, S2CellId last, java.util.List<S2CellId> cellIds)
Computes the smallest S2Cell that covers the S2Cell range (first, last) and adds this cell to "cellIds".S2Cap
getCapBound()
Return a bounding spherical cap.void
getCellUnionBound(java.util.List<S2CellId> cellIds)
Clears the given list of cells and adds the cell union of this index.S2LatLngRect
getRectBound()
Return a bounding latitude-longitude rectangle.boolean
mayIntersect(S2Cell target)
Returns true if any shape intersects "target".
-
-
-
Field Detail
-
model
private final S2ContainsPointQuery.S2VertexModel model
The vertex model for contains(S2Point) tests.
-
it
private final S2Iterator<S2ShapeIndex.Cell> it
The iterator.
-
union
private final S2CellUnion union
Temporary cell union for internal usage.
-
edge
private final S2Shape.MutableEdge edge
Temporary edge for internal usage.
-
bound
private final R2Rect bound
Temporary bound for internal usage.
-
p0
private final R2Vector p0
Temporary R2 point for internal usage.
-
p1
private final R2Vector p1
Temporary R2 point for internal usage.
-
-
Constructor Detail
-
S2ShapeIndexRegion
public S2ShapeIndexRegion(S2ShapeIndex index)
Creates a new region with the given index, and asemi-open
vertex model.
-
S2ShapeIndexRegion
public S2ShapeIndexRegion(S2ShapeIndex index, S2ContainsPointQuery.S2VertexModel model)
Creates a new region with the given index, and a givenS2ContainsPointQuery.S2VertexModel
.
-
-
Method Detail
-
getCapBound
public S2Cap getCapBound()
Description copied from interface:S2Region
Return a bounding spherical cap.- Specified by:
getCapBound
in interfaceS2Region
-
getRectBound
public S2LatLngRect getRectBound()
Description copied from interface:S2Region
Return a bounding latitude-longitude rectangle.- Specified by:
getRectBound
in interfaceS2Region
-
getCellUnionBound
public void getCellUnionBound(java.util.List<S2CellId> cellIds)
Clears the given list of cells and adds the cell union of this index. An index of shapes in one face adds up to 4 cells, otherwise up to 6 may be added.
-
coverRange
private static void coverRange(S2CellId first, S2CellId last, java.util.List<S2CellId> cellIds)
Computes the smallest S2Cell that covers the S2Cell range (first, last) and adds this cell to "cellIds".- Throws:
java.lang.IllegalArgumentException
- "first" and "last" don't have a common ancestor.
-
contains
public boolean contains(S2Point p)
Returns true if the given point is contained by any two-dimensional shape (i.e., polygon). Zero and one-dimensional shapes are ignored by this method.
-
contains
public boolean contains(S2Cell target)
Returns true if 'target' is contained by any single shape. If the cell is covered by a union of different shapes then it may return false.This implementation is conservative but not exact; if a shape just barely contains the given cell then it may return false. The maximum error is less than 10 * DBL_EPSILON radians (or about 15 nanometers).
-
mayIntersect
public boolean mayIntersect(S2Cell target)
Returns true if any shape intersects "target".This implementation is conservative but not exact; if a shape is just barely disjoint from the given cell then it may return true. The maximum error is less than 10 * DBL_EPSILON radians (or about 15 nanometers).
- Specified by:
mayIntersect
in interfaceS2Region
-
anyEdgeIntersects
private boolean anyEdgeIntersects(S2ShapeIndex.S2ClippedShape clipped, S2Cell target)
Returns true if any edge of the indexed shape "clipped" intersects the cell "target". It may also return true if an edge is very close to "target"; the maximum error is less than 10 * DBL_EPSILON radians (about 15 nanometers).
-
-