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

Rotation api extension #15169

Merged
merged 4 commits into from
Sep 16, 2024
Merged

Conversation

RobWalt
Copy link
Contributor

@RobWalt RobWalt commented Sep 12, 2024

Objective

Solution

  • Add methods on Rot2
    • turn_fraction(fraction: f32) -> Self
    • as_turn_fraction(self) -> f32
  • Also add some documentation on range of rotation

Testing

  • extended existing tests
  • added new tests

Showcase

let rotation1 = Rot2::degrees(90.0);
let rotation2 = Rot2::turn_fraction(0.25);

// rotations should be equal
assert_relative_eq!(rotation1, rotation2);

// The rotation should be 90 degrees
assert_relative_eq!(rotation2.as_radians(), FRAC_PI_2);
assert_relative_eq!(rotation2.as_degrees(), 90.0);

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

LGTM! I think this is a useful API. Left some non-blocking suggestions

crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
@Jondolf Jondolf added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Math Fundamental domain-agnostic mathematical operations S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 12, 2024
@Jondolf
Copy link
Contributor

Jondolf commented Sep 12, 2024

CC @johannesvollmer; this doesn't fully address what you described in #11132 (comment), because Rot2 is a unit complex number that should always be normalized, so it can't represent turns greater than a full rotation, and the internal representation still isn't turns. But at the API level, I think this is still useful for rotations.

@johannesvollmer
Copy link
Contributor

Yes, still useful :) nice

@Jondolf Jondolf added the X-Uncontroversial This work is generally agreed upon label Sep 12, 2024
Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

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

Nice! Left some minor documentation improvements :)
IMO the "resulting rotation" in the docs would be clearer as the "input rotation", since otherwise it reads as if the resulting rotation was once in radians, once in degrees, and once in fractions, which is not the case. But I'll leave that up to you.

crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/rotation2d.rs Outdated Show resolved Hide resolved
@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 14, 2024
Co-authored-by: Jan Hohenheim <[email protected]>
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 16, 2024
Merged via the queue into bevyengine:main with commit 29c4c79 Sep 16, 2024
26 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 C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants