Class S2ShapeUtil.S2EdgeVectorShape
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<S2Edge>
-
- com.google.common.geometry.S2ShapeUtil.S2EdgeVectorShape
-
- All Implemented Interfaces:
S2Shape
,java.lang.Iterable<S2Edge>
,java.util.Collection<S2Edge>
,java.util.List<S2Edge>
- Enclosing class:
- S2ShapeUtil
static class S2ShapeUtil.S2EdgeVectorShape extends java.util.AbstractList<S2Edge> implements S2Shape
S2EdgeVectorShape is an S2Shape representing a set of unrelated edges. It contains no area and has no interior. Although it implements List, only the add(S2Point, S2Point)
method can mutate the list of edges.It is mainly used for testing, but it can also be useful if you have, say, a collection of polylines and don't care about memory efficiency (since this class would store most of the vertices twice.) If the vertices are already stored somewhere else, you would be better off writing your own subclass of S2Shape that points to the existing vertex data rather than copying it.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.common.geometry.S2Shape
S2Shape.MutableEdge, S2Shape.ReferencePoint
-
-
Constructor Summary
Constructors Constructor Description S2EdgeVectorShape()
Default constructor creates a vector with no edges.S2EdgeVectorShape(S2Point a, S2Point b)
Convenience constructor for creating a vector of length 1.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(S2Point a, S2Point b)
Adds an edge to the vector.boolean
containsOrigin()
Returns true if this shape containsS2.origin()
.int
dimension()
Returns the dimension of the geometry represented by this shape.S2Edge
get(int index)
void
getChainEdge(int chainId, int offset, S2Shape.MutableEdge result)
Returns the edge for the given chain id and offset inresult
.int
getChainLength(int chainId)
Returns the number of edge ids corresponding to the edge chain for the given chain id.int
getChainStart(int chainId)
Returns the first edge id corresponding to the edge chain for the given chain id.S2Point
getChainVertex(int chainId, int edgeOffset)
Returns the start point of the edge that would be returned byS2Shape.getChainEdge(int, int, com.google.common.geometry.S2Shape.MutableEdge)
, or the endpoint of the last edge ifedgeOffset==getChainLength(chainId)
.void
getEdge(int index, S2Shape.MutableEdge result)
Returns the edge for the given index inresult
.boolean
hasInterior()
Returns true if this shape has an interior, i.e.int
numChains()
Returns the number of contiguous edge chains in the shape.int
numEdges()
Returns the number of edges in this shape.int
size()
-
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Methods inherited from interface com.google.common.geometry.S2Shape
chain, chains, getReferencePoint
-
-
-
-
Field Detail
-
edges
private final java.util.List<S2Edge> edges
-
-
Method Detail
-
getEdge
public void getEdge(int index, S2Shape.MutableEdge result)
Description copied from interface:S2Shape
Returns the edge for the given index inresult
. Must not return zero-length edges.- Specified by:
getEdge
in interfaceS2Shape
- Parameters:
index
- which edge to set intoresult
, from 0 toS2Shape.numEdges()
- 1
-
hasInterior
public boolean hasInterior()
Description copied from interface:S2Shape
Returns true if this shape has an interior, i.e. the shape consists of one or more closed non-intersecting loops.- Specified by:
hasInterior
in interfaceS2Shape
-
containsOrigin
public boolean containsOrigin()
Description copied from interface:S2Shape
Returns true if this shape containsS2.origin()
. Should return false for shapes that do not have an interior.- Specified by:
containsOrigin
in interfaceS2Shape
-
numEdges
public int numEdges()
Description copied from interface:S2Shape
Returns the number of edges in this shape.
-
numChains
public int numChains()
Description copied from interface:S2Shape
Returns the number of contiguous edge chains in the shape. For example, a shape whose edges are [AB, BC, CD, AE, EF] may consist of two chains [A, B, C, D] and [A, E, F]. Every chain is assigned a chain id numbered sequentially starting from zero.An empty shape has no chains. A full shape (which contains the entire globe) has one chain with no edges. Other shapes should have at least one chain, and the sum of all valid
chain lengths
should equalS2Shape.numEdges()
(that is, edges may only be used by a single chain).Note that it is always acceptable to implement this method by returning
S2Shape.numEdges()
(i.e. every chain consists of a single edge), but this may reduce the efficiency of some algorithms.
-
getChainStart
public int getChainStart(int chainId)
Description copied from interface:S2Shape
Returns the first edge id corresponding to the edge chain for the given chain id. The edge chains must form contiguous, non-overlapping ranges that cover the entire range of edge ids.- Specified by:
getChainStart
in interfaceS2Shape
- Parameters:
chainId
- which edge chain to return its start, from 0 toS2Shape.numChains()
- 1
-
getChainLength
public int getChainLength(int chainId)
Description copied from interface:S2Shape
Returns the number of edge ids corresponding to the edge chain for the given chain id. The edge chains must form contiguous, non-overlapping ranges that cover the entire range of edge ids.- Specified by:
getChainLength
in interfaceS2Shape
- Parameters:
chainId
- which edge chain to return its length, from 0 toS2Shape.numChains()
- 1
-
getChainEdge
public void getChainEdge(int chainId, int offset, S2Shape.MutableEdge result)
Description copied from interface:S2Shape
Returns the edge for the given chain id and offset inresult
. Must not return zero-length edges.- Specified by:
getChainEdge
in interfaceS2Shape
- Parameters:
chainId
- which chain contains the edge to return, from 0 toS2Shape.numChains()
- 1offset
- position from chain start for the edge to return, from 0 toS2Shape.getChainLength(int)
- 1
-
getChainVertex
public S2Point getChainVertex(int chainId, int edgeOffset)
Description copied from interface:S2Shape
Returns the start point of the edge that would be returned byS2Shape.getChainEdge(int, int, com.google.common.geometry.S2Shape.MutableEdge)
, or the endpoint of the last edge ifedgeOffset==getChainLength(chainId)
.- Specified by:
getChainVertex
in interfaceS2Shape
-
dimension
public int dimension()
Description copied from interface:S2Shape
Returns 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.
-
get
public S2Edge get(int index)
-
-