quantities/
acceleration.rs

1// ---------------------------------------------------------------------------
2// Copyright:   (c) 2022 ff. Michael Amrhein (michael@adrhinum.de)
3// License:     This program is part of a larger application. For license
4//              details please read the file LICENSE.TXT provided together
5//              with the application.
6// ---------------------------------------------------------------------------
7// $Source:     src/acceleration.rs $
8// $Revision:   2022-04-16T08:18:48+02:00 $
9
10//! Definition of derived quantity `Acceleration`.
11
12use crate::{duration::Duration, prelude::*, speed::Speed};
13
14#[quantity(Speed / Duration)]
15#[ref_unit(
16    Meter_per_Second_squared,
17    "m/s²",
18    NONE,
19    "Reference unit of quantity `Acceleration`"
20)]
21#[unit(Yards_per_Second_squared, "yd/s²", 0.9144, "yd/s²")]
22/// Rate of change of an objects speed with respect to time.
23///
24/// Definition: Speed/Duration = Length/Duration²
25///
26/// Reference unit: Meter per Second squared ('m/s²')
27///
28/// Predefined units:
29///
30/// | Symbol | Name                     | Definition    | Equivalent in 'm/s²' |
31/// |--------|--------------------------|---------------|----------------------|
32/// | yd/s²  | Yards per Second squared | yd/s²         | 0.9144               |
33pub struct Acceleration {}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38    use crate::{
39        assert_almost_eq, duration::MILLISECOND, speed::METER_PER_SECOND,
40    };
41
42    #[test]
43    fn test_speed_div_duration() {
44        let av: AmountT = Amnt!(2.94);
45        let v = av * METER_PER_SECOND;
46        let at = Amnt!(7.);
47        let t = at * MILLISECOND;
48        let a = v / t;
49        assert_almost_eq!(a.amount(), av / at * Amnt!(1000.));
50        assert_eq!(a.unit(), METER_PER_SECOND_SQUARED);
51    }
52}