avian3d/math/
single.rs

1use super::AdjustPrecision;
2use bevy_math::*;
3
4/// The floating point number type used by Avian.
5pub type Scalar = f32;
6/// The PI/2 constant.
7pub const FRAC_PI_2: Scalar = core::f32::consts::FRAC_PI_2;
8/// The PI constant.
9pub const PI: Scalar = core::f32::consts::PI;
10/// The TAU constant.
11pub const TAU: Scalar = core::f32::consts::TAU;
12/// 1/sqrt(2)
13pub const FRAC_1_SQRT_2: Scalar = core::f32::consts::FRAC_1_SQRT_2;
14
15/// The vector type used by Avian.
16#[cfg(feature = "2d")]
17pub type Vector = Vec2;
18/// The vector type used by Avian.
19#[cfg(feature = "3d")]
20pub type Vector = Vec3;
21/// The vector type used by Avian. This is always a 2D vector regardless of the chosen dimension.
22pub type Vector2 = Vec2;
23/// The vector type used by Avian. This is always a 3D vector regardless of the chosen dimension.
24pub type Vector3 = Vec3;
25
26/// The dimension-specific matrix type used by Avian.
27#[cfg(feature = "2d")]
28pub type Matrix = Mat2;
29/// The dimension-specific matrix type used by Avian.
30#[cfg(feature = "3d")]
31pub type Matrix = Mat3;
32/// The 2x2 matrix type used by Avian.
33pub type Matrix2 = Mat2;
34/// The 3x3 matrix type used by Avian.
35pub type Matrix3 = Mat3;
36/// The quaternion type used by Avian.
37pub type Quaternion = Quat;
38
39impl AdjustPrecision for f32 {
40    type Adjusted = Scalar;
41    fn adjust_precision(&self) -> Self::Adjusted {
42        *self as Scalar
43    }
44}
45
46impl AdjustPrecision for f64 {
47    type Adjusted = Scalar;
48    fn adjust_precision(&self) -> Self::Adjusted {
49        *self as Scalar
50    }
51}
52
53impl AdjustPrecision for Vec3 {
54    type Adjusted = Vector3;
55    fn adjust_precision(&self) -> Self::Adjusted {
56        *self
57    }
58}
59
60impl AdjustPrecision for DVec3 {
61    type Adjusted = Vector3;
62    fn adjust_precision(&self) -> Self::Adjusted {
63        self.as_vec3()
64    }
65}
66
67impl AdjustPrecision for Vec2 {
68    type Adjusted = Vector2;
69    fn adjust_precision(&self) -> Self::Adjusted {
70        *self
71    }
72}
73
74impl AdjustPrecision for DVec2 {
75    type Adjusted = Vector2;
76    fn adjust_precision(&self) -> Self::Adjusted {
77        self.as_vec2()
78    }
79}
80
81impl AdjustPrecision for Quat {
82    type Adjusted = Quaternion;
83    fn adjust_precision(&self) -> Self::Adjusted {
84        *self
85    }
86}
87
88impl AdjustPrecision for DQuat {
89    type Adjusted = Quaternion;
90    fn adjust_precision(&self) -> Self::Adjusted {
91        self.as_quat()
92    }
93}
94
95impl AdjustPrecision for Mat3 {
96    type Adjusted = Matrix3;
97    fn adjust_precision(&self) -> Self::Adjusted {
98        *self
99    }
100}
101
102impl AdjustPrecision for DMat3 {
103    type Adjusted = Matrix3;
104    fn adjust_precision(&self) -> Self::Adjusted {
105        self.as_mat3()
106    }
107}