Add new_and_length
method to Direction2d
and Direction3d
#11172
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
When creating a normalized direction from a vector, it can be useful to get both the direction and the original length of the vector.
This came up when I was recreating some Parry APIs using bevy_math, and doing it manually is quite painful. Nalgebra calls this method
Unit::try_new_and_get
.Solution
Add a
new_and_length
method toDirection2d
andDirection3d
.Usage:
I'm open to different names, couldn't come up with a perfectly clear one that isn't too long. My reasoning with the current name is that it's like using
new
and callinglength
on the original vector.