public void TestCount()
        {
            List <IVector>   vecs = new List <IVector>(VectorSampling.InAABB(10, 2, -100.0, 100.0, 10));
            KdTree <IVector> tree = new KdTree <IVector>(2, new Accelerators.Subdivision.SubdivisionPolicyConnector(1));


            Assert.AreEqual(0, tree.Count);
            tree.Add(vecs[0]);
            Assert.AreEqual(1, tree.Count);
            tree.Add(vecs[1]);
            Assert.AreEqual(2, tree.Count);
            tree.Add(vecs[2]);
            Assert.AreEqual(3, tree.Count);
            tree.Remove(vecs[2]);
            Assert.AreEqual(2, tree.Count);
            tree.Remove(vecs[5]);
            Assert.AreEqual(2, tree.Count);
            tree.Remove(vecs[1]);
            Assert.AreEqual(1, tree.Count);
            tree.Remove(vecs[0]);
            Assert.AreEqual(0, tree.Count);
            tree.Add(vecs[0]);
            tree.Clear();
            Assert.AreEqual(0, tree.Count);
        }
Exemple #2
0
        public void TestEnlargeCollection()
        {
            AABB box = new AABB(2);

            box.Enlarge(VectorSampling.InAABB(1000, 2, -1.0, 1.0, 10));
            Assert.LessOrEqual(-1.0, box.Lower[0]);
            Assert.LessOrEqual(-1.0, box.Lower[1]);
            Assert.GreaterOrEqual(1.0, box.Upper[0]);
            Assert.GreaterOrEqual(1.0, box.Upper[1]);
        }
Exemple #3
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);
        }
        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);
        }
Exemple #5
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);
        }
        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)));
        }
Exemple #7
0
        public void TestInside()
        {
            AABB box = new AABB(Vector.Create(-1.0, -1.0), Vector.Create(1.0, 1.0));

            // Perform a monte-carlo integration test
            const int      count = 100000;
            List <IVector> vecs  = new List <IVector>(VectorSampling.InAABB(count, 2, -2.0, 2.0, 10));

            int inside = 0;

            foreach (IVector v in vecs)
            {
                if (box.Inside(v))
                {
                    inside += 1;
                }
            }

            double ratio            = (double)inside / count;
            double volume_outer_box = 4.0 * 4.0;
            double volume_inner_box = volume_outer_box * ratio;

            Assert.AreEqual(4.0, volume_inner_box, 0.1);
        }
Exemple #8
0
        public void TestInside()
        {
            Ball b = new Ball(Vector.Create(0.0, 0.0, 0.0), 1.0);

            // Perform a monte-carlo integration test
            const int      count = 10000;
            List <IVector> vecs  = new List <IVector>(VectorSampling.InAABB(count, 3, -1.0, 1.0, 10));

            int inside = 0;

            foreach (IVector v in vecs)
            {
                if (b.Inside(v))
                {
                    inside += 1;
                }
            }

            double ratio            = (double)inside / count;
            double volume_outer_box = 8.0;
            double volume_sphere    = volume_outer_box * ratio;

            Assert.AreEqual((4.0 / 3.0) * Math.PI, volume_sphere, 0.1);
        }