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

Fixes #16480: Prevent exponential denormalization on Transform::rotate_axis #17604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Novakasa
Copy link

@Novakasa Novakasa commented Jan 29, 2025

Objective

Fixes #16480

When repeatedly using Transform::roatate_axis and feeding a axis that is based on the current Transform::rotation, the floating point errors could accumulate exponentially, resulting in denormalized rotation, which panics.

Solution

Normalize the quaternion in Transform::rotate_axis.

Testing

I confirmed that this fixes the issue reported in #16480.

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@@ -314,7 +314,7 @@ impl Transform {
/// If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent.
#[inline]
pub fn rotate_axis(&mut self, axis: Dir3, angle: f32) {
self.rotate(Quat::from_axis_angle(axis.into(), angle));
self.rotation = ((Quat::from_axis_angle(axis.into(), angle)) * self.rotation).normalize();
Copy link
Member

Choose a reason for hiding this comment

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

Link the issue here in a comment please; this normalization looks out of place otherwise.

Copy link
Author

Choose a reason for hiding this comment

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

Done! Is it fine like this or should I add the full link?

@Novakasa Novakasa force-pushed the rotate-axis-normalize branch from 0f2a51d to a4a1078 Compare January 29, 2025 20:38
@Novakasa Novakasa force-pushed the rotate-axis-normalize branch from a4a1078 to e23fe5f Compare January 29, 2025 20:50
@mockersf mockersf added the A-Math Fundamental domain-agnostic mathematical operations label Jan 29, 2025
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Transform Translations, rotations and scales S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 29, 2025
@alice-i-cecile alice-i-cecile added the X-Contentious There are nontrivial implications that should be thought through label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Math Fundamental domain-agnostic mathematical operations A-Transform Translations, rotations and scales C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transform::rotation denormalizes after applying successive rotations.
5 participants