zmatrix 0.4.9

Compile-time dimensional analysis & physics-aware linear algebra for aerospace and robotics
Documentation
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
use std::any::Any;
use std::ops::{Add, Div, Mul, Neg, Sub};
use crate::physics::basic::{
    Coef, Distance, GravitationalParameter, Mass, PhysicalQuantity, SpecificAngularMomentum,
    SpecificAngularMomentumType, VectorQuantity, Velocity,
};

/// `1 km²/s` 等于多少 `m²/s`。
///
/// 1e6,不是 1e3 —— 平方公里的「平方」也在分子上。
const KM2_TO_M2: f64 = 1e6;

impl Default for SpecificAngularMomentum {
    fn default() -> Self {
        Self::from_m2_per_second(0.0)
    }
}

impl PhysicalQuantity for SpecificAngularMomentum {
    fn as_any(&self) -> &dyn Any {
        self
    }

    fn is_zero(&self) -> bool {
        self.v == 0.0
    }

    fn default_unit_value(&self) -> f64 {
        self.as_m2_per_second()
    }

    fn set_value(&mut self, value: f64) {
        self.v = value;
    }

    fn unit_display_name(&self) -> String {
        "SpecificAngularMomentum (m²/s)".to_string()
    }
}

impl VectorQuantity for SpecificAngularMomentum {}

impl SpecificAngularMomentum {
    pub fn from_m2_per_second(v: f64) -> Self {
        Self {
            default_type: SpecificAngularMomentumType::M2PerSecond,
            v,
        }
    }

    pub fn from_km2_per_second(v: f64) -> Self {
        Self {
            default_type: SpecificAngularMomentumType::Km2PerSecond,
            v,
        }
    }

    pub fn as_m2_per_second(&self) -> f64 {
        match self.default_type {
            SpecificAngularMomentumType::M2PerSecond => self.v,
            SpecificAngularMomentumType::Km2PerSecond => self.v * KM2_TO_M2,
        }
    }

    pub fn as_km2_per_second(&self) -> f64 {
        match self.default_type {
            SpecificAngularMomentumType::M2PerSecond => self.v / KM2_TO_M2,
            SpecificAngularMomentumType::Km2PerSecond => self.v,
        }
    }
}

impl Add for SpecificAngularMomentum {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        Self::from_m2_per_second(self.as_m2_per_second() + rhs.as_m2_per_second())
    }
}

impl<'a, 'b> Add<&'b SpecificAngularMomentum> for &'a SpecificAngularMomentum {
    type Output = SpecificAngularMomentum;
    fn add(self, rhs: &'b SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_m2_per_second() + rhs.as_m2_per_second(),
        )
    }
}
impl<'a> Add<&'a SpecificAngularMomentum> for SpecificAngularMomentum {
    type Output = SpecificAngularMomentum;
    fn add(self, rhs: &'a SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_m2_per_second() + rhs.as_m2_per_second(),
        )
    }
}
impl<'a> Add<SpecificAngularMomentum> for &'a SpecificAngularMomentum {
    type Output = SpecificAngularMomentum;
    fn add(self, rhs: SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_m2_per_second() + rhs.as_m2_per_second(),
        )
    }
}

impl Sub for SpecificAngularMomentum {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        Self::from_m2_per_second(self.as_m2_per_second() - rhs.as_m2_per_second())
    }
}

impl<'a, 'b> Sub<&'b SpecificAngularMomentum> for &'a SpecificAngularMomentum {
    type Output = SpecificAngularMomentum;
    fn sub(self, rhs: &'b SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_m2_per_second() - rhs.as_m2_per_second(),
        )
    }
}
impl<'a> Sub<&'a SpecificAngularMomentum> for SpecificAngularMomentum {
    type Output = SpecificAngularMomentum;
    fn sub(self, rhs: &'a SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_m2_per_second() - rhs.as_m2_per_second(),
        )
    }
}
impl<'a> Sub<SpecificAngularMomentum> for &'a SpecificAngularMomentum {
    type Output = SpecificAngularMomentum;
    fn sub(self, rhs: SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_m2_per_second() - rhs.as_m2_per_second(),
        )
    }
}

impl Neg for SpecificAngularMomentum {
    type Output = Self;
    fn neg(self) -> Self::Output {
        Self::from_m2_per_second(-self.as_m2_per_second())
    }
}

impl Mul<f64> for SpecificAngularMomentum {
    type Output = Self;
    fn mul(self, rhs: f64) -> Self::Output {
        Self::from_m2_per_second(self.as_m2_per_second() * rhs)
    }
}

impl Div<f64> for SpecificAngularMomentum {
    type Output = Self;
    fn div(self, rhs: f64) -> Self::Output {
        Self::from_m2_per_second(self.as_m2_per_second() / rhs)
    }
}

impl Mul<SpecificAngularMomentum> for f64 {
    type Output = SpecificAngularMomentum;
    fn mul(self, rhs: SpecificAngularMomentum) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(self * rhs.as_m2_per_second())
    }
}

impl Mul<Coef> for SpecificAngularMomentum {
    type Output = Self;
    fn mul(self, rhs: Coef) -> Self::Output {
        Self::from_m2_per_second(self.as_m2_per_second() * rhs.get_value())
    }
}

impl Div<Coef> for SpecificAngularMomentum {
    type Output = Self;
    fn div(self, rhs: Coef) -> Self::Output {
        Self::from_m2_per_second(self.as_m2_per_second() / rhs.get_value())
    }
}

// 比角动量 ÷ 距离 = 速度:v = h/r
impl Div<Distance> for SpecificAngularMomentum {
    type Output = Velocity;
    fn div(self, rhs: Distance) -> Self::Output {
        Velocity::from_m_per_sec(self.as_m2_per_second() / rhs.as_m())
    }
}

impl Div<Distance> for &SpecificAngularMomentum {
    type Output = Velocity;
    fn div(self, rhs: Distance) -> Self::Output {
        Velocity::from_m_per_sec(self.as_m2_per_second() / rhs.as_m())
    }
}

impl<'a> Div<&'a Distance> for SpecificAngularMomentum {
    type Output = Velocity;
    fn div(self, rhs: &'a Distance) -> Self::Output {
        Velocity::from_m_per_sec(self.as_m2_per_second() / rhs.as_m())
    }
}

impl<'a, 'b> Div<&'b Distance> for &'a SpecificAngularMomentum {
    type Output = Velocity;
    fn div(self, rhs: &'b Distance) -> Self::Output {
        Velocity::from_m_per_sec(self.as_m2_per_second() / rhs.as_m())
    }
}

// 速度 × 距离 = 比角动量(标量形式,只对垂直情形成立)
impl Mul<Distance> for Velocity {
    type Output = SpecificAngularMomentum;
    fn mul(self, rhs: Distance) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(self.as_m_per_sec() * rhs.as_m())
    }
}

impl Mul<Velocity> for Distance {
    type Output = SpecificAngularMomentum;
    fn mul(self, rhs: Velocity) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(self.as_m() * rhs.as_m_per_sec())
    }
}

// 角动量 ÷ 质量 = 比角动量:h = L/m
impl Div<Mass> for crate::physics::basic::AngularMomentum {
    type Output = SpecificAngularMomentum;
    fn div(self, rhs: Mass) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_kg_m2_per_second() / rhs.as_kg(),
        )
    }
}

impl Div<Mass> for &crate::physics::basic::AngularMomentum {
    type Output = SpecificAngularMomentum;
    fn div(self, rhs: Mass) -> Self::Output {
        SpecificAngularMomentum::from_m2_per_second(
            self.as_kg_m2_per_second() / rhs.as_kg(),
        )
    }
}

// 比角动量 × 质量 = 角动量
impl Mul<Mass> for SpecificAngularMomentum {
    type Output = crate::physics::basic::AngularMomentum;
    fn mul(self, rhs: Mass) -> Self::Output {
        crate::physics::basic::AngularMomentum::from_kg_m2_per_second(
            self.as_m2_per_second() * rhs.as_kg(),
        )
    }
}

// 比角动量 × 引力参数 = ?(m⁵/s⁴,无物理意义,不提供)
//
// 但 比角动量² = m⁴/s²,÷ 引力参数 = m。这个链条在轨道计算里常用,
// 所以提供命名方法而不是运算符:
impl SpecificAngularMomentum {
    /// 半通径:`p = h² / μ`。
    ///
    /// **这是半通径(semi-latus rectum),不是半长轴。**
    /// 关系是 `p = a(1 − e²)`,所以 `a = p / (1 − e²)`。
    ///
    /// # 为什么用方法而不是运算符
    ///
    /// `h * h / mu` 能算出来,但中间量 `h²` 的量纲是 `m⁴/s²`——
    /// 这个量在物理上只做一件事就是除以 `μ`,为它单独建类型不值得。
    ///
    /// # 示例
    /// ```
    /// use zmatrix::physics::basic::{GravitationalParameter, SpecificAngularMomentum};
    ///
    /// let earth = GravitationalParameter::from_m3_per_s2(3.986004418e14);
    /// // 700 km 圆轨道:h = r·v = 7078e3 × 7507 ≈ 5.313e10
    /// let h = SpecificAngularMomentum::from_m2_per_second(5.313e10);
    /// let p = h.semi_latus_rectum(earth);
    /// assert!((p.as_m() - 7.083e6).abs() < 1e4);
    /// ```
    pub fn semi_latus_rectum(&self, mu: GravitationalParameter) -> Distance {
        let h = self.as_m2_per_second();
        Distance::from_m(h * h / mu.as_m3_per_s2())
    }

    /// 半长轴:`a = p / (1 − e²)`,其中 `p = h²/μ`。
    ///
    /// 抛物线轨道(`e = 1`)时 `a` 无定义,返回 `None`。
    /// **不返回 `inf`**:无穷大混进后续计算会静默污染结果,
    /// 而 `Option` 强制调用方处理这个边界。
    ///
    /// 双曲线(`e > 1`)时 `1 − e² < 0`,得到负的 `a`。
    /// 这是双曲线轨道的约定(`a < 0` 表示不闭合),不是错误,所以照常返回。
    ///
    /// # 示例
    /// ```
    /// use zmatrix::physics::basic::{Coef, GravitationalParameter, SpecificAngularMomentum};
    ///
    /// let earth = GravitationalParameter::from_m3_per_s2(3.986004418e14);
    /// let h = SpecificAngularMomentum::from_m2_per_second(5.313e10);
    ///
    /// // 圆轨道 e=0:a = p
    /// let p = h.semi_latus_rectum(earth);
    /// let a = h.semi_major_axis(earth, Coef::new(0.0)).unwrap();
    /// assert!((a.as_m() - p.as_m()).abs() < 1e-6);
    ///
    /// // 抛物线 e=1:a 无定义
    /// assert!(h.semi_major_axis(earth, Coef::new(1.0)).is_none());
    /// ```
    pub fn semi_major_axis(
        &self,
        mu: GravitationalParameter,
        eccentricity: Coef,
    ) -> Option<Distance> {
        let p = self.semi_latus_rectum(mu).as_m();
        let e = eccentricity.get_value();
        let denom = 1.0 - e * e;
        if denom.abs() < 1e-15 {
            return None;
        }
        Some(Distance::from_m(p / denom))
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use approx::assert_relative_eq;

    #[test]
    fn test_construction_and_units() {
        let h = SpecificAngularMomentum::from_m2_per_second(1e6);
        assert_relative_eq!(h.as_m2_per_second(), 1e6, epsilon = 1e-6);
        assert_relative_eq!(h.as_km2_per_second(), 1.0, epsilon = 1e-12);

        let h = SpecificAngularMomentum::from_km2_per_second(1.0);
        assert_relative_eq!(h.as_m2_per_second(), 1e6, epsilon = 1e-6);
    }

    #[test]
    fn test_km2_factor_is_1e6_not_1e3() {
        // 最易错处:平方公里的「平方」也在分子上,因子是 1e6
        let km = SpecificAngularMomentum::from_km2_per_second(1.0);
        assert_relative_eq!(km.as_m2_per_second(), 1e6, epsilon = 1e-6);
        assert!((km.as_m2_per_second() - 1e3).abs() > 1.0, "不是 1e3");
    }

    #[test]
    fn test_all_unit_branches() {
        let a = SpecificAngularMomentum::from_m2_per_second(5.9e10);
        let b = SpecificAngularMomentum::from_km2_per_second(5.9e4);

        for h in [a, b] {
            assert_relative_eq!(h.as_m2_per_second(), 5.9e10, epsilon = 1e4);
            assert_relative_eq!(h.as_km2_per_second(), 5.9e4, epsilon = 1e-8);
        }
    }

    #[test]
    fn test_unit_round_trip() {
        for v in [0.0, 1.0, 5.9e10, 1e15] {
            let h = SpecificAngularMomentum::from_m2_per_second(v);
            assert_relative_eq!(
                SpecificAngularMomentum::from_km2_per_second(h.as_km2_per_second())
                    .as_m2_per_second(),
                v,
                epsilon = v.abs() * 1e-12 + 1e-12
            );
        }
    }

    #[test]
    fn test_arith() {
        let a = SpecificAngularMomentum::from_m2_per_second(10.0);
        let b = SpecificAngularMomentum::from_m2_per_second(4.0);

        assert_relative_eq!((a + b).as_m2_per_second(), 14.0, epsilon = 1e-12);
        assert_relative_eq!((&a + &b).as_m2_per_second(), 14.0, epsilon = 1e-12);
        assert_relative_eq!((a + &b).as_m2_per_second(), 14.0, epsilon = 1e-12);
        assert_relative_eq!((&a + b).as_m2_per_second(), 14.0, epsilon = 1e-12);

        assert_relative_eq!((a - b).as_m2_per_second(), 6.0, epsilon = 1e-12);
        assert_relative_eq!((&a - &b).as_m2_per_second(), 6.0, epsilon = 1e-12);
        assert_relative_eq!((a - &b).as_m2_per_second(), 6.0, epsilon = 1e-12);
        assert_relative_eq!((&a - b).as_m2_per_second(), 6.0, epsilon = 1e-12);

        assert_relative_eq!((a * 2.0).as_m2_per_second(), 20.0, epsilon = 1e-12);
        assert_relative_eq!((a / 4.0).as_m2_per_second(), 2.5, epsilon = 1e-12);
        assert_relative_eq!((0.5 * a).as_m2_per_second(), 5.0, epsilon = 1e-12);
        assert_relative_eq!((a * Coef::new(3.0)).as_m2_per_second(), 30.0, epsilon = 1e-12);
        assert_relative_eq!((a / Coef::new(2.0)).as_m2_per_second(), 5.0, epsilon = 1e-12);
        assert_relative_eq!((-a).as_m2_per_second(), -10.0, epsilon = 1e-12);
    }

    #[test]
    fn test_div_distance_gives_velocity() {
        // h/r = v:圆轨道 7000 km,h = 7000e3 × 7546
        let h = SpecificAngularMomentum::from_m2_per_second(7000e3 * 7546.0);
        let r = Distance::from_m(7000e3);
        assert_relative_eq!(h.div(r).as_m_per_sec(), 7546.0, epsilon = 1e-9);
    }

    #[test]
    fn test_div_distance_all_ref_variants() {
        // 4 个引用变体都要覆盖
        let h = SpecificAngularMomentum::from_m2_per_second(7000e3 * 7546.0);
        let r = Distance::from_m(7000e3);

        assert_relative_eq!((h / r).as_m_per_sec(), 7546.0, epsilon = 1e-9);
        assert_relative_eq!((&h / r).as_m_per_sec(), 7546.0, epsilon = 1e-9);
        assert_relative_eq!((h / &r).as_m_per_sec(), 7546.0, epsilon = 1e-9);
        assert_relative_eq!((&h / &r).as_m_per_sec(), 7546.0, epsilon = 1e-9);
    }

    #[test]
    fn test_scalar_mul_distance_gives_h() {
        // v × r = h(标量,仅垂直情形)
        let v = Velocity::from_m_per_sec(7546.0);
        let r = Distance::from_m(7000e3);
        assert_relative_eq!((v * r).as_m2_per_second(), 7000e3 * 7546.0, epsilon = 1e-6);
        assert_relative_eq!((r * v).as_m2_per_second(), 7000e3 * 7546.0, epsilon = 1e-6);
    }

    #[test]
    fn test_angular_momentum_div_mass_gives_specific() {
        // h = L/m
        use crate::physics::basic::AngularMomentum;
        let l = AngularMomentum::from_kg_m2_per_second(7000e3 * 7546.0 * 500.0);
        let m = Mass::from_kg(500.0);
        assert_relative_eq!((l / m).as_m2_per_second(), 7000e3 * 7546.0, epsilon = 1e-6);
        assert_relative_eq!((&l / m).as_m2_per_second(), 7000e3 * 7546.0, epsilon = 1e-6);
    }

    #[test]
    fn test_specific_mul_mass_gives_angular_momentum() {
        let h = SpecificAngularMomentum::from_m2_per_second(7000e3 * 7546.0);
        let l = h * Mass::from_kg(500.0);
        assert_relative_eq!(
            l.as_kg_m2_per_second(),
            7000e3 * 7546.0 * 500.0,
            epsilon = 1e-2
        );
    }

    #[test]
    fn test_semi_latus_rectum() {
        // 地球 700 km 圆轨道:r = 7078e3, v = 7507 m/s
        let mu = GravitationalParameter::from_m3_per_s2(3.986004418e14);
        let h = SpecificAngularMomentum::from_m2_per_second(7078e3 * 7507.0);
        let p = h.semi_latus_rectum(mu);
        // 圆轨道 p = a = r
        assert_relative_eq!(p.as_m(), 7078e3, epsilon = 1e4);
    }

    #[test]
    fn test_semi_major_axis_circular() {
        // e=0:a = p
        let mu = GravitationalParameter::from_m3_per_s2(3.986004418e14);
        let h = SpecificAngularMomentum::from_m2_per_second(7078e3 * 7507.0);
        let p = h.semi_latus_rectum(mu);
        let a = h.semi_major_axis(mu, Coef::new(0.0)).unwrap();
        assert_relative_eq!(a.as_m(), p.as_m(), epsilon = 1e-6);
    }

    #[test]
    fn test_semi_major_axis_elliptic() {
        // a = 7000 km, e = 0.1 → p = a(1-e²) = 6930 km
        let mu = GravitationalParameter::from_m3_per_s2(3.986004418e14);
        let a_true = 7000e3;
        let e = 0.1;
        let p_true = a_true * (1.0 - e * e);
        // 由 p 反算 h
        let h_true = (mu.as_m3_per_s2() * p_true).sqrt();
        let h = SpecificAngularMomentum::from_m2_per_second(h_true);

        let p = h.semi_latus_rectum(mu);
        assert_relative_eq!(p.as_m(), p_true, epsilon = 1.0);

        let a = h.semi_major_axis(mu, Coef::new(e)).unwrap();
        assert_relative_eq!(a.as_m(), a_true, epsilon = 1.0);
    }

    #[test]
    fn test_semi_major_axis_parabolic_is_none() {
        // e=1:a 无定义
        let mu = GravitationalParameter::from_m3_per_s2(3.986004418e14);
        let h = SpecificAngularMomentum::from_m2_per_second(5.9e10);
        assert!(h.semi_major_axis(mu, Coef::new(1.0)).is_none());
        assert!(h.semi_major_axis(mu, Coef::new(-1.0)).is_none());
    }

    #[test]
    fn test_semi_major_axis_hyperbolic_is_negative() {
        // e > 1:a < 0,双曲线约定
        let mu = GravitationalParameter::from_m3_per_s2(3.986004418e14);
        let h = SpecificAngularMomentum::from_m2_per_second(5.9e10);
        let a = h.semi_major_axis(mu, Coef::new(2.0)).unwrap();
        assert!(a.as_m() < 0.0, "双曲线 a 应为负");
    }

    #[test]
    fn test_wrong_formula_would_be_wrong_by_1_minus_e_squared() {
        // 本测试钉住「乘 (1-e²)」是错的:那等于 a(1−e²)²,而不只是差 (1−e²) 倍
        let mu = GravitationalParameter::from_m3_per_s2(3.986004418e14);
        let a_true = 7000e3;
        let e = 0.1;
        let p = a_true * (1.0 - e * e);
        let h = SpecificAngularMomentum::from_m2_per_second((mu.as_m3_per_s2() * p).sqrt());

        let correct = h.semi_major_axis(mu, Coef::new(e)).unwrap().as_m();
        let wrong = h.semi_latus_rectum(mu).as_m() * (1.0 - e * e);

        assert_relative_eq!(correct, a_true, epsilon = 1.0);

        // wrong = a(1−e²)²,而 correct = a,所以比值是 1/(1−e²)²
        let factor = 1.0 - e * e;
        assert_relative_eq!(correct / wrong, 1.0 / (factor * factor), epsilon = 1e-9);

        // 具体数值:e=0.1 时偏小 1.99%
        assert_relative_eq!(wrong / correct, 0.9801, epsilon = 1e-9);
    }

    #[test]
    fn test_physical_quantity_contract() {
        let h = SpecificAngularMomentum::default();
        assert!(h.is_zero());
        assert_eq!(h.default_unit_value(), 0.0);
        assert_eq!(h.unit_display_name(), "SpecificAngularMomentum (m²/s)");

        let mut h2 = SpecificAngularMomentum::default();
        h2.set_value(5.9e10);
        assert_relative_eq!(h2.as_m2_per_second(), 5.9e10, epsilon = 1e-4);
        assert!(!h2.is_zero());

        assert!(h2.as_any().downcast_ref::<SpecificAngularMomentum>().is_some());
    }
}