use crate::vector::Vector2F;
use pathfinder_simd::default::F32x2;
#[derive(Clone, Copy, Debug)]
pub struct UnitVector(pub Vector2F);
impl UnitVector {
#[inline]
pub fn from_angle(theta: f32) -> UnitVector {
UnitVector(Vector2F::new(theta.cos(), theta.sin()))
}
#[inline]
pub fn rotate_by(&self, other: UnitVector) -> UnitVector {
let products = (self.0).0.to_f32x4().xyyx() * (other.0).0.to_f32x4().xyxy();
UnitVector(Vector2F::new(products[0] - products[1], products[2] + products[3]))
}
#[inline]
pub fn rev_rotate_by(&self, other: UnitVector) -> UnitVector {
let products = (self.0).0.to_f32x4().xyyx() * (other.0).0.to_f32x4().xyxy();
UnitVector(Vector2F::new(products[0] + products[1], products[2] - products[3]))
}
#[inline]
pub fn halve_angle(&self) -> UnitVector {
let x = self.0.x();
let term = F32x2::new(x, -x);
UnitVector(Vector2F((F32x2::splat(0.5) * (F32x2::splat(1.0) + term)).max(F32x2::default())
.sqrt()))
}
}