Interface S2LaxPolygonShape
- All Superinterfaces:
S2Shape,S2ShapeAspect.ChainAspect,S2ShapeAspect.EdgeAspect,S2ShapeAspect.EdgeAspect.Closed,S2ShapeAspect.Mixed,S2ShapeAspect.TopoAspect,S2ShapeAspect.VertexAspect
- All Known Implementing Classes:
S2LaxPolygonShape.MultiArray,S2LaxPolygonShape.MultiList,S2LaxPolygonShape.MultiPacked,S2LaxPolygonShape.MultiSnapped,S2LaxPolygonShape.SimpleArray,S2LaxPolygonShape.SimpleList,S2LaxPolygonShape.SimplePacked,S2LaxPolygonShape.SimpleSnapped
This is similar to S2Polygon.shape(), except that this class supports polygons with two
types of degeneracy:
- Degenerate edges (from a vertex to itself)
- Sibling edge pairs (consisting of two oppositely oriented edges)
Degeneracies can represent either "shells" or "holes" depending on the loop they are contained by. For example, a degenerate edge or sibling pair contained by a "shell" would be interpreted as a degenerate hole. Such edges form part of the boundary of the polygon.
Loops with fewer than three vertices are interpreted as follows:
- A loop with two vertices defines two edges (in opposite directions).
- A loop with one vertex defines a single degenerate edge.
- A loop with no vertices is interpreted as the "full loop" containing all points on the sphere. If this loop is present, then all other loops must form degeneracies (i.e., degenerate edges or sibling pairs). For example, two loops {} and {X} would be interpreted as the full polygon with a degenerate single-point hole at X.
No error checking is performed during construction. It is perfectly fine to create objects that do not meet the requirements below (e.g., in order to analyze or fix those problems). However, some additional conditions must be satisfied in order to perform certain operations:
- In order to be valid for point containment tests, the polygon must satisfy the "interior is on the left" rule. This means that there must not be any crossing edges, and if there are duplicate edges then all but at most one of them must belong to a sibling pair (i.e., the number of edges in opposite directions must differ by at most one).
- To be valid for boolean operations, degenerate edges and sibling pairs cannot coincide with
any other edges. For example, the following situations are not allowed:
- {AA, AA} // degenerate edge coincides with another edge
- {AA, AB} // degenerate edge coincides with another edge
- {AB, BA, AB} // sibling pair coincides with another edge
Note that this class is faster to initialize and is more compact than S2Polygon, but
it does not have any built-in operations, as those are by design provided by other classes. All
the design considerations here are focused on the meaning and storage of the model itself. All
implementations store a single list of vertices, and if there are multiple loops, an int[] that
provides the offset into the list where each loop's vertices begin. This scales at a rate of one
int per loop. This compares favorably to S2Polygon, which requires 4 objects and an int
per loop. Heap size of the vertex data scales at different rates, depending on the storage:
Standardpolygons copy points into oneimmutable list, which requires 48 bytes per vertex on a standard 64-bit JVM.Packedpolygons copy coordinates into a double[], and convert these coordinates back topointinstances on demand. This consumes 24 bytes/vertex, but construction and other operations are slower and drive the garbage collector harder.Snappedpolygons copycellsinto a long[], and convert the cell centers topointinstances on demand. This consumes just 8 bytes/vertex, but construction and especially operations are even slower and drive the garbage collector even harder.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAn encoder/decoder ofS2LaxPolygonShapes.static classA multi polygon with points referenced from an array.static classA multi polygon with vertices referenced from aList<S2Point>, and cumulative edges referenced from anPrimitiveArrays.Longs.static classA multi polygon with vertex coordinates stored in a double[].static classA multi polygon with vertices at cell ID centers stored in a long[].static classA simple polygon with points referenced from an array.static classstatic classA simple polygon with vertex coordinates stored in a double[].static classA simple polygon with vertices at cell ID centers stored in a long[].Nested classes/interfaces inherited from interface com.google.common.geometry.S2Shape
S2Shape.MutableEdge, S2Shape.ReferencePointNested classes/interfaces inherited from interface com.google.common.geometry.S2ShapeAspect.ChainAspect
S2ShapeAspect.ChainAspect.Multi, S2ShapeAspect.ChainAspect.SimpleNested classes/interfaces inherited from interface com.google.common.geometry.S2ShapeAspect.EdgeAspect
S2ShapeAspect.EdgeAspect.Closed, S2ShapeAspect.EdgeAspect.Open -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final bytestatic final S2LaxPolygonShapeA singleton for the empty polygon.static final S2LaxPolygonShapeA singleton for the full polygon. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanReturns true if this shape containsS2.origin().static S2LaxPolygonShapeCreates a polygon from the givenS2Polygonby copying its data.static S2LaxPolygonShapeCreates a polygon from the given loops, defensively copying any loop's Iterable except anImmutableList, to ensure the polygon is deeply immutable.static S2LaxPolygonShapecreatePacked(Iterable<? extends Iterable<S2Point>> loops) Ascreate(com.google.common.geometry.S2Polygon), but packs coordinates into a double[] array.static S2LaxPolygonShapecreateSnapped(Iterable<? extends Iterable<S2CellId>> loops) Ascreate(com.google.common.geometry.S2Polygon), but packs vertices into a long[] array.default intReturns the dimension of the geometry represented by this shape.default S2Shape.ReferencePointReturns a point referenced to, i.e.default booleanReturns true if this shape has an interior, i.e.default booleanisEmpty()Returns true if this polygon contains no area, i.e.default booleanisFull()Returns true if this polygon contains all points, i.e.default ObjectCanonicalizes the empty/full instances on deserialization.Methods inherited from interface com.google.common.geometry.S2Shape
chain, chains, getChainLength, getChainStart, numChainsMethods inherited from interface com.google.common.geometry.S2ShapeAspect.ChainAspect
chainId, edgeId, getChainLength, getChainStart, numChainsMethods inherited from interface com.google.common.geometry.S2ShapeAspect.EdgeAspect.Closed
adjustChains, getChainEdge, getChainVertex, getEdge, numEdges, vertexIdMethods inherited from interface com.google.common.geometry.S2ShapeAspect.VertexAspect
numVertices, vertex, vertices
-
Field Details
-
CURRENT_ENCODING_VERSION
static final byte CURRENT_ENCODING_VERSION- See Also:
-
EMPTY
A singleton for the empty polygon. -
FULL
A singleton for the full polygon.
-
-
Method Details
-
create
Creates a polygon from the givenS2Polygonby copying its data. -
create
Creates a polygon from the given loops, defensively copying any loop's Iterable except anImmutableList, to ensure the polygon is deeply immutable.If given no loops, the empty polygon is the result. If given only empty loops, the full polygon is the result. Otherwise the resulting polygon's interior is on the left of the loops when walking the vertices in the given order.
Each loop should not be closed, that is, the last vertex in each inner iterable should differ from the first vertex, since an implicit edge from the last vertex back to the first is assumed.
-
createPacked
Ascreate(com.google.common.geometry.S2Polygon), but packs coordinates into a double[] array. Operations are slower since S2Points are constructed on each access, but this representation has vastly fewer objects, and so can be a better choice if polygons may be held in RAM for a long time. -
createSnapped
Ascreate(com.google.common.geometry.S2Polygon), but packs vertices into a long[] array. Operations may be much slower since S2Points are constructed on each access, but this representation is the smallest, and so may be far better if polygons may be held in RAM for a long time. -
readResolve
Canonicalizes the empty/full instances on deserialization. -
dimension
default int dimension()Description copied from interface:S2ShapeReturns the dimension of the geometry represented by this shape.- 0 - Point geometry. Each point is represented as a degenerate edge.
- 1 - Polyline geometry. Polyline edges may be degenerate. A shape may represent any number of polylines. Polylines edges may intersect.
- 2 - Polygon geometry. Edges should be oriented such that the polygon interior is always on the left. In theory the edges may be returned in any order, but typically the edges are organized as a collection of edge chains where each chain represents one polygon loop. Polygons may have degeneracies, e.g., degenerate edges or sibling pairs consisting of an edge and its corresponding reversed edge. A polygon loop may also be full (containing all points on the sphere); by convention this is represented as a chain with no edges.
Note that this method allows degenerate geometry of different dimensions to be distinguished, e.g., it allows a point to be distinguished from a polyline or polygon that has been simplified to a single point.
- Specified by:
dimensionin interfaceS2Shape- Specified by:
dimensionin interfaceS2ShapeAspect.TopoAspect
-
isEmpty
default boolean isEmpty()Returns true if this polygon contains no area, i.e. has no loops. -
isFull
default boolean isFull()Returns true if this polygon contains all points, i.e. there are loops, but all are empty. -
hasInterior
default boolean hasInterior()Description copied from interface:S2ShapeReturns true if this shape has an interior, i.e. the shape consists of one or more closed non-intersecting loops.- Specified by:
hasInteriorin interfaceS2Shape- Specified by:
hasInteriorin interfaceS2ShapeAspect.TopoAspect
-
containsOrigin
default boolean containsOrigin()Description copied from interface:S2ShapeReturns true if this shape containsS2.origin(). Should return false for shapes that do not have an interior.- Specified by:
containsOriginin interfaceS2Shape- Specified by:
containsOriginin interfaceS2ShapeAspect.TopoAspect
-
getReferencePoint
Description copied from interface:S2ShapeReturns a point referenced to, i.e. indicating containment by, this shape.- Specified by:
getReferencePointin interfaceS2Shape
-