From c430b993b77089f584c39b2a6f62b961f5b01189 Mon Sep 17 00:00:00 2001 From: Helge Eichhorn Date: Mon, 22 Jan 2024 15:08:55 +0100 Subject: [PATCH] Re-add TwoBody trait --- crates/lox_core/src/coords.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/crates/lox_core/src/coords.rs b/crates/lox_core/src/coords.rs index 6014e8e4..d0a1f59f 100644 --- a/crates/lox_core/src/coords.rs +++ b/crates/lox_core/src/coords.rs @@ -26,6 +26,16 @@ pub trait CoordinateSystem { fn reference_frame(&self) -> Self::Frame; } +pub trait TwoBody +where + T: PointMass + Copy, + S: InertialFrame + Copy, +{ + fn to_cartesian(&self) -> Cartesian; + + fn to_keplerian(&self) -> Keplerian; +} + #[derive(Debug, Copy, Clone, PartialEq)] pub struct Cartesian where @@ -64,12 +74,16 @@ where } } -impl Cartesian +impl TwoBody for Cartesian where T: PointMass + Copy, S: InertialFrame + Copy, { - pub fn to_keplerian(&self) -> Keplerian { + fn to_cartesian(&self) -> Cartesian { + *self + } + + fn to_keplerian(&self) -> Keplerian { Keplerian::from(*self) } } @@ -178,10 +192,20 @@ where pub fn true_anomaly(&self) -> f64 { self.state.true_anomaly() } +} - pub fn to_cartesian(&self) -> Cartesian { +impl TwoBody for Keplerian +where + T: PointMass + Copy, + S: InertialFrame + Copy, +{ + fn to_cartesian(&self) -> Cartesian { Cartesian::from(*self) } + + fn to_keplerian(&self) -> Keplerian { + *self + } } impl CoordinateSystem for Keplerian