예제 #1
0
 private double getFx(string expr)
 {
     //if (expr.StartsWith("log(-") || expr.StartsWith("log((-") || expr.StartsWith("sqrt(-") || expr.StartsWith("sqrt((-"))
     //{
     //    throw new ArithmeticException("Not Real Expression");
     //}
     return((UpperY - ParseExpression.parse(expr)) * UnitHeight);
 }
예제 #2
0
        private void showTracingInfo(Point point, Line line)
        {
            tracingInfoBox.Children.Clear();
            GraphCanvas.Children.Remove(tracingInfoBox);

            tracingInfoBox.Orientation = Orientation.Vertical;
            tracingInfoBox.Margin      = new Thickness(0, 0, 0, 0);
            tracingInfoBox.Background  = Brushes.White;

            string expr = "";

            foreach (var child in FunctionList.Items)
            {
                StackPanel stackPanel = (StackPanel)(child);
                Label      exprLabel  = stackPanel.Children.OfType <Label>().ElementAt(1);
                if (exprLabel.Foreground == line.Stroke)
                {
                    expr = exprLabel.Content.ToString();
                    break;
                }
            }

            Label funcLabel = new Label();

            funcLabel.Content = expr;

            Label xLabel = new Label();

            xLabel.Content = "X: " + (graphPlotter.LowerX + (point.X / graphPlotter.UnitWidth));

            Label yLabel = new Label();

            try
            {
                yLabel.Content = "Y: " + Math.Round(ParseExpression.parse(ParseExpression.replaceVariable(expr,
                                                                                                          "(" + Convert.ToString(Math.Round((graphPlotter.LowerX + (point.X / graphPlotter.UnitWidth)), 3)) + ")")), 2);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
            }

            tracingInfoBox.Children.Add(funcLabel);
            tracingInfoBox.Children.Add(xLabel);
            tracingInfoBox.Children.Add(yLabel);

            GraphCanvas.Children.Add(tracingInfoBox);
        }
예제 #3
0
        private List <Point> getPointsFromExpression(string variableExpr)
        {
            List <Point> points = new List <Point>();
            string       expr;

            for (double x = 0; x <= GraphCanvas.Width; x += steps)
            {
                double num = LowerX + (x / UnitWidth);
                expr = ParseExpression.replaceVariable(variableExpr, "(" + Convert.ToString(Math.Round(num, 3)) + ")");

                try
                {
                    double y = getFx(expr);
                    if (y < 0)
                    {
                        y = 0;
                    }
                    if (y > GraphCanvas.Height)
                    {
                        y = GraphCanvas.Height;
                    }
                    points.Add(new Point(x, y));
                    //Trace.WriteLine(num + " " + Convert.ToDouble(parser.Parse(expr)) + "\n");
                }
                catch (Exception e)
                {
                    if (e.Message == "Not Real Expression")
                    {
                        if (x < OriginX)
                        {
                            x = OriginX;
                        }
                        else
                        {
                            x = GraphCanvas.Width;
                        }
                    }
                    Trace.WriteLine(num + e.Message);
                }
            }
            return(points);
        }
예제 #4
0
 private void addBtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string expr = ParseExpression.replaceVariable(inputTB.Text, "(0)");
         ParseExpression.parse(expr);
         addExpressionToList();
     }
     catch (Exception exception)
     {
         if (exception.Message.StartsWith("Value was either too large") ||
             exception.Message.StartsWith("Attempted to divide by zero"))
         {
             addExpressionToList();
         }
         else
         {
             MessageBox.Show(invalidFunctionErrorMessage + exception.Message);
         }
     }
 }