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 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
FieldsModifier and TypeFieldDescriptionprivate final R2Rect
Temporary bound for internal usage.private final S2Shape.MutableEdge
Temporary edge for internal usage.private final S2Iterator
<S2ShapeIndex.Cell> The iterator.private final S2ContainsPointQuery.S2VertexModel
The vertex model for contains(S2Point) tests.private final R2Vector
Temporary R2 point for internal usage.private final R2Vector
Temporary R2 point for internal usage.private final S2CellUnion
Temporary cell union for internal usage. -
Constructor Summary
ConstructorsConstructorDescriptionS2ShapeIndexRegion
(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
Modifier and TypeMethodDescriptionprivate boolean
anyEdgeIntersects
(S2ShapeIndex.S2ClippedShape clipped, S2Cell target) Returns true if any edge of the indexed shape "clipped" intersects the cell "target".boolean
Returns true if 'target' is contained by any single shape.boolean
Returns true if the given point is contained by any two-dimensional shape (i.e., polygon).private static void
coverRange
(S2CellId first, S2CellId last, List<S2CellId> cellIds) Computes the smallest S2Cell that covers the S2Cell range (first, last) and adds this cell to "cellIds".Return a bounding spherical cap.void
getCellUnionBound
(List<S2CellId> cellIds) Clears the given list of cells and adds the cell union of this index.Return a bounding latitude-longitude rectangle.boolean
mayIntersect
(S2Cell target) Returns true if any shape intersects "target".
-
Field Details
-
model
The vertex model for contains(S2Point) tests. -
it
The iterator. -
union
Temporary cell union for internal usage. -
edge
Temporary edge for internal usage. -
bound
Temporary bound for internal usage. -
p0
Temporary R2 point for internal usage. -
p1
Temporary R2 point for internal usage.
-
-
Constructor Details
-
S2ShapeIndexRegion
Creates a new region with the given index, and asemi-open
vertex model. -
S2ShapeIndexRegion
Creates a new region with the given index, and a givenS2ContainsPointQuery.S2VertexModel
.
-
-
Method Details
-
getCapBound
Description copied from interface:S2Region
Return a bounding spherical cap.- Specified by:
getCapBound
in interfaceS2Region
-
getRectBound
Description copied from interface:S2Region
Return a bounding latitude-longitude rectangle.- Specified by:
getRectBound
in interfaceS2Region
-
getCellUnionBound
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
Computes the smallest S2Cell that covers the S2Cell range (first, last) and adds this cell to "cellIds".- Throws:
IllegalArgumentException
- "first" and "last" don't have a common ancestor.
-
contains
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
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
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
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).
-