QuadTree/QuadTree.SharedProject/QuadTree.cs
/// <summary>
/// Add an item to the quadtree
/// </summary>
/// <param name="quadObject"></param>
Add an item to the quadtree
Add an item to the quadtree
public void Insert(T quadObject)
		{
			var bounds = quadObject.Bounds;
			if (Root == null)
			{
				var rootSize = new Vector2((float)Math.Ceiling(bounds.Width / minLeafSize.X),
										(float)Math.Ceiling(bounds.Height / minLeafSize.Y));
				var multiplier = Math.Max(rootSize.X, rootSize.Y);
				rootSize = new Vector2(minLeafSize.X * multiplier, minLeafSize.Y * multiplier);
				var center = new Point(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
				var rootOrigin = new Point((int)(center.X - rootSize.X / 2), (int)(center.Y - rootSize.Y / 2));
				Root = new QuadNode<T>(new Rectangle(rootOrigin.X, rootOrigin.Y, (int)rootSize.X, (int)rootSize.Y));
			}
			while (!Root.Bounds.Contains(bounds))
			{
				ExpandRoot(bounds);
			}
			InsertNodeObject(Root, quadObject);
		}
public void Insert ( T quadObject ) { var bounds = quadObject . Bounds ; if ( Root == null ) { var rootSize = new Vector2 ( ( float ) Math . Ceiling ( bounds . Width / minLeafSize . X ) , ( float ) Math . Ceiling ( bounds . Height / minLeafSize . Y ) ) ; var multiplier = Math . Max ( rootSize . X , rootSize . Y ) ; rootSize = new Vector2 ( minLeafSize . X * multiplier , minLeafSize . Y * multiplier ) ; var center = new Point ( bounds . X + bounds . Width / 2 , bounds . Y + bounds . Height / 2 ) ; var rootOrigin = new Point ( ( int ) ( center . X - rootSize . X / 2 ) , ( int ) ( center . Y - rootSize . Y / 2 ) ) ; Root = new QuadNode < T > ( new Rectangle ( rootOrigin . X , rootOrigin . Y , ( int ) rootSize . X , ( int ) rootSize . Y ) ) ; } while ( ! Root . Bounds . Contains ( bounds ) ) { ExpandRoot ( bounds ) ; } InsertNodeObject ( Root , quadObject ) ; }
Add an item to the quadtree
Add an item to the quadtree
quadObject
T
None