Skip to content

Commit

Permalink
Re-add TwoBody trait
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Jan 22, 2024
1 parent 7cc0ebd commit c430b99
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions crates/lox_core/src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ pub trait CoordinateSystem {
fn reference_frame(&self) -> Self::Frame;
}

pub trait TwoBody<T, S>
where
T: PointMass + Copy,
S: InertialFrame + Copy,
{
fn to_cartesian(&self) -> Cartesian<T, S>;

fn to_keplerian(&self) -> Keplerian<T, S>;
}

#[derive(Debug, Copy, Clone, PartialEq)]

Check warning on line 39 in crates/lox_core/src/coords.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox_core/src/coords.rs#L39

Added line #L39 was not covered by tests
pub struct Cartesian<T, S>
where
Expand Down Expand Up @@ -64,12 +74,16 @@ where
}
}

impl<T, S> Cartesian<T, S>
impl<T, S> TwoBody<T, S> for Cartesian<T, S>
where
T: PointMass + Copy,
S: InertialFrame + Copy,
{
pub fn to_keplerian(&self) -> Keplerian<T, S> {
fn to_cartesian(&self) -> Cartesian<T, S> {
*self
}

Check warning on line 84 in crates/lox_core/src/coords.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox_core/src/coords.rs#L82-L84

Added lines #L82 - L84 were not covered by tests

fn to_keplerian(&self) -> Keplerian<T, S> {
Keplerian::from(*self)
}
}
Expand Down Expand Up @@ -178,10 +192,20 @@ where
pub fn true_anomaly(&self) -> f64 {
self.state.true_anomaly()
}
}

pub fn to_cartesian(&self) -> Cartesian<T, S> {
impl<T, S> TwoBody<T, S> for Keplerian<T, S>
where
T: PointMass + Copy,
S: InertialFrame + Copy,
{
fn to_cartesian(&self) -> Cartesian<T, S> {
Cartesian::from(*self)
}

fn to_keplerian(&self) -> Keplerian<T, S> {
*self
}

Check warning on line 208 in crates/lox_core/src/coords.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox_core/src/coords.rs#L206-L208

Added lines #L206 - L208 were not covered by tests
}

impl<T, S> CoordinateSystem for Keplerian<T, S>
Expand Down

0 comments on commit c430b99

Please sign in to comment.