Package com.google.common.geometry
Class S2ShapeIndex.S2ClippedShape
- java.lang.Object
-
- com.google.common.geometry.S2ShapeIndex.Cell
-
- com.google.common.geometry.S2ShapeIndex.S2ClippedShape
-
- All Implemented Interfaces:
S2Iterator.Entry,java.io.Serializable
- Direct Known Subclasses:
S2ShapeIndex.S2ClippedShape.Contained,S2ShapeIndex.S2ClippedShape.EdgeRange,S2ShapeIndex.S2ClippedShape.ManyEdges,S2ShapeIndex.S2ClippedShape.OneEdge
- Enclosing class:
- S2ShapeIndex
public abstract static class S2ShapeIndex.S2ClippedShape extends S2ShapeIndex.Cell
S2ClippedShape represents the part of a shape that intersects an S2Cell. It consists of the set of edge ids that intersect that cell, and a boolean indicating whether the center of the cell is inside the shape (for shapes that have an interior). Edges themselves are not clipped; we always use the original edges for intersection tests so that the results will be the same as the original shape.Most of the index memory is consumed here, so we have several strategies to be as efficient as possible:
- Since only the first clipped shape in a cell needs to store the cell ID, we have subclasses for both cases based on whether a cell ID was provided.
- Since no edges, one edge, and one dense range of edges are very common cases, we have more efficient subclasses for those situations, in addition to the general purpose implementation.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classS2ShapeIndex.S2ClippedShape.ContainedAn S2ClippedShape for a shape that completely contains the cell (no edge intersections and containsCenter is true.)private static classS2ShapeIndex.S2ClippedShape.EdgeRangeAn S2ClippedShape containing a single range of contiguous edge IDs.private static classS2ShapeIndex.S2ClippedShape.ManyEdgesAn S2ClippedShape that contains the non-contiguous edges fromstarttoendinedges.private static classS2ShapeIndex.S2ClippedShape.OneEdgeAn S2ClippedShape that contains a single edge from a given shape.
-
Constructor Summary
Constructors Modifier Constructor Description privateS2ClippedShape(S2Shape shape)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description S2ShapeIndex.S2ClippedShapeclipped(int i)For implementing the Cell interface, this class contains just 1 shape (itself.)abstract booleancontainsCenter()Returns whether the center of the S2CellId is inside the shape, and always returns false for shapes that do not have an interior according toS2Shape.hasInterior().booleancontainsEdge(int edgeId)Returns whether the clipped shape contains the given edge id.(package private) static S2ShapeIndex.S2ClippedShapecreate(S2CellId cellId, S2Shape shape, boolean containsCenter, int[] edges)(package private) static S2ShapeIndex.S2ClippedShapecreate(S2CellId cellId, S2Shape shape, boolean containsCenter, int offset, int count)(package private) static S2ShapeIndex.S2ClippedShapecreate(S2CellId cellId, S2Shape shape, boolean containsCenter, java.util.List<S2ShapeIndex.ClippedEdge> edges, int start, int end)abstract intedge(int i)Returns theith edge ID of this clipped shape.abstract intnumEdges()Returns the number of edges that intersect the S2CellId.intnumShapes()For implementing the Cell interface, this class contains just 1 shape (itself.)S2Shapeshape()Returns the original shape this clipped shape was clipped from.-
Methods inherited from class com.google.common.geometry.S2ShapeIndex.Cell
create, findClipped, id
-
-
-
-
Field Detail
-
shape
private final S2Shape shape
If positive, this is the shape ID and the shape does not contain the center of the cell. Otherwise the shape ID is ~this.shapeId and the shape does contains the center of the cell. This is done to save memory, since this single bit of information can otherwise be padded out up to 4 or 8 additional bytes, depending on the fields in the subclass.
-
-
Constructor Detail
-
S2ClippedShape
private S2ClippedShape(S2Shape shape)
-
-
Method Detail
-
create
static S2ShapeIndex.S2ClippedShape create(S2CellId cellId, S2Shape shape, boolean containsCenter, java.util.List<S2ShapeIndex.ClippedEdge> edges, int start, int end)
-
create
static S2ShapeIndex.S2ClippedShape create(@Nullable S2CellId cellId, S2Shape shape, boolean containsCenter, int[] edges)
-
create
static S2ShapeIndex.S2ClippedShape create(@Nullable S2CellId cellId, S2Shape shape, boolean containsCenter, int offset, int count)
-
shape
public final S2Shape shape()
Returns the original shape this clipped shape was clipped from.
-
containsCenter
public abstract boolean containsCenter()
Returns whether the center of the S2CellId is inside the shape, and always returns false for shapes that do not have an interior according toS2Shape.hasInterior().
-
numEdges
public abstract int numEdges()
Returns the number of edges that intersect the S2CellId.
-
edge
public abstract int edge(int i)
Returns theith edge ID of this clipped shape. Edges are sorted in increasing order of edge ID. The edge IDs may be passed to the corresponding shape'sS2Shape.getEdge(int, com.google.common.geometry.S2Shape.MutableEdge)method.- Parameters:
i- must be at least 0 and less thannumEdges()
-
containsEdge
public final boolean containsEdge(int edgeId)
Returns whether the clipped shape contains the given edge id.
-
numShapes
public final int numShapes()
For implementing the Cell interface, this class contains just 1 shape (itself.)- Specified by:
numShapesin classS2ShapeIndex.Cell
-
clipped
public final S2ShapeIndex.S2ClippedShape clipped(int i)
For implementing the Cell interface, this class contains just 1 shape (itself.)- Specified by:
clippedin classS2ShapeIndex.Cell- Parameters:
i- must be at least 0 and less thanS2ShapeIndex.Cell.numShapes()
-
-