use crate::math::*;
pub trait Window {
fn relative_value_at(&self, x: f64) -> f64;
}
#[derive(Clone, Debug)]
pub struct Rectangular;
impl Window for Rectangular {
fn relative_value_at(&self, _: f64) -> f64 {
1.0
}
}
#[derive(Clone, Debug)]
pub struct Kaiser {
beta: f64,
}
impl Window for Kaiser {
fn relative_value_at(&self, x: f64) -> f64 {
kaiser_rel_with_beta(self.beta, x)
}
}
impl Kaiser {
pub fn with_beta(beta: f64) -> Self {
Self { beta }
}
pub fn with_alpha(alpha: f64) -> Self {
Self {
beta: kaiser_alpha_to_beta(alpha),
}
}
pub fn with_null_at_bin(n: f64) -> Self {
Self {
beta: kaiser_null_at_bin_to_beta(n),
}
}
}
pub struct CustomWindow<F>(pub F);
impl<F> Window for CustomWindow<F>
where
F: Fn(f64) -> f64,
{
fn relative_value_at(&self, x: f64) -> f64 {
(self.0)(x)
}
}