Exemple #1
0
        public void AddEmptyArray()
        {
            var q = new QuadTree <CustomData, CustomNode <CustomData> >();

            var datas = new List <CustomData>();

            var root = q.AddAll(datas).Root;

            Assert.AreEqual(root, null);
            Assert.AreEqual(q.Extents, null);

            var datas2 = new List <CustomData> {
                new CustomData {
                    X = 0, Y = 0
                },
                new CustomData {
                    X = 1, Y = 1
                },
            };

            root = q.AddAll(datas2).Root;
            Assert.AreEqual(datas2[0], root[0].Data);
            Assert.AreEqual(datas2[1], root[3].Data);

            root = q.AddAll(datas).Root;
            Assert.AreEqual(datas2[0], root[0].Data);
            Assert.AreEqual(datas2[1], root[3].Data);
            Assert.AreEqual(null, root[1]);
            Assert.AreEqual(null, root[2]);

            Tests.AreValuesEqual(new double[, ] {
                { 0, 0 }, { 2, 2 }
            }, q.Extents);
        }
Exemple #2
0
        public void ClosetPointWithinRadiusasInfinity()
        {
            var q = new QuadTree <CustomData, QuadNode <CustomData> >();

            var datas = new List <CustomData>()
            {
                new CustomData {
                    X = 0, Y = 0
                },
                new CustomData {
                    X = 100, Y = 0
                },
                new CustomData {
                    X = 0, Y = 100
                },
                new CustomData {
                    X = 100, Y = 100
                },
            };

            q.AddAll(datas);

            CustomData data = q.Find(20, 20, double.NaN);

            Assert.AreEqual(data.X, 0); Assert.AreEqual(data.Y, 0);
            data = q.Find(20, 20, double.PositiveInfinity);
            Assert.AreEqual(data.X, 0); Assert.AreEqual(data.Y, 0);
            data = q.Find(20, 20, double.NegativeInfinity);
            Assert.IsNull(data);
        }
Exemple #3
0
        public void ClosetPoint()
        {
            var q = new QuadTree <CustomData, QuadNode <CustomData> >();

            var datas = new List <CustomData>();

            for (int i = 0; i < 17 * 17; i++)
            {
                datas.Add(new CustomData
                {
                    X = i % 17d,
                    Y = i / 17 | 0
                });
            }
            q.AddAll(datas);

            CustomData data = q.Find(0.1, 0.1);

            Assert.AreEqual(data.X, 0); Assert.AreEqual(data.Y, 0);
            data = q.Find(7.1, 7.1);
            Assert.AreEqual(data.X, 7); Assert.AreEqual(data.Y, 7);
            data = q.Find(0.1, 15.9);
            Assert.AreEqual(data.X, 0); Assert.AreEqual(data.Y, 16);
            data = q.Find(15.9, 15.9);
            Assert.AreEqual(data.X, 16); Assert.AreEqual(data.Y, 16);
        }
Exemple #4
0
        public void AddAllPointsIgnoreInvalid()
        {
            var q = new QuadTree <CustomData, CustomNode <CustomData> >();

            var datas = new List <CustomData> {
                new CustomData {
                    X = double.NaN, Y = 0
                },
                new CustomData {
                    X = 0, Y = double.NaN
                },
            };

            var root = q.AddAll(datas).Root;

            Assert.AreEqual(root, null);
            Assert.AreEqual(q.Extents, null);

            var datas2 = new List <CustomData> {
                new CustomData {
                    X = 0, Y = 0
                },
                new CustomData {
                    X = 0.9, Y = 0.9
                },
            };

            root = q.AddAll(datas2).Root;
            Assert.AreEqual(datas2[0], root[0].Data);
            Assert.AreEqual(datas2[1], root[3].Data);

            root = q.AddAll(datas).Root;
            Assert.AreEqual(datas2[0], root[0].Data);
            Assert.AreEqual(datas2[1], root[3].Data);
            Assert.AreEqual(null, root[1]);
            Assert.AreEqual(null, root[2]);

            Tests.AreValuesEqual(new double[, ] {
                { 0, 0 }, { 1, 1 }
            }, q.Extents);
        }
Exemple #5
0
        public void DataInTree()
        {
            var q = new QuadTree <CustomData, CustomNode <CustomData> >();

            Assert.AreEqual(q.Data.Count, 0);

            var datas = new List <CustomData>()
            {
                new CustomData {
                    X = 0, Y = 0
                },
                new CustomData {
                    X = 1, Y = 2
                },
            };

            q.AddAll(datas);
            var ds = q.Data;

            Assert.AreEqual(ds[0], datas[0]);
            Assert.AreEqual(ds[1], datas[1]);
        }