avian2d/math/
single.rs

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