示例#1
0
        static public void WriteResult(string formula, double step, double xStart, double xEnd)
        {
            double x, y;
            Rpn    rpn     = new Rpn(formula);
            int    maxSize = GetMaxSizeXY(rpn, 2, xStart, step, xEnd);
            string text    = "";

            //Отрисовка
            text = WriteBorder('─', '┌', '┬', '┐', maxSize, text);

            text = WriteMid(' ', '│', "X", "Y", (maxSize - 1) / 2, (maxSize - 1) / 2,
                            (int)Math.Ceiling((double)(maxSize - 1) / 2),
                            (int)Math.Ceiling((double)(maxSize - 1) / 2), text);

            text = WriteBorder('─', '├', '┼', '┤', maxSize, text);

            x = xStart;
            do
            {
                y = GetY(rpn, x);

                text = WriteMid(' ', '│', Convert.ToString(x), Convert.ToString(y),
                                (maxSize - GetDigitSize(x)) / 2,
                                (maxSize - GetDigitSize(y)) / 2,
                                (int)Math.Ceiling((double)(maxSize - GetDigitSize(x)) / 2),
                                (int)Math.Ceiling((double)(maxSize - GetDigitSize(y)) / 2), text);

                x = Convert.ToDouble(Convert.ToDecimal(x) + Convert.ToDecimal(step));
            } while ((step > 0 && x <= xEnd) || (step < 0 && x >= xEnd));

            text = WriteBorder('─', '└', '┴', '┘', maxSize, text);

            Console.WriteLine(text);
        }
示例#2
0
        public Rpn GetNewRpnWithSetVariable(double digit)
        {
            Rpn output = new Rpn(this);

            for (int i = 0; i < tokens.Count; i++)
            {
                if (tokens[i].Type == TokenType.Variable)
                {
                    output.tokens[i] = new Token(digit);
                }
            }

            return(output);
        }
示例#3
0
        static public string AskFormula(string text)
        {
            string output;

            Console.Write("\r" + new string(' ', Console.WindowWidth - Console.CursorLeft) + "\r" + text);
            output = Console.ReadLine();
            while (!Rpn.IsExpressionCorrectly(output, out string errorText))
            {
                Console.SetCursorPosition(0, 0);
                Console.Write("\r" + new string(' ', Console.WindowWidth - Console.CursorLeft) + "\r" + errorText);
                Console.ReadKey(true);
                Console.Write("\r" + new string(' ', Console.WindowWidth - Console.CursorLeft) + "\r" + text);
                output = Console.ReadLine();
            }

            return(output);
        }
示例#4
0
        public static List <DoublePoint> GetPointsList(Rpn rpn, double xStart, double xEnd, double step, double zoom)
        {
            var output = new List <DoublePoint>();

            Rpn    localRpn;
            double x = xStart;

            do
            {
                double y = rpn.GetNewRpnWithSetVariable(x * zoom).Calculate() / zoom;

                output.Add(new DoublePoint(x, y));

                x += step;
            } while (x <= xEnd);

            return(output);
        }
示例#5
0
        static int GetMaxSizeXY(Rpn rpn, int maxSize, double x, double step, double xEnd)
        {
            double y;

            do
            {
                y = GetY(rpn, x);
                if (GetDigitSize(y) > maxSize)
                {
                    maxSize = GetDigitSize(y);
                }
                if (GetDigitSize(x) > maxSize)
                {
                    maxSize = GetDigitSize(x);
                }
                x += step;
            } while ((step > 0 && x <= xEnd) || (step < 0 && x >= xEnd));

            return(maxSize);
        }
示例#6
0
 static double GetY(Rpn rpn, double x)
 {
     return(rpn.GetNewRpnWithSetVariable(x).Calculate());
 }
示例#7
0
 public Rpn(Rpn input)
 {
     tokens = new List <Token>(input.tokens);
 }
示例#8
0
 public bool FormulaCorrectlyTest(string formula)
 {
     return(Rpn.IsExpressionCorrectly(formula, out string s));
 }