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

Reference frame basics #102

Merged
merged 11 commits into from
Jun 29, 2024
Merged

Reference frame basics #102

merged 11 commits into from
Jun 29, 2024

Conversation

jbangelo
Copy link
Collaborator

@jbangelo jbangelo commented Jun 26, 2024

This adds common functionality related to reference frame conversion.

  • Adds some basic operations to help ease the use of the ECEF type, which gets mathematically manipulated in the reference frame transformations
  • Adds a helper function to get the fractional year representation of a point in time, which is helpful in the reference frame transformations
  • Adds a new Coordinate type which aggregates together position, velocity, time, and reference frame.
  • Adds a new Transformation type which contains the needed information to transform between two reference frames, and can transform a Coordinate object

@jbangelo jbangelo force-pushed the jbangelo/reference-frame-impl branch from a5f9642 to bbd4b45 Compare June 26, 2024 23:03
@jbangelo jbangelo changed the title Jbangelo/reference frame impl Reference frame basics Jun 26, 2024
@jbangelo jbangelo force-pushed the jbangelo/reference-frame-impl branch 4 times, most recently from d61a42a to d263c56 Compare June 27, 2024 03:59
@jbangelo jbangelo force-pushed the jbangelo/reference-frame-impl branch from d263c56 to 9477e5d Compare June 27, 2024 04:01
@jbangelo jbangelo marked this pull request as ready for review June 27, 2024 04:17
Copy link

@JADC362 JADC362 left a comment

Choose a reason for hiding this comment

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

Overall it looks good to me, based on my low Rust knowledge.

}
}

pub fn with_velocity(
Copy link

Choose a reason for hiding this comment

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

Perhaps new_with_velocity? Same for new_without_velocity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At least in the standard library it's the naming convention is to only have a single new function, and alternate constructor method names take the form of with_*. See String::with_capacity

Choose a reason for hiding this comment

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

in general i think you might be better off using the builder pattern if you find that you end up needing a lot of these. i think it is probably fine as is though

Comment on lines +601 to +606
Coordinate {
position: self.position + dt * v,
velocity: self.velocity,
epoch: *new_epoch,
reference_frame: self.reference_frame,
}
Copy link

Choose a reason for hiding this comment

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

Perhaps this is way to do in Rust, but why don't just modify the position and velocity alone? I guess self would will have to be mutable. That's the reason for this approach?

Suggested change
Coordinate {
position: self.position + dt * v,
velocity: self.velocity,
epoch: *new_epoch,
reference_frame: self.reference_frame,
}
self.position = self.position + dt * v
self.epoch = *new_epoch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The style I typically write Rust code with definitely has more copies than is strictly necessary, and you're right that to change this method so it changes the coordinate in place without making a new copy would require making self a mutable borrow. Since this is a library it's probably better to offer both forms as options, though I'll have to figure out the right naming convention to use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After sleeping on this some, I think this is a preferable form of the function. This produces cleaner code in the majority of cases but still allows someone to make the change in place if they desired. I will make sure to have Coordinate derive the Copy trait to make it a bit easier to use though, it's a fixed size and not terrible large so implicit copies shouldn't be a problem.

let mut c = Coordinate::new(...);

// with &mut self
c.adjust_epoch(t);

// vs just re-assign
c = c.adjust_epoch(t);

@jbangelo jbangelo merged commit 0f4a162 into master Jun 29, 2024
6 checks passed
@jbangelo jbangelo deleted the jbangelo/reference-frame-impl branch June 29, 2024 00:00
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.

4 participants