protected internal void Split()
{
// Make sure we're bigger than the minimum, if we care,
if (MinSize != NoMinSize)
if (Math.Abs(Bounds.Top - Bounds.Bottom) < MinSize &&
Math.Abs(Bounds.Right - Bounds.Left) < MinSize &&
Math.Abs(Bounds.Front - Bounds.Back) < MinSize)
return;
var nsHalf = (float)(Bounds.Top - (Bounds.Top - Bounds.Bottom) * 0.5);
var ewHalf = (float)(Bounds.Right - (Bounds.Right - Bounds.Left) * 0.5);
var fbHalf = (float)(Bounds.Front - (Bounds.Front - Bounds.Back) * 0.5);
Branch = new OctreeNode[8];
Branch[0] = new OctreeNode(ewHalf, Bounds.Left, Bounds.Front, fbHalf, Bounds.Top, nsHalf, MaxItems); //left-front-top
Branch[1] = new OctreeNode(Bounds.Right, ewHalf, Bounds.Front, fbHalf, Bounds.Top, nsHalf, MaxItems);
Branch[2] = new OctreeNode(ewHalf, Bounds.Left, Bounds.Front, fbHalf, nsHalf, Bounds.Bottom, MaxItems);
Branch[3] = new OctreeNode(Bounds.Right, ewHalf, Bounds.Front, fbHalf, nsHalf, Bounds.Bottom, MaxItems);
Branch[4] = new OctreeNode(ewHalf, Bounds.Left, fbHalf, Bounds.Back, Bounds.Top, nsHalf, MaxItems); //left-back-top
Branch[5] = new OctreeNode(Bounds.Right, ewHalf, fbHalf, Bounds.Back, Bounds.Top, nsHalf, MaxItems);
Branch[6] = new OctreeNode(ewHalf, Bounds.Left, fbHalf, Bounds.Back, nsHalf, Bounds.Bottom, MaxItems);
Branch[7] = new OctreeNode(Bounds.Right, ewHalf, fbHalf, Bounds.Back, nsHalf, Bounds.Bottom, MaxItems);
var temp = (ArrayList)Items.Clone();
Items.Clear();
var things = temp.GetEnumerator();
while (things.MoveNext())
{
AddNode((OctreeLeaf)things.Current);
}
}