private static void GatherStats(S2Cell cell) { var s = level_stats[cell.Level]; double exact_area = cell.ExactArea(); double approx_area = cell.ApproxArea(); double min_edge = 100, max_edge = 0, avg_edge = 0; double min_diag = 100, max_diag = 0; double min_width = 100, max_width = 0; double min_angle_span = 100, max_angle_span = 0; for (int i = 0; i < 4; ++i) { double edge = cell.VertexRaw(i).Angle(cell.VertexRaw(i + 1)); min_edge = Math.Min(edge, min_edge); max_edge = Math.Max(edge, max_edge); avg_edge += 0.25 * edge; S2Point mid = cell.VertexRaw(i) + cell.VertexRaw(i + 1); double width = S2.M_PI_2 - mid.Angle(cell.EdgeRaw(i + 2)); min_width = Math.Min(width, min_width); max_width = Math.Max(width, max_width); if (i < 2) { double diag = cell.VertexRaw(i).Angle(cell.VertexRaw(i + 2)); min_diag = Math.Min(diag, min_diag); max_diag = Math.Max(diag, max_diag); double angle_span = cell.EdgeRaw(i).Angle(-cell.EdgeRaw(i + 2)); min_angle_span = Math.Min(angle_span, min_angle_span); max_angle_span = Math.Max(angle_span, max_angle_span); } } s.Count += 1; s.Min_area = Math.Min(exact_area, s.Min_area); s.Max_area = Math.Max(exact_area, s.Max_area); s.Avg_area += exact_area; s.Min_width = Math.Min(min_width, s.Min_width); s.Max_width = Math.Max(max_width, s.Max_width); s.Avg_width += 0.5 * (min_width + max_width); s.Min_edge = Math.Min(min_edge, s.Min_edge); s.Max_edge = Math.Max(max_edge, s.Max_edge); s.Avg_edge += avg_edge; s.Max_edge_aspect = Math.Max(max_edge / min_edge, s.Max_edge_aspect); s.Min_diag = Math.Min(min_diag, s.Min_diag); s.Max_diag = Math.Max(max_diag, s.Max_diag); s.Avg_diag += 0.5 * (min_diag + max_diag); s.Max_diag_aspect = Math.Max(max_diag / min_diag, s.Max_diag_aspect); s.Min_angle_span = Math.Min(min_angle_span, s.Min_angle_span); s.Max_angle_span = Math.Max(max_angle_span, s.Max_angle_span); s.Avg_angle_span += 0.5 * (min_angle_span + max_angle_span); double approx_ratio = approx_area / exact_area; s.Min_approx_ratio = Math.Min(approx_ratio, s.Min_approx_ratio); s.Max_approx_ratio = Math.Max(approx_ratio, s.Max_approx_ratio); }
private static void TestCellOps(S2LatLngRect r, S2Cell cell, int level) { // Test the relationship between the given rectangle and cell: // 0 == no intersection, 1 == MayIntersect, 2 == Intersects, // 3 == Vertex Containment, 4 == Contains bool vertex_contained = false; for (int i = 0; i < 4; ++i) { if (r.Contains(cell.VertexRaw(i)) || (!r.IsEmpty() && cell.Contains(r.Vertex(i).ToPoint()))) { vertex_contained = true; } } Assert.Equal(r.MayIntersect(cell), level >= 1); Assert.Equal(r.Intersects(cell), level >= 2); Assert.Equal(vertex_contained, level >= 3); Assert.Equal(r.Contains(cell), level >= 4); }