public void TestCount()
        {
            CoverFieldTree <Rect> coverFieldTree = new CoverFieldTree <Rect>(16, 16, 0.3, 0, 0, 1);
            List <Rect>           rects          = new List <Rect>()
            {
                new Rect(new Point(1, 1), new Size(1, 1)),
                new Rect(new Point(3, 3), new Size(1, 1)),
                new Rect(new Point(-3, 2), new Size(1, 1)),
                new Rect(new Point(-1, 0), new Size(1, 1)),
                new Rect(new Point(-2, -2), new Size(1, 1)),
                new Rect(new Point(2, -2), new Size(1, 1)),
                new Rect(new Point(3, -3), new Size(1, 1))
            };

            coverFieldTree.AddMany(rects);
            Assert.AreEqual(coverFieldTree.Count(), 7);

            int totalNum = 7;

            foreach (var item in rects)
            {
                coverFieldTree.Remove(item);
                totalNum -= 1;
                Assert.AreEqual(coverFieldTree.Count(), totalNum);
            }
            Assert.AreEqual(coverFieldTree.IsEmpty(), true);
        }
        public void TestRangeQuery()
        {
            CoverFieldTree <Rect> coverFieldTree = new CoverFieldTree <Rect>(10, 10, 0.3, 0, 0, 1);
            List <Rect>           rects          = new List <Rect>()
            {
                new Rect(new Point(1, 1), new Size(1, 1)),
                new Rect(new Point(3, 3), new Size(1, 1)),
                new Rect(new Point(-3, 2), new Size(1, 1)),
                new Rect(new Point(-1, 0), new Size(1, 1)),
                new Rect(new Point(-2, -2), new Size(1, 1)),
                new Rect(new Point(2, -2), new Size(1, 1)),
                new Rect(new Point(3, -3), new Size(1, 1))
            };

            coverFieldTree.AddMany(rects);
            Assert.AreEqual(coverFieldTree.IsEmpty(), false);

            var r1 = coverFieldTree.RangeQuery(0, 0, 3);

            Assert.AreEqual(r1.Count, 2);

            var r2 = coverFieldTree.RangeQuery(0, 0, 3, 2);

            Assert.AreEqual(r2.Count, 1);

            var r3 = coverFieldTree.RangeQuery(-1, 0, 4, 10);

            Assert.AreEqual(r3.Count, 2);
        }
        public void TestAddMultipleRectangles()
        {
            CoverFieldTree <Rect> coverFieldTree = new CoverFieldTree <Rect>(10, 10, 0.3);
            List <Rect>           rects          = new List <Rect>()
            {
                new Rect(new Point(1, 1), new Size(1, 1)),
                new Rect(new Point(3, 3), new Size(1, 1)),
                new Rect(new Point(-3, 2), new Size(1, 1)),
                new Rect(new Point(-1, 0), new Size(1, 1)),
                new Rect(new Point(-2, -2), new Size(1, 1)),
                new Rect(new Point(2, -2), new Size(1, 1)),
                new Rect(new Point(3, -3), new Size(1, 1))
            };

            coverFieldTree.AddMany(rects);
            Assert.AreEqual(coverFieldTree.IsEmpty(), false);
            var r = coverFieldTree.FindNearestObjects(0, 0);

            Assert.AreEqual(r.Count, 1);
            Assert.AreEqual(r[0].Equals(new Rect(new Point(-1, 0), new Size(1, 1))), true);

            r = coverFieldTree.FindNearestObjects(2, 0);
            Assert.AreEqual(r.Count, 1);
            Assert.AreEqual(r[0].Equals(new Rect(new Point(1, 1), new Size(1, 1))), true);
        }
        public void TestAll()
        {
            CoverFieldTree <Rect> coverFieldTree = new CoverFieldTree <Rect>(16, 16, 0.3, 0, 0, 1);
            List <Rect>           rects          = new List <Rect>()
            {
                new Rect(new Point(1, 1), new Size(1, 1)),
                new Rect(new Point(3, 3), new Size(1, 1)),
                new Rect(new Point(-3, 2), new Size(1, 1)),
                new Rect(new Point(-1, 0), new Size(1, 1)),
                new Rect(new Point(-2, -2), new Size(1, 1)),
                new Rect(new Point(2, -2), new Size(1, 1)),
                new Rect(new Point(3, -3), new Size(1, 1))
            };

            coverFieldTree.AddMany(rects);
            Assert.AreEqual(coverFieldTree.IsEmpty(), false);

            var r1 = coverFieldTree.All();

            Assert.AreEqual(r1.Count, 7);
        }
        public void TestINN()
        {
            CoverFieldTree <Rect> coverFieldTree = new CoverFieldTree <Rect>(10, 10, 0.3, 0, 0, 1);
            List <Rect>           rects          = new List <Rect>()
            {
                new Rect(new Point(1, 1), new Size(1, 1)),
                new Rect(new Point(3, 3), new Size(1, 1)),
                new Rect(new Point(-3, 2), new Size(1, 1)),
                new Rect(new Point(-1, 0), new Size(1, 1)),
                new Rect(new Point(-2, -2), new Size(1, 1)),
                new Rect(new Point(2, -2), new Size(1, 1)),
                new Rect(new Point(3, -3), new Size(1, 1))
            };

            coverFieldTree.AddMany(rects);
            Assert.AreEqual(coverFieldTree.IsEmpty(), false);

            coverFieldTree.InitIncrementalNearestNeighbor(0, 0);
            var r = coverFieldTree.IncrementalNearestNeighborFindNext();

            Assert.AreEqual(r.Equals(new Rect(new Point(-1, 0), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r.Equals(new Rect(new Point(1, 1), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r.Equals(new Rect(new Point(2, -2), new Size(1, 1))) || r.Equals(new Rect(new Point(-2, -2), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r.Equals(new Rect(new Point(2, -2), new Size(1, 1))) || r.Equals(new Rect(new Point(-2, -2), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r.Equals(new Rect(new Point(-3, 2), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r.Equals(new Rect(new Point(3, 3), new Size(1, 1))) || r.Equals(new Rect(new Point(3, -3), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r.Equals(new Rect(new Point(3, 3), new Size(1, 1))) || r.Equals(new Rect(new Point(3, -3), new Size(1, 1))), true);
            r = coverFieldTree.IncrementalNearestNeighborFindNext();
            Assert.AreEqual(r, null);
        }