use bevy_math::*;
pub trait RecipOrZero {
fn recip_or_zero(self) -> Self;
}
impl RecipOrZero for f32 {
#[inline]
fn recip_or_zero(self) -> Self {
if self != 0.0 && self.is_finite() {
self.recip()
} else {
0.0
}
}
}
impl RecipOrZero for f64 {
#[inline]
fn recip_or_zero(self) -> Self {
if self != 0.0 && self.is_finite() {
self.recip()
} else {
0.0
}
}
}
impl RecipOrZero for Vec2 {
#[inline]
fn recip_or_zero(self) -> Self {
Self::new(self.x.recip_or_zero(), self.y.recip_or_zero())
}
}
impl RecipOrZero for Vec3 {
#[inline]
fn recip_or_zero(self) -> Self {
Self::new(
self.x.recip_or_zero(),
self.y.recip_or_zero(),
self.z.recip_or_zero(),
)
}
}
impl RecipOrZero for DVec2 {
#[inline]
fn recip_or_zero(self) -> Self {
Self::new(self.x.recip_or_zero(), self.y.recip_or_zero())
}
}
impl RecipOrZero for DVec3 {
#[inline]
fn recip_or_zero(self) -> Self {
Self::new(
self.x.recip_or_zero(),
self.y.recip_or_zero(),
self.z.recip_or_zero(),
)
}
}
pub trait MatExt {
fn inverse_or_zero(self) -> Self;
}
impl MatExt for Mat2 {
#[inline]
fn inverse_or_zero(self) -> Self {
if self.determinant() == 0.0 {
Self::ZERO
} else {
self.inverse()
}
}
}
impl MatExt for DMat2 {
#[inline]
fn inverse_or_zero(self) -> Self {
if self.determinant() == 0.0 {
Self::ZERO
} else {
self.inverse()
}
}
}
impl MatExt for Mat3 {
#[inline]
fn inverse_or_zero(self) -> Self {
if self.determinant() == 0.0 {
Self::ZERO
} else {
self.inverse()
}
}
}
impl MatExt for DMat3 {
#[inline]
fn inverse_or_zero(self) -> Self {
if self.determinant() == 0.0 {
Self::ZERO
} else {
self.inverse()
}
}
}