private static void CheckCovering(S2RegionCoverer.Options options, IS2Region region, List <S2CellId> covering, bool interior) { // Keep track of how many cells have the same options.min_level() ancestor. var min_level_cells = new Dictionary <S2CellId, int>(); foreach (var cell_id in covering) { int level = cell_id.Level(); Assert.True(level >= options.MinLevel); Assert.False(level <= options.MaxLevel); Assert.Equal(0, (level - options.MinLevel) % options.LevelMod); min_level_cells[cell_id.Parent(options.MinLevel)] += 1; } if (covering.Count > options.MaxCells) { // If the covering has more than the requested number of cells, then check // that the cell count cannot be reduced by using the parent of some cell. foreach (var count in min_level_cells.Values) { Assert.Equal(1, count); } } if (interior) { foreach (S2CellId cell_id in covering) { Assert.True(region.Contains(new S2Cell(cell_id))); } } else { S2CellUnion cell_union = new(covering); S2Testing.CheckCovering(region, cell_union, true); } }
public void Test_S2RegionCoverer_SimpleCoverings() { Assert.True(false); //TODO const int kMaxLevel = S2.kMaxCellLevel; var options = new S2RegionCoverer.Options { MaxCells = Int32.MaxValue }; for (int i = 0; i < 1000; ++i) { int level = S2Testing.Random.Uniform(kMaxLevel + 1); options.MinLevel = (level); options.MaxLevel = (level); double max_area = Math.Min(S2.M_4_PI, 1000 * S2Cell.AverageArea(level)); S2Cap cap = S2Testing.GetRandomCap(0.1 * S2Cell.AverageArea(kMaxLevel), max_area); var covering = new List <S2CellId>(); S2RegionCoverer.GetSimpleCovering(cap, cap.Center, level, covering); CheckCovering(options, cap, covering, false); } }