Beispiel #1
0
        public void TestAdd()
        {
            DwarfCorp.OctTreeNode <TestObj> octree = new DwarfCorp.OctTreeNode <TestObj>(new Vector3(-40, -40, -40), new Vector3(40, 40, 40));
            var obj = new TestObj(0);

            AddPoint(octree, obj, -4, -4, -4);
            HashSet <TestObj> set = new HashSet <TestObj>();

            octree.EnumerateItems(new BoundingBox(new Vector3(-4, -4, -4), new Vector3(0, 0, 0)), set);
            Assert.AreEqual(set.Count, 1);
            foreach (var pt in set)
            {
                Assert.AreEqual(pt, obj);
            }
        }
Beispiel #2
0
        public void TestAddRemove()
        {
            DwarfCorp.OctTreeNode <TestObj> octree = new DwarfCorp.OctTreeNode <TestObj>(new Vector3(-40, -40, -40), new Vector3(40, 40, 40));
            Assert.IsTrue(octree.IsLeaf());
            List <TestObj>     objects = new List <TestObj>();
            List <BoundingBox> boxes   = new List <BoundingBox>();
            int k = 0;

            for (float dx = -30; dx < 30; dx += 10)
            {
                for (float dy = -30; dy < 30; dy += 10)
                {
                    for (float dz = -30; dz < 30; dz += 10)
                    {
                        var obj = new TestObj(k++);
                        objects.Add(obj);
                        var box = AddPoint(octree, obj, dx, dy, dz);
                        boxes.Add(box);
                    }
                }
            }

            Assert.IsFalse(octree.IsLeaf());

            for (int i = 0; i < boxes.Count; i++)
            {
                HashSet <TestObj> set = new HashSet <TestObj>();
                octree.EnumerateItems(boxes[i], set);

                Assert.AreEqual(1, set.Count);
                foreach (var item in set)
                {
                    Assert.AreEqual(objects[i], item);
                }
                var numRemoved = octree.Remove(objects[i], boxes[i]);
                Assert.IsTrue(numRemoved > 0);
            }

            Assert.IsTrue(octree.IsLeaf());
        }