/// <summary> /// Constructor. Initializes all starting parameters. /// </summary> /// <param name="target"></param> /// <param name="rangeH"></param> /// <param name="rangeV"></param> public GraphRenderer(PictureBox target, ExpressionExt expression, Range rangeH, Range rangeV) { TargetPictureBox = target; RangeHorizontal = rangeH; RangeVertical = rangeV; AlgebraicExpression = expression; if (TargetPictureBox.Image == null) { TargetPictureBox.Image = new Bitmap(TargetPictureBox.Width, TargetPictureBox.Height); } }
/// <summary> /// Constructor. /// </summary> /// <param name="title"></param> /// <param name="dimension"></param> /// <param name="points"></param> public FormPoint(string title, int dimension, ExpressionExt expression = null, List <float[]> points = null) { InitializeComponent(); Dimension = dimension; Text = title; // add one row for the user to edit if (expression == null || points == null) { for (int i = 1; i < Dimension + 1; i++) { dataGridViewCoordinates.Columns.Add($"x{i}", $"x{i}"); } dataGridViewCoordinates.ReadOnly = false; dataGridViewCoordinates.Rows.Add(); } else // add all points provided { // add header dataGridViewCoordinates.Columns.Add("lp", "lp"); dataGridViewCoordinates.Columns.Add("f_x", "f(x)"); for (int i = 1; i < Dimension + 1; i++) { dataGridViewCoordinates.Columns.Add($"x{i}", $"x{i}"); } // set the datagridview to readonly dataGridViewCoordinates.ReadOnly = true; // cancel button is irrelevant, hide it buttonCancel.Visible = false; // move accept button as though there is no cancel button buttonOk.Location = buttonCancel.Location; for (int i = 0; i < points.Count; i++) { string[] row = new string[points[0].Count() + 2]; row[0] = $"x({i})"; row[1] = expression.Evaluate(points[i]).ToString(); points[i].Select(x => x.ToString()).ToArray().CopyTo(row, 2); dataGridViewCoordinates.Rows.Add(row); } } dataGridViewCoordinates.Select(); }
/// <summary> /// Constructor. Initializes target PictureBox and Expression, leaving Range default. /// </summary> /// <param name="target"></param> /// <param name="expression"></param> public GraphRenderer(PictureBox target, ExpressionExt expression) : this(target, expression, new Range(-5, 5), new Range(-5, 5)) { }
/// <summary> /// Writes point info to the console, providing optional additional information. /// </summary> /// <param name="point"></param> /// <param name="expression"></param> /// <param name="additionalInfo"></param> public static void ShowPointInfo(float[] point, ExpressionExt expression, string additionalInfo = "") { Console.WriteLine(additionalInfo + " " + GeneratePointString(point) + ", val=" + expression.Evaluate(point)); }