Ejemplo n.º 1
0
        public void SaveIndexTest()
        {
            DynamicRTree <BoundedInt32> rTree = new DynamicRTree <BoundedInt32>(
                _factories.GeoFactory,
                new GuttmanQuadraticInsert <BoundedInt32>(_factories.GeoFactory),
                new GuttmanQuadraticSplit <BoundedInt32>(_factories.GeoFactory),
                new DynamicRTreeBalanceHeuristic());

            addRandomEntries(rTree);
            MemoryStream s = new MemoryStream();

            rTree.SaveIndex(s);
            rTree.Dispose();

            s.Position = 0;
            DynamicRTree <BoundedInt32> rTree2 = DynamicRTree <BoundedInt32> .FromStream(s, _factories.GeoFactory);

            List <Int32> results = new List <Int32>();

            results.AddRange(rTree2.Query(rTree2.Root.Bounds, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));
            Assert.Equal(99990, results.Count);
        }
Ejemplo n.º 2
0
		public void CreateRTreeTest()
		{
			DynamicRTree<int> rTree = new DynamicRTree<int>(new GuttmanQuadraticInsert<int>(),
			                                                new GuttmanQuadraticSplit<int>(), new DynamicRTreeBalanceHeuristic());

			rTree.Dispose();
		}
Ejemplo n.º 3
0
        public void DynamicRTreeCreationAndDisposalSucceeds()
        {
            DynamicRTree <BoundedInt32> rTree = new DynamicRTree <BoundedInt32>(
                _factories.GeoFactory,
                new GuttmanQuadraticInsert <BoundedInt32>(_factories.GeoFactory),
                new GuttmanQuadraticSplit <BoundedInt32>(_factories.GeoFactory),
                new DynamicRTreeBalanceHeuristic());

            rTree.Dispose();
        }
Ejemplo n.º 4
0
		public void InsertTest()
		{
			DynamicRTree<int> rTree = new DynamicRTree<int>(new GuttmanQuadraticInsert<int>(),
			                                                new GuttmanQuadraticSplit<int>(), new DynamicRTreeBalanceHeuristic());

			addEntries(rTree);

			Assert.AreEqual(new BoundingBox(-100, -100, 5928.57523425, 3252.50803582), rTree.Root.BoundingBox);

			rTree.Dispose();
		}
Ejemplo n.º 5
0
        public void LoadingWith100000ObjectsCompletesAndDoesntCrash()
        {
            Int32 nodeItemMax;
            DynamicRTree <BoundedInt32> rTree = createNewRTree(out nodeItemMax);

            List <Int32> resultsList = new List <Int32>();

            addRandomEntries(rTree);

            rTree.Dispose();
        }
Ejemplo n.º 6
0
        public void RemovingItemSucceeds()
        {
            Int32 nodeItemMax;
            DynamicRTree <BoundedInt32> rTree = createNewRTree(out nodeItemMax);

            List <BoundedInt32> entries = new List <BoundedInt32>();

            addEntries(rTree, entries, nodeItemMax + 1);

            rTree.Remove(entries[0]);

            Assert.Equal(entries.Count - 1, rTree.Root.TotalItemCount);
        }
Ejemplo n.º 7
0
        public void InsertingItemsOverMaxNodeItemsSucceeds()
        {
            Int32 nodeItemMax;
            DynamicRTree <BoundedInt32> rTree = createNewRTree(out nodeItemMax);

            addEntries(rTree, null, nodeItemMax + 1);

            IExtents expected = _factories.GeoFactory.CreateExtents2D(-100,
                                                                      -100,
                                                                      5928.57523425,
                                                                      3252.50803582);

            Assert.Equal(expected, rTree.Root.Bounds);

            rTree.Dispose();
        }
Ejemplo n.º 8
0
		public void SearchTest()
		{
			DynamicRTree<int> rTree = new DynamicRTree<int>(new GuttmanQuadraticInsert<int>(),
			                                                new GuttmanQuadraticSplit<int>(), new DynamicRTreeBalanceHeuristic());

			addEntries(rTree);

			List<RTreeIndexEntry<int>> resultsList = new List<RTreeIndexEntry<int>>();

			resultsList.AddRange(rTree.Search(new BoundingBox(-100, -100, 5928.57523425, 3252.50803582)));
			Assert.AreEqual(8, resultsList.Count);
			resultsList.Clear();

			resultsList.AddRange(rTree.Search(new BoundingBox(0, 0, 100, 100)));
			Assert.AreEqual(6, resultsList.Count);
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 1; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 2; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 3; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 6; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 7; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 8; }));
			resultsList.Clear();

			resultsList.AddRange(rTree.Search(new BoundingBox(1500, 1500, 1500, 1500)));
			Assert.AreEqual(2, resultsList.Count);
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 4; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 5; }));
			resultsList.Clear();

			resultsList.AddRange(rTree.Search(new BoundingBox(100, 100, 100, 100)));
			Assert.AreEqual(4, resultsList.Count);
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 1; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 2; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 7; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 8; }));
			resultsList.Clear();

			addRandomEntries(rTree);
			resultsList.AddRange(rTree.Search(new BoundingBox(100, 100, 100, 100)));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 1; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 2; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 7; }));
			Assert.IsTrue(resultsList.Exists(delegate(RTreeIndexEntry<int> match) { return match.Value == 8; }));
			resultsList.Clear();

			rTree.Dispose();
		}
Ejemplo n.º 9
0
        public void InsertingAndRemovingItemsSucceeds()
        {
            Int32 nodeItemMax;
            DynamicRTree <BoundedInt32> rTree = createNewRTree(out nodeItemMax);

            List <BoundedInt32> entries = new List <BoundedInt32>();

            addEntries(rTree, entries, nodeItemMax + 1);

            for (Int32 i = entries.Count - 1; i >= 0; i--)
            {
                rTree.Remove(entries[i]);
            }

            Assert.Equal(0, rTree.Root.TotalItemCount);
            Assert.Equal(0, rTree.Root.TotalNodeCount);
        }
Ejemplo n.º 10
0
		public void SaveIndexTest()
		{
			DynamicRTree<int> rTree = new DynamicRTree<int>(new GuttmanQuadraticInsert<int>(),
			                                                new GuttmanQuadraticSplit<int>(), new DynamicRTreeBalanceHeuristic());

			addRandomEntries(rTree);
			MemoryStream s = new MemoryStream();
			rTree.SaveIndex(s);
			rTree.Dispose();

			s.Position = 0;
			DynamicRTree<int> rTree2 = DynamicRTree<int>.FromStream(s);
			List<RTreeIndexEntry<int>> results = new List<RTreeIndexEntry<int>>();
			results.AddRange(rTree2.Search(rTree2.Root.BoundingBox));
			Assert.AreEqual(99990, results.Count);
		}
Ejemplo n.º 11
0
		private static void addRandomEntries(DynamicRTree<int> rTree)
		{
			Random rnd = new Random();

			for (int i = 10; i < 100000; i++)
			{
				double xMin = rnd.NextDouble()*(rnd.Next(0, 1) == 1 ? -1 : 1)*rnd.Next();
				double xMax = rnd.NextDouble()*(rnd.Next(0, 1) == 1 ? -1 : 1)*rnd.Next();
				double yMin = rnd.NextDouble()*(rnd.Next(0, 1) == 1 ? -1 : 1)*rnd.Next();
				double yMax = rnd.NextDouble()*(rnd.Next(0, 1) == 1 ? -1 : 1)*rnd.Next();

				BoundingBox bounds = new BoundingBox(xMin, yMin, xMax, yMax);
				rTree.Insert(new RTreeIndexEntry<int>(i, bounds));
			}
		}
Ejemplo n.º 12
0
		private static void addEntries(DynamicRTree<int> rTree)
		{
			rTree.Insert(new RTreeIndexEntry<int>(1, new BoundingBox(0, 0, 100, 100)));
			rTree.Insert(new RTreeIndexEntry<int>(2, new BoundingBox(50, 50, 150, 150)));
			rTree.Insert(new RTreeIndexEntry<int>(3, new BoundingBox(-100, -100, 0, 0)));
			rTree.Insert(new RTreeIndexEntry<int>(4, new BoundingBox(1000, 1000, 2000, 2000)));
			rTree.Insert(new RTreeIndexEntry<int>(5, new BoundingBox(346.23975, 424.5720832, 5928.57523425, 3252.50803582)));
			rTree.Insert(new RTreeIndexEntry<int>(6, new BoundingBox(0, 0, 0, 0)));
			rTree.Insert(new RTreeIndexEntry<int>(7, new BoundingBox(100, 100, 100, 100)));
			rTree.Insert(new RTreeIndexEntry<int>(8, new BoundingBox(0, 0, 100, 100)));
		}
Ejemplo n.º 13
0
        public void SearchingInIndexWithMoreThanMaxNodeItemsSucceeds()
        {
            Int32 nodeItemMax;
            DynamicRTree <BoundedInt32> rTree = createNewRTree(out nodeItemMax);

            addEntries(rTree, null, nodeItemMax + 1);

            List <Int32> resultsList = new List <Int32>();

            IExtents searchExtents = _factories.GeoFactory.CreateExtents2D(-100, -100, 5928.57523425, 3252.50803582);

            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));

            Assert.Equal(11, resultsList.Count);

            resultsList.Clear();

            searchExtents = _factories.GeoFactory.CreateExtents2D(0, 0, 100, 100);

            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));

            Assert.Equal(9, resultsList.Count);
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 1); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 2); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 3); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 6); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 7); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 8); }));
            resultsList.Clear();

            searchExtents = _factories.GeoFactory.CreateExtents2D(1500, 1500, 1500, 1500);
            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));
            Assert.Equal(2, resultsList.Count);
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 4); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 5); }));
            resultsList.Clear();

            searchExtents = _factories.GeoFactory.CreateExtents2D(100, 100, 100, 100);
            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));
            Assert.Equal(7, resultsList.Count);
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 1); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 2); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 7); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 8); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 9); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 10); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 11); }));

            rTree.Dispose();
        }
Ejemplo n.º 14
0
        public void SearchingInIndexWithLessThanMaxNodeItemsSucceeds()
        {
            Int32 nodeItemMax;
            DynamicRTree <BoundedInt32> rTree = createNewRTree(out nodeItemMax);

            addEntries(rTree, null, nodeItemMax - 2);

            List <Int32> resultsList = new List <Int32>();

            IExtents searchExtents = _factories.GeoFactory.CreateExtents2D(-100,
                                                                           -100,
                                                                           5928.57523425,
                                                                           3252.50803582);

#if DOTNET35
            // Man, I can't wait.
            resultsList.AddRange(rTree.Query(searchExtents, x => x.Value));
#else
            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));
#endif
            Assert.Equal(8, resultsList.Count);

            resultsList.Clear();

            searchExtents = _factories.GeoFactory.CreateExtents2D(0, 0, 100, 100);

            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));

            Assert.Equal(6, resultsList.Count);
#if DOTNET35
            Assert.True(resultsList.Exists(x => x == 1));
            Assert.True(resultsList.Exists(x => x == 2));
            Assert.True(resultsList.Exists(x => x == 3));
            Assert.True(resultsList.Exists(x => x == 6));
            Assert.True(resultsList.Exists(x => x == 7));
            Assert.True(resultsList.Exists(x => x == 8));
#else
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 1); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 2); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 3); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 6); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 7); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 8); }));
#endif
            resultsList.Clear();

            searchExtents = _factories.GeoFactory.CreateExtents2D(1500, 1500, 1500, 1500);
            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));
            Assert.Equal(2, resultsList.Count);
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 4); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 5); }));
            resultsList.Clear();

            searchExtents = _factories.GeoFactory.CreateExtents2D(100, 100, 100, 100);
            resultsList.AddRange(rTree.Query(searchExtents, (Func <BoundedInt32, Int32>) delegate(BoundedInt32 item)
            {
                return(item.Value);
            }));
            Assert.Equal(4, resultsList.Count);
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 1); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 2); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 7); }));
            Assert.True(resultsList.Exists(delegate(Int32 match) { return(match == 8); }));
            resultsList.Clear();
        }