1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use super::AdjustPrecision;
use bevy_math::*;

/// The floating point number type used by Avian.
pub type Scalar = f32;
/// The PI/2 constant.
pub const FRAC_PI_2: Scalar = std::f32::consts::FRAC_PI_2;
/// The PI constant.
pub const PI: Scalar = std::f32::consts::PI;
/// The TAU constant.
pub const TAU: Scalar = std::f32::consts::TAU;
/// 1/sqrt(2)
pub const FRAC_1_SQRT_2: Scalar = std::f32::consts::FRAC_1_SQRT_2;

/// The vector type used by Avian.
#[cfg(feature = "2d")]
pub type Vector = Vec2;
/// The vector type used by Avian.
#[cfg(feature = "3d")]
pub type Vector = Vec3;
/// The vector type used by Avian. This is always a 2D vector regardless of the chosen dimension.
pub type Vector2 = Vec2;
/// The vector type used by Avian. This is always a 3D vector regardless of the chosen dimension.
pub type Vector3 = Vec3;

/// The dimension-specific matrix type used by Avian.
#[cfg(feature = "2d")]
pub type Matrix = Mat2;
/// The dimension-specific matrix type used by Avian.
#[cfg(feature = "3d")]
pub type Matrix = Mat3;
/// The 2x2 matrix type used by Avian.
pub type Matrix2 = Mat2;
/// The 3x3 matrix type used by Avian.
pub type Matrix3 = Mat3;
/// The quaternion type used by Avian.
pub type Quaternion = Quat;

impl AdjustPrecision for f32 {
    type Adjusted = Scalar;
    fn adjust_precision(&self) -> Self::Adjusted {
        *self as Scalar
    }
}

impl AdjustPrecision for f64 {
    type Adjusted = Scalar;
    fn adjust_precision(&self) -> Self::Adjusted {
        *self as Scalar
    }
}

impl AdjustPrecision for Vec3 {
    type Adjusted = Vector3;
    fn adjust_precision(&self) -> Self::Adjusted {
        *self
    }
}

impl AdjustPrecision for DVec3 {
    type Adjusted = Vector3;
    fn adjust_precision(&self) -> Self::Adjusted {
        self.as_vec3()
    }
}

impl AdjustPrecision for Vec2 {
    type Adjusted = Vector2;
    fn adjust_precision(&self) -> Self::Adjusted {
        *self
    }
}

impl AdjustPrecision for DVec2 {
    type Adjusted = Vector2;
    fn adjust_precision(&self) -> Self::Adjusted {
        self.as_vec2()
    }
}

impl AdjustPrecision for Quat {
    type Adjusted = Quaternion;
    fn adjust_precision(&self) -> Self::Adjusted {
        *self
    }
}

impl AdjustPrecision for DQuat {
    type Adjusted = Quaternion;
    fn adjust_precision(&self) -> Self::Adjusted {
        self.as_quat()
    }
}

impl AdjustPrecision for Mat3 {
    type Adjusted = Matrix3;
    fn adjust_precision(&self) -> Self::Adjusted {
        *self
    }
}

impl AdjustPrecision for DMat3 {
    type Adjusted = Matrix3;
    fn adjust_precision(&self) -> Self::Adjusted {
        self.as_mat3()
    }
}