Beispiel #1
0
        public void RootLeafSplitWorks()
        {
            var data = GetPoints(12);

            var tree = new RBush <Point>();

            for (var i = 0; i < 9; i++)
            {
                tree.Insert(data[i]);
            }

            Assert.Equal(1, tree.Root.Height);
            Assert.Equal(9, tree.Root.children.Count);
            Assert.True(tree.Root.IsLeaf);

            Assert.Equal(0, tree.Root.Envelope.MinX);
            Assert.Equal(0, tree.Root.Envelope.MinY);
            Assert.Equal(8, tree.Root.Envelope.MaxX);
            Assert.Equal(8, tree.Root.Envelope.MaxY);

            tree.Insert(data[9]);

            Assert.Equal(2, tree.Root.Height);
            Assert.Equal(2, tree.Root.children.Count);
            Assert.False(tree.Root.IsLeaf);

            Assert.Equal(0, tree.Root.Envelope.MinX);
            Assert.Equal(0, tree.Root.Envelope.MinY);
            Assert.Equal(9, tree.Root.Envelope.MaxX);
            Assert.Equal(9, tree.Root.Envelope.MaxY);
        }
Beispiel #2
0
        public void TestSearchAfterInsertWithSplitRoot()
        {
            var maxEntries = 4;
            var tree       = new RBush <Point>(maxEntries);

            var numFirstSet = maxEntries * maxEntries + 2;              // Split-root will occur twice.
            var firstSet    = points.Take(numFirstSet);

            foreach (var p in firstSet)
            {
                tree.Insert(p);
            }

            var numExtraPoints         = 5;
            var extraPointsSet         = points.Skip(points.Length - numExtraPoints);
            var extraPointsSetEnvelope =
                extraPointsSet.Aggregate(Envelope.EmptyBounds, (e, p) => e.Extend(p.Envelope));

            foreach (var p in extraPointsSet)
            {
                tree.Insert(p);
            }

            // first 10 entries and last 5 entries are completely mutually exclusive
            // so searching the bounds of the new set should only return the new set exactly
            Assert.Equal(extraPointsSet.OrderBy(x => x), tree.Search(extraPointsSetEnvelope).OrderBy(x => x));
        }
Beispiel #3
0
        public void TestSearch_AfterInsertWithSplitRoot()
        {
            int maxEntries = 4;
            var tree       = new RBush <Point>(maxEntries);

            int      numFirstSet      = maxEntries * maxEntries + 2;   // Split-root will occur twice.
            var      firstSet         = points.Take(numFirstSet);
            Envelope firstSetEnvelope =
                new Envelope(
                    firstSet.Min(p => p.Envelope.MinX),
                    firstSet.Min(p => p.Envelope.MinY),
                    firstSet.Max(p => p.Envelope.MaxX),
                    firstSet.Max(p => p.Envelope.MaxY));

            foreach (var p in firstSet)
            {
                tree.Insert(p);
            }

            int      numExtraPoints         = 5;
            var      extraPointsSet         = points.TakeLast(numExtraPoints);
            Envelope extraPointsSetEnvelope =
                new Envelope(
                    extraPointsSet.Min(p => p.Envelope.MinX),
                    extraPointsSet.Min(p => p.Envelope.MinY),
                    extraPointsSet.Max(p => p.Envelope.MaxX),
                    extraPointsSet.Max(p => p.Envelope.MaxY));

            foreach (var p in extraPointsSet)
            {
                tree.Insert(p);
            }

            Assert.Equal(extraPointsSet.OrderBy(x => x), tree.Search(extraPointsSetEnvelope).OrderBy(x => x));
        }
Beispiel #4
0
 public void BodyAdd(Body body)
 {
     Bodies.Add(body);
     if (body.IsStatic)
     {
         RTreeStatic.Insert(body);
     }
 }
Beispiel #5
0
        public void Delete_DeletingLastPoint_ShouldNotThrow()
        {
            var   tree = new RBush <Point>();
            Point p    = new Point(1, 1, 1, 1);

            tree.Insert(p);

            tree.Delete(p);

            Assert.Equal(0, tree.Count);
        }
Beispiel #6
0
        public void InsertTestData()
        {
            var tree = new RBush <Point>();

            foreach (var p in points)
            {
                tree.Insert(p);
            }

            Assert.Equal(points.Length, tree.Count);
            Assert.Equal(points.OrderBy(x => x), tree.Search().OrderBy(x => x));
        }
Beispiel #7
0
        public void InsertAfterDeleteTest2()
        {
            var pts       = GetPoints(20);
            var ptsDelete = pts.Take(4);
            var tree      = new RBush <Point>(maxEntries: 4);

            foreach (var item in pts)
            {
                tree.Insert(item);
            }

            foreach (var item in ptsDelete)
            {
                tree.Delete(item);
            }

            foreach (var item in ptsDelete)
            {
                tree.Insert(item);
            }

            Assert.Equal(pts.Count, tree.Search().Count);
            Assert.Equal(pts.OrderBy(x => x).ToList(), tree.Search().OrderBy(x => x).ToList());
        }
Beispiel #8
0
        public void TestSearchAfterInsert()
        {
            var maxEntries = 9;
            var tree       = new RBush <Point>(maxEntries);

            var firstSet         = points.Take(maxEntries);
            var firstSetEnvelope =
                firstSet.Aggregate(Envelope.EmptyBounds, (e, p) => e.Extend(p.Envelope));

            foreach (var p in firstSet)
            {
                tree.Insert(p);
            }

            Assert.Equal(firstSet.OrderBy(x => x), tree.Search(firstSetEnvelope).OrderBy(x => x));
        }
Beispiel #9
0
        public void InsertTestData()
        {
            var tree = new RBush <Point>();

            foreach (var p in points)
            {
                tree.Insert(p);
            }

            Assert.Equal(points.Length, tree.Count);
            Assert.Equal(points.OrderBy(x => x), tree.Search().OrderBy(x => x));

            Assert.Equal(
                points.Aggregate(Envelope.EmptyBounds, (e, p) => e.Extend(p.Envelope)),
                tree.Envelope);
        }
Beispiel #10
0
        public void AdditionalRemoveTest()
        {
            var tree      = new RBush <Point>();
            var numDelete = 18;

            foreach (var p in points)
            {
                tree.Insert(p);
            }

            foreach (var p in points.Take(numDelete))
            {
                tree.Delete(p);
            }

            Assert.Equal(points.Length - numDelete, tree.Count);
            Assert.Equal(points.Skip(numDelete).OrderBy(x => x), tree.Search().OrderBy(x => x));
        }
Beispiel #11
0
        public void MissingEnvelopeTestInsertIndividually()
        {
            var tree = new RBush <Point>();

            foreach (var p in missingEnvelopeTestData)
            {
                tree.Insert(p);
            }

            var envelope = new Envelope(
                minX: 34.73274678,
                minY: 31.87729923,
                maxX: 34.73274678,
                maxY: 31.87729923);

            Assert.Equal(
                expected: tree.Search().Where(p => p.Envelope.Intersects(envelope)).Count(),
                actual: tree.Search(envelope).Count);
        }
Beispiel #12
0
        public void TestSearchAfterInsert()
        {
            int maxEntries = 9;
            var tree       = new RBush <Point>(maxEntries);

            var      firstSet         = points.Take(maxEntries);
            Envelope firstSetEnvelope =
                new Envelope(
                    firstSet.Min(p => p.Envelope.MinX),
                    firstSet.Min(p => p.Envelope.MinY),
                    firstSet.Max(p => p.Envelope.MaxX),
                    firstSet.Max(p => p.Envelope.MaxY));

            foreach (var p in firstSet)
            {
                tree.Insert(p);
            }

            Assert.Equal(firstSet.OrderBy(x => x), tree.Search(firstSetEnvelope).OrderBy(x => x));
        }