Exemplo n.º 1
0
        public void TestStaticConstruction()
        {
            KdTree <IVector> tree = new KdTree <IVector>(VectorSampling.InAABB(5000, 2, -100.0, 100.0, 10), new SubdivisionPolicyConnector(1));

            KdNodeInvariants.AreMetBy(tree.Root);
            int count = 0;

            foreach (KdNode <IVector> n in tree.Root.Leaves)
            {
                count += n.Vectors.Count;
            }
            Assert.AreEqual(5000, count);
        }
Exemplo n.º 2
0
        public void TestAdd()
        {
            KdTree <IVector> tree = new KdTree <IVector>(2, new SubdivisionPolicyConnector(1));

            foreach (IVector iv in VectorSampling.InAABB(5000, 2, -100.0, 100.0, 10))
            {
                tree.Add(iv);
            }
            KdNodeInvariants.AreMetBy(tree.Root);
            int count = 0;

            foreach (KdNode <IVector> n in tree.Root.Leaves)
            {
                count += n.Vectors.Count;
            }
            Assert.AreEqual(5000, count);
        }
Exemplo n.º 3
0
        public void TestOptimize()
        {
            List <IVector>   vecs = new List <IVector>(VectorSampling.InAABB(500, 2, -100.0, 100.0, 10));
            KdTree <IVector> tree = new KdTree <IVector>(2, new SubdivisionPolicyConnector(1));

            foreach (IVector iv in vecs)
            {
                tree.Add(iv);
            }

            SubdivisionPolicyConnector spc = new SubdivisionPolicyConnector(3, new AxisOfMaximumSpreadSelector(), new MedianSelector(), new NoOperationResolver());

            tree.Optimize(spc);

            Assert.AreEqual(500, tree.Count);
            KdNodeInvariants.AreMetBy(tree.Root);
        }
Exemplo n.º 4
0
        public void TestRemove()
        {
            List <IVector>   vecs = new List <IVector>(VectorSampling.InAABB(5000, 2, -100.0, 100.0, 10));
            KdTree <IVector> tree = new KdTree <IVector>(vecs, new SubdivisionPolicyConnector(1));

            for (int i = 0; i < 500; ++i)
            {
                Assert.IsTrue(tree.Remove(vecs[i]));
            }
            KdNodeInvariants.AreMetBy(tree.Root);
            Assert.AreEqual(5000 - 500, tree.Count);
            int count = 0;

            foreach (KdNode <IVector> n in tree.Root.Leaves)
            {
                count += n.Vectors.Count;
            }
            Assert.AreEqual(5000 - 500, count);

            // Removing of non-existant elements
            Assert.IsFalse(tree.Remove(Vector.Create(200.0, 200.0)));
        }