use crate::math::{Real, Vector};
use na::Unit;
#[cfg(feature = "rkyv")]
use rkyv::{bytecheck, CheckBytes};
#[derive(PartialEq, Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, CheckBytes),
archive(as = "Self")
)]
#[repr(C)]
pub struct HalfSpace {
pub normal: Unit<Vector<Real>>,
}
impl HalfSpace {
#[inline]
pub fn new(normal: Unit<Vector<Real>>) -> HalfSpace {
HalfSpace { normal }
}
pub fn scaled(self, scale: &Vector<Real>) -> Option<Self> {
Unit::try_new(self.normal.component_mul(scale), 0.0).map(|normal| Self { normal })
}
}