unitforge/quantities/
angular_velocity.rs1use crate::impl_macros::macros::*;
2use crate::PhysicsUnit;
3use core::f64::consts::PI;
4
5#[cfg_attr(feature = "strum", derive(EnumIter))]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)]
8#[cfg_attr(feature = "pyo3", pyclass(eq, eq_int, from_py_object))]
9pub enum AngularVelocityUnit {
10 rad_s,
11 deg_s,
12 rpm,
13}
14
15impl AngularVelocityUnit {
16 pub const fn base_per_x_const(self) -> (f64, i32) {
17 match self {
18 AngularVelocityUnit::rad_s => (1., 0),
19 AngularVelocityUnit::deg_s => (PI / 180., 0),
20 AngularVelocityUnit::rpm => (2.0 * PI / 60.0, 0),
21 }
22 }
23}
24
25impl PhysicsUnit for AngularVelocityUnit {
26 fn name(&self) -> &str {
27 match &self {
28 AngularVelocityUnit::rad_s => "rad/s",
29 AngularVelocityUnit::deg_s => "°/s",
30 AngularVelocityUnit::rpm => "rpm",
31 }
32 }
33
34 fn base_per_x(&self) -> (f64, i32) {
35 (*self).base_per_x_const()
36 }
37}
38
39impl_quantity!(
40 AngularVelocity,
41 AngularVelocityUnit,
42 [AngularVelocityUnit::deg_s]
43);
44impl_div_with_self_to_f64!(AngularVelocity);