public QuadTree(Vector2 mapSize) { this.mapSize = mapSize; leafDictionary = new LeafDictionary(this); Rectangle mapRectangle = new Rectangle(0, 0, (int)Math.Ceiling(mapSize.X), (int)Math.Ceiling(mapSize.Y)); root = new InternalNode(true, null, mapRectangle, leafDictionary); }
public QuadTree(Vector2 mapSize, GetTreePosition positionFunc) { this.mapSize = mapSize; this.positionFunc = positionFunc; leafDictionary = new LeafDictionary(this); Rectangle mapRectangle = new Rectangle(0, 0, (int)Math.Ceiling(mapSize.X), (int)Math.Ceiling(mapSize.Y)); root = new InternalNode(true, null, mapRectangle, leafDictionary, this.positionFunc); }
public QuadTree(Vector2 mapSize) { this.mapSize = mapSize; //RectangleF mapRectangle = new RectangleF(new Vector2(0), mapSize); Rectangle mapRectangle = new Rectangle(0, 0, (int)Math.Ceiling(mapSize.X), (int)Math.Ceiling(mapSize.Y)); //root = Node.ConstructRoot(mapRectangle); root = new InternalNode(true, null, mapRectangle);//Node.ConstructBranch(null, mapRectangle, 2); }
public InternalNode(Boolean root, InternalNode parent, Rectangle mapSpace) : base(parent) { this.root = root; this.mapSpace = mapSpace; int halfWidth = mapSpace.Width / 2; int halfHeight = mapSpace.Height / 2; Rectangle swRectangle = new Rectangle(mapSpace.X, mapSpace.Y, halfWidth, halfHeight); Rectangle seRectangle = new Rectangle(mapSpace.X + halfWidth, mapSpace.Y, mapSpace.Width - halfWidth, halfHeight); Rectangle nwRectangle = new Rectangle(mapSpace.X, mapSpace.Y + halfHeight, halfWidth, mapSpace.Height - halfHeight); Rectangle neRectangle = new Rectangle(mapSpace.X + halfWidth, mapSpace.Y + halfHeight, mapSpace.Width - halfWidth, mapSpace.Height - halfHeight); nw = new Leaf(this, nwRectangle);//Node.ConstructBranch(this, nwRectangle, height - 1); ne = new Leaf(this, neRectangle);//Node.ConstructBranch(this, neRectangle, height - 1); sw = new Leaf(this, swRectangle);//Node.ConstructBranch(this, swRectangle, height - 1); se = new Leaf(this, seRectangle);//Node.ConstructBranch(this, seRectangle, height - 1); }
public bool IsChild(Node node) { return this.children.Contains(node); }
public void Replace(Node current, Node newNode) { if (current is InternalNode == newNode is InternalNode) { throw new Exception("Illegal replacement type"); } if (!children.Contains(current)) { throw new Exception("Cannot replace a non child"); } children.Remove(current); children.Add(newNode); if (children.Count != 4) { throw new Exception("incorrect child count"); } }
public void Replace(Node current, Node newNode) { if (current is InternalNode == newNode is InternalNode) { throw new Exception("Illegal replacement type"); } if (nw == newNode || ne == newNode || sw == newNode || se == newNode) { throw new Exception("Cannot replace with current child"); } if(nw.Equals(current)) { nw = newNode; } else if(ne.Equals(current)) { ne = newNode; } else if (sw.Equals(current)) { sw = newNode; } else if (se.Equals(current)) { se = newNode; } else { throw new Exception("Cannot replace a non child"); } }