diff --git a/MyExpression.Wpf/FunctionGraph.cs b/MyExpression.Wpf/FunctionGraph.cs index d652964..4e864d9 100644 --- a/MyExpression.Wpf/FunctionGraph.cs +++ b/MyExpression.Wpf/FunctionGraph.cs @@ -28,19 +28,30 @@ public class FunctionGraph : Canvas, IEnumerable public Point Scale { get; set; } - private IList Functions { get; set; } = new List(1); + public IList Functions { get; set; } = new List(1); public class DrawableFunction { - public Func Function { get; set; } - public SolidColorBrush Brush { get; set; } = Brushes.DarkMagenta; - public Interval DefinitionArea { get; set; } + public Func Function { get; private set; } + + public SolidColorBrush LineBrush { get; private set; } = Brushes.DarkMagenta; + + public Interval DefinitionArea { get; private set; } + + // TODO: разобраться с сеттером public bool IsDrawed { get; set; } - public DrawableFunction(Func f, Interval defarea, SolidColorBrush brush = null) + + public SolidColorBrush RootsBrush { get; private set; } = Brushes.Indigo; + + public IList Roots { get; set; } + + public DrawableFunction(Func f, Interval defarea, SolidColorBrush brush = null, SolidColorBrush rootbrush = null, IList roots = null) { Function = f; DefinitionArea = new Interval(defarea.Left, defarea.Right); - if (brush != null) Brush = brush; + if (brush != null) LineBrush = brush; + if (rootbrush != null) RootsBrush = rootbrush; + if (roots != null) Roots = new List(roots); } } @@ -96,7 +107,7 @@ public void DrawFunction() f.IsDrawed = true; var l = new Polyline { - Stroke = f.Brush, + Stroke = f.LineBrush, StrokeThickness = 1 }; for (var i = f.DefinitionArea.Left; i <= f.DefinitionArea.Right; i += Step) @@ -113,7 +124,7 @@ public void DrawFunction() Children.Add(l); l = new Polyline { - Stroke = f.Brush, + Stroke = f.LineBrush, StrokeThickness = 1 }; } @@ -127,6 +138,29 @@ public void DrawFunction() } } + public void DrawRoots() + { + foreach (var f in Functions) + { + if (f.Roots is null) continue; + foreach (var i in f.Roots) + { + var wh = 5; + var p = new Ellipse + { + Width = wh, + Height = wh, + Fill = f.RootsBrush, + Stroke = Brushes.IndianRed, + StrokeThickness = 0.5 + }; + SetLeft(p, i * Scale.X - wh / 2.0); + SetTop(p, f.Function(i) * Scale.Y - wh / 2.0); + Children.Add(p); + } + } + } + public Point CellsStep { get; set; } public Interval CellsIntervalX { get; set; } @@ -197,10 +231,12 @@ public void ClearAll() public void Clear() { Functions.Clear(); - for (var i = 0; i < Children.Count; i++) - { - if (Children[i] is Polyline) Children.RemoveAt(i); - } + Children.Clear(); + DrawAxis(); + //for (var i = 0; i < Children.Count; i++) + //{ + // if (Children[i] is Polyline) Children.RemoveAt(i); + //} } public IEnumerator GetEnumerator() => Functions.GetEnumerator(); diff --git a/MyExpression.Wpf/MainWindow.xaml b/MyExpression.Wpf/MainWindow.xaml index ae2e20b..f1b5fdb 100644 --- a/MyExpression.Wpf/MainWindow.xaml +++ b/MyExpression.Wpf/MainWindow.xaml @@ -49,6 +49,7 @@