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

Fix look_to variable naming #8627

Merged
merged 2 commits into from
May 23, 2023

Conversation

lewiszlw
Copy link
Member

@lewiszlw lewiszlw commented May 17, 2023

Objective

  • If I understand correctly, forward points in direction, so the negative of direction should be back.

Migration Guide

  • Transform::look_to method changed default value of direction.try_normalize() from Vec3::Z to Vec3::NEG_Z

@nicopap nicopap added C-Code-Quality A section of code that is hard to understand or change A-Transform Translations, rotations and scales labels May 21, 2023
@nicopap
Copy link
Contributor

nicopap commented May 21, 2023

In rust the minus sign - has lower priority than method call, so it's actually -Z. Here is how it looks like with parenthesis:

        let back = -(  direction.try_normalize().unwrap_or(Vec3::Z)  );

I still suggest a change though. It's a bit clearer:

        let back = direction.try_normalize().map_or(-Vec3::Z, |d| -d);

The change from forward to back seems correct though.

@lewiszlw
Copy link
Member Author

Why default value should be -Vec3::Z? According to my understanding, -Vec3::Z should be forward. @nicopap

@nicopap
Copy link
Contributor

nicopap commented May 22, 2023

-Vec3::Z is to keep the same behavior as in 0.10.1 Any change to this value is a breaking change, it also needs to update the doc to reflect this change.

I think it's OK (but not important) to change it to -Vec3::NEG_Z (I would keep the - for clarity), but you need then to mark this PR as breaking (and update the doc)

@lewiszlw
Copy link
Member Author

lewiszlw commented May 22, 2023

Added migration guide! Another question, I think unwrap_or might have better readability than map_or, at least for me.

@nicopap nicopap added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label May 22, 2023
Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

Keep it as unwrap_or if you think it's more readable. I think it's good enough.

I can't comment on it, but at line 354 there is this:

    /// * if `up` is zero, `Vec3::Y` is used instead

This needs to be replaced by

    /// * if `up` is zero, `Vec3::NEG_Y` is used instead

@lewiszlw
Copy link
Member Author

You mean

if `direction` is zero, `Vec3::Z` is used instead

?
Already changed.

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

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

Good job! I think this change is positive.

@alice-i-cecile alice-i-cecile removed the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label May 22, 2023
@alice-i-cecile
Copy link
Member

Appears to be no longer breaking :)

@alice-i-cecile alice-i-cecile 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 May 22, 2023
@alice-i-cecile
Copy link
Member

@lewiszlw can you update the PR description to reflect the final state of this PR?

@lewiszlw
Copy link
Member Author

The default behavior changed when direction can't be normalized. So marked it breaking. @alice-i-cecile

@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label May 23, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 23, 2023
Merged via the queue into bevyengine:main with commit df3e81c May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Transform Translations, rotations and scales C-Code-Quality A section of code that is hard to understand or change 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