Example #1
0
        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);
            }
        }
        /**
         * Checks that "covering" completely covers the given region. If "check_tight"
         * is true, also checks that it does not contain any cells that do not
         * intersect the given region. ("id" is only used internally.)
         */

        protected void checkCovering(IS2Region region, S2CellUnion covering, bool checkTight, S2CellId id)
        {
            if (!id.IsValid)
            {
                for (var face = 0; face < 6; ++face)
                {
                    checkCovering(region, covering, checkTight, S2CellId.FromFacePosLevel(face, 0, 0));
                }
                return;
            }

            if (!region.MayIntersect(new S2Cell(id)))
            {
                // If region does not intersect id, then neither should the covering.
                if (checkTight)
                {
                    Assert.True(!covering.Intersects(id));
                }
            }
            else if (!covering.Contains(id))
            {
                // The region may intersect id, but we can't assert that the covering
                // intersects id because we may discover that the region does not actually
                // intersect upon further subdivision. (MayIntersect is not exact.)
                Assert.True(!region.Contains(new S2Cell(id)));
                var result = !id.IsLeaf;
                Assert.True(result);
                var end = id.ChildEnd;
                for (var child = id.ChildBegin; !child.Equals(end); child = child.Next)
                {
                    checkCovering(region, covering, checkTight, child);
                }
            }
        }
        public void checkCovering(
            S2RegionCoverer coverer, IS2Region region, List <S2CellId> covering, bool interior)
        {
            // Keep track of how many cells have the same coverer.min_level() ancestor.
            IDictionary <S2CellId, int> minLevelCells = new Dictionary <S2CellId, int>();

            for (var i = 0; i < covering.Count; ++i)
            {
                var level = covering[i].Level;
                assertTrue(level >= coverer.MinLevel);
                assertTrue(level <= coverer.MaxLevel);
                assertEquals((level - coverer.MinLevel) % coverer.LevelMod, 0);
                var key = covering[i].ParentForLevel(coverer.MinLevel);
                if (!minLevelCells.ContainsKey(key))
                {
                    minLevelCells.Add(key, 1);
                }
                else
                {
                    minLevelCells[key] = minLevelCells[key] + 1;
                }
            }
            if (covering.Count > coverer.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 i in minLevelCells.Values)
                {
                    assertEquals(i, 1);
                }
            }

            if (interior)
            {
                for (var i = 0; i < covering.Count; ++i)
                {
                    assertTrue(region.Contains(new S2Cell(covering[i])));
                }
            }
            else
            {
                var cellUnion = new S2CellUnion();
                cellUnion.InitFromCellIds(covering);
                checkCovering(region, cellUnion, true, new S2CellId());
            }
        }
        public void checkCovering(
            S2RegionCoverer coverer, IS2Region region, List<S2CellId> covering, bool interior)
        {
            // Keep track of how many cells have the same coverer.min_level() ancestor.
            IDictionary<S2CellId, int> minLevelCells = new Dictionary<S2CellId, int>();
            for (var i = 0; i < covering.Count; ++i)
            {
                var level = covering[i].Level;
                assertTrue(level >= coverer.MinLevel);
                assertTrue(level <= coverer.MaxLevel);
                assertEquals((level - coverer.MinLevel)%coverer.LevelMod, 0);
                var key = covering[i].ParentForLevel(coverer.MinLevel);
                if (!minLevelCells.ContainsKey(key))
                {
                    minLevelCells.Add(key, 1);
                }
                else
                {
                    minLevelCells[key] = minLevelCells[key] + 1;
                }
            }
            if (covering.Count > coverer.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 i in minLevelCells.Values)
                {
                    assertEquals(i, 1);
                }
            }

            if (interior)
            {
                for (var i = 0; i < covering.Count; ++i)
                {
                    assertTrue(region.Contains(new S2Cell(covering[i])));
                }
            }
            else
            {
                var cellUnion = new S2CellUnion();
                cellUnion.InitFromCellIds(covering);
                checkCovering(region, cellUnion, true, new S2CellId());
            }
        }
        /**
         * Checks that "covering" completely covers the given region. If "check_tight"
         * is true, also checks that it does not contain any cells that do not
         * intersect the given region. ("id" is only used internally.)
         */

        protected void checkCovering(IS2Region region, S2CellUnion covering, bool checkTight, S2CellId id)
        {
            if (!id.IsValid)
            {
                for (var face = 0; face < 6; ++face)
                {
                    checkCovering(region, covering, checkTight, S2CellId.FromFacePosLevel(face, 0, 0));
                }
                return;
            }

            if (!region.MayIntersect(new S2Cell(id)))
            {
                // If region does not intersect id, then neither should the covering.
                if (checkTight)
                {
                    Assert.True(!covering.Intersects(id));
                }
            }
            else if (!covering.Contains(id))
            {
                // The region may intersect id, but we can't assert that the covering
                // intersects id because we may discover that the region does not actually
                // intersect upon further subdivision. (MayIntersect is not exact.)
                Assert.True(!region.Contains(new S2Cell(id)));
                var result = !id.IsLeaf;
                Assert.True(result);
                var end = id.ChildEnd;
                for (var child = id.ChildBegin; !child.Equals(end); child = child.Next)
                {
                    checkCovering(region, covering, checkTight, child);
                }
            }
        }