use plotters::prelude::*;
use ray_tracing_core::{math::material::fresnel_real, prelude::*};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = BitMapBackend::new("fresnel.png", (640, 480)).into_drawing_area();
    root.fill(&WHITE)?;
    let mut chart = ChartBuilder::on(&root)
        .caption("Fresnel", ("sans-serif", 50).into_font())
        .margin(5)
        .x_label_area_size(30)
        .y_label_area_size(30)
        .build_cartesian_2d(0.0..FloatConsts::FRAC_PI_2, 0.0..1.0f32)?;

    chart.configure_mesh().draw()?;

    chart.draw_series(LineSeries::new(
        (0..=300)
            .map(|x| x as Float * FloatConsts::FRAC_PI_2 / 300.0)
            .map(|x| (x, fresnel_real(Float::cos(x), 1.0, 1.5))),
        &RED,
    ))?;

    root.present()?;

    Ok(())
}
