use nalgebra::{Point3, RealField, Unit, Vector3};
#[derive(Debug, Clone)]
pub struct Ray<T: RealField + Copy> {
pub origin: Point3<T>,
pub direction: Unit<Vector3<T>>,
pub inv_direction: Vector3<T>,
pub sign: [usize; 3],
}
impl<T: RealField + Copy> Ray<T> {
pub fn new(origin: Point3<T>, direction: Unit<Vector3<T>>) -> Self {
let inv_direction = Vector3::new(T::one() / direction.x, T::one() / direction.y, T::one() / direction.z);
let sign = [
usize::from(inv_direction.x < T::zero()),
usize::from(inv_direction.y < T::zero()),
usize::from(inv_direction.z < T::zero()),
];
Self {
origin,
direction,
inv_direction,
sign,
}
}
}