mod checker;
mod constant;
mod envmap;
mod image;
mod mandelbrot;
mod noise;
pub use crate::texture::checker::CheckerTexture;
pub use crate::texture::constant::ConstantTexture;
pub use crate::texture::envmap::EnvMap;
pub use crate::texture::image::ImageTexture;
pub use crate::texture::mandelbrot::Mandelbrot;
pub use crate::texture::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.])
        );
    }
}
