Class S2ShapeIndex

java.lang.Object
com.google.common.geometry.S2ShapeIndex
All Implemented Interfaces:
Serializable

@GwtCompatible public class S2ShapeIndex extends Object implements Serializable
See Also:
  • Field Details

    • 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:
      1. 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.
      2. 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.

    • 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:
    • 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 towards S2ShapeIndex.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:
    • 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:
    • shapes

      protected List<S2Shape> shapes
      Shapes currently in the index.
  • Constructor Details

    • 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 Details

    • 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.