public bool IsNodeNeighbor(PartitionNode <T> node) { int dx = Math.Abs(node.GetBounds().Center.X - Bounds.Center.X); int dy = Math.Abs(node.GetBounds().Center.Y - Bounds.Center.Y); return(dx <= Bounds.Width && dx > 0 && dy <= Bounds.Height && dy > 0); }
public void AddParent(PartitionNode <T> parent) { if (!Parents.Contains(parent)) { Parents.Add(parent); } }
public void RemoveChild(PartitionNode <T> child) { if (Children.Contains(child)) { Children.Remove(child); } }
public void CreateChildren() { // Do nothing, if children are already created if (Children.Count > 1) { return; } // Adding exisitng children List <PartitionNode <T> > siblings = FindSiblings(); Children.AddRange(FindExistingChildren(siblings).Where(x => !Children.Contains(x))); int children_layer = LayerNum + 1; Size children_size = new Size(Bounds.Width / 2, Bounds.Height / 2); List <PartitionNode <T> > parent = new List <PartitionNode <T> > { this }; int nodeX = Bounds.Center.X - (Bounds.Width / 2); int nodeY = Bounds.Center.Y - (Bounds.Height / 2); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int centX = nodeX + ((Bounds.Width / 2) * i); int centY = nodeY + ((Bounds.Height / 2) * j); PartitionNode <T> new_child = new PartitionNode <T>(new Rectangle(new Point(centX, centY), children_size), Capacity, children_layer, parent); if (!Children.Contains(new_child)) { Children.Add(new_child); } } } // Updating all known parents foreach (var child in Children) { foreach (var par in siblings.Where(x => x.IntersectsWith(child.GetBounds()))) { child.AddParent(par); } } }
public bool Equals(PartitionNode <T> other) { return(LayerNum == other.LayerNum && Bounds.Equals(other.Bounds)); }