unitforge/quantities/
force.rs

1use 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 ForceUnit {
13    GN,
14    MN,
15    kN,
16    N,
17    dN,
18    cN,
19    mN,
20    muN,
21    nN,
22}
23
24impl PhysicsUnit for ForceUnit {
25    fn name(&self) -> &str {
26        match &self {
27            ForceUnit::GN => "GN",
28            ForceUnit::MN => "MN",
29            ForceUnit::kN => "kN",
30            ForceUnit::N => "N",
31            ForceUnit::dN => "dN",
32            ForceUnit::cN => "cN",
33            ForceUnit::mN => "mN",
34            ForceUnit::muN => "μm",
35            ForceUnit::nN => "nN",
36        }
37    }
38
39    fn base_per_x(&self) -> (f64, i32) {
40        match self {
41            ForceUnit::GN => (1., 9),
42            ForceUnit::MN => (1., 6),
43            ForceUnit::kN => (1., 3),
44            ForceUnit::N => (1., 0),
45            ForceUnit::dN => (1., -1),
46            ForceUnit::cN => (1., -2),
47            ForceUnit::mN => (1., -3),
48            ForceUnit::muN => (1., -6),
49            ForceUnit::nN => (1., -9),
50        }
51    }
52}
53
54impl_quantity!(Force, ForceUnit, ForceUnit::N);
55impl_div_with_self_to_f64!(Force);
56
57impl_mul!(Force, Distance, Moment);
58impl_div!(Force, Stress, Area);
59impl_div!(Force, Area, Stress);
60impl_div!(Force, Distance, Stiffness);
61impl_div!(Force, Stiffness, Distance);
62impl_mul!(Force, Area, ForceArea);