use crate::Float;
use crate::core::filter::{FilterSample, FilterSampler, FilterTrait};
use crate::core::geometry::{Point2f, Vector2f};
use crate::utils::math::{lerp, windowed_sinc};

#[repr(C)]
#[derive(Clone, Debug, Copy)]
pub struct LanczosSincFilter {
    pub radius: Vector2f,
    pub tau: Float,
    pub sampler: FilterSampler,
    pub integral: Float,
}

impl FilterTrait for LanczosSincFilter {
    fn radius(&self) -> Vector2f {
        self.radius
    }

    fn evaluate(&self, p: Point2f) -> Float {
        windowed_sinc(p.x(), self.radius.x(), self.tau)
            * windowed_sinc(p.y(), self.radius.y(), self.tau)
    }

    fn integral(&self) -> Float {
        self.integral
    }

    fn sample(&self, u: Point2f) -> FilterSample {
        self.sampler.sample(u)
    }
}
