public QuadTree(int width, int height, int minWidth, int minHeight) { _width = width; _height = height; _minWidth = minWidth; _minHeight = minHeight; MapBoundary = new Rectangle(0, 0, _width, _height); _root = new QuadTreeNode(MapBoundary, _minWidth, _minHeight, null); }
public QuadTreeNode(Rectangle bound, int minWidth, int minHeight, QuadTreeNode parent) { Bounds = bound; _minWidth = minWidth; _minHeight = minHeight; Contents = new List<Collidable>(); Children = new List<QuadTreeNode>(4); Parent = parent; UpdatedAtInterval = -1; Leaf = false; // Will build out the tree Partition(); }
// Expands by a multiple of 4 public void ExpandTo(int newWidth, int newHeight, int newMinWidth, int newMinHeight) { // We will be larger, so we want to have larger min-width's _root.LiftLeafNodes(newMinWidth, newMinHeight); MapBoundary = new Rectangle(0,0,newWidth,newHeight); // Create larger quad tree map QuadTreeNode newRoot = new QuadTreeNode(MapBoundary,newMinWidth,newMinHeight,null); // Maybe fix in the future, newRoot generates a topLeft that will be replaced newRoot.TopLeft = _root; // Make old root a child _root.Parent = newRoot; // Assign a new root _root = newRoot; }
public void Clear() { _root.ClearCollidableMaps(); MapBoundary = new Rectangle(0, 0, _width, _height); _root = new QuadTreeNode(MapBoundary, _minWidth, _minHeight, null); }
public void SetMapArea(QuadTreeNode node) { _mapLocation = node; }
public void ClearMapArea() { _mapLocation = null; }