unitforge/quantities/
velocity.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 VelocityUnit {
18 km_s,
19 m_s,
20 cm_s,
21 mm_s,
22 km_h,
23}
24
25impl PhysicsUnit for VelocityUnit {
26 fn name(&self) -> &str {
27 match &self {
28 VelocityUnit::km_s => "km/s",
29 VelocityUnit::m_s => "m/s",
30 VelocityUnit::cm_s => "cm/s",
31 VelocityUnit::mm_s => "mm/s",
32 VelocityUnit::km_h => "km/h",
33 }
34 }
35
36 fn base_per_x(&self) -> (f64, i32) {
37 match self {
38 VelocityUnit::km_s => (1., 3),
39 VelocityUnit::m_s => (1., 0),
40 VelocityUnit::cm_s => (1., 2),
41 VelocityUnit::mm_s => (1., 3),
42 VelocityUnit::km_h => (1. / 3.6, 0),
43 }
44 }
45}
46
47impl_const!(Velocity, c, 2.99792458, 8);
48
49impl_quantity!(Velocity, VelocityUnit, VelocityUnit::m_s);
50impl_div_with_self_to_f64!(Velocity);