Esempio n. 1
0
        /// <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>
 /// 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));
 }