From c4987ed3a3434aaff6f09694d155ebf6355c5449 Mon Sep 17 00:00:00 2001 From: "Paul \"Lorxus\" Rapoport" Date: Wed, 12 Nov 2025 15:16:34 -0800 Subject: [PATCH] added more astronomical units --- whippyunits-core/src/units.rs | 67 ++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/whippyunits-core/src/units.rs b/whippyunits-core/src/units.rs index af4df10..9d61c1b 100644 --- a/whippyunits-core/src/units.rs +++ b/whippyunits-core/src/units.rs @@ -307,7 +307,36 @@ impl Unit { exponents: TypeDimensionExponents::new(), system: System::Imperial, }; - // To add: Earth mass, Jupiter mass, Sol mass + + pub const EARTHMASS: Self = Self { + name: "earth_mass", + symbols: &["M⊕"], + scale: ScaleExponents::_10(25), + conversion_factor: 0.59722, + affine_offset: NONE, + exponents: TypeDimensionExponents::new(), + system: System::Astronomical, + }; + + pub const JUPITERMASS: Self = Self { + name: "jupiter_mass", + symbols: &["M♃"], + scale: ScaleExponents::_10(27), + conversion_factor: 1.89813, + affine_offset: NONE, + exponents: TypeDimensionExponents::new(), + system: System::Astronomical, + }; + + pub const SOLMASS: Self = Self { + name: "sol_mass", + symbols: &["M☉"], + scale: ScaleExponents::_10(30), + conversion_factor: 1.98847, + affine_offset: NONE, + exponents: TypeDimensionExponents::new(), + system: System::Astronomical, + }; } /// Length @@ -392,6 +421,26 @@ impl Unit { system: System::Imperial, }; + pub const LIGHT_SECOND: Self = Self { + name: "light_second", + symbols: &["ls"], + scale: ScaleExponents::_10(8), + conversion_factor: 2.99792458, + affine_offset: NONE, + exponents: TypeDimensionExponents::new(), + system: System::Astronomical, + }; + + pub const LUNAR_DISTANCE: Self = Self { + name: "lunar_distance", + symbols: &["LD"], + scale: ScaleExponents::_10(9), + conversion_factor: 0.3844, + affine_offset: NONE, + exponents: TypeDimensionExponents::new(), + system: System::Astronomical, + }; + pub const ASTRONOMICAL_UNIT: Self = Self { name: "astronomical_unit", symbols: &["AU"], @@ -764,6 +813,16 @@ impl Unit { exponents: TypeDimensionExponents::new(), system: System::Imperial, }; + + pub const SUN_LUMINOSITY: Self = Self { + name: "sun_luminosity", + symbols: &["L☉"], + scale: ScaleExponents::_10(27), + conversion_factor: 0.3828, + affine_offset: NONE, + exponents: TypeDimensionExponents::new(), + system: System::Astronomical, + }; } /// Pressure @@ -858,7 +917,7 @@ impl Unit { }; } -// Electric resistance +/// Electric resistance impl Unit { pub const OHM: Self = Self { name: "ohm", @@ -920,7 +979,7 @@ impl Unit { }; } -/// Magnetic flex +/// Magnetic flux impl Unit { pub const WEBER: Self = Self { name: "weber", @@ -945,7 +1004,7 @@ impl Unit { system: System::Metric, }; - pub const LUMEN: Self = Self { + pub const LUMEN: Self = Self { /// IIRC a lux is a lumen/m^2 - do we really want this here? name: "lumen", symbols: &["lm"], scale: ScaleExponents::IDENTITY,