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