use super::prelude::*;
use num_traits::{Float, One};
use std::iter::Sum;
use std::ops::{Add, Mul};
pub struct Ray<T, const N: usize> {
pub origin: Vector<T, N>,
pub direction: Vector<T, N>,
}
impl<T, const N: usize> Ray<T, N> {
pub fn new(origin: Vector<T, N>, direction: Vector<T, N>) -> Self
where
T: Mul<T, Output = T> + Clone + Sum + One + Float,
{
let direction_normalised = direction.normalised();
unsafe { Self::new_unchecked(origin, direction_normalised) }
}
pub unsafe fn new_unchecked(origin: Vector<T, N>, direction: Vector<T, N>) -> Self {
Self { origin, direction }
}
pub fn at(&self, t: T) -> Vector<T, N>
where
T: Add<T, Output = T> + Mul<T, Output = T> + Clone,
{
let ds = self.direction.clone() * t;
self.origin.clone() + ds
}
}