-
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
Adds Vector3 Rust API. #15
Conversation
19b692a
to
c0d78bd
Compare
6c65913
to
792a24a
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.
Leaving some comments here also not trying to block merging but to learn more about rust.
assert_eq!(v.z(), 3.0); | ||
assert_eq!(v.norm(), (1.0_f64.powi(2) + 2.0_f64.powi(2) + 3.0_f64.powi(2)).sqrt()); | ||
assert_eq!(v.dot(&v), 1.0_f64.powi(2) + 2.0_f64.powi(2) + 3.0_f64.powi(2)); | ||
assert_eq!(v.cross(&v), Vector3::new(0.0, 0.0, 0.0)); |
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.
I wonder if we should allow also default zero initialization in the parent PR.
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.
Debatable based on Rust programming ways:
- https://cppfaq.rs/signatures.html?highlight=constructor#how-do-i-overload-constructors
- https://doc.rust-lang.org/nomicon/constructors.html
Note we don't have constructors, the new method is just a method, we could add another new_default method if necessary and makes sense.
/// } | ||
/// ``` | ||
pub struct Vector3 { | ||
v: cxx::UniquePtr<maliput_sys::math::ffi::Vector3>, |
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.
For my own understanding, is this the right way of handing intra domain memory compatibility? Using the heap?
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.
When creating bindings to Cpp for classes like Vector3 or such (Opaque types) we can only access to them via an indirection. --> Check https://cxx.rs/concepts.html
} | ||
} | ||
|
||
mod tests { |
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.
Is it common to keep tests within the same file than the type implementation?
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.
Are we missing debug and non debug format checks?
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.
Is it common to keep tests within the same file than the type implementation?
Yes. Unit tests should be located at the same file or evean you can create a submodule for tests.
Integration Tests are the ones that are expected to be put under /root/tests folder
See:
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.
Are we missing debug and non debug format checks?
Not sure if I follow you, can you explain?
|
||
} | ||
|
||
impl Eq for Vector3 {} |
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.
Interesting thing about partial equality and equality traits!
Signed-off-by: Franco Cipollone <franco.c@ekumenlabs.com>
792a24a
to
6e2cbaf
Compare
I will proceed and merge this PR @agalbachicar . Feel free to make another pass for a follow-up PR. |
🎉 New feature
Related to #14
Goes on top of #12
Summary
maliput
rust packageTest it
An example using vector has been added.
Checklist
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.