/// <summary>
        /// Grow the octree to fit in all objects.
        /// </summary>
        /// <param name="direction">Direction to grow.</param>
        void Grow(XYZ direction)
        {
            int xDirection = direction.X >= 0 ? 1 : -1;
            int yDirection = direction.Y >= 0 ? 1 : -1;
            int zDirection = direction.Z >= 0 ? 1 : -1;
            BoundsOctreeNode <T> oldRoot = rootNode;
            float half      = rootNode.BaseLength / 2;
            float newLength = rootNode.BaseLength * 2;
            var   newCenter = rootNode.Center + new XYZ(xDirection * half, yDirection * half, zDirection * half);

            // Create a new, bigger octree root node
            rootNode = new BoundsOctreeNode <T>(newLength, minSize, looseness, newCenter);

            // Create 7 new octree children to go with the old root as children of the new root
            int rootPos = GetRootPosIndex(xDirection, yDirection, zDirection);

            BoundsOctreeNode <T>[] children = new BoundsOctreeNode <T> [8];
            for (int i = 0; i < 8; i++)
            {
                if (i == rootPos)
                {
                    children[i] = oldRoot;
                }
                else
                {
                    xDirection  = i % 2 == 0 ? -1 : 1;
                    yDirection  = i > 3 ? -1 : 1;
                    zDirection  = (i < 2 || (i > 3 && i < 6)) ? -1 : 1;
                    children[i] = new BoundsOctreeNode <T>(rootNode.BaseLength, minSize, looseness, newCenter + new XYZ(xDirection * half, yDirection * half, zDirection * half));
                }
            }

            // Attach the new children to the new root node
            rootNode.SetChildren(children);
        }