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