use crate::{Ops, math::Vec3};
pub(super) struct RawTangentSpace<O: Ops> {
pub(super) s: Vec3<O>,
pub(super) t: Vec3<O>,
pub(super) s_magnitude: f32,
pub(super) t_magnitude: f32,
}
impl<O: Ops> PartialEq for RawTangentSpace<O> {
fn eq(&self, other: &Self) -> bool {
self.s == other.s
&& self.t == other.t
&& self.s_magnitude == other.s_magnitude
&& self.t_magnitude == other.t_magnitude
}
}
impl<O: Ops> Copy for RawTangentSpace<O> {}
impl<O: Ops> Clone for RawTangentSpace<O> {
fn clone(&self) -> Self {
*self
}
}
impl<O: Ops> RawTangentSpace<O> {
pub(super) const ZERO: Self = Self {
s: Vec3::ZERO,
t: Vec3::ZERO,
s_magnitude: 0f32,
t_magnitude: 0f32,
};
}
impl<O: Ops> RawTangentSpace<O> {
pub(super) fn combine(self, rhs: Self) -> Self {
if self == rhs {
self
} else {
RawTangentSpace {
s_magnitude: 0.5f32 * (self.s_magnitude + rhs.s_magnitude),
t_magnitude: 0.5f32 * (self.t_magnitude + rhs.t_magnitude),
s: (self.s + rhs.s).normalized_or_zero(),
t: (self.t + rhs.t).normalized_or_zero(),
}
}
}
}