[−][src]Function norman::normalize
pub fn normalize<T: Norm<D, Output = R> + DivAssign<R>, R: Num, D>(
v: &mut T,
desc: D
)
Normalizes the vector v
according to the norm desc
,
i.e. divides it by its norm.
As long as the implementations of Div
and DivAssign
on T
match,
v
will be equal to normalized(v)
after calling this function.
Attention
Due to numerical errors, v
is not guaranteed to have exactly norm 1
after calling this function.
On integer types this function will do complete nonsense since
DivAssign
is implemented as an integer division for integers.
Example
use norman::normalize; use norman::desc::Abs; let mut a = 0.25f32; normalize(&mut a, Abs::new()); assert_eq!(a, 1.0); let mut a = -3.0f32; normalize(&mut a, Abs::new()); assert_eq!(a, -1.0);