use nalgebra::{Point2, RealField, Unit, Vector2, Vector3, convert};
use simba::scalar::SubsetOf;
#[derive(Debug, Clone, Default)]
pub struct First<N: Copy + RealField> {
ray: Option<Unit<Vector3<N>>>,
}
impl<N: Copy + RealField> First<N> {
pub const fn capture(&mut self, yaw_axis: Unit<Vector3<N>>) {
self.ray = Some(yaw_axis);
}
pub fn compute(&self, vec: &Vector2<N>, max: &Point2<N>) -> Option<(N, N, &Unit<Vector3<N>>)> {
self.ray.as_ref().map(|ray| {
let max = max.x.max(max.y) * convert(0.5);
(vec.y / max, vec.x / max, ray)
})
}
pub const fn discard(&mut self) {
self.ray = None;
}
#[must_use]
pub const fn enabled(&self) -> bool {
self.ray.is_some()
}
#[must_use]
pub const fn yaw_axis(&self) -> Option<&Unit<Vector3<N>>> {
self.ray.as_ref()
}
#[must_use]
pub fn cast<M: Copy + RealField>(self) -> First<M>
where
N: SubsetOf<M>,
{
First {
ray: self.ray.map(Unit::<Vector3<N>>::cast),
}
}
}