use crate::texture::Texture;
use crate::vec3::Vec3;

pub struct CheckerTexture<T>
where
    T: Texture,
{
    odd: T,
    even: T,
}

impl<T> CheckerTexture<T>
where
    T: Texture,
{
    pub fn new(odd: T, even: T) -> CheckerTexture<T> {
        CheckerTexture { odd, even }
    }
}

impl<T> Texture for CheckerTexture<T>
where
    T: Texture,
{
    fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3 {
        let sines = (10. * p.x).sin() * (10. * p.y).sin() * (10. * p.z).sin();
        if sines < 0. {
            self.odd.value(u, v, p)
        } else {
            self.even.value(u, v, p)
        }
    }
}
