Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Copies this formula
 /// </summary>
 /// <returns>the copy</returns>
 public virtual MathFormula Copy()
 {
     form = new MathFormula(level, sizes);
     for (int i = 0; i < Count; i++)
     {
         MathSymbol s = this[i].Copy();
         s.Parent = form;
         form.Add(s);
     }
     return(form);
 }
        /// <summary>
        /// Transformation of properties
        /// </summary>
        /// <param name="formula"></param>
        /// <returns></returns>
        static public MathFormula TransformPropery(this MathFormula formula)
        {
            MathFormula form = new MathFormula(formula.Level, formula.Sizes);
            int         n    = formula.Count;

            for (int i = 0; i < n; i++)
            {
                MathSymbol         s = formula[i].Copy();
                List <MathFormula> c = s.Children;
                if (i < n + 2)
                {
                    MathSymbol p  = formula[i + 1];
                    MathSymbol pn = formula[i + 2];
                    if (p.Symbol == '.')
                    {
                        s = new PropertySymbol(s.String, p.String);
                    }
                }
                s.Parent = form;
                form.Add(s);
            }
            return(form);
        }