예제 #1
0
        /// <summary>
        /// Insert an item into this QuadTree with the specified Bounds
        /// </summary>
        /// <param name="item">the item to insert</param>
        /// <param name="bounds">the bounds of the item</param>
        /// <returns>true if the item could be inserted, false otherwise</returns>
        public bool Insert(T item, Bounds bounds)
        {
            BoundsLink <T> member = new BoundsLink <T>(item, bounds);
            bool           ret    = Insert(member);

            if (ret)
            {
                AllMembers.Add(member);
            }

            return(ret);
        }
예제 #2
0
        private bool Insert(BoundsLink <T> member)
        {
            // make sure we intersect with the bounds of this object
            if (!Bounds.IntersectsWith(member.bounds, true))
            {
                return(false);
            }
            if (Members.Count < MaxReferencesPerTree)
            {
                Members.Add(member);
                return(true);
            }

            // else we are full, but need to store this object
            if (!IsDivided)
            {
                Subdivide();
            }

            bool Inserted = false;

            if (SW.Insert(member))
            {
                Inserted = true;
            }
            if (NW.Insert(member))
            {
                Inserted = true;
            }
            if (NE.Insert(member))
            {
                Inserted = true;
            }
            if (SE.Insert(member))
            {
                Inserted = true;
            }
            return(Inserted);
        }