-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
a5f9642
to
bbd4b45
Compare
d61a42a
to
d263c56
Compare
d263c56
to
9477e5d
Compare
There was a problem hiding this 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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Coordinate { | ||
position: self.position + dt * v, | ||
velocity: self.velocity, | ||
epoch: *new_epoch, | ||
reference_frame: self.reference_frame, | ||
} |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
This adds common functionality related to reference frame conversion.
ECEF
type, which gets mathematically manipulated in the reference frame transformationsCoordinate
type which aggregates together position, velocity, time, and reference frame.Transformation
type which contains the needed information to transform between two reference frames, and can transform aCoordinate
object