/// <summary> /// Creates formula /// </summary> /// <param name="tree">Operation tree</param> /// <param name="level">Formula level</param> /// <param name="sizes">Sizes of symbols</param> /// <returns>The formula</returns> public MathFormula CreateFormula(ObjectFormulaTree tree, byte level, int[] sizes) { MathFormula form = new MathFormula(level, sizes); for (int i = 0; i < 2; i++) { IFormulaCreatorOperation op = tree[i].Operation as IFormulaCreatorOperation; MathFormula f = op.CreateFormula(tree[i], level, sizes); MathFormula fp = null; if (op.OperationPriority < OperationPriority) { fp = new MathFormula(level, sizes); MathSymbol s = new BracketsSymbol(); s.Append(fp); fp.First[0] = f; } else { fp = f; } form.Add(fp); if (i == 0) { MathSymbol s = new BinarySymbol(symbol); s.Append(form); } } return(form); }
/// <summary> /// Creates formula /// </summary> /// <param name="operation">Operation of formula creator</param> /// <param name="tree">Tree</param> /// <param name="level">Level</param> /// <param name="sizes">Sizes</param> /// <param name="str">Str of binrary</param> /// <returns>The formula</returns> public static MathFormula CreateFormula(IFormulaCreatorOperation operation, ObjectFormulaTree tree, byte level, int[] sizes, string str) { MathFormula form = new MathFormula(level, sizes); for (int i = 0; i < str.Length + 1; i++) { IFormulaCreatorOperation op = tree[i].Operation as IFormulaCreatorOperation; MathFormula f = op.CreateFormula(tree[i], level, sizes); MathFormula fp = null; if (op.OperationPriority < operation.OperationPriority) { fp = new MathFormula(level, sizes); MathSymbol s = new BracketsSymbol(); s.Append(fp); fp.First[0] = f; } else { fp = f; } form.Add(fp); if (i < str.Length) { MathSymbol s = new BinarySymbol(str[i]); s.Append(form); } } return(form); }
/// <summary> /// Detects operation acceptor /// </summary> /// <param name="s">Operation symbol</param> /// <returns>The acceptor</returns> public IBinaryAcceptor Detect(MathSymbol s) { if (!(s is BinarySymbol)) { return(null); } BinarySymbol sym = s as BinarySymbol; if (s.Symbol != symbol) { return(null); } return(this); }
/// <summary> /// Creates formula /// </summary> /// <param name="tree">Operation tree</param> /// <param name="level">Formula level</param> /// <param name="sizes">Sizes of symbols</param> /// <returns>The formula</returns> public MathFormula CreateFormula(ObjectFormulaTree tree, byte level, int[] sizes) { MathFormula form = new MathFormula(level, sizes); MathFormula f = new MathFormula(level, sizes); MathSymbol sym = null; if (symbol == '-') { sym = new BinarySymbol('-'); } else { sym = new SimpleSymbol(symbol, false, (byte)FormulaConstants.Unary); } sym.Append(form); sym = new BracketsSymbol(); sym.Append(form); form.Last.Children[0] = FormulaCreator.CreateFormula(tree[0], level, sizes); form.Last.Children[1] = new MathFormula((byte)(level + 1), sizes); return(form); }
public BinarySymbolDrawable(BinarySymbol symbol) : base(symbol.Symbol, symbol.Italic, symbol.String) { }
/// <summary> /// Creates symbol from string vector and sets it to formula /// </summary> /// <param name="f">the formula to set</param> /// <param name="v">the string vector</param> /// <param name="b">the begin position of symbol on string vector</param> /// <param name="e">the end position of symbol on string vector</param> /// <returns>The symbol</returns> public static MathSymbol CreateSymbol(MathFormula f, List <byte[]> v, int b, int e) { char c = (char)GetByte(v, b); byte by = GetByte(v, b + 1); char cb = (char)by; MathSymbol s = null; switch (by) { case (byte)'1': if (c == '%') { s = new SimpleSymbol('%', (byte)FormulaConstants.Variable, true, "\u03c0"); break; } s = new SimpleSymbol(c); break; case (byte)'2': if (c == 'P') { s = new BracketsSymbol(); } else if (c == 'F') { s = new FractionSymbol(); } else if (c == 'A') { s = new BinaryFunctionSymbol('A', "atan2"); } else if (c == 'M') { return(new AbsSymbol()); } else { s = new RootSymbol(); } break; case (byte)'3': string ss = ""; ss += c; if (c == (byte)'*') { ss = "\u2219"; } s = new BinarySymbol(c, false, ss); break; case (byte)'4': s = new SimpleSymbol(c, false, (byte)FormulaConstants.Unary); break; case (byte)'5': s = new SimpleSymbol(c, false, (byte)FormulaConstants.Number); break; case (byte)'7': s = new SeriesSymbol(Int32.Parse(c + "")); break; } s.Append(f); MathSymbol symb = f.Last; int j = b + SHIFT; if (symb.Count > 0) { for (int i = 0; i < symb.Count; i++) { int m = 0; for (int k = j; /*k <= e*/; k++) { byte bt = GetByte(v, k); if (bt == BEGIN_SEPARATOR) { m++; } else if (bt == END_SEPARATOR) { m--; } if (m == 0) { if (symb[i] != null) { MathFormula formula = new MathFormula(symb[i].Level, f.Sizes, v, j + 1, k - 1); symb[i] = formula; j = k + 1; break; } } } } } return(symb); }