public virtual void AddChild(Node childNode) { Children.Add(childNode); childNode.Parent = this; childNode.Ancestors.AddAll(this.Ancestors); childNode.Ancestors.Add(this); this.Descendants.Add(childNode); }
private Node Search(Node node, Vertex vertex) { foreach (Node childNode in node.Children) { if (childNode.Face.Inside(vertex)) { return Search(childNode, vertex); } } return node; }
public Tree(Face root) { Root = new Node(root); }
private void DrawTree(Node root, int level = 0, float scale = 1.0f) { for (int index = 0; index < root.Children.Count; index++) { Node node = root.Children[index]; float localscale = scale * 1f / (root.Children.Count + 1) * (index + 1); float radius = 20; SolidColorBrush solidColorBrush = new SolidColorBrush { Color = Colors.Red }; Ellipse elipse = new Ellipse { Stroke = solidColorBrush, Width = radius * 2, Height = radius * 2 }; treeCanvas.Children.Add(elipse); Canvas.SetLeft(elipse, (treeCanvas.ActualWidth * scale) + (localscale * treeCanvas.ActualWidth) - radius); Canvas.SetTop(elipse, 50 * (level + 1) - radius); Label label = new Label { Content = $"F{node.Face.Id:d}", Foreground = solidColorBrush, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, Width = radius * 2, Height = radius * 2 }; Canvas.SetLeft(label, treeCanvas.ActualWidth * localscale - radius); Canvas.SetTop(label, 50 * (level + 1) - radius); treeCanvas.Children.Add(label); DrawTree(node, level + 1, localscale); } }