public IBlock FindNodeById(string id) { if (id == ID) { return(this); } else { if (null != RootIndex) { var node = RootIndex.FindNodeById(id); if (null != node) { return(node); } } if (null != Radicand) { var deNode = Radicand.FindNodeById(id); if (null != deNode) { return(deNode); } } return(null); } }
public override int GetHashCode() { int h1 = Coefficient.GetHashCode(); int h2 = Radicand.GetHashCode(); int h3 = (((h1 << 5) + h1) ^ h2); int h4 = Index.GetHashCode(); return(((h3 << 5) + h3) ^ h4); }
private Size GetRadicandSize() { if (null == Radicand) { return(new Size(FontManager.Instance.FontSize, FontManager.Instance.FontSize)); } else { return(Radicand.GetSize()); } }
public void RemoveChild(IBlock block) { if (null != RootIndex) { RootIndex.RemoveChild(block);; } if (null != Radicand) { Radicand.RemoveChild(block); } }
public void GetElementBeforeCaret(Point caretLocation) { if (null != RootIndex) { RootIndex.GetElementBeforeCaret(caretLocation); } if (null != Radicand) { Radicand.GetElementBeforeCaret(caretLocation); } }
public void AddChildrenAfterBlock(IBlock block, IEnumerable <IBlock> inputCharactors) { if (RootIndex != null && RootIndex.Children.Contains(block)) { RootIndex.AddChildrenAfterBlock(block, inputCharactors); } if (Radicand != null) { if (Radicand.Children.Contains(block)) { Radicand.AddChildrenAfterBlock(block, inputCharactors); } } }
public XElement Serialize() { var typeFraction = (new Radical()).GetType(); XElement fraction = new XElement("Radical"); XElement molecule = new XElement("RootIndex"); XElement denominator = new XElement("Radicand"); XElement rootIndexBlockNode = RootIndex.Serialize(); molecule.Add(rootIndexBlockNode); XElement radicandBlockNode = Radicand.Serialize(); denominator.Add(radicandBlockNode); fraction.Add(molecule); fraction.Add(denominator); return(fraction); }
public void SetBlockLocation(double locationX, double alignmentCenterY, double rowY) { var rootindexSize = GetRootIndexSize(); double rootIndexY = alignmentCenterY - GetVerticalAlignmentCenter(); this.Location = new Point(locationX, rootIndexY); if (null != RootIndex) { RootIndex.Location = new Point(locationX, rootIndexY); var rootIndexVerticalCenter = RootIndex.GetVerticalAlignmentCenter(); RootIndex.SetBlockLocation(locationX, RootIndex.Location.Y + rootIndexVerticalCenter, rowY); } if (null != Radicand) { Radicand.Location = new Point(locationX + rootindexSize.Width + 10, this.Location.Y + rootindexSize.Height / 3); double radicandVerticalCenter = Radicand.GetVerticalAlignmentCenter(); Radicand.SetBlockLocation(Radicand.Location.X, Radicand.Location.Y + radicandVerticalCenter, rowY); } }
public IBlock GetCaretBrotherElement(bool before, Point caretPoint) { if (null != RootIndex) { var block = RootIndex.GetCaretBrotherElement(before, caretPoint); if (null != block) { return(block); } } if (null != Radicand) { var block = Radicand.GetCaretBrotherElement(before, caretPoint); if (null != block) { return(block); } } return(null); }
public void AddChildren(IEnumerable <IBlock> inputCharactors, Point caretPoint, string parentId) { if (IsRootIndexContains(caretPoint)) { if (null == RootIndex) { RootIndex = new BlockNode(); RootIndex.ParentId = ID; } RootIndex.AddChildren(inputCharactors, caretPoint, parentId); } if (IsRadicandContains(caretPoint)) { if (null == Radicand) { Radicand = new BlockNode(); Radicand.ParentId = ID; } Radicand.AddChildren(inputCharactors, caretPoint, parentId); } }
public void DrawBlock(Canvas canvas) { Polyline radicalPolyline = CreateRadicalPolyline(); var rootIndexRect = GetRootIndexRect(); var rootIndexRectangle = CreateRangeRect(rootIndexRect); var radicandRect = GetRadicandRect(); var radicandRectangle = CreateRangeRect(radicandRect); canvas.Children.Add(rootIndexRectangle); canvas.Children.Add(radicandRectangle); canvas.Children.Add(radicalPolyline); if (null != RootIndex) { RootIndex.DrawBlock(canvas); } if (null != Radicand) { Radicand.DrawBlock(canvas); } }
public double GetVerticalAlignmentCenter() { Size rootIndexSize; if (null == RootIndex) { rootIndexSize = new Size(12, FontManager.Instance.FontSize); } else { rootIndexSize = RootIndex.GetSize(); } if (null == Radicand) { return(FontManager.Instance.FontSize / 2 + rootIndexSize.Height / 3); } else { double verticalCenter = Radicand.GetVerticalAlignmentCenter(); return(verticalCenter + rootIndexSize.Height / 3); } }
/// <summary> /// S = simplest form, R = all under the radical /// </summary> /// <param name="format"></param> /// <param name="formatProvider"></param> /// <returns></returns> public string ToString(string format, IFormatProvider formatProvider) { if (Coefficient.IsZero) { return("0"); } if (Radicand.IsZero) { return("0"); } if (format == null) { format = "S"; } if (IsZero) { return(0.ToString()); } if (IsOne) { return(1.ToString()); } var result = new StringBuilder(); // Simplest form if ("S".Equals(format)) { // Handle coefficient // TODO: Pass format through if (Coefficient.Denominator.IsOne) { if (!Coefficient.Numerator.IsOne || (Coefficient.Numerator.IsOne && Radicand.IsOne)) { if (Sign < 0) { result.Append("(" + Coefficient.Numerator.ToString() + ")"); } else { result.Append(Coefficient.Numerator.ToString()); } } } else { result.Append("(" + Coefficient.ToString() + ")"); } // Handle radicand if (Index > 1 && Radicand > 1) { if (result.Length > 0) { result.Append("*"); } if (Index == 2) { result.Append("Sqrt"); } else { result.Append("Nth-Root[index:" + Index.ToString() + "]"); } result.Append("(" + Radicand.ToString() + ")"); } } else if ("R".Equals(format)) { if (Index == 1) { if (Coefficient.Denominator.IsOne) { if (!Coefficient.Numerator.IsOne || (Coefficient.Numerator.IsOne && Radicand.IsOne)) { result.Append(Coefficient.Numerator.ToString()); } } else { result.Append("(" + Coefficient.ToString() + ")"); } } else { if (Sign < 0) { result.Append("-"); } // Get the rational for all under the radical if (Index == 2) { result.Append("Sqrt"); } else { result.Append("Nth-Root[index:" + Index.ToString() + "]"); } var radicand = RaisedToIndexPower; if (radicand.Denominator.IsOne) { result.Append("(" + BigInteger.Abs(radicand.Numerator).ToString() + ")"); } else { result.Append("(" + Rational.Abs(radicand.CanonicalForm).ToString() + ")"); } } } return(result.ToString()); }