autd3_core/defined/
angle.rs

1/// \[°\]
2#[allow(non_camel_case_types)]
3pub struct deg;
4
5/// \[rad\]
6#[allow(non_camel_case_types)]
7pub struct rad;
8
9use derive_more::Debug;
10
11/// Angle
12#[repr(C)]
13#[derive(Clone, Copy, PartialEq, Debug)]
14#[debug("{}rad", radian)]
15pub struct Angle {
16    radian: f32,
17}
18
19impl Angle {
20    /// Returns the angle in radian
21    #[must_use]
22    pub const fn radian(self) -> f32 {
23        self.radian
24    }
25
26    /// Returns the angle in degree
27    #[must_use]
28    pub const fn degree(self) -> f32 {
29        self.radian.to_degrees()
30    }
31}
32
33impl std::ops::Mul<deg> for f32 {
34    type Output = Angle;
35
36    fn mul(self, _rhs: deg) -> Self::Output {
37        Self::Output {
38            radian: self.to_radians(),
39        }
40    }
41}
42
43impl std::ops::Mul<rad> for f32 {
44    type Output = Angle;
45
46    fn mul(self, _rhs: rad) -> Self::Output {
47        Self::Output { radian: self }
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn dbg() {
57        assert_eq!(format!("{:?}", 1.0 * rad), "1rad");
58    }
59}