private void ApplyValuesButton_Click(object sender, EventArgs e)
        {
            _numberOfIterations = 0;

            if (_drawingFinished)
            {
                _displayElementsValues2DArray = null;
                _displayElementsValues2DArray = new DisplayElement[DrawArea.Height][];
                for (var i = 0; i < DrawArea.Height; i++)
                {
                    _displayElementsValues2DArray[i] = new DisplayElement[DrawArea.Width];
                    for (var j = 0; j < DrawArea.Width; j++)
                    {
                        _displayElementsValues2DArray[i][j] = new DisplayElement(
                            _displayElementsValues2DArrayCopy[i][j].Position,
                            _displayElementsValues2DArrayCopy[i][j].Value);
                    }
                }

                ResultButton.Enabled = true;
            }

            if (!double.TryParse(epsilonTextBox.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out _epsilon))
            {
                MessageBox.Show(@"Invalid epsilon value", @"Invalid value");
            }

            if (!double.TryParse(betaTextBox.Text, NumberStyles.Number, CultureInfo.InvariantCulture, out _beta))
            {
                MessageBox.Show(@"Invalid beta value", @"Invalid value");
            }

            ResetButton.Enabled = true;
        }
        public MainWindow()
        {
            InitializeComponent();
            DisplayColorMapButton.Enabled = false;
            ResultButton.Enabled          = false;
            ResetButton.Enabled           = false;
            DrawingFinishedButton.Enabled = false;

            IterationsTextBox.Enabled = false;
            _polygonPointsList        = new List <Point>();


            _displayElementsValues2DArray = new DisplayElement[DrawArea.Height][];
            for (var i = 0; i < DrawArea.Height; i++)
            {
                _displayElementsValues2DArray[i] = new DisplayElement[DrawArea.Width];
                for (var j = 0; j < DrawArea.Width; j++)
                {
                    _displayElementsValues2DArray[i][j] = new DisplayElement(j, i);
                }
            }

            betaTextBox.Text          = _beta.ToString("F4", CultureInfo.InvariantCulture);
            epsilonTextBox.Text       = _epsilon.ToString("F4", CultureInfo.InvariantCulture);
            linePotentialTextBox.Text = 1.ToString("F4", CultureInfo.InvariantCulture);
        }
        private void ResetButton_Click(object sender, EventArgs e)
        {
            _drawingAllowed = true;
            _polygonPointsList.Clear();
            _pointIndex    = 0;
            DrawArea.Image = new Bitmap(DrawArea.Width, DrawArea.Height);
            DrawingFinishedButton.Enabled     = true;
            _displayElementsValues2DArray     = null;
            _displayElementsValues2DArrayCopy = null;
            _displayElementsValues2DArray     = new DisplayElement[DrawArea.Height][];
            _displayElementsValues2DArrayCopy = new DisplayElement[DrawArea.Height][];
            _drawingFinished = false;

            for (var i = 0; i < DrawArea.Height; i++)
            {
                _displayElementsValues2DArray[i] = new DisplayElement[DrawArea.Width];
                for (var j = 0; j < DrawArea.Width; j++)
                {
                    _displayElementsValues2DArray[i][j] = new DisplayElement(j, i);
                    ((Bitmap)DrawArea.Image).SetPixel(j, i, Color.White);
                }
            }

            IterationsTextBox.Text        = "";
            ResultButton.Enabled          = false;
            DisplayColorMapButton.Enabled = false;

            DrawArea.Refresh();
            Refresh();
        }
        private void Finished_Click(object sender, EventArgs e)
        {
            ResultButton.Enabled = true;
            _drawingFinished     = true;
            if (_polygonPointsList[_pointIndex - 1] != _polygonPointsList[0])
            {
                if (_lastX)
                {
                    var newY = _polygonPointsList[0].Y + 5;
                    var newX = _polygonPointsList[0].X;

                    _polygonPointsList.Add(new Point(_previousX, newY));
                    if (_previousY > newY)
                    {
                        for (var i = newY; i <= _previousY; i++)
                        {
                            _displayElementsValues2DArray[i][_previousX].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        for (var i = _previousY; i <= newY; i++)
                        {
                            _displayElementsValues2DArray[i][_previousX].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }

                    _previousY = newY;
                    _polygonPointsList.Add(new Point(newX, newY));
                    if (_previousX > newX)
                    {
                        for (var i = newX; i <= _previousX; i++)
                        {
                            _displayElementsValues2DArray[_previousY][i].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        for (var i = _previousX; i <= newX; i++)
                        {
                            _displayElementsValues2DArray[_previousY][i].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }

                    newY = _polygonPointsList[0].Y;
                    _polygonPointsList.Add(new Point(newX, newY));
                    if (_previousY > newY)
                    {
                        for (var i = newY; i <= _previousY; i++)
                        {
                            _displayElementsValues2DArray[i][_previousX].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        for (var i = _previousY; i <= newY; i++)
                        {
                            _displayElementsValues2DArray[i][_previousX].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }

                    _pointIndex += 3;
                }
                else
                {
                    var newY = _polygonPointsList[0].Y;
                    var newX = _polygonPointsList[0].X;

                    _polygonPointsList.Add(new Point(newX, _previousY));
                    if (_previousX > newX)
                    {
                        for (var i = newX; i <= _previousX; i++)
                        {
                            _displayElementsValues2DArray[_previousY][i].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        for (var i = _previousX; i <= newX; i++)
                        {
                            _displayElementsValues2DArray[_previousY][i].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }

                    _previousX = newX;
                    _polygonPointsList.Add(new Point(newX, newY));
                    if (_previousY > newY)
                    {
                        for (var i = newY; i <= _previousY; i++)
                        {
                            _displayElementsValues2DArray[i][_previousX].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        for (var i = _previousY; i <= newY; i++)
                        {
                            _displayElementsValues2DArray[i][_previousX].Value = double.Parse(linePotentialTextBox.Text,
                                                                                              CultureInfo.InvariantCulture);
                        }
                    }

                    _previousY   = newY;
                    _pointIndex += 2;
                }
            }

            _drawingAllowed = false;
            DrawingFinishedButton.Enabled = false;

            for (var i = 0; i < DrawArea.Height; i++)
            {
                for (var j = 0; j < DrawArea.Width; j++)
                {
                    if (!(_displayElementsValues2DArray[i][j].Value > -99))
                    {
                        continue;
                    }
                    j++;
                    if (_displayElementsValues2DArray[i][j].Value > -99)
                    {
                        break;
                    }

                    if (j >= _displayElementsValues2DArray[i].Length - 1)
                    {
                        continue;
                    }

                    while (true)
                    {
                        _displayElementsValues2DArray[i][j++].Value = 0;
                        if (j >= _displayElementsValues2DArray[i].Length - 1)
                        {
                            break;
                        }
                        if (_displayElementsValues2DArray[i][j].Value > -99)
                        {
                            break;
                        }
                    }
                }
            }

            _displayElementsValues2DArrayCopy = new DisplayElement[DrawArea.Height][];
            for (var i = 0; i < DrawArea.Height; i++)
            {
                _displayElementsValues2DArrayCopy[i] = new DisplayElement[DrawArea.Width];
                for (var j = 0; j < DrawArea.Width; j++)
                {
                    _displayElementsValues2DArrayCopy[i][j] = new DisplayElement(
                        _displayElementsValues2DArray[i][j].Position, _displayElementsValues2DArray[i][j].Value);
                }
            }

            Refresh();
        }