Skip to main content

avian3d/math/
single.rs

1use super::ToRealPrecision;
2use crate::{math::DRot2, physics_transform::Rotation};
3use bevy_math::*;
4use glam_matrix_extras::*;
5
6/// The real number type used by Avian.
7///
8/// This is a type alias for `f32` in single-precision mode
9/// and `f64` in double-precision mode.
10pub type Real = f32;
11
12/// The real number 2D vector type used by Avian.
13///
14/// This is a type alias for `Vec2` in single-precision mode
15/// and `DVec2` in double-precision mode.
16pub type RVec2 = Vec2;
17
18/// The real number 3D vector type used by Avian.
19///
20/// This is a type alias for `Vec3` in single-precision mode
21/// and `DVec3` in double-precision mode.
22pub type RVec3 = Vec3;
23
24/// The real number 2x2 matrix type used by Avian.
25///
26/// This is a type alias for `Mat2` in single-precision mode
27/// and `DMat2` in double-precision mode.
28pub type RMat2 = Mat2;
29
30/// The real number 3x3 matrix type used by Avian.
31///
32/// This is a type alias for `Mat3` in single-precision mode
33/// and `DMat3` in double-precision mode.
34pub type RMat3 = Mat3;
35
36impl ToRealPrecision for f32 {
37    type Adjusted = Real;
38    fn real(&self) -> Self::Adjusted {
39        *self as Real
40    }
41}
42
43impl ToRealPrecision for f64 {
44    type Adjusted = Real;
45    fn real(&self) -> Self::Adjusted {
46        *self as Real
47    }
48}
49
50impl ToRealPrecision for Vec3 {
51    type Adjusted = Vec3;
52    fn real(&self) -> Self::Adjusted {
53        *self
54    }
55}
56
57impl ToRealPrecision for DVec3 {
58    type Adjusted = Vec3;
59    fn real(&self) -> Self::Adjusted {
60        self.as_vec3()
61    }
62}
63
64impl ToRealPrecision for Vec2 {
65    type Adjusted = Vec2;
66    fn real(&self) -> Self::Adjusted {
67        *self
68    }
69}
70
71impl ToRealPrecision for DVec2 {
72    type Adjusted = Vec2;
73    fn real(&self) -> Self::Adjusted {
74        self.as_vec2()
75    }
76}
77
78impl ToRealPrecision for Quat {
79    type Adjusted = Quat;
80    fn real(&self) -> Self::Adjusted {
81        *self
82    }
83}
84
85impl ToRealPrecision for DQuat {
86    type Adjusted = Quat;
87    fn real(&self) -> Self::Adjusted {
88        self.as_quat()
89    }
90}
91
92impl ToRealPrecision for Rot2 {
93    type Adjusted = Rot2;
94    fn real(&self) -> Self::Adjusted {
95        *self
96    }
97}
98
99impl ToRealPrecision for DRot2 {
100    type Adjusted = Rot2;
101    fn real(&self) -> Self::Adjusted {
102        Rot2::from_sin_cos(self.sin as f32, self.cos as f32)
103    }
104}
105
106#[cfg(feature = "2d")]
107impl ToRealPrecision for Rotation {
108    type Adjusted = Rot2;
109    fn real(&self) -> Self::Adjusted {
110        Rot2::from_sin_cos(self.sin, self.cos)
111    }
112}
113
114#[cfg(feature = "3d")]
115impl ToRealPrecision for Rotation {
116    type Adjusted = Quat;
117    fn real(&self) -> Self::Adjusted {
118        self.0
119    }
120}