Beispiel #1
0
        /// <summary>
        /// runs three fail-over range checks for a given node
        /// </summary>
        /// <param name="node">node to check</param>
        /// <param name="point">location from which range check is made</param>
        /// <param name="range">the length of the range check</param>
        /// <returns>true if in range, false if not</returns>
        private bool nodeWithinRange(QuadNode <E> node, Vector2 point, float range)
        {
            if (node.contains(point))
            {
                return(true);
            }
            else if (Vector2.Distance(node.Center, point) <= range)
            {
                return(true);
            }
            else
            {
                //get the vector from the point to the node's center
                Vector2 pToC = node.Center - point;
                pToC.Normalize();

                //find the closest position to the node center that is at max range from the point
                pToC = point + pToC * range;

                //if that point is within the node, then the node is within range
                if (node.contains(pToC))
                {
                    return(true);
                }
            }

            //node not within range
            return(false);
        }
Beispiel #2
0
 /// <summary>
 /// sets the content at the leaf node descendant from the given node
 /// </summary>
 /// <param name="node">given node</param>
 /// <param name="val">content to be set</param>
 /// <param name="point">location of the content</param>
 /// <returns>the leaf node set or null if set failed or content already exists</returns>
 private QuadNode <E> setContentAtLocation(QuadNode <E> node, E val, Vector2 point)
 {
     if (node.Q1 == null || node.Q2 == null || node.Q3 == null || node.Q4 == null)
     {
         if (node.contains(point))
         {
             if (!node.Contents.Contains(val))
             {
                 node.Contents.Add(val);
             }
             return(node);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         if (node.Q1.contains(point))
         {
             return(setContentAtLocation(node.Q1, val, point));
         }
         if (node.Q2.contains(point))
         {
             return(setContentAtLocation(node.Q2, val, point));
         }
         if (node.Q3.contains(point))
         {
             return(setContentAtLocation(node.Q3, val, point));
         }
         if (node.Q4.contains(point))
         {
             return(setContentAtLocation(node.Q4, val, point));
         }
         return(null);
     }
 }