Пример #1
0
        public QuadTreeLeafNode CreateLeafOrGetReference(uint x, uint y, uint level)
        {
            if (IsLeaf)
            {
                return((QuadTreeLeafNode)this);
            }

            var childIndex = ComputeChildrenIndex(x, y);

            if (Children[childIndex] == null)
            {
                // Oughta create a new child
                if (level == Floor.FloorBits)
                {
                    Children[childIndex] = new QuadTreeLeafNode();
                }
                else
                {
                    Children[childIndex] = new QuadTreeNode();
                }
            }
            else
            {
                // Child is already not null, no need to do anything
            }

            return(Children[childIndex].CreateLeafOrGetReference(x << 1, y << 1, level - 1));
        }
Пример #2
0
        public bool TryGetLeaf(uint x, uint y, out QuadTreeLeafNode leaf)
        {
            if (IsLeaf)
            {
                leaf = (QuadTreeLeafNode)this;
                return(true);
            }

            var node = Children[ComputeChildrenIndex(x, y)];

            if (node != null)
            {
                return(node.TryGetLeaf(x << 1, y << 1, out leaf));
            }

            // Node not created yet
            leaf = null;
            return(false);
        }