public RBTViewModel(Node _node) : base(_node) { SwitchToBlack = new RelayCommand<MouseButtonEventArgs>(ToBlack); SwitchToRed = new RelayCommand<MouseButtonEventArgs>(ToRed); _ColorOfText = Brushes.White; }
public NodeViewModel(Node node) { color = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, node.color.R, node.color.G, node.color.B)); preColor = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, node.preColor.R, node.preColor.G, node.preColor.B)); _node = node; Offset = 47; DeleteCommand = new RelayCommand<MouseButtonEventArgs>(deleteNode); borderColor = Brushes.Black; borderThickness = 1; }
public T234ViewModel(Node _node,int n) : base(_node) { ShowOneT234 = new RelayCommand<MouseButtonEventArgs>(ShowOneT234Node); ShowTwoT234 = new RelayCommand<MouseButtonEventArgs>(ShowTwoT234Node); ShowThreeT234 = new RelayCommand<MouseButtonEventArgs>(ShowThreeT234Node); switch (n) { case 1: ShowOneT234Node(null); break; case 2: ShowTwoT234Node(null); break; default: ShowThreeT234Node(null); break; } _ColorOfText = Brushes.Black; }
//returns true if tree is valid after remove public bool removeNeighbour(Node node) { return Node.removeNeighbour(node); }
public bool isChild(Node node) { return Node.isChild(node); }
//returns true if tree is valid after add public bool addNeighbour(Node node) { return Node.addNeighbour(node); }
private bool pushAncenstors(Node orig) { Node parent = getParent(); if (parent == null) { return false; } if (parent.x + X_ONSET-1 > orig.x && parent.x - X_ONSET+1 < orig.x) { if(x < parent.x) { getRoot().pushTree(LEFT, parent.x, orig, X_ONSET + (orig.x - parent.x) ); orig.move(LEFT, X_ONSET + (orig.x - parent.x)); } else { getRoot().pushTree(RIGHT, parent.x, orig, X_ONSET + (parent.x - orig.x) ); orig.move(RIGHT, X_ONSET + (parent.x - orig.x) ); } } return parent.pushAncenstors(orig); }
private bool pushTree(int direction, double threshold, Node orig, double offset) { Node[] children = getChildren(); if(this == orig) return true; if (direction == LEFT && x < threshold) move(LEFT, offset); else if (direction == RIGHT && threshold < x) move(RIGHT, offset); int i = 0; while (children[i] != null) { children[i].pushTree(direction, threshold, orig, offset); i++; } return true; }
//returns true if tree is valid after remove public bool removeNeighbour(Node node) { node.neighbours.Remove(this); neighbours.Remove(node); return isValid() && node.isValid(); }
private bool moveOffset(Node child, int direction) { if (LEFT == direction) child.X = x - X_OFFSET; else child.X = x + X_OFFSET; child.Y = y + Y_OFFSET; return true; }
public bool isChild(Node node) { return node.y > y; }
//use on valid bst //USE ON ROOT //KIG MERE HER (visuelle del) public Node insertBST(Node newnode) { Node[] children = getChildren(); if (children[0] == null) { addNeighbour(newnode); return this; } else if (children[1] == null) if ((key < newnode.key && children[0].key < newnode.key) || (key >= newnode.key && children[0].key >= newnode.key)) return children[0].insertBST(newnode); else { addNeighbour(newnode); return this; } else if (key < newnode.key) return children[0].insertBST(newnode); else return children[1].insertBST(newnode); }
//Move this to BST only. public Node[] getChildren() { Node[] children = new Node[3]; int i = 0; foreach (Node neighbour in neighbours) if (neighbour.y > y) { children[i] = neighbour; i++; } if(i == 2 && children[0].x > children[1].x) { Node temp = children[0]; children[0] = children[1]; children[1] = temp; } return children; }
//returns true if tree is valid after add public bool addNeighbour(Node node) { neighbours.AddLast(node); node.neighbours.AddLast(this); return isValid() && node.isValid(); }
// For changing the current state of the diagram. public MoveNodeCommand(Node _node, double _offsetX, double _offsetY) { node = _node; offsetX = _offsetX; offsetY = _offsetY; }