1use bevy_math::*;
4
5pub trait RecipOrZero {
7 fn recip_or_zero(self) -> Self;
10}
11
12impl RecipOrZero for f32 {
13 #[inline]
14 fn recip_or_zero(self) -> Self {
15 if self != 0.0 && self.is_finite() {
16 self.recip()
17 } else {
18 0.0
19 }
20 }
21}
22
23impl RecipOrZero for f64 {
24 #[inline]
25 fn recip_or_zero(self) -> Self {
26 if self != 0.0 && self.is_finite() {
27 self.recip()
28 } else {
29 0.0
30 }
31 }
32}
33
34impl RecipOrZero for Vec2 {
35 #[inline]
36 fn recip_or_zero(self) -> Self {
37 Self::new(self.x.recip_or_zero(), self.y.recip_or_zero())
38 }
39}
40
41impl RecipOrZero for Vec3 {
42 #[inline]
43 fn recip_or_zero(self) -> Self {
44 Self::new(
45 self.x.recip_or_zero(),
46 self.y.recip_or_zero(),
47 self.z.recip_or_zero(),
48 )
49 }
50}
51
52impl RecipOrZero for DVec2 {
53 #[inline]
54 fn recip_or_zero(self) -> Self {
55 Self::new(self.x.recip_or_zero(), self.y.recip_or_zero())
56 }
57}
58
59impl RecipOrZero for DVec3 {
60 #[inline]
61 fn recip_or_zero(self) -> Self {
62 Self::new(
63 self.x.recip_or_zero(),
64 self.y.recip_or_zero(),
65 self.z.recip_or_zero(),
66 )
67 }
68}