/// <summary> /// Visits all crossings of the current edge with all edges of the given index /// cell of B. Terminates early and returns false if visitor_ returns false. /// </summary> private bool VisitEdgeCellCrossings(ShapeEdge a, S2ShapeIndexCell b_cell) { // Test the current edge of A against all edges of "b_cell". // Note that we need to use a new S2EdgeCrosser (or call Init) whenever we // replace the contents of b_shape_edges_, since S2EdgeCrosser requires that // its S2Point arguments point to values that persist between Init() calls. GetShapeEdges(b_index_, b_cell, b_shape_edges_); var crosser = new S2EdgeCrosser(a.V0, a.V1); foreach (var b in b_shape_edges_) { if (crosser.C == S2Point.Empty || crosser.C != b.V0) { crosser.RestartAt(b.V0); } int sign = crosser.CrossingSign(b.V1); if (sign >= min_crossing_sign_) { if (!VisitEdgePair(a, b, sign == 1)) { return(false); } } } return(true); }
/// <summary> /// Given two index cells, visits all crossings between edges of those cells. /// Terminates early and returns false if visitor_ returns false. /// </summary> public bool VisitCellCellCrossings(S2ShapeIndexCell a_cell, S2ShapeIndexCell b_cell) { // Test all edges of "a_cell" against all edges of "b_cell". GetShapeEdges(a_index_, a_cell, a_shape_edges_); GetShapeEdges(b_index_, b_cell, b_shape_edges_); return(VisitEdgesEdgesCrossings(a_shape_edges_, b_shape_edges_)); }
/// <summary> /// Appends all edges in the given S2ShapeIndexCell to the given vector. /// </summary> private static void AppendShapeEdges(S2ShapeIndex index, S2ShapeIndexCell cell, ShapeEdgeVector shape_edges) { for (int s = 0; s < cell.NumClipped(); ++s) { var clipped = cell.Clipped(s); var shape = index.Shape(clipped.ShapeId); var num_edges = clipped.NumEdges; for (int i = 0; i < num_edges; i++) { shape_edges.Add(new ShapeEdge(shape, clipped.Edge(i))); } } }
// Visits all crossings of any edge in "a_cell" with any index cell of B that // is a descendant of "b_id". Terminates early and returns false if // visitor_ returns false. private bool VisitSubcellCrossings(S2ShapeIndexCell a_cell, S2CellId b_id) { // Test all edges of "a_cell" against the edges contained in B index cells // that are descendants of "b_id". GetShapeEdges(a_index_, a_cell, a_shape_edges_); var b_root = new S2PaddedCell(b_id, 0); foreach (var a in a_shape_edges_) { // Use an S2CrossingEdgeQuery starting at "b_root" to find the index cells // of B that might contain crossing edges. var result = b_query_.VisitCells(a.V0, a.V1, b_root, (S2ShapeIndexCell cell) => VisitEdgeCellCrossings(a, cell)); if (!result) { return(false); } } return(true); }
/// <summary> /// Returns a vector containing all edges in the given S2ShapeIndexCell. /// (The result is returned as an output parameter so that the same storage can /// be reused, rather than allocating a new temporary vector each time.) /// </summary> private static void GetShapeEdges(S2ShapeIndex index, S2ShapeIndexCell cell, ShapeEdgeVector shape_edges) { shape_edges.Clear(); AppendShapeEdges(index, cell, shape_edges); }