zmatrix 0.3.1

This is a matrix calculation lib
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
use std::f64::consts::PI;
use std::ops::{Add, Div, Mul, Neg, Sub};
use std::time::Duration;
use super::*;

impl AngularAcceleration {
    pub fn from_rad_per_second2(v: f64) -> Self {
        AngularAcceleration {
            default_type: AngularAccelerationType::RadperSecond2,
            v,
        }
    }

    pub fn from_deg_per_second2(v: f64) -> Self {
        AngularAcceleration {
            default_type: AngularAccelerationType::DegPerSecond2,
            v,
        }
    }

    pub fn as_rad_per_second2(&self) -> f64 {
        return match self.default_type {
            AngularAccelerationType::RadperSecond2 => self.v,
            AngularAccelerationType::DegPerSecond2 => {
                self.v * PI / 180.0
            }
        };
    }

    pub fn as_deg_per_second2(&self) -> f64 {
        return match self.default_type {
            AngularAccelerationType::RadperSecond2 => self.v * 180.0 / PI,
            AngularAccelerationType::DegPerSecond2 => self.v,
        };
    }
}


impl PhysicalQuantity for AngularAcceleration {
    fn as_any(&self) -> &dyn Any {
        self
}
    fn is_zero(&self) -> bool {
        self.v == 0.0
    }

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

    fn set_value(&mut self, value: f64) {
        self.v = value;
    }
    fn unit_display_name(&self) -> String {
        "AngularAcceleration (rad/s²)".to_string()
    }
}

impl Div<Duration> for AngularAcceleration {
    type Output = AngularVelocity;

    fn div(self, rhs: Duration) -> Self::Output {
        let v = self.as_rad_per_second2() / rhs.as_secs_f64();
        AngularVelocity::from_rad_per_second(v)
    }
}

impl Div<chrono::TimeDelta> for AngularAcceleration {
    type Output = AngularVelocity;

    fn div(self, rhs: chrono::TimeDelta) -> Self::Output {
        let v = self.as_rad_per_second2() / time_delta_to_secs_f64(&rhs);
        AngularVelocity::from_rad_per_second(v)
    }
}


impl Add for AngularAcceleration {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        let v = self.as_rad_per_second2() + rhs.as_rad_per_second2();
        AngularAcceleration::from_rad_per_second2(v)
    }
}

// 引用-引用 与 混合引用:AngularAcceleration 加法
impl<'a, 'b> Add<&'b AngularAcceleration> for &'a AngularAcceleration {
    type Output = AngularAcceleration;
    fn add(self, rhs: &'b AngularAcceleration) -> Self::Output { AngularAcceleration::from_rad_per_second2(self.as_rad_per_second2() + rhs.as_rad_per_second2()) }
}
impl<'a> Add<&'a AngularAcceleration> for AngularAcceleration {
    type Output = AngularAcceleration;
    fn add(self, rhs: &'a AngularAcceleration) -> Self::Output { AngularAcceleration::from_rad_per_second2(self.as_rad_per_second2() + rhs.as_rad_per_second2()) }
}
impl<'a> Add<AngularAcceleration> for &'a AngularAcceleration {
    type Output = AngularAcceleration;
    fn add(self, rhs: AngularAcceleration) -> Self::Output { AngularAcceleration::from_rad_per_second2(self.as_rad_per_second2() + rhs.as_rad_per_second2()) }
}

impl Add<f64> for AngularAcceleration {
    type Output = Self;
    fn add(self, rhs: f64) -> Self::Output {
        let v = self.v + rhs;
        AngularAcceleration {
            v,
            default_type: self.default_type,
        }
    }
}

impl Sub for AngularAcceleration {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        let v = self.as_rad_per_second2() - rhs.as_rad_per_second2();
        AngularAcceleration::from_rad_per_second2(v)
    }
}

// 引用-引用 与 混合引用:AngularAcceleration 减法
impl<'a, 'b> Sub<&'b AngularAcceleration> for &'a AngularAcceleration {
    type Output = AngularAcceleration;
    fn sub(self, rhs: &'b AngularAcceleration) -> Self::Output { AngularAcceleration::from_rad_per_second2(self.as_rad_per_second2() - rhs.as_rad_per_second2()) }
}
impl<'a> Sub<&'a AngularAcceleration> for AngularAcceleration {
    type Output = AngularAcceleration;
    fn sub(self, rhs: &'a AngularAcceleration) -> Self::Output { AngularAcceleration::from_rad_per_second2(self.as_rad_per_second2() - rhs.as_rad_per_second2()) }
}
impl<'a> Sub<AngularAcceleration> for &'a AngularAcceleration {
    type Output = AngularAcceleration;
    fn sub(self, rhs: AngularAcceleration) -> Self::Output { AngularAcceleration::from_rad_per_second2(self.as_rad_per_second2() - rhs.as_rad_per_second2()) }
}

impl Sub<f64> for AngularAcceleration {
    type Output = Self;
    fn sub(self, rhs: f64) -> Self::Output {
        let v = self.v - rhs;
        AngularAcceleration {
            v,
            default_type: self.default_type,
        }
    }
}
// 从角加速度变成角速度
impl Mul<Duration> for AngularAcceleration {
    type Output = AngularVelocity;

    fn mul(self, rhs: Duration) -> Self::Output {
        let v = self.as_rad_per_second2() * rhs.as_secs_f64();
        AngularVelocity::from_rad_per_second(v)
    }
}

impl Mul<chrono::TimeDelta> for AngularAcceleration {
    type Output = AngularVelocity;

    fn mul(self, rhs: chrono::TimeDelta) -> Self::Output {
        let v = self.as_rad_per_second2() * time_delta_to_secs_f64(&rhs);
        AngularVelocity::from_rad_per_second(v)
    }
}

// 引用版本:AngularAcceleration * Duration -> AngularVelocity
impl<'a> Mul<Duration> for &'a AngularAcceleration {
    type Output = AngularVelocity;
    fn mul(self, rhs: Duration) -> Self::Output { AngularVelocity::from_rad_per_second(self.as_rad_per_second2() * rhs.as_secs_f64()) }
}
impl<'a> Mul<&'a Duration> for AngularAcceleration {
    type Output = AngularVelocity;
    fn mul(self, rhs: &'a Duration) -> Self::Output { AngularVelocity::from_rad_per_second(self.as_rad_per_second2() * rhs.as_secs_f64()) }
}
impl<'a, 'b> Mul<&'b Duration> for &'a AngularAcceleration {
    type Output = AngularVelocity;
    fn mul(self, rhs: &'b Duration) -> Self::Output { AngularVelocity::from_rad_per_second(self.as_rad_per_second2() * rhs.as_secs_f64()) }
}

// 引用版本:AngularAcceleration * TimeDelta -> AngularVelocity
impl<'a> Mul<chrono::TimeDelta> for &'a AngularAcceleration {
    type Output = AngularVelocity;
    fn mul(self, rhs: chrono::TimeDelta) -> Self::Output { AngularVelocity::from_rad_per_second(self.as_rad_per_second2() * time_delta_to_secs_f64(&rhs)) }
}
impl<'a> Mul<&'a chrono::TimeDelta> for AngularAcceleration {
    type Output = AngularVelocity;
    fn mul(self, rhs: &'a chrono::TimeDelta) -> Self::Output { AngularVelocity::from_rad_per_second(self.as_rad_per_second2() * time_delta_to_secs_f64(rhs)) }
}
impl<'a, 'b> Mul<&'b chrono::TimeDelta> for &'a AngularAcceleration {
    type Output = AngularVelocity;
    fn mul(self, rhs: &'b chrono::TimeDelta) -> Self::Output { AngularVelocity::from_rad_per_second(self.as_rad_per_second2() * time_delta_to_secs_f64(rhs)) }
}

// 从角加速度变成线加速度
impl Mul<Distance> for AngularAcceleration {
    type Output = Acceleration;
    fn mul(self, rhs: Distance) -> Self::Output {
        let v = self.as_rad_per_second2() * rhs.as_m();
        Acceleration::from_m_per_s2(v)
    }
}

// 引用版本:AngularAcceleration * Distance -> Acceleration
impl<'a, 'b> Mul<&'b Distance> for &'a AngularAcceleration {
    type Output = Acceleration;
    fn mul(self, rhs: &'b Distance) -> Self::Output { Acceleration::from_m_per_s2(self.as_rad_per_second2() * rhs.as_m()) }
}
impl<'a> Mul<&'a Distance> for AngularAcceleration {
    type Output = Acceleration;
    fn mul(self, rhs: &'a Distance) -> Self::Output { Acceleration::from_m_per_s2(self.as_rad_per_second2() * rhs.as_m()) }
}
impl<'a> Mul<Distance> for &'a AngularAcceleration {
    type Output = Acceleration;
    fn mul(self, rhs: Distance) -> Self::Output { Acceleration::from_m_per_s2(self.as_rad_per_second2() * rhs.as_m()) }
}

impl Mul<f64> for AngularAcceleration {
    type Output = Self;
    fn mul(self, rhs: f64) -> Self::Output {
        let v = self.as_rad_per_second2() * rhs;
        Self::from_rad_per_second2(v)
    }
}

impl Div<f64> for AngularAcceleration {
    type Output = Self;
    fn div(self, rhs: f64) -> Self::Output {
        let v = self.as_rad_per_second2() / rhs;
        Self::from_rad_per_second2(v)
    }
}

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

impl Div<AngularAcceleration> for f64 {
    type Output = AngularAcceleration;
    fn div(self, rhs: AngularAcceleration) -> Self::Output {
        let v = self / rhs.v;
        AngularAcceleration {
            default_type: rhs.default_type,
            v: v,
        }
    }
}

impl Mul<Coef> for AngularAcceleration {
    type Output = Self;
    fn mul(self, rhs: Coef) -> Self::Output {
        let v = self.as_rad_per_second2() * rhs.get_value();
        Self::from_rad_per_second2(v)
    }
}

impl Div<Coef> for AngularAcceleration {
    type Output = Self;
    fn div(self, rhs: Coef) -> Self::Output {
        let v = self.as_rad_per_second2() / rhs.get_value();
        Self::from_rad_per_second2(v)
    }
}

impl Neg for AngularAcceleration {
    type Output = Self;
    fn neg(self) -> Self::Output {
        let v = -self.as_rad_per_second2();
        Self::from_rad_per_second2(v)
    }
}

#[cfg(test)]
mod tests {
    use approx::assert_relative_eq;
    use super::*;
    #[test]
    fn test_angular_acceleration_from() {
        let alpha1 = AngularAcceleration::from_rad_per_second2(6.0 * PI);
        assert_eq!(alpha1.default_type, AngularAccelerationType::RadperSecond2);
        assert_eq!(alpha1.v, 6.0 * PI);

        let alpha1 = AngularAcceleration::from_deg_per_second2(360.0);
        assert_eq!(alpha1.default_type, AngularAccelerationType::DegPerSecond2);
        assert_eq!(alpha1.v, 360.0);
    }

    #[test]
    fn test_angular_acceleration_as() {
        let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
        assert_relative_eq!(alpha1.as_rad_per_second2(), 1.0*PI);
        assert_relative_eq!(alpha1.as_deg_per_second2(), 180.0);

        let alpha1 = AngularAcceleration::from_deg_per_second2(180.0);
        assert_eq!(alpha1.as_deg_per_second2(), 180.0);
        assert_relative_eq!(alpha1.as_rad_per_second2(), PI);
    }

    #[test]
    fn test_angular_acceleration_change() {
        let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
        let duration = Duration::from_secs_f64(10.0);
        let omg1 = alpha1 / duration;
        assert_eq!(omg1.default_type, AngularVelocityType::RadperSecond);
        assert_relative_eq!(omg1.as_rad_per_second(), 0.1 * PI);

        let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
        let distance = Distance::from_m(10.0);
        let a1 = alpha1 * distance;
        assert_relative_eq!(a1.as_m_per_s2(),10.0 * PI);

        let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
        let omg = alpha1 * duration;
        assert_relative_eq!(omg.as_rad_per_second(), 10.0* PI);
    }

    #[test]
    fn test_angular_acceleration_change_timedelta() {
        let alpha = AngularAcceleration::from_rad_per_second2(PI);
        let td = time_delta_from_secs_f64(10.0);
        let omg = alpha / td;
        assert_relative_eq!(omg.as_rad_per_second(), 0.1 * PI);

        // 负时间 → 负角速度
        let neg_td = time_delta_from_secs_f64(-10.0);
        let omg_neg = alpha / neg_td;
        assert_relative_eq!(omg_neg.as_rad_per_second(), -0.1 * PI);

        // 乘法
        let omg2 = alpha * td;
        assert_relative_eq!(omg2.as_rad_per_second(), 10.0 * PI);

        // 负时间乘法
        let omg_neg2 = alpha * neg_td;
        assert_relative_eq!(omg_neg2.as_rad_per_second(), -10.0 * PI);
    }

    #[test]
    fn test_angular_acceleration_add() {
        {
            let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha2 = AngularAcceleration::from_rad_per_second2(PI + PI);
            let alpha3 = alpha1 + alpha2;
            assert_relative_eq!(alpha3.as_rad_per_second2(), 3.0 * PI);

            let alpha1 = AngularAcceleration::from_deg_per_second2(100.0);
            let alpha2 = AngularAcceleration::from_deg_per_second2(100.0);
            let alpha3 = alpha1 + alpha2;
            assert_relative_eq!(alpha3.as_deg_per_second2(), 200.0);

            let alpha1 = AngularAcceleration::from_deg_per_second2(180.0);
            let alpha2 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha3 = alpha1 + alpha2;
            assert_relative_eq!(alpha3.as_deg_per_second2(), 360.0);

            let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha2 = AngularAcceleration::from_deg_per_second2(180.0);
            let alpha3 = alpha1 + alpha2;
            assert_relative_eq!(alpha3.as_deg_per_second2(), 360.0);
        }
        {
            let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha2 = alpha1 + PI;
            assert_relative_eq!(alpha2.as_rad_per_second2(), 2.0*PI);

            let alpha1 = AngularAcceleration::from_deg_per_second2(90.0);
            let alpha2 = alpha1 + 90.0;
            assert_relative_eq!(alpha2.as_deg_per_second2(), 180.0);
        }
    }

    #[test]
    fn test_angular_acceleration_sub() {
        {
            let alpha1 = AngularAcceleration::from_rad_per_second2(PI + PI);
            let alpha2 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha3 = alpha1 - alpha2;
            assert_relative_eq!(alpha3.as_rad_per_second2(), PI);

            let alpha1 = AngularAcceleration::from_deg_per_second2(100.0);
            let alpha2 = AngularAcceleration::from_deg_per_second2(100.0);
            let alpha3 = alpha1 - alpha2;
            assert_relative_eq!(alpha3.as_deg_per_second2(), 0.0);

            let alpha1 = AngularAcceleration::from_deg_per_second2(180.0);
            let alpha2 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha3 = alpha1 - alpha2;
            assert_relative_eq!(alpha3.as_deg_per_second2(), 0.0);

            let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha2 = AngularAcceleration::from_deg_per_second2(180.0);
            let alpha3 = alpha1 - alpha2;
            assert_relative_eq!(alpha3.as_deg_per_second2(), 0.0);
        }
        {
            let alpha1 = AngularAcceleration::from_rad_per_second2(PI);
            let alpha2 = alpha1 - PI;
            assert_relative_eq!(alpha2.as_rad_per_second2(), 0.0);

            let alpha1 = AngularAcceleration::from_deg_per_second2(90.0);
            let alpha2 = alpha1 - 90.0;
            assert_relative_eq!(alpha2.as_deg_per_second2(), 0.0);
        }
    }
    #[test]
    fn test_to_mul() {
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        let d2 = d1 * 2.0;
        assert_eq!(d2.as_rad_per_second2(), 2000.0);
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        let d2 = d1 * Coef::new(2.0);
        assert_eq!(d2.as_rad_per_second2(), 2000.0);
    }

    #[test]
    fn test_to_div() {
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        let d2 = d1 / 2.0;
        assert_eq!(d2.as_rad_per_second2(), 500.0);
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        let d2 = d1 / Coef::new(2.0);
        assert_eq!(d2.as_rad_per_second2(), 500.0);
    }

    #[test]
    fn test_as_any(){
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        let dw = d1.as_any();
        let d2 = dw.downcast_ref::<AngularAcceleration>().unwrap();
    }

    #[test]
    fn test_is_zero(){
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        let d2 = AngularAcceleration::from_rad_per_second2(0.0);
        assert_eq!(d1.is_zero(),false);
        assert_eq!(d2.is_zero(),true);
    }

    #[test]
    fn test_default_unit_value(){
        let d1 = AngularAcceleration::from_rad_per_second2(1000.0);
        assert_eq!(d1.default_unit_value(),1000.0);

        let d1 = AngularAcceleration::from_deg_per_second2(180.0);
        assert_eq!(d1.default_unit_value(),PI);

        let mut d1 = AngularAcceleration::from_rad_per_second2(PI);
        d1.set_value(1000.0);
        assert_eq!(d1.default_unit_value(),1000.0);
    }

    #[test]
    fn test_f64_mul_angular_acceleration() {
        // f64 * AngularAcceleration 测试
        let a = AngularAcceleration::from_rad_per_second2(PI);
        let result = 2.0 * a;
        assert_relative_eq!(result.as_rad_per_second2(), 2.0 * PI);

        let a = AngularAcceleration::from_deg_per_second2(90.0);
        let result = 2.0 * a;
        assert_relative_eq!(result.as_deg_per_second2(), 180.0);
    }

    #[test]
    fn test_f64_div_angular_acceleration() {
        // f64 / AngularAcceleration 测试
        let a = AngularAcceleration::from_rad_per_second2(PI);
        let result = 2.0 * PI / a;
        assert_relative_eq!(result.as_rad_per_second2(), 2.0);

        let a = AngularAcceleration::from_deg_per_second2(180.0);
        let result = 180.0 / a;
        assert_relative_eq!(result.as_deg_per_second2(), 1.0);
    }

    #[test]
    fn test_angular_acceleration_ref_ops() {
        let a1 = AngularAcceleration::from_rad_per_second2(std::f64::consts::PI);
        let a2 = AngularAcceleration::from_deg_per_second2(180.0); // PI rad/s2
        let s = &a1 + &a2;
        assert_relative_eq!(s.as_rad_per_second2(), 2.0 * std::f64::consts::PI);

        let d = &a1 - &a2;
        assert_relative_eq!(d.as_rad_per_second2(), 0.0);

        let v = &a1 * &std::time::Duration::from_secs(2);
        assert_relative_eq!(v.as_rad_per_second(), 2.0 * std::f64::consts::PI);

        let acc = &a1 * &Distance::from_m(2.0);
        assert_relative_eq!(acc.as_m_per_s2(), 2.0 * std::f64::consts::PI);

        // 混合引用:加/减
        let s2 = a1 + &a2;
        assert_relative_eq!(s2.as_rad_per_second2(), 2.0 * std::f64::consts::PI);
        let s3 = &a1 + a2;
        assert_relative_eq!(s3.as_rad_per_second2(), 2.0 * std::f64::consts::PI);
        let a2b = AngularAcceleration::from_deg_per_second2(180.0);
        let d2 = a1 - &a2b;
        assert_relative_eq!(d2.as_rad_per_second2(), 0.0);
        let d3 = &a1 - a2b;
        assert_relative_eq!(d3.as_rad_per_second2(), 0.0);

        // 混合引用:* Duration
        let dur = std::time::Duration::from_secs(2);
        let w2 = a1 * &dur;
        assert_relative_eq!(w2.as_rad_per_second(), 2.0 * std::f64::consts::PI);
        let w3 = &a1 * dur;
        assert_relative_eq!(w3.as_rad_per_second(), 2.0 * std::f64::consts::PI);

        // 混合引用:* TimeDelta
        let td = time_delta_from_secs_f64(2.0);
        let w4 = a1 * &td;
        assert_relative_eq!(w4.as_rad_per_second(), 2.0 * std::f64::consts::PI);
        let w5 = &a1 * td;
        assert_relative_eq!(w5.as_rad_per_second(), 2.0 * std::f64::consts::PI);
        let td2 = time_delta_from_secs_f64(2.0);
        let w6 = &a1 * &td2;
        assert_relative_eq!(w6.as_rad_per_second(), 2.0 * std::f64::consts::PI);

        // 混合引用:* Distance
        let acc2 = a1 * &Distance::from_m(2.0);
        assert_relative_eq!(acc2.as_m_per_s2(), 2.0 * std::f64::consts::PI);
        let acc3 = &a1 * Distance::from_m(2.0);
        assert_relative_eq!(acc3.as_m_per_s2(), 2.0 * std::f64::consts::PI);
    }

    #[test]
    fn test_angular_acceleration_neg() {
        // 测试正值的负号
        let a1 = AngularAcceleration::from_rad_per_second2(PI);
        let neg_a1 = -a1;
        assert_relative_eq!(neg_a1.as_rad_per_second2(), -PI);

        // 测试负值的负号
        let a2 = AngularAcceleration::from_deg_per_second2(-90.0);
        let neg_a2 = -a2;
        assert_relative_eq!(neg_a2.as_deg_per_second2(), 90.0);

        // 测试零值
        let a3 = AngularAcceleration::from_rad_per_second2(0.0);
        let neg_a3 = -a3;
        assert_relative_eq!(neg_a3.as_rad_per_second2(), 0.0);

        // 测试不同单位的负号操作
        let a4 = AngularAcceleration::from_deg_per_second2(180.0);
        let neg_a4 = -a4;
        assert_relative_eq!(neg_a4.as_rad_per_second2(), -PI);

        // 测试大数值
        let a5 = AngularAcceleration::from_rad_per_second2(2.0 * PI);
        let neg_a5 = -a5;
        assert_relative_eq!(neg_a5.as_deg_per_second2(), -360.0);
    }
}