use shared::Float;
use shared::core::filter::FilterSampler;
use shared::core::geometry::{Point2f, Vector2f};
use shared::filters::MitchellFilter;

pub trait MitchellFilterCreator {
    fn new(radius: Vector2f, b: Float, c: Float) -> Self;
}

impl MitchellFilterCreator for MitchellFilter {
    fn new(radius: Vector2f, b: Float, c: Float) -> Self {
        let sampler = FilterSampler::new(radius, move |p: Point2f| {
            let nx = 2.0 * p.x() / radius.x();
            let ny = 2.0 * p.y() / radius.y();
            Self::mitchell_1d_eval(b, c, nx) * Self::mitchell_1d_eval(b, c, ny)
        });

        Self {
            radius,
            b,
            c,
            sampler,
        }
    }
}
