Skip to content

Add perp method to Dir2 - #25422

Merged
alice-i-cecile merged 6 commits into
bevyengine:mainfrom
ParvePalial:impl-dir2-perp
Aug 18, 2026
Merged

Add perp method to Dir2#25422
alice-i-cecile merged 6 commits into
bevyengine:mainfrom
ParvePalial:impl-dir2-perp

Conversation

@ParvePalial

Copy link
Copy Markdown
Contributor

Fixes #25418

This PR adds a perp method to Dir2 inline with how glam implements it for Vec2. It utilizesSelf::new_unchecked since rotating a normalized 2D unit vector by 90 degrees inherently preserves its unit length.

Unit tests have been added to verify correct rotation and length preservation.

@github-actions

Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@JMS55

JMS55 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Any reason not to call it perpendicular ?

@Jengamon Jengamon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with @JMS55 about naming the method perpendicular, with 2 main points:

  • this keeps code like the one changed in bevy_gizmos working without change
  • it follows the general pattern I notice elsewhere in bevy_math where operations tend to be spelled-out

Comment thread crates/bevy_math/src/direction.rs
Comment thread crates/bevy_math/src/direction.rs Outdated
Comment thread crates/bevy_math/src/direction.rs Outdated
Comment thread crates/bevy_math/src/direction.rs Outdated
Comment thread crates/bevy_math/src/direction.rs Outdated
Comment thread crates/bevy_math/src/direction.rs Outdated
Comment thread crates/bevy_math/src/direction.rs Outdated
Comment thread crates/bevy_gizmos/src/primitives/dim2.rs Outdated
@ParvePalial

Copy link
Copy Markdown
Contributor Author

I agree with perpendicular() method if complete names are common practice
and thanks for correcting out the - typo in counterclockwise

@hukasu

hukasu commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

The one vantage of calling it perp is that it would shadow the impl accessible through the deref

@hukasu hukasu added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it A-Math Fundamental domain-agnostic mathematical operations D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Aug 16, 2026
@ParvePalial

Copy link
Copy Markdown
Contributor Author

I am happy to change it back to perp if the core maintainers prefer that behavior, but I will leave it as perpendicular() for now based on the previous feedback.

@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Aug 18, 2026
Merged via the queue into bevyengine:main with commit 30b9741 Aug 18, 2026
38 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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples 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.

bevy_math Dir2 does not implement perp

7 participants