// Construct the child of "parent" with the given (i,j) index. The four // child cells have indices of (0,0), (0,1), (1,0), (1,1), where the i and j // indices correspond to increasing u- and v-values respectively. public S2PaddedCell(S2PaddedCell parent, int i, int j) { ij_lo_ = new int[2]; Padding = parent.Padding; Level = parent.Level + 1; // Compute the position and orientation of the child incrementally from the // orientation of the parent. int pos = S2.kIJtoPos[parent.orientation_][2 * i + j]; Id = parent.Id.Child(pos); int ij_size = S2CellId.SizeIJ(Level); ij_lo_[0] = parent.ij_lo_[0] + i * ij_size; ij_lo_[1] = parent.ij_lo_[1] + j * ij_size; orientation_ = parent.orientation_ ^ S2.kPosToOrientation[pos]; // For each child, one corner of the bound is taken directly from the parent // while the diagonally opposite corner is taken from middle(). var middle = parent.Middle; var x = new double[] { parent.Bound[0][0], parent.Bound[0][1] }; var y = new double[] { parent.Bound[1][0], parent.Bound[1][1] }; x[1 - i] = middle[0][1 - i]; y[1 - j] = middle[1][1 - j]; Bound = new R2Rect(new R1Interval(x), new R1Interval(y)); }
private static void CompareS2CellToPadded(S2Cell cell, S2PaddedCell pcell, double padding) { Assert.Equal(cell.Id, pcell.Id); Assert.Equal(cell.Level, pcell.Level); Assert.Equal(padding, pcell.Padding); Assert.Equal(cell.BoundUV.Expanded(padding), pcell.Bound); var center_uv = cell.Id.CenterUV(); Assert.Equal(R2Rect.FromPoint(center_uv).Expanded(padding), pcell.Middle); Assert.Equal(cell.Center(), pcell.GetCenter()); }
// 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); }