Nez.Portable/Physics/QuadTree/QuadTreeNode.cs
/// <summary>
/// Subdivide this QuadTree and move it's children into the appropriate Quads where applicable.
/// </summary>
Subdivide this QuadTree and move it's children into the appropriate Quads where applicable.
Subdivide this QuadTree and move it ' s children into the appropriate Quads where applicable .
void subdivide()
        {
            var size = new Point(_rect.Width / 2, _rect.Height / 2);
            var mid = new Point(_rect.X + size.X, _rect.Y + size.Y);
            _childTL = new QuadTreeNode<T>(this, new Rectangle(_rect.Left, _rect.Top, size.X, size.Y));
            _childTR = new QuadTreeNode<T>(this, new Rectangle(mid.X, _rect.Top, size.X, size.Y));
            _childBL = new QuadTreeNode<T>(this, new Rectangle(_rect.Left, mid.Y, size.X, size.Y));
            _childBR = new QuadTreeNode<T>(this, new Rectangle(mid.X, mid.Y, size.X, size.Y));
            for (var i = 0; i < _objects.Count; i++)
            {
                var destTree = getDestinationTree(_objects[i]);
                if (destTree != this)
                {
                    destTree.insert(_objects[i]);
                    remove(_objects[i]);
                    i--;
                }
            }
        }
void subdivide ( ) { var size = new Point ( _rect . Width / 2 , _rect . Height / 2 ) ; var mid = new Point ( _rect . X + size . X , _rect . Y + size . Y ) ; _childTL = new QuadTreeNode < T > ( this , new Rectangle ( _rect . Left , _rect . Top , size . X , size . Y ) ) ; _childTR = new QuadTreeNode < T > ( this , new Rectangle ( mid . X , _rect . Top , size . X , size . Y ) ) ; _childBL = new QuadTreeNode < T > ( this , new Rectangle ( _rect . Left , mid . Y , size . X , size . Y ) ) ; _childBR = new QuadTreeNode < T > ( this , new Rectangle ( mid . X , mid . Y , size . X , size . Y ) ) ; for ( var i = 0 ; i < _objects . Count ; i ++ ) { var destTree = getDestinationTree ( _objects [ i ] ) ; if ( destTree != this ) { destTree . insert ( _objects [ i ] ) ; remove ( _objects [ i ] ) ; i -- ; } } }
Subdivide this QuadTree and move it's children into the appropriate Quads where applicable.
Subdivide this QuadTree and move it ' s children into the appropriate Quads where applicable .
// We've reached capacity, subdivide... // If they're completely contained by the quad, bump objects down // Insert to the appropriate tree, remove the object, and back up one in the loop