private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { if (drawer == null) { return; } if (editboxes.ContainsKey((sender as TextBox))) { editboxes.Remove((sender as TextBox)); } editboxes.Add((sender as TextBox), (sender as TextBox).Text); Dictionary <TextBox, String> .Enumerator iterator = editboxes.GetEnumerator(); List <FormulaPart> formulae = new List <FormulaPart>(); try { while (iterator.MoveNext()) { formulae.Add(FormulaPart.ProcessString(iterator.Current.Value)); } } catch (ArgumentException ex) { Title = ex.Message; } drawer.Formulae = formulae; ReDrawGraph(); }
protected virtual void ParseFormulaVerse() { var value = StringUtils.GetStringLastNumber(FormulaPart); if (!value.HasValue) { if (FormulaPart.Length == 1) // только "X" { Deviation = 0; } else { ThrowUnsupportedFormulaException("x004"); } } else { Deviation = value.Value; } if (FormulaPart.IndexOf("+") == -1) { Deviation *= -1; } }
public void DrawPopup(Vector2 point) { Vector2 graph_coords = TranslatePointToVector(point); FormulaPart closestgraph = null; double closestvalue = double.PositiveInfinity; double closestvalue_dx = double.PositiveInfinity; List <Tuple <string, double> > variables = new List <Tuple <string, double> >(); variables.Add(new Tuple <string, double>("x", graph_coords.X)); List <Tuple <string, double> > variables_prime = new List <Tuple <string, double> >(); variables_prime.Add(new Tuple <string, double>("x", graph_coords.X + 1e-6)); foreach (FormulaPart formula in Formulae) { double answer = formula.Evaluate(variables); if (Math.Abs(answer - graph_coords.Y) < Math.Abs(closestvalue - graph_coords.Y)) { closestvalue = answer; closestvalue_dx = formula.Evaluate(variables_prime); closestgraph = formula; } } if (closestgraph == null) { return; } Ellipse dot = new Ellipse(); dot.Width = 6; dot.Height = 6; dot.StrokeThickness = 2; dot.Stroke = new SolidColorBrush(Colors.Blue); Vector2 canvaspoint = TranslateCoordsToCanvas(graph_coords.X, closestvalue); Canvas.SetLeft(dot, canvaspoint.X); Canvas.SetTop(dot, canvaspoint.Y); Canvas.SetZIndex(dot, 10); canvas.Children.Add(dot); Rectangle rect = new Rectangle(); rect.Width = 100; rect.Height = 100; rect.Fill = new SolidColorBrush(Colors.SteelBlue); rect.StrokeThickness = 4; rect.Stroke = new SolidColorBrush(Colors.Blue); Canvas.SetLeft(rect, 10); Canvas.SetTop(rect, 10); canvas.Children.Add(rect); canvas.Children.Add( CreateText(new Vector2(20, 20), "Trace:") ); canvas.Children.Add( CreateText(new Vector2(20, 30), "X : " + graph_coords.X) ); canvas.Children.Add( CreateText(new Vector2(20, 40), "f(X) : " + closestvalue) ); canvas.Children.Add( CreateText(new Vector2(20, 50), "f(X)' : " + (closestvalue_dx - closestvalue) / 1e-6) ); }