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

Make Transform::rotate_axis and Transform::rotate_local_axis use Dir3 #12986

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

mweatherley
Copy link
Contributor

Objective

Related to #12981

Presently, there is a footgun where we allow non-normalized vectors to be passed in the axis parameters of Transform::rotate_axis and Transform::rotate_local_axis. These methods invoke Quat::from_axis_angle which expects the vector to be normalized. This PR aims to address this.

Solution

Require Dir3-valued axis parameters for these functions so that the vector's normalization can be enforced at type-level.


Migration Guide

All calls to Transform::rotate_axis and Transform::rotate_local_axis will need to be updated to use a Dir3 for the axis parameter rather than a Vec3. For a general input, this means calling Dir3::new and handling the Result, but if the previous vector is already known to be normalized, Dir3::new_unchecked can be called instead. Note that literals like Vec3::X also have corresponding Dir3 literals; e.g. Dir3::X, Dir3::NEG_Y and so on.


Discussion

This axis input is unambigiously a direction instead of a vector, and that should probably be reflected and enforced by the function signature. In previous cases where we used, e.g., impl TryInto<Dir3>, the associated methods already implemented (and required!) additional fall-back logic, since the input is conceptually more complicated than merely specifying an axis. In this case, I think it's fairly cut-and-dry, and I'm pretty sure these methods just predate our direction types.

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Transform Translations, rotations and scales A-Math Fundamental domain-agnostic mathematical operations M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Apr 16, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Yep, this predates our Dir3 type :) I agree with using the strict Dir3 here: the normalization is required.

@pablo-lua pablo-lua added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 16, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 16, 2024
Merged via the queue into bevyengine:main with commit 221d925 Apr 16, 2024
33 checks passed
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-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants