![]() # 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`](https://docs.rs/nalgebra/latest/nalgebra/base/struct.Unit.html#method.try_new_and_get). ## Solution Add a `new_and_length` method to `Direction2d` and `Direction3d`. Usage: ```rust if let Ok((direction, length)) = Direction2d::new_and_length(Vec2::X * 10.0) { assert_eq!(direction, Vec2::X); assert_eq!(length, 10.0); } ``` 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 calling `length` on the original vector. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |