using GenDanDoZad;
using System;
using System.Windows.Forms;

namespace _08_Interpolacja
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        double a, b;
        int stopien, licznosc, licznosc2;
        double[][] XY;
        Generator generator = new Generator();
        ChartForm chartForm = new ChartForm();
        Interpolacja interpol = new Interpolacja();
        double[][] xy = new double[2][];

        void CzytajDane()
        {
            a = double.Parse(textBox1.Text);
            b = double.Parse(textBox2.Text);
            stopien = int.Parse(textBox3.Text);
            licznosc = int.Parse(textBox4.Text);
            licznosc2 = int.Parse(textBox5.Text);
        }



        private void button1_Click(object sender, EventArgs e)
        {
            chartForm.Clear();
            CzytajDane();
            XY = generator.PolyM(a, b, stopien, licznosc);
            ChartForm.ShowPoints(XY[0], XY[1], $"Poly-{stopien}");
        }



        private void button2_Click(object sender, EventArgs e)
        {
            xy[0] = new double[licznosc2];
            xy[1] = new double[licznosc2];
            double dx = (b - a) / (licznosc2 - 1);
            for (int i = 0; i < licznosc2; i++)
            {
                xy[0][i] = a + i * dx;
                xy[1][i] = interpol.WielLagr1(XY[0], XY[1], xy[0][i]);
            }
            ChartForm.ShowLines(xy[0], xy[1], "intWielLagr1");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            xy[0] = new double[licznosc2];
            xy[1] = new double[licznosc2];
            double dx = (b - a) / (licznosc2 - 1);
            for (int i = 0; i < licznosc2; i++)
            {
                xy[0][i] = a + i * dx;
                xy[1][i] = interpol.WielLagr2(XY[0], XY[1], xy[0][i]);
            }
            ChartForm.ShowLines(xy[0], xy[1], "intWielLagr2");
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }
    }
}
