space_units/quantities/
orbital.rs1use super::DisplayWithUnit;
2
3#[must_use]
19#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
20pub struct GravitationalParameter(pub(crate) f64);
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum GravitationalParameterUnit {
25 M3PerS2,
27 Km3PerS2,
29}
30
31impl GravitationalParameterUnit {
32 const fn symbol(self) -> &'static str {
33 match self {
34 Self::M3PerS2 => "m^3/s^2",
35 Self::Km3PerS2 => "km^3/s^2",
36 }
37 }
38
39 const fn m3ps2_per_unit(self) -> f64 {
40 match self {
41 Self::M3PerS2 => 1.0,
42 Self::Km3PerS2 => 1e9,
43 }
44 }
45}
46
47impl GravitationalParameter {
48 pub const fn from_m3ps2(val: f64) -> Self {
50 Self(val)
51 }
52
53 pub const fn from_km3ps2(val: f64) -> Self {
55 Self(val * 1e9)
56 }
57
58 pub const fn in_m3ps2(self) -> f64 {
60 self.0
61 }
62
63 pub const fn in_km3ps2(self) -> f64 {
65 self.0 / 1e9
66 }
67
68 pub fn in_unit(self, unit: GravitationalParameterUnit) -> f64 {
70 self.0 / unit.m3ps2_per_unit()
71 }
72
73 pub fn display_as(self, unit: GravitationalParameterUnit) -> DisplayWithUnit {
75 DisplayWithUnit {
76 value: self.in_unit(unit),
77 symbol: unit.symbol(),
78 }
79 }
80
81 pub fn abs(self) -> Self {
83 Self(self.0.abs())
84 }
85}
86
87impl_quantity_display!(GravitationalParameter, "m³/s²");
88
89impl_common_ops!(GravitationalParameter);
90
91#[must_use]
106#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
107pub struct SpecificAngularMomentum(pub(crate) f64);
108
109#[derive(Debug, Clone, Copy, PartialEq, Eq)]
111pub enum SpecificAngularMomentumUnit {
112 M2PerS,
114 Km2PerS,
116}
117
118impl SpecificAngularMomentumUnit {
119 const fn symbol(self) -> &'static str {
120 match self {
121 Self::M2PerS => "m^2/s",
122 Self::Km2PerS => "km^2/s",
123 }
124 }
125
126 const fn m2ps_per_unit(self) -> f64 {
127 match self {
128 Self::M2PerS => 1.0,
129 Self::Km2PerS => 1e6,
130 }
131 }
132}
133
134impl SpecificAngularMomentum {
135 pub const fn from_m2ps(val: f64) -> Self {
137 Self(val)
138 }
139
140 pub const fn from_km2ps(val: f64) -> Self {
142 Self(val * 1e6)
143 }
144
145 pub const fn in_m2ps(self) -> f64 {
147 self.0
148 }
149
150 pub const fn in_km2ps(self) -> f64 {
152 self.0 / 1e6
153 }
154
155 pub fn in_unit(self, unit: SpecificAngularMomentumUnit) -> f64 {
157 self.0 / unit.m2ps_per_unit()
158 }
159
160 pub fn display_as(self, unit: SpecificAngularMomentumUnit) -> DisplayWithUnit {
162 DisplayWithUnit {
163 value: self.in_unit(unit),
164 symbol: unit.symbol(),
165 }
166 }
167
168 pub fn abs(self) -> Self {
170 Self(self.0.abs())
171 }
172}
173
174impl_quantity_display!(SpecificAngularMomentum, "m²/s");
175
176impl_common_ops!(SpecificAngularMomentum);