Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lox-orbits crate #89

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Add lox-orbits crate #89

wants to merge 14 commits into from

Conversation

helgee
Copy link
Member

@helgee helgee commented Apr 2, 2024

WIP

Supersedes: #82 #83 #57

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 61.97183% with 459 lines in your changes are missing coverage. Please review.

Project coverage is 96.01%. Comparing base (bb12229) to head (8fc61fe).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/lox-orbits/src/two_body/cartesian.rs 0.00% 117 Missing ⚠️
crates/lox-orbits/src/two_body/keplerian.rs 0.00% 116 Missing ⚠️
...ates/lox-orbits/src/propagators/semi_analytical.rs 58.12% 85 Missing ⚠️
crates/lox-orbits/src/events.rs 0.00% 73 Missing ⚠️
crates/lox-utils/src/roots.rs 83.75% 26 Missing ⚠️
crates/lox-orbits/src/trajectories.rs 90.90% 23 Missing ⚠️
crates/lox-orbits/src/anomalies.rs 18.18% 9 Missing ⚠️
crates/lox-orbits/src/two_body.rs 75.00% 6 Missing ⚠️
crates/lox-utils/src/glam.rs 0.00% 3 Missing ⚠️
crates/lox-orbits/src/trajectories/base.rs 99.17% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   98.13%   96.01%   -2.13%     
==========================================
  Files          55       67      +12     
  Lines       19560    20792    +1232     
==========================================
+ Hits        19195    19963     +768     
- Misses        365      829     +464     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@AngusGMorrison AngusGMorrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of comments as it's a big PR, but they should all be quite straightforward.

I'll reiterate my usual plea for much more documentation. In the near term, not being able to read what each step of an algorithm is intended to do leaves me unable to sanity check it effectively. The Brent implementation in particular is a hurricane of arithmetic on cryptically named variables.

let const_ident = format_ident!("{}", ident.to_string().to_uppercase());

let output = quote! {
const #const_ident: #ident = #ident;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The singleton function needs a doc comment detailing the expected inputs and output, asince this output is quite puzzling to anyone who hasn't been part of our conversations. The derive macro is only applicable to the specific case of a zero-sized marker type whose single instance is representable as a constant.

pub fn hyperbolic_to_true(hyperbolic_anomaly: f64, eccentricity: f64) -> f64 {
use lox_utils::types::units::Radians;

// Hyperbolic Anomaly <-> True Anomaly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This information would be better off as doc comments on the corresponding functions.

@@ -18,6 +19,8 @@ pub trait BaseTwoBody {
fn to_keplerian_state(&self, grav_param: f64) -> BaseKeplerian;
}

pub type BaseState = (BaseTime, BaseCartesian);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blah, blah, doc comments for exported types, blah

if n < 2 {
return events;
}
let time1 = time0 + *deltas.last().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth implementing Add<&TimeDelta> for ergonomics. The implementation could just deref the delta and call the existing Add<TimeDelta> method.

return events;
}

if signs.iter().all(|&s| s < 0.0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments throughout explaining why each step of the algorithm is doing what it's doing would be a huge help to those who come after. Porting the uncommented AstroTime.jl code is hard.

}
}

fn perifocal(&self) -> (DVec3, DVec3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (pos, vel) tuple type worth a struct declaration?

fn sub(self, rhs: BaseTime) -> Self::Output {
let mut subsec = self.subsecond.0 - rhs.subsecond.0;
let mut seconds = self.seconds - rhs.seconds;
if subsec.is_sign_negative() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this implementation is missing the case of (-lhs) - (-rhs) where the sign of the result becomes positive. The subsecond subtraction has to be treated as an addition, since we always represent subseconds as positive. These annoying branches are why, for TimeDelta Sub, I chose to use Neg on the rhs when it was negative and treat it as an addition.

fn find_root(&self, f: F, initial_guess: f64) -> Result<f64, RootError> {
let mut p0 = initial_guess;
let mut i = 0u32;
while i < self.max_iter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _ in 0..self.max_iter or (0..self.max_iter).for_each should work here, since the only non-incrementing branch terminates the loop.

fn find_root(&self, f: F, deriv: D, initial_guess: f64) -> Result<f64, RootError> {
let mut p0 = initial_guess;
let mut i = 0u32;
while i < self.max_iter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about idiomatic loop construction.

return Ok(xcur);
}

while i < self.max_iter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about idiomatic loop construction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants