예제 #1
0
        /// <summary>
        /// Get the objects in this tree that intersect with the specified rectangle.
        /// </summary>
        /// <param name="searchRect">The rectangle to find objects in.</param>
        /// <param name="results">A reference to a list that will be populated with the results.</param>
        internal void getObjects(Rectangle searchRect, ref List <T> results)
        {
            // We can't do anything if the results list doesn't exist
            if (results != null)
            {
                if (searchRect.Contains(this._rect))
                {
                    // If the search area completely contains this quad, just get every object this quad and all it's children have
                    getAllObjects(ref results);
                }
                else if (searchRect.Intersects(this._rect))
                {
                    // Otherwise, if the quad isn't fully contained, only add objects that intersect with the search rectangle
                    if (_objects != null)
                    {
                        for (int i = 0; i < _objects.Count; i++)
                        {
                            if (searchRect.Intersects(_objects[i].data.bounds))
                            {
                                results.Add(_objects[i].data);
                            }
                        }
                    }

                    // Get the objects for the search rectangle from the children
                    if (_childTL != null)
                    {
                        _childTL.getObjects(searchRect, ref results);
                        _childTR.getObjects(searchRect, ref results);
                        _childBL.getObjects(searchRect, ref results);
                        _childBR.getObjects(searchRect, ref results);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Insert an item into this QuadTree object.
        /// </summary>
        /// <param name="item">The item to insert.</param>
        internal void insert(QuadTreeObject <T> item)
        {
            // If this quad doesn't contain the items rectangle, do nothing, unless we are the root
            if (!_rect.Contains(item.data.bounds))
            {
                //Insist.isNull( _parent, "We are not the root, and this object doesn't fit here. How did we get here?" );
                if (_parent == null)
                {
                    // This object is outside of the QuadTree bounds, we should add it at the root level
                    add(item);
                }
                else
                {
                    return;
                }
            }

            if (_objects == null || (_childTL == null && _objects.Count + 1 <= maxObjectsPerNode))
            {
                // If there's room to add the object, just add it
                add(item);
            }
            else
            {
                // No quads, create them and bump objects down where appropriate
                if (_childTL == null)
                {
                    subdivide();
                }

                // Find out which tree this object should go in and add it there
                var destTree = getDestinationTree(item);
                if (destTree == this)
                {
                    add(item);
                }
                else
                {
                    destTree.insert(item);
                }
            }
        }
        static StackObject *Contains_27(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Vector2Int @position = (UnityEngine.Vector2Int) typeof(UnityEngine.Vector2Int).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.RectInt instance_of_this_method = (UnityEngine.RectInt) typeof(UnityEngine.RectInt).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.Contains(@position);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }