Package com.google.common.geometry
Class S2EdgeQuery
- java.lang.Object
-
- com.google.common.geometry.S2EdgeQuery
-
@GwtCompatible public class S2EdgeQuery extends Object
S2EdgeQuery is used to find edges or shapes that are crossed by an edge. If you need to query many edges, it is more efficient to declare a single S2EdgeQuery object and reuse it so that temporary storage does not need to be reallocated each time.Here is an example showing how to index a set of polylines, and then find the polylines that are crossed by a given edge AB:
void test(Collection
polylines, S2Point a0, S2Point a1) { S2ShapeIndex index = new S2ShapeIndex(); for (int i = 0; i < polylines.size(); ++i) { index.add(polylines[i]); } S2EdgeQuery query = new S2EdgeQuery(index); Map results = query.getCrossings(a, b); for (Map.Entry entry : results.entrySet()) { S2Polyline polyline = (S2Polyline) entry.getKey(); for (Edges edges = entry.getValue(); !edges.isEmpty(); ) { int edge = edges.getNext(); S2Point b0 = polyline.vertex(edge); S2Point b1 = polyline.vertex(edge + 1); // Guaranteed that each resulting edge is either a crossing or a degenerate crossing. assertTrue(S2EdgeUtil.robustCrossing(a0, a1, b0, b1) >= 0); } } } Note that if you need to query many edges, it is more efficient to declare a single S2EdgeQuery object and reuse it so that temporary storage does not need to be reallocated each time.
This class is not thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceS2EdgeQuery.EdgesAn iterator over the sorted unique edge IDs of a shape that may intersect some query edge.static classS2EdgeQuery.ShapeEdgesAnEdgesthat contains all the edges of a shape with the given number of edges.
-
Constructor Summary
Constructors Constructor Description S2EdgeQuery(S2ShapeIndex index)Constructor from anS2ShapeIndex.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<S2Shape,S2EdgeQuery.Edges>getCandidates(S2Point a, S2Point b)Given a query edge AB, returns a map from the indexed shapes to a superset of the edges for each shape that intersect AB.S2EdgeQuery.EdgesgetCandidates(S2Point a, S2Point b, S2Shape shape)Given a query edge AB and a shapeshape, returns a superset of the edges ofshapethat intersect AB.booleangetCells(S2Point a, S2Point b, S2PaddedCell root, List<S2ShapeIndex.Cell> cells)Convenience method for callinggetCells(S2Point, R2Vector, S2Point, R2Vector, S2PaddedCell, List).Map<S2Shape,S2EdgeQuery.Edges>getCrossings(S2Point a, S2Point b)Returns edges for each shape that either crosses AB or shares a vertex with AB.S2EdgeQuery.EdgesgetCrossings(S2Point a, S2Point b, S2Shape shape)Returns edges from a given shape that either cross AB or share a vertex with AB.
-
-
-
Constructor Detail
-
S2EdgeQuery
public S2EdgeQuery(S2ShapeIndex index)
Constructor from anS2ShapeIndex.
-
-
Method Detail
-
getCrossings
public S2EdgeQuery.Edges getCrossings(S2Point a, S2Point b, S2Shape shape)
Returns edges from a given shape that either cross AB or share a vertex with AB.
-
getCrossings
public Map<S2Shape,S2EdgeQuery.Edges> getCrossings(S2Point a, S2Point b)
Returns edges for each shape that either crosses AB or shares a vertex with AB.
-
getCandidates
public S2EdgeQuery.Edges getCandidates(S2Point a, S2Point b, S2Shape shape)
Given a query edge AB and a shapeshape, returns a superset of the edges ofshapethat intersect AB. Consider usingS2EdgeQuery.ShapeEdgesinstead, if the shape has few enough edges.
-
getCandidates
public Map<S2Shape,S2EdgeQuery.Edges> getCandidates(S2Point a, S2Point b)
Given a query edge AB, returns a map from the indexed shapes to a superset of the edges for each shape that intersect AB. Consider usingS2EdgeQuery.ShapeEdgesinstead, if there is just one indexed shape with few enough edges.CAVEAT: This method may return shapes that have an empty set of candidate edges, i.e.
result.get(shape).isEmpty() == true.
-
getCells
public boolean getCells(S2Point a, S2Point b, S2PaddedCell root, List<S2ShapeIndex.Cell> cells)
Convenience method for callinggetCells(S2Point, R2Vector, S2Point, R2Vector, S2PaddedCell, List).
-
-