Ejemplo n.º 1
0
        /// <summary> Considering splitting a space into 4 Sub-spaces
        /// 
        /// </summary>
        /// <param name="space">The space to subdivide
        /// </param>
        /// <param name="level">The number of levels of subdivision allowed 
        /// </param>
        /// <param name="target">The target number of bodies per space
        /// </param>
        /// <param name="spaceList">The list of spaces to populate
        /// </param>
        /// <returns> True if the target has found
        /// </returns>
        private bool SplitSpace(Space space, int level, int target, IList<Space> spaceList)
        {
            if (space.Size() <= target)
            {
                spaceList.Add(space);
                return true;
            }
            if (level > maxLevels)
            {
                spaceList.Add(space);
                return true;
            }

            Space[] spaces = space.QuadSpaces;
            for (int j = 0; j < 4; j++)
            {
                SplitSpace(spaces[j], level + 1, target, spaceList);
            }

            return false;
        }