bitshifter / glam-rs

A simple and fast linear algebra library for games and graphics
Apache License 2.0
1.55k stars 158 forks source link

Add method to vector types that returns direction and length #291

Open bitshifter opened 2 years ago

bitshifter commented 2 years ago

It's not uncommon to find the direction and length of a vector, but it is a hassle to do it manually. It would be good to have a method for this.

paul-hansen commented 2 years ago

Just poking through the open issues and seeing if there is anything I can help with.

Looks like length is already done: https://docs.rs/glam/0.21.3/glam/?search=length Direction would probably just be normalize which is already done too: https://docs.rs/glam/0.21.3/glam/?search=normalize Unless you meant something else.

Anything else needed/missing here?

We could probably add a doc alias for normalize or something if we wanted to make normalize show up when you search for "direction"

janhohenheim commented 4 months ago

Late to the party, but I found this issue while looking whether there was something convenient to get both the direction and length of a vector, since normalizing it indirectly involves calculating the length. Something like the following:

let (norm, len) = some_vec.normalize_and_length();
bitshifter commented 4 months ago

yes, that's what I was meaning. I think I managed to completely miss paul-hansen's comment from 2 years ago, whoops!