/// <summary>Gets all objects within a specified radius.</summary>
 /// <typeparam name="T">the minimum type of the objects to retrieve</typeparam>
 /// <param name="sphere">the area to search</param>
 /// <param name="entities">the list to append retrieved objects to</param>
 internal void GetEntitiesInArea <T>(ref BoundingSphere sphere, List <T> entities, Func <T, bool> filter,
                                     uint phase, ref int limitCounter) where T : WorldObject
 {
     if (IsLeaf)
     {
         if (!HasObjects)
         {
             return;
         }
         foreach (WorldObject worldObject in m_objects.Values)
         {
             Vector3 position = worldObject.Position;
             if (sphere.Contains(ref position) && worldObject.IsInPhase(phase) && worldObject is T)
             {
                 T obj = worldObject as T;
                 if (filter(obj))
                 {
                     entities.Add(obj);
                     if (--limitCounter == 0)
                     {
                         break;
                     }
                 }
             }
         }
     }
     else
     {
         for (int index1 = 0; index1 < 2; ++index1)
         {
             for (int index2 = 0; index2 < 2; ++index2)
             {
                 ZoneSpacePartitionNode child = m_children[index1, index2];
                 if (child.Bounds.Intersects(ref sphere).HasAnyFlag(IntersectionType.Touches))
                 {
                     child.GetEntitiesInArea(ref sphere, entities, filter, phase, ref limitCounter);
                 }
             }
         }
     }
 }
 /// <summary>Gets all objects within a specified radius.</summary>
 /// <param name="box">the area to search</param>
 /// <param name="entities">the list to append retrieved objects to</param>
 /// <param name="filter">the type (in respect to the WoW client) that the object must be</param>
 internal void GetEntitiesInArea(ref BoundingBox box, List <WorldObject> entities, ObjectTypes filter, uint phase,
                                 ref int limitCounter)
 {
     if (IsLeaf)
     {
         if (!HasObjects)
         {
             return;
         }
         foreach (WorldObject worldObject in m_objects.Values)
         {
             Vector3 position = worldObject.Position;
             if (box.Contains(ref position) && worldObject.IsInPhase(phase) &&
                 worldObject.Type.HasAnyFlag(filter))
             {
                 entities.Add(worldObject);
                 if (--limitCounter == 0)
                 {
                     break;
                 }
             }
         }
     }
     else
     {
         for (int index1 = 0; index1 < 2; ++index1)
         {
             for (int index2 = 0; index2 < 2; ++index2)
             {
                 ZoneSpacePartitionNode child = m_children[index1, index2];
                 if (child.Bounds.Intersects(ref box).HasAnyFlag(IntersectionType.Touches))
                 {
                     child.GetEntitiesInArea(ref box, entities, filter, phase, ref limitCounter);
                 }
             }
         }
     }
 }