/// <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); MathSymbol sym = new FractionSymbol(); sym.Append(form); for (int i = 0; i < 2; i++) { form.First[i] = FormulaCreator.CreateFormula(tree[i], level, sizes); } return(form); }
/// <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); }