Beispiel #1
0
        public void CanMaintainDirtyFlag()
        {
            var qt = new PointQuadtree <int>();

            // New empty inverted index isn't dirty:
            Assert.False(qt.IsDirty);

            qt.Add(0, new Point(0, 0));

            // After adding an item, it's dirty:
            Assert.True(qt.IsDirty);

            qt.Build();

            // After building, the index is clean:
            Assert.False(qt.IsDirty);

            qt.Add(1, new Point(1, 1));

            // After adding items, index is dirty:
            Assert.True(qt.IsDirty);

            qt.Clear();

            // After clearing, index is empty and thus clean:
            Assert.False(qt.IsDirty);
        }
Beispiel #2
0
        public void CanBoundingBox()
        {
            var qt = new PointQuadtree <int>();

            Assert.False(qt.IsDirty);
            Assert.Equal(0, qt.ItemCount);
            Assert.Null(qt.BoundingBox);

            qt.Add(33, new Point(3, 3));
            qt.Build();

            Assert.NotNull(qt.BoundingBox);
            Assert.Equal(new Envelope(3, 3, 3, 3), qt.BoundingBox);

            qt.Add(55, new Point(5, 5));
            qt.Build();

            Assert.NotNull(qt.BoundingBox);
            Assert.Equal(new Envelope(3, 3, 5, 5), qt.BoundingBox);

            qt.Clear();

            Assert.False(qt.IsDirty);
            Assert.Null(qt.BoundingBox);
        }
Beispiel #3
0
        private static PointQuadtree <Place> GetSampleDataset()
        {
            var quadtree = new PointQuadtree <Place>();

            quadtree.Add(Chicago, Chicago.Point);
            quadtree.Add(Mobile, Mobile.Point);
            quadtree.Add(Toronto, Toronto.Point);
            quadtree.Add(Buffalo, Buffalo.Point);
            quadtree.Add(Denver, Denver.Point);
            quadtree.Add(Omaha, Omaha.Point);
            quadtree.Add(Atlanta, Atlanta.Point);
            quadtree.Add(Miami, Miami.Point);
            // don't add Memphis

            quadtree.Build();

            return(quadtree);
        }
Beispiel #4
0
        private static PointQuadtree <Place> GetGlobalDataset()
        {
            var places = new[]
            {
                FernsehturmBerlin, ElizabethTowerLondon, NotreDameTourNord, NotreDameTourSud,
                EiffelTower, EsriRedlands, LadyLiberty, SydneyOpera, Anadyr, Josefstrasse21,
                Josefstrasse211, Josefstrasse212, Josefstrasse214, Josefstrasse216,
                Josefstrasse218, KigaliAirport, StMatthewIsland, Longyearbyen
            };

            var quadtree = new PointQuadtree <Place>();

            foreach (var place in places)
            {
                quadtree.Add(place, place.Point);
            }

            quadtree.Build();

            return(quadtree);
        }
Beispiel #5
0
        public void LargeQuadtreeTest()
        {
            const int numPoints = 1000000;
            var       random    = new Random();
            var       timer     = new Stopwatch();

            // Build quadtree with numPoints points having
            // random x and y coordinates in the real interval:
            timer.Start();
            var qt = new PointQuadtree <int>();

            for (int id = 0; id < numPoints; id++)
            {
                double x = 100 * random.NextDouble();
                double y = 100 * random.NextDouble();

                qt.Add(id, new Point(x, y));
            }
            timer.Stop();
            _output.WriteLine("Built QT with {0:N0} random points in {1}",
                              numPoints, timer.Elapsed);

            timer.Reset();

            timer.Start();
            var r1 = new List <int>();
            int c1 = qt.Query(new Envelope(0, 0, 100, 100), null, r1);

            Assert.Equal(numPoints, c1);
            Assert.Equal(numPoints, r1.Count);
            timer.Stop();
            _output.WriteLine("Queried world rectangle in {0}", timer.Elapsed);

            timer.Reset();

            timer.Start();
            int c2 = qt.Count(new Envelope(0, 0, 100, 100), null);

            Assert.Equal(numPoints, c2);
            timer.Stop();
            _output.WriteLine("Counted world rectangle in {0}", timer.Elapsed);

            timer.Reset();

            timer.Start();
            var r3 = new List <int>();
            int c3 = qt.Query(new Envelope(0, 0, 50, 50), null, r3);

            Assert.True(r3.Count == c3);
            timer.Stop();
            _output.WriteLine("Queried SW quadrant ({0} points) in {1}",
                              c3, timer.Elapsed);

            timer.Reset();

            timer.Start();
            int c4 = qt.Count(new Envelope(0, 0, 50, 50), null);

            timer.Stop();
            _output.WriteLine("Counted SW quadrant ({0} points) in {1}",
                              c4, timer.Elapsed);

            ShowStats(qt);
        }
Beispiel #6
0
        public void CanHandleCoincidentPoints()
        {
            var qt = new PointQuadtree <Place>();

            qt.Add(Chicago, Chicago.Point);
            qt.Add(Chicago, Chicago.Point);             // again

            string serializedQuadtree = GetSerializedQuadtree(qt);

            Assert.Equal("(Chicago (Chicago ....)...)", serializedQuadtree);

            var r1 = new List <Place>();
            int c1 = qt.Query(new Envelope(0, 0, 100, 100), null, r1);

            Assert.Equal(2, c1);
            Assert.Equal(r1.OrderBy(p => p.Tag), Seq(Chicago, Chicago));

            var r2 = new List <Place>();
            int c2 = qt.Query(new Envelope(Chicago.Point, Chicago.Point), null, r2);

            Assert.Equal(2, c2);
            Assert.Equal(r2.OrderBy(p => p.Tag), Seq(Chicago, Chicago));

            qt.Add(Mobile, Mobile.Point);
            qt.Add(Mobile, Mobile.Point);             // again

            var r3 = new List <Place>();
            int c3 = qt.Query(new Envelope(Mobile.Point, Mobile.Point), null, r3);

            Assert.Equal(2, c3);
            Assert.Equal(r3.OrderBy(p => p.Tag), Seq(Mobile, Mobile));

            var r4 = new List <Place>();
            int c4 = qt.Query(new Envelope(Chicago.Point, Mobile.Point), null, r4);

            Assert.Equal(4, c4);
            Assert.Equal(r4.OrderBy(p => p.Tag), Seq(Chicago, Chicago, Mobile, Mobile));

            serializedQuadtree = GetSerializedQuadtree(qt);
            Assert.Equal("(Chicago (Chicago ....)..(Mobile (Mobile ....)...))", serializedQuadtree);

            qt.Add(Toronto, Toronto.Point);
            qt.Add(Buffalo, Buffalo.Point);
            qt.Add(Denver, Denver.Point);
            qt.Add(Omaha, Omaha.Point);
            qt.Add(Atlanta, Atlanta.Point);
            qt.Add(Miami, Miami.Point);
            qt.Add(Memphis, Memphis.Point);
            qt.Add(Memphis, Memphis.Point);             // again

            serializedQuadtree = GetSerializedQuadtree(qt);
            Assert.Equal(
                "(Chicago (Chicago (Toronto ...(Buffalo ....))...)(Denver ....)(Omaha ....)(Mobile (Mobile (Atlanta ....)...)(Memphis (Memphis ....)...).(Miami ....)))",
                serializedQuadtree);

            var r5 = new List <Place>();
            int c5 = qt.Query(new Envelope(30, 5, 60, 25), null, r5);

            Assert.Equal(4, c5);
            Assert.Equal(r5.OrderBy(p => p.Tag), Seq(Memphis, Memphis, Mobile, Mobile));

            ShowStats(qt);
        }