unitforge/quantities/
force.rs1use crate::impl_macros::macros::*;
2use crate::prelude::*;
3use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
4use num_traits::identities::Zero;
5use num_traits::FromPrimitive;
6#[cfg(feature = "pyo3")]
7use pyo3::pyclass;
8#[cfg(feature = "serde")]
9use serde::{Deserialize, Serialize};
10use std::cmp::Ordering;
11use std::fmt;
12use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
13
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15#[derive(Copy, Clone, PartialEq, Debug)]
16#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int))]
17pub enum ForceUnit {
18 GN,
19 MN,
20 kN,
21 N,
22 dN,
23 cN,
24 mN,
25 muN,
26 nN,
27 lbf,
28 kgf,
29}
30
31impl PhysicsUnit for ForceUnit {
32 fn name(&self) -> &str {
33 match &self {
34 ForceUnit::GN => "GN",
35 ForceUnit::MN => "MN",
36 ForceUnit::kN => "kN",
37 ForceUnit::N => "N",
38 ForceUnit::dN => "dN",
39 ForceUnit::cN => "cN",
40 ForceUnit::mN => "mN",
41 ForceUnit::muN => "μm",
42 ForceUnit::nN => "nN",
43 ForceUnit::lbf => "lbf",
44 ForceUnit::kgf => "kgf",
45 }
46 }
47
48 fn base_per_x(&self) -> (f64, i32) {
49 match self {
50 ForceUnit::GN => (1., 9),
51 ForceUnit::MN => (1., 6),
52 ForceUnit::kN => (1., 3),
53 ForceUnit::N => (1., 0),
54 ForceUnit::dN => (1., -1),
55 ForceUnit::cN => (1., -2),
56 ForceUnit::mN => (1., -3),
57 ForceUnit::muN => (1., -6),
58 ForceUnit::nN => (1., -9),
59 ForceUnit::lbf => (4.44822, 0),
60 ForceUnit::kgf => (9.80665, 0),
61 }
62 }
63}
64
65impl_quantity!(Force, ForceUnit, ForceUnit::N);
66impl_div_with_self_to_f64!(Force);