Exemplo n.º 1
0
        public void TestQuadtreeSplitMerge()
        {
            TestQuadTreeNode root = new TestQuadTreeNode();

            root.NodeData = new QuadTreeNodeData <TestQuadTreeNode>(
                new BoundingBox(new Vector3(-100, -5, -100), new Vector3(100, 5, 100)).dx()
                );

            QuadTree.Split(root, 4);

            QuadTree.Merge(root.NodeData.LowerRight.NodeData.LowerRight.NodeData.UpperLeft);

            QuadTree.MergeRecursive(root.NodeData.LowerLeft.NodeData.UpperRight);

            QuadTree.MergeRecursive(root.NodeData.UpperRight);

            QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA();

            XNAGame game = new XNAGame();

            game.DrawEvent +=
                delegate
            {
                visualizer.RenderNodeGroundBoundig(game, root);
                visualizer.RenderNodeBoundingBox(game, root);
            };

            game.Run();
        }
Exemplo n.º 2
0
        public void TestQuadtreeVisualizer()
        {
            TestQuadTreeNode      root       = createSimpleQuadtree();
            QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA();

            XNAGame game = new XNAGame();

            game.DrawEvent += delegate
            {
                visualizer.RenderNodeGroundBoundig(game, root);
            };

            game.Run();
        }
Exemplo n.º 3
0
            public void SetUp()
            {
                _quadTree = new QuadTree <TestQuadTreeNode>(new Rectangle(-500, -500, 1000, 1000));

                for (int i = 0; i < _testRectangles.Length; i++)
                {
                    var node = new TestQuadTreeNode()
                    {
                        Id        = i + 1,
                        Rectangle = _testRectangles[i]
                    };

                    _quadTree.Insert(node, node.Rectangle);
                }
            }
Exemplo n.º 4
0
            public void ReIndex_ShouldBeCorrect_WhenBoundsChanged()
            {
                var insertNode = new TestQuadTreeNode()
                {
                    Id        = _quadTree.Nodes.Count() + 1,
                    Rectangle = new Rectangle(-600, -600, 100, 100)
                };

                _quadTree.Insert(insertNode, insertNode.Rectangle);

                foreach (var bounds in _searchBounds)
                {
                    var insideNodesIds     = _quadTree.GetNodesInside(bounds).Select(n => n.Id);
                    var overlappedNodesIds = SlowGetOverlappedNodes(bounds, _quadTree.Nodes).Select(n => n.Id);
                    insideNodesIds.Should().BeEquivalentTo(overlappedNodesIds);
                }

                _quadTree.HasNodesInside(new Rectangle(-550, -550, 100, 100)).Should().BeTrue();
            }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a simple quadtree from scratch, without using any other functions (split/merge etc)
        /// </summary>
        private TestQuadTreeNode createSimpleQuadtree()
        {
            TestQuadTreeNode root = new TestQuadTreeNode();
            QuadTreeNodeData <TestQuadTreeNode> rootNodeData = new QuadTreeNodeData <TestQuadTreeNode>();

            rootNodeData.BoundingBox = new BoundingBox(new Vector3(-20, -20, -20), new Vector3(20, 20, 20)).dx();


            TestQuadTreeNode child = new TestQuadTreeNode();
            QuadTreeNodeData <TestQuadTreeNode> childNodeData = new QuadTreeNodeData <TestQuadTreeNode>();

            child = new TestQuadTreeNode();
            rootNodeData.UpperLeft    = child;
            childNodeData.Parent      = root;
            childNodeData.BoundingBox = new BoundingBox(new Vector3(-20, -20, -20), new Vector3(0, 20, 0)).dx();

            child.NodeData = childNodeData;

            root.NodeData = rootNodeData;

            return(root);
        }