public override Sink Locate(Edge edge) { if (_edge.IsAbove(edge.P)) { // Move down the graph return(RightChild.Locate(edge)); } if (_edge.IsBelow(edge.P)) { // Move up the graph return(LeftChild.Locate(edge)); } // s and segment share the same endpoint, p if (edge.Slope < _edge.Slope) { // Move down the graph return(RightChild.Locate(edge)); } // Move up the graph return(LeftChild.Locate(edge)); }
public override string ToString() { return(String.Format("{0}({1},{2})", Label, LeftChild != null ? LeftChild.ToString() : null, RightChild != null ? RightChild.ToString() : null)); }
public override string ToString() { return(Value + "{" + (LeftChild != null ? LeftChild.ToString() : "-") + (RightChild != null ? RightChild.ToString() : "-") + "}"); }
public string ToSql() { return($"{LeftChild.ToSql()} {GetOperator()} {RightChild.ToSql()}"); }
/// <summary> /// Prints node parsing /// </summary> public override string Print() => "( / " + LeftChild.Print() + RightChild.Print() + ") ";
/// <summary> /// Evaluate as boolean /// </summary> internal override bool BoolEvaluate(ConditionEvaluationState state) { ProjectErrorUtilities.VerifyThrowInvalidProject (LeftChild.CanNumericEvaluate(state) && RightChild.CanNumericEvaluate(state), state.conditionAttribute, "ComparisonOnNonNumericExpression", state.parsedCondition, /* helpfully display unexpanded token and expanded result in error message */ (LeftChild.CanNumericEvaluate(state) ? RightChild.GetUnexpandedValue(state) : LeftChild.GetUnexpandedValue(state)), (LeftChild.CanNumericEvaluate(state) ? RightChild.GetExpandedValue(state) : LeftChild.GetExpandedValue(state))); return(Compare(LeftChild.NumericEvaluate(state), RightChild.NumericEvaluate(state))); }
public void EachPostOrder(Action <T> action) { LeftChild?.EachPostOrder(action); RightChild?.EachPostOrder(action); action.Invoke(this.Value); }
public void Remove(T value) { if (value.CompareTo(Value) == 0) { Parent.IsChanged = true; if (RightChild == null && LeftChild == null) { Parent.ParentRemove(value); } if (RightChild == null && LeftChild != null) { LeftChild.Parent = Parent; if (value.CompareTo(Parent.Value) < 0) { Parent.LeftChild = LeftChild; } if (value.CompareTo(Parent.Value) > 0) { Parent.RightChild = LeftChild; } } if (RightChild != null && LeftChild == null) { RightChild.Parent = Parent; if (value.CompareTo(Parent.Value) < 0) { Parent.LeftChild = RightChild; } if (value.CompareTo(Parent.Value) > 0) { Parent.RightChild = RightChild; } } if (RightChild != null && LeftChild != null) { if (RightChild.RightChild == null && RightChild.LeftChild == null) { RightChild.IsChanged = true; RightChild.LeftChild = LeftChild; RightChild.Parent = Parent; if (value.CompareTo(Parent.Value) < 0) { Parent.LeftChild = RightChild; } if (value.CompareTo(Parent.Value) > 0) { Parent.RightChild = RightChild; } } else { BinarySearchTreeNode <T> tmpChild = RightChild.TraverstLeft(); this.Remove(tmpChild.Value); _value = tmpChild.Value; } } } else { if (value.CompareTo(Value) < 0) { if (LeftChild != null) { LeftChild.Remove(value); } } if (value.CompareTo(Value) >= 0) { if (RightChild != null) { RightChild.Remove(value); } } } }
/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public override object Clone() { return(new EndLinkedDawgNode <TKey, TValue>(Key, LeftChild == null? null: (IDawgNode <TKey, TValue>)LeftChild.Clone(), RightSibling == null? null: (IDawgNode <TKey, TValue>)RightSibling.Clone(), Value)); }
/// <summary> /// calculates Perlin Noise using left child as x and right child as y /// </summary> /// <returns>Mathf.PlerlinNoise(LC.Eval,RC.Eval)</returns> public override float Evaluate() { return(Mathf.PerlinNoise(LeftChild.Evaluate(), RightChild.Evaluate())); }
/// <summary> /// tar bort en nod med angivet värde från trädet /// </summary> /// <param name="value">värdet på norden som ska tas bort</param> public void Remove(T value) { if (value.CompareTo(Value) == 0) //om infört (eftersökt) värde hittas { Parent.IsChanged = true; if (LeftChild == null && RightChild == null) //om noden är ett löv { if (IsRightChild == true) //om noden är ett högerbarn { Parent.RightChild = null; } else { Parent.LeftChild = null; } } if (LeftChild == null && RightChild != null) //noden har endast ett högerbarn { if (IsRightChild) //om noden har högerbarn { Parent.RightChild = RightChild; RightChild.Parent = Parent; } else //om något undantag, dvs vänsterbarn skulle smita förbi { Parent.LeftChild = RightChild; RightChild.Parent = Parent; } } if (LeftChild != null && RightChild == null) //om noden har endast ett vänsterbarn { if (IsLeftChild) //om noden har vänsterbarn { Parent.LeftChild = LeftChild; LeftChild.Parent = Parent; } else //om något undantag, dvs högerbarn, skulle smita förbi { Parent.RightChild = LeftChild; LeftChild.Parent = Parent; } } if (LeftChild != null && RightChild != null) //om noden har två barn, ett höger och ett vänster { BinarySearchTreeNode <T> temp = LeftChild; //instantierar temporär variabel av klassen BinarySearchTreeNode som är ett vänsterbarn while (temp.RightChild != null) //går sålänge den tillfälliga variabeln, som rör sig mellan noder, har ett högerbarn { temp = temp.RightChild; //ge den temporära variabeln högerbarnets värde } this.Value = temp.Value; //ge det aktuella värdet den temporära variabelns värde if (LeftChild != null) { LeftChild.Remove(temp.Value); } } } else if (value.CompareTo(this.Value) > 0) { RightChild.Remove(value); } else if (value.CompareTo(this.Value) < 0) { LeftChild.Remove(value); } }
public void ForEachInOrder(Action <T> action) { LeftChild?.ForEachInOrder(action); action.Invoke(this.Value); RightChild?.ForEachInOrder(action); }
/// <summary> /// Evaluate as boolean /// </summary> internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state) { return(!LeftChild.BoolEvaluate(state)); }
/// <summary> /// Calculates the operation of division. /// </summary> /// <returns>Result of the division.</returns> public override int Data() => LeftChild.Data() / RightChild.Data();
/// <summary> /// Returns string, representing the expression of the tree, which head is this node /// </summary> /// <returns>String, representing the expression of the tree, which head is this node</returns> public string GetLine() { return("( " + data + " " + LeftChild.GetLine() + " " + RightChild.GetLine() + " )"); }
public override TreeNode Clone(TreeNode parent = null) { return(new BinaryOperationTreeNode(Operation, LeftChild.Clone(this), RightChild.Clone(this), parent)); }
public override double Calculate() => LeftChild.Calculate() *RightChild.Calculate();
public override double Count() => Math.Abs(RightChild.Count()) <= 1e-6 ? throw new DivideByZeroException() : LeftChild.Count() / RightChild.Count();
public void PrintIndentedPreOrder(int indent = 0) { Console.WriteLine(new string(' ', indent) + this.Value); LeftChild?.PrintIndentedPreOrder(indent + 2); RightChild?.PrintIndentedPreOrder(indent + 2); }
public Image Draw(out int center) { center = _lastImageLocationOfStarterNode; if (!IsChanged) // if the current node and it's childs are up to date, just return the last drawed image. { return(_lastImage); } var lCenter = 0; var rCenter = 0; Image lNodeImg = null, rNodeImg = null; if (LeftChild != null) // draw left node's image { lNodeImg = LeftChild.Draw(out lCenter); } if (RightChild != null) // draw right node's image { rNodeImg = RightChild.Draw(out rCenter); } // draw current node and it's childs (left node image and right node image) var lSize = new Size(); var rSize = new Size(); var under = (lNodeImg != null) || (rNodeImg != null);// if true the current node has childs if (lNodeImg != null) { lSize = lNodeImg.Size; } if (rNodeImg != null) { rSize = rNodeImg.Size; } var maxHeight = lSize.Height; if (maxHeight < rSize.Height) { maxHeight = rSize.Height; } if (lSize.Width <= 0) { lSize.Width = (_nodeBg.Width - _freeSpace.Width) / 2; } if (rSize.Width <= 0) { rSize.Width = (_nodeBg.Width - _freeSpace.Width) / 2; } var resSize = new Size { Width = lSize.Width + rSize.Width + _freeSpace.Width, Height = _nodeBg.Size.Height + (under ? maxHeight + _freeSpace.Height : 0) }; var result = new Bitmap(resSize.Width, resSize.Height); var g = Graphics.FromImage(result); g.SmoothingMode = SmoothingMode.HighQuality; g.FillRectangle(Brushes.White, new Rectangle(new Point(0, 0), resSize)); g.DrawImage(_nodeBg, lSize.Width - _nodeBg.Width / 2 + _freeSpace.Width / 2, 0); var str = Value.ToString(); g.DrawString(str, font, Brushes.Black, lSize.Width - _nodeBg.Width / 2 + _freeSpace.Width / 2 + (2 + (str.Length == 1 ? 10 : str.Length == 2 ? 5 : 0)) * Coef, _nodeBg.Height / 2f - 12 * Coef); center = lSize.Width + _freeSpace.Width / 2; var pen = new Pen(Brushes.Black, 1.2f * Coef) { EndCap = LineCap.ArrowAnchor, StartCap = LineCap.Round }; float x1 = center; float y1 = _nodeBg.Height; float y2 = _nodeBg.Height + _freeSpace.Height; float x2 = lCenter; var h = Math.Abs(y2 - y1); var w = Math.Abs(x2 - x1); if (lNodeImg != null) { g.DrawImage(lNodeImg, 0, _nodeBg.Size.Height + _freeSpace.Height); var points1 = new List <PointF> { new PointF(x1, y1), new PointF(x1 - w / 6, y1 + h / 3.5f), new PointF(x2 + w / 6, y2 - h / 3.5f), new PointF(x2, y2), }; g.DrawCurve(pen, points1.ToArray(), 0.5f); } if (rNodeImg != null) { g.DrawImage(rNodeImg, lSize.Width + _freeSpace.Width, _nodeBg.Size.Height + _freeSpace.Height); x2 = rCenter + lSize.Width + _freeSpace.Width; w = Math.Abs(x2 - x1); var points = new List <PointF> { new PointF(x1, y1), new PointF(x1 + w / 6, y1 + h / 3.5f), new PointF(x2 - w / 6, y2 - h / 3.5f), new PointF(x2, y2) }; g.DrawCurve(pen, points.ToArray(), 0.5f); } IsChanged = false; _lastImage = result; _lastImageLocationOfStarterNode = center; return(result); }
/// <summary> /// Evaluate as boolean /// </summary> internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state) { bool isLeftNum = LeftChild.CanNumericEvaluate(state); bool isLeftVersion = LeftChild.CanVersionEvaluate(state); bool isRightNum = RightChild.CanNumericEvaluate(state); bool isRightVersion = RightChild.CanVersionEvaluate(state); bool isNumeric = isLeftNum && isRightNum; bool isVersion = isLeftVersion && isRightVersion; bool isValidComparison = isNumeric || isVersion || (isLeftNum && isRightVersion) || (isLeftVersion && isRightNum); ProjectErrorUtilities.VerifyThrowInvalidProject (isValidComparison, state.ElementLocation, "ComparisonOnNonNumericExpression", state.Condition, /* helpfully display unexpanded token and expanded result in error message */ LeftChild.CanNumericEvaluate(state) ? RightChild.GetUnexpandedValue(state) : LeftChild.GetUnexpandedValue(state), LeftChild.CanNumericEvaluate(state) ? RightChild.GetExpandedValue(state) : LeftChild.GetExpandedValue(state)); // If the values identify as numeric, make that comparison instead of the Version comparison since numeric has a stricter definition if (isNumeric) { return(Compare(LeftChild.NumericEvaluate(state), RightChild.NumericEvaluate(state))); } else if (isVersion) { return(Compare(LeftChild.VersionEvaluate(state), RightChild.VersionEvaluate(state))); } // If the numbers are of a mixed type, call that specific Compare method if (isLeftNum && isRightVersion) { return(Compare(LeftChild.NumericEvaluate(state), RightChild.VersionEvaluate(state))); } else if (isLeftVersion && isRightNum) { return(Compare(LeftChild.VersionEvaluate(state), RightChild.NumericEvaluate(state))); } // Throw error here as this code should be unreachable ErrorUtilities.ThrowInternalErrorUnreachable(); return(false); }
public virtual void Print() { LeftChild.Print(); RightChild.Print(); Console.Write(") "); }
/// <summary> /// Calculates the node value /// </summary> /// <returns>Value of node after calculation</returns> public override int Calculate() => LeftChild.Calculate() / RightChild.Calculate();
public override int Calculate() { return(LeftChild.Calculate() + RightChild.Calculate()); }
//--------------------------------------------------------------------------------------- // Returns an enumerable that represents the query executing sequentially. // internal override IEnumerable <TSource> AsSequentialQuery(CancellationToken token) { return(LeftChild.AsSequentialQuery(token).Concat(RightChild.AsSequentialQuery(token))); }
internal override bool CanBoolEvaluate(ConditionEvaluationState state) { return(LeftChild.CanBoolEvaluate(state)); }
/// <summary> /// Subtraction's counting /// </summary> /// <returns>Subtraction's result</returns> public override double Counting() => LeftChild.Counting() - RightChild.Counting();
/// <summary> /// Returns expanded value with '!' prepended. Useful for error messages. /// </summary> internal override string GetExpandedValue(ConditionEvaluationState state) { return("!" + LeftChild.GetExpandedValue(state)); }
//--------------------------------------------------------------------------------------- // Returns an enumerable that represents the query executing sequentially. // internal override IEnumerable <TInputOutput> AsSequentialQuery(CancellationToken token) { IEnumerable <TInputOutput> wrappedLeftChild = CancellableEnumerable.Wrap(LeftChild.AsSequentialQuery(token), token); IEnumerable <TInputOutput> wrappedRightChild = CancellableEnumerable.Wrap(RightChild.AsSequentialQuery(token), token); return(wrappedLeftChild.Intersect(wrappedRightChild, _comparer)); }
internal override void ResetState() { LeftChild?.ResetState(); RightChild?.ResetState(); }