public void DestroyLeaf(Leaf l) { Dictionary<CompositePhysicalObject, Leaf> copy = new Dictionary<CompositePhysicalObject, Leaf>(leafDictionary); foreach (CompositePhysicalObject obj in copy.Keys) { if (copy[obj] == l) { leafDictionary.Remove(obj); } } }
public void SetLeaf(CompositePhysicalObject obj, Leaf leaf) { //this.Invariant(); if (leaf != null) { if (!leafDictionary.ContainsKey(obj)) { leafDictionary.Add(obj, leaf); } leafDictionary[obj] = leaf; } else { leafDictionary.Remove(obj); } //this.Invariant(); }
public InternalNode(Boolean root, InternalNode parent, Rectangle mapSpace, LeafDictionary leafDictionary, GetTreePosition positionFunc) : base(parent, mapSpace, leafDictionary, positionFunc) { this.root = root; 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); Node nw = new Leaf(this, nwRectangle, leafDictionary, positionFunc); Node ne = new Leaf(this, neRectangle, leafDictionary, positionFunc); Node sw = new Leaf(this, swRectangle, leafDictionary, positionFunc); Node se = new Leaf(this, seRectangle, leafDictionary, positionFunc); children.Add(nw); children.Add(ne); children.Add(sw); children.Add(se); }
public void Collapse() { if (this.ObjectCount() < Node.max_count) { if (AllChildrenAreLeaves()) { if (this.Parent != null) { if (!this.Parent.IsChild(this)) { throw new Exception("incorrect child/parent"); } Leaf newNode = new Leaf(this.Parent, this.MapSpace, leafDictionary); this.Parent.Replace(this, newNode); foreach (Leaf leaf in children) { foreach (CompositePhysicalObject myObjects in leaf.CompleteList()) { this.Remove(myObjects); if (!newNode.Add(myObjects)) { this.Parent.Move(myObjects); } } leafDictionary.DestroyLeaf(leaf); } this.Parent.Collapse(); } } else { throw new Exception("Children did not collapse"); } } }
public void SetLeaf(Leaf leaf) { this.leaf = leaf; }
public void Collapse() { if (this.ObjectCount() < Node.max_count) { if (nw is Leaf && ne is Leaf && sw is Leaf && se is Leaf) { if (this.Parent != null) { Node newNode = new Leaf(this.Parent, this.mapSpace); this.Parent.Replace(this, newNode); foreach (CompositePhysicalObject myObjects in this.CompleteList()) { newNode.Add(myObjects); } this.Parent.Collapse(); } } else { throw new Exception("Children did not collapse"); } } }