Example #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);
 }
Example #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);
        }
Example #3
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);
         }
     }
 }