mod checker;
mod constant;
mod envmap;
mod image;
mod mandelbrot;
mod noise;
pub use crate::texture::{
    checker::CheckerTexture, constant::ConstantTexture, envmap::EnvMap, image::ImageTexture,
    mandelbrot::Mandelbrot, noise::NoiseTexture,
};

use std::sync::Arc;

use crate::vec3::Vec3;

pub trait Texture: Send + Sync {
    fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3;
}

impl Texture for Arc<dyn Texture> {
    fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3 {
        (**self).value(u, v, p)
    }
}

impl Texture for Box<dyn Texture> {
    fn value(&self, u: f32, v: f32, p: Vec3) -> Vec3 {
        (**self).value(u, v, p)
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn constant_texture_from_array() {
        assert_eq!(
            ConstantTexture::new(Vec3::new(1., 2., 3.)),
            ConstantTexture::new([1., 2., 3.])
        );
    }
}
