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

Introduce DualQuaternion type #810

Merged
merged 3 commits into from Dec 18, 2020
Merged

Conversation

chinedufn
Copy link
Contributor

This commit introduces the DualQuaternion type, in line with the plan
laid out in #487.

Copy link
Contributor Author

@chinedufn chinedufn left a comment

Choose a reason for hiding this comment

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

The instructions that you laid out were very helpful, thanks a lot

#487 (comment)

src/geometry/dual_quaternion_ops.rs Outdated Show resolved Hide resolved
@chinedufn
Copy link
Contributor Author

@sebcrozet anything blocking this from landing? Happy to make any changes that you suggest.

Copy link
Member

@sebcrozet sebcrozet left a comment

Choose a reason for hiding this comment

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

Hi! Thank you for this PR.

src/geometry/dual_quaternion.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion.rs Show resolved Hide resolved
This commit introduces the `DualQuaternion` type, in line with the plan
laid out in [dimforge#487].

[dimforge#487]: dimforge#487
Copy link
Contributor Author

@chinedufn chinedufn left a comment

Choose a reason for hiding this comment

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

@sebcrozet thanks for the helpful review - I've addressed all of your feedback.

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct DualQuaternion<N: SimdRealField> {
// [real(w, i, j, k), dual(w, i, j, k)]
pub(crate) dq: [N; 8],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to store internally as an array (instead of storing real and dual part separately) so that we don't need an if statement when indexing.

Copy link
Member

Choose a reason for hiding this comment

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

I think what you did before was better since it made it more explicit that it is composed of two quaternions. And these two quaternions could be public fields for easier access.

Regarding indexing, you can simply:

  • Add #[repr(C)] to DualQuaternion.
  • Add an implementation of AsRef and AsMut. Something like:
impl<N: SimdRealField> AsRef<[N; 8]> for DualQuaternion<N> {
    #[inline]
    fn as_ref(&self) -> &[N; 8] {
       unsafe { mem::transmute(self) }
   }
}

// Do something similar for AsMut.

and use these in the implementation of Index and IndexMut.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I like your suggestion better, thanks will change.

Question though - why are quaternions stored internally at [i,j,k,w]? I would've expected [w,i,j,k] given that Quaternion::new(w,i,j,k).

No big deal, just curious.

Copy link
Member

Choose a reason for hiding this comment

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

Question though - why are quaternions stored internally at [i,j,k,w]? I would've expected [w,i,j,k] given that Quaternion::new(w,i,j,k).

By similarity with the Eigen library, mostly.

@sebcrozet
Copy link
Member

@sebcrozet thanks for the helpful review - I've addressed all of your feedback.

Thank you for addressing the feedbacks. Though keep in mind that it is generally better to push new commits instead of overwriting the previous one(s). That way it is easier to review your changes because I can see easily what changed since my last review.

@chinedufn
Copy link
Contributor Author

Though keep in mind that it is generally better to push new commits instead of overwriting the previous one(s)

Ah, I thought that the PR was small enough that it was fine. Okay great, noted for next time. Thank you

@chinedufn
Copy link
Contributor Author

@sebcrozet thanks again for the help, all feedback addressed.

Copy link
Member

@sebcrozet sebcrozet left a comment

Choose a reason for hiding this comment

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

Thanks! There are a few things that can be removed here:

src/geometry/dual_quaternion_ops.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion_ops.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion_ops.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion_ops.rs Outdated Show resolved Hide resolved
src/geometry/dual_quaternion_construction.rs Outdated Show resolved Hide resolved
@chinedufn
Copy link
Contributor Author

@sebcrozet feedback addressed!

@sebcrozet sebcrozet merged commit d8fa3ff into dimforge:dev Dec 18, 2020
@sebcrozet
Copy link
Member

Great, thanks!

@chinedufn chinedufn deleted the dual-quaternion branch December 18, 2020 16:04
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