コード例 #1
0
ファイル: Quadtree.cs プロジェクト: HubertBalcerzak/libKratos
        private void CreateQuadtree(Vector2[] verts, float radius, int maxLevels)
        {
            LinkedList <IndexedVertex2d> nodes = new LinkedList <IndexedVertex2d>();

            for (int i = 0; i < verts.Length; i++)
            {
                nodes.AddLast(new IndexedVertex2d(i, verts[i]));
            }

            _node = new QuadtreeInternalNode();
            _node.Process(nodes, 0, 0, 0, radius, maxLevels);
        }
コード例 #2
0
        public void Process(LinkedList <IndexedVertex2d> nodes, int depth, float x, float y, float radius,
                            int maxDepth)
        {
            _x      = x;
            _y      = y;
            _radius = radius;
            _count  = nodes.Count;

            LinkedList <IndexedVertex2d>[] lists = new LinkedList <IndexedVertex2d> [4];
            for (int i = 0; i < 4; i++)
            {
                lists[i] = new LinkedList <IndexedVertex2d>();
            }

            foreach (var node in nodes)
            {
                var current = node.Vertex;
                lists[GetSubtreeIndex(current.X, current.Y)].AddLast(node);
            }


            for (int i = 0; i < 4; i++)
            {
                if (depth < maxDepth && lists[i].Count > 1)
                {
                    subTrees[i] = new QuadtreeInternalNode();
                }
                else
                {
                    subTrees[i] = new QuadtreeLeaf();
                }

                subTrees[i].Process(lists[i], depth + 1, GetX(i), GetY(i),
                                    radius / 2, maxDepth);
            }
        }
コード例 #3
0
ファイル: Quadtree.cs プロジェクト: HubertBalcerzak/libKratos
 private void CreateQuadTreeWithList(LinkedList <IndexedVertex2d> nodes, float radius, int maxLevels)
 {
     _node = new QuadtreeInternalNode();
     _node.Process(nodes, 0, 0, 0, radius, maxLevels);
 }