unitforge/quantities/
moment.rs1use crate::impl_macros::macros::*;
2use crate::prelude::*;
3use crate::quantities::*;
4use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
5use num_traits::identities::Zero;
6use num_traits::FromPrimitive;
7use std::cmp::Ordering;
8use std::fmt;
9use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
10
11#[derive(Copy, Clone, PartialEq)]
12pub enum MomentUnit {
13 Nm,
14 Ndm,
15 Ncm,
16 Nmm,
17 kNm,
18 kNdm,
19 kNcm,
20 kNmm,
21}
22
23impl PhysicsUnit for MomentUnit {
24 fn name(&self) -> &str {
25 match &self {
26 MomentUnit::Nm => "Nm",
27 MomentUnit::Ndm => "Ndm",
28 MomentUnit::Ncm => "Ncm",
29 MomentUnit::Nmm => "Nmm",
30 MomentUnit::kNm => "nKm",
31 MomentUnit::kNdm => "kNdm",
32 MomentUnit::kNcm => "kNcm",
33 MomentUnit::kNmm => "kNmm",
34 }
35 }
36
37 fn base_per_x(&self) -> (f64, i32) {
38 match self {
39 MomentUnit::Nmm => (1., -3),
40 MomentUnit::Ncm => (1., -2),
41 MomentUnit::Ndm => (1., -1),
42 MomentUnit::Nm => (1., 0),
43 MomentUnit::kNm => (1., 3),
44 MomentUnit::kNdm => (1., 2),
45 MomentUnit::kNcm => (1., 1),
46 MomentUnit::kNmm => (1., 0),
47 }
48 }
49}
50
51impl_quantity!(Moment, MomentUnit, MomentUnit::Nm);
52impl_div_with_self_to_f64!(Moment);
53impl_div!(Moment, Distance, Force);
54impl_div!(Moment, Force, Distance);
55impl_mul!(Moment, Distance, ForceArea);