micromath
micromath copied to clipboard
Add vector normalization to Vector trait
This addresses #99 and performs vector normalization by reusing the existing magnitude implementation, i.e. it goes through f32, normalizes in f32 and then converts back to C by using FromIterator.
I attempted pre-calculating the inverse of the magnitude and then multiplying by that, but it brought the results too far off in terms of error.
I thought about factoring out invsqrt into a trait and then implement that trait for F32 and f32 alike. This way the magnitude function could be more generic (C: InvSqrt instead of C: Into<f32>) and wouldn't require the use of f32 explicitly.