use crate::vec3::Vec3;

#[derive(Copy, Clone, Debug, Default)]
pub struct Ray {
    pub origin: Vec3,
    pub direction: Vec3,
    pub time: f32,
    pub inv_direction: Vec3,
    pub sign: [usize; 3],
}

impl Ray {
    pub fn new<V>(origin: V, direction: V, time: f32) -> Ray
    where
        V: Into<Vec3>,
    {
        let direction = direction.into();
        let origin = origin.into();
        let inv = 1. / direction;
        Ray {
            origin,
            direction,
            time,
            inv_direction: inv,
            sign: [
                (inv.x < 0.) as usize,
                (inv.y < 0.) as usize,
                (inv.z < 0.) as usize,
            ],
        }
    }
    pub fn point_at_parameter(self, t: f32) -> Vec3 {
        self.origin + self.direction * t
    }
}
