Beispiel #1
0
 public SquareRootElement(FormulaElement element)
 {
     this.element = element;
     Width        = element.Width + SqrtWidth + Margin;
     Height       = element.Height + Margin * 2;
 }
Beispiel #2
0
 public BracketElement(FormulaElement element)
 {
     this.element = element;
     Width        = element.Width + OpenBracket.Width + CloseBracket.Width + BracketGap * 2;
     Height       = element.Height;
 }
Beispiel #3
0
 public AbsoluteElement(FormulaElement element)
 {
     this.element = element;
     Width        = element.Width + (SymbolWidth + Gap) * 2;
     Height       = element.Height;
 }
Beispiel #4
0
        private static FormulaElement CreateFormulaElement(TokenType type, int size)
        {
            int i = 0;

            if (type is ExprCore.Types.Expression expr)
            {
                return(ConvertAsFormulaElement(expr.ExprTree, size));
            }
            else if (type is Function func)
            {
                if (func.funcName == "sqrt")
                {
                    return(new SquareRootElement(CreateFormulaElement(func.parameters[0], size)));
                }
                else if (func.funcName == "abs")
                {
                    return(new AbsoluteElement(CreateFormulaElement(func.parameters[0], size)));
                }
                else
                {
                    FormulaElement[] parameters = new FormulaElement[func.parameters.Count];
                    foreach (TokenType t in func.parameters)
                    {
                        parameters[i++] = CreateFormulaElement(t, size);
                    }
                    return(new SequenceElement(new List <FormulaElement>()
                    {
                        new TextElement(func.funcName, size), new CommaBracketElement(parameters)
                    }));
                }
            }
            else if (type is ExprCore.Types.Matrix mat)
            {
                double           rowMax    = 0;
                double           columnMax = 0;
                FormulaElement[] elements  = new FormulaElement[mat.rows * mat.columns];
                for (int r = 0; r < mat.rows; r++)
                {
                    for (int c = 0; c < mat.columns; c++)
                    {
                        elements[i] = CreateFormulaElement(mat.data[r, c], size);
                        rowMax      = Math.Max(rowMax, elements[i].Height);
                        columnMax   = Math.Max(columnMax, elements[i].Width);
                        i++;
                    }
                }
                return(new MatrixElement(rowMax, columnMax, mat.rows, mat.columns, elements));
            }
            else if (type is ExprCore.Types.Vector vec)
            {
                FormulaElement[] elements = new FormulaElement[vec.vecData.Length];
                foreach (TokenType t in vec.vecData)
                {
                    elements[i++] = CreateFormulaElement(t, size);
                }
                return(new CommaBracketElement(elements));
            }
            else if (type is Fraction frac)
            {
                if (UseFractionForm)
                {
                    FormulaElement n = new TextElement(frac.numerator.ToString(), size);
                    FormulaElement d = new TextElement(frac.denomiator.ToString(), size);
                    if (frac.denomiator == 1)
                    {
                        return(n);
                    }
                    else
                    {
                        return(new FractionElement(n, d));
                    }
                }
                else
                {
                    return(new TextElement(frac.GetValue().ToString(), size));
                }
            }
            else if (type is UnaryOperatorWrapper unary)
            {
                FormulaElement innerElement = CreateFormulaElement(unary.token, size);
                FormulaElement wrapper      = innerElement;
                if (unary.token is ExprCore.Types.Expression)
                {
                    wrapper = new BracketElement(innerElement);
                }
                return(new SequenceElement(new List <FormulaElement>()
                {
                    new TextElement(unary.operation.ToString(), size), wrapper
                }));
            }
            else
            {
                return(new TextElement(type.ToString(), size));
            }
        }