marg_orientation/
accelerometer_noise.rs

1use crate::impl_standard_traits;
2use core::fmt::{Debug, Formatter};
3use core::ops::Mul;
4use uniform_array_derive::UniformArray;
5
6#[derive(UniformArray)]
7#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
8#[repr(C)]
9pub struct AccelerometerNoise<T> {
10    /// The acceleration noise along the x-axis, in meters per second.
11    pub x: T,
12    /// The acceleration noise along the y-axis, in meters per second.
13    pub y: T,
14    /// The acceleration noise along the z-axis, in meters per second.
15    pub z: T,
16}
17
18impl<T> AccelerometerNoise<T> {
19    /// Initializes a new [`AccelerometerNoise`] instance.
20    #[inline(always)]
21    pub const fn new(x: T, y: T, z: T) -> Self {
22        Self { x, y, z }
23    }
24}
25
26impl<T> Default for AccelerometerNoise<T>
27where
28    T: Default,
29{
30    #[inline]
31    fn default() -> Self {
32        Self::new(Default::default(), Default::default(), Default::default())
33    }
34}
35
36impl<T> Clone for AccelerometerNoise<T>
37where
38    T: Clone,
39{
40    fn clone(&self) -> Self {
41        Self {
42            x: self.x.clone(),
43            y: self.y.clone(),
44            z: self.z.clone(),
45        }
46    }
47}
48
49impl<T> Debug for AccelerometerNoise<T>
50where
51    T: Debug,
52{
53    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
54        f.debug_tuple("AccelerometerNoise")
55            .field(&self.x)
56            .field(&self.y)
57            .field(&self.z)
58            .finish()
59    }
60}
61
62impl<T> Mul<T> for AccelerometerNoise<T>
63where
64    T: Mul<T, Output = T> + Clone,
65{
66    type Output = AccelerometerNoise<T>;
67
68    fn mul(self, rhs: T) -> Self::Output {
69        Self {
70            x: self.x * rhs.clone(),
71            y: self.y * rhs.clone(),
72            z: self.z * rhs.clone(),
73        }
74    }
75}
76
77impl_standard_traits!(AccelerometerNoise, T);
78
79#[cfg(test)]
80mod test {
81    use super::*;
82
83    #[test]
84    fn test_len() {
85        let reading = AccelerometerNoise::<f32>::default();
86        assert_eq!(reading.len(), 3);
87    }
88
89    #[test]
90    fn test_index() {
91        let reading = AccelerometerNoise::<f32> {
92            x: 1.0,
93            y: 2.0,
94            z: 3.0,
95        };
96
97        assert_eq!(reading[0], 1.0);
98        assert_eq!(reading[1], 2.0);
99        assert_eq!(reading[2], 3.0);
100    }
101}