Package com.google.common.geometry
Class S2ShapeIndex
- java.lang.Object
-
- com.google.common.geometry.S2ShapeIndex
-
- All Implemented Interfaces:
Serializable
@GwtCompatible public class S2ShapeIndex extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classS2ShapeIndex.CellThis class contains the set of clipped shapes within a particular index cell, sorted in increasing order of shape id.static classS2ShapeIndex.CellRelationThe possible relationships between a "target" cell and the cells of the S2ShapeIndex.static classS2ShapeIndex.OptionsOptions that affect construction of the S2ShapeIndex.static classS2ShapeIndex.RangeIteratorRangeIterator is a wrapper over CellIterator that is specialized for merging shape indices.static classS2ShapeIndex.S2ClippedShapeS2ClippedShape represents the part of a shape that intersects an S2Cell.
-
Field Summary
Fields Modifier and Type Field Description static doubleCELL_PADDINGThe amount in UV coordinates by which cells are "padded" to compensate for numerical errors when clipping line segments to cell boundaries.static intCURRENT_ENCODING_VERSIONThe current encoding version.static doubleDEFAULT_CELL_SIZE_TO_LONG_EDGE_RATIODefault maximum cell size, relative to an edge's length, for which that edge is considered 'long'.static intDEFAULT_MAX_EDGES_PER_CELLDefault maximum number of edges per cell (not counting 'long' edges).protected List<S2Shape>shapesShapes currently in the index.
-
Constructor Summary
Constructors Constructor Description S2ShapeIndex()Creates an S2ShapeIndex that uses the default options,S2ShapeIndex.Options.S2ShapeIndex(S2ShapeIndex.Options options)Creates an S2ShapeIndex with the given options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(S2Shape shape)Adds the given shape to this index.List<S2Shape>getShapes()Returns an immutable list view of shapes in the index.booleanisFresh()Returns true if there are no pending updates that need to be applied.S2Iterator<S2ShapeIndex.Cell>iterator()Returns a new iterator over the cells of this index, positioned at the first cell in the index, after initializing any pending updates.S2ShapeIndex.Optionsoptions()Returns the options used for this index.voidremove(S2Shape shape)Currently not implemented.voidreset()Clears the contents of the index and resets it to its original state.
-
-
-
Field Detail
-
CELL_PADDING
public static final double CELL_PADDING
The amount in UV coordinates by which cells are "padded" to compensate for numerical errors when clipping line segments to cell boundaries. The total error when clipping an edge comes from two sources:- Clipping the original spherical edge to a cube face (the "face edge"). The maximum error
in this step is
S2EdgeUtil.FACE_CLIP_ERROR_UV_COORD. - Clipping the face edge to the u- or v-coordinate of a cell boundary. The maximum error in
this step is
S2EdgeUtil.EDGE_CLIP_ERROR_UV_COORD.
Finally, since we encounter the same errors when clipping query edges, we double the total error so that we only need to pad edges during indexing and not at query time.
- Clipping the original spherical edge to a cube face (the "face edge"). The maximum error
in this step is
-
DEFAULT_MAX_EDGES_PER_CELL
public static final int DEFAULT_MAX_EDGES_PER_CELL
Default maximum number of edges per cell (not counting 'long' edges). Reasonable values range from 10 to 50. Small values makes queries faster, while large values make construction faster and use less memory.- See Also:
- Constant Field Values
-
DEFAULT_CELL_SIZE_TO_LONG_EDGE_RATIO
public static final double DEFAULT_CELL_SIZE_TO_LONG_EDGE_RATIO
Default maximum cell size, relative to an edge's length, for which that edge is considered 'long'. Long edges are not counted towardsS2ShapeIndex.Options.maxEdgesPerCell. The size and speed of the index are typically not very sensitive to this parameter. Reasonable values range from 0.1 to 10, with smaller values causing more aggressive subdivision of long edges grouped closely together.- See Also:
- Constant Field Values
-
CURRENT_ENCODING_VERSION
public static final int CURRENT_ENCODING_VERSION
The current encoding version. When adding a new encoding, be aware that old binaries will not be able to decode it.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
S2ShapeIndex
public S2ShapeIndex()
Creates an S2ShapeIndex that uses the default options,S2ShapeIndex.Options.
-
S2ShapeIndex
public S2ShapeIndex(S2ShapeIndex.Options options)
Creates an S2ShapeIndex with the given options.
-
-
Method Detail
-
options
public S2ShapeIndex.Options options()
Returns the options used for this index.
-
getShapes
public List<S2Shape> getShapes()
Returns an immutable list view of shapes in the index. When shapes are added or removed, the returned view is updated as well.
-
add
public void add(S2Shape shape)
Adds the given shape to this index. Invalidates all iterators and their associated data.
-
remove
public void remove(S2Shape shape)
Currently not implemented. Will eventually remove the given shape from the index, and invalidate all iterators and their associated data.- Parameters:
shape- the shape to remove
-
reset
public void reset()
Clears the contents of the index and resets it to its original state.
-
iterator
public S2Iterator<S2ShapeIndex.Cell> iterator()
Returns a new iterator over the cells of this index, positioned at the first cell in the index, after initializing any pending updates.
-
isFresh
public boolean isFresh()
Returns true if there are no pending updates that need to be applied. This can be useful to avoid building the index unnecessarily, or for choosing between two different algorithms depending on whether the index is available.
-
-