Normalizes a quaternion in place and returns the length it had. A quaternion of length zero is set to the identity Quaternion.{} instead of dividing by zero.
q := Quaternion.{ 0, 0, 0, 2 };
assert(normalize_or_identity(*q) == 2 && q == Quaternion.{ 0, 0, 0, 1 });
z := Quaternion.{ 0, 0, 0, 0 };
normalize_or_identity(*z);
assert(z == Quaternion.{});normalize_or_identity :: (q: *Quaternion) -> float
Scales *q to length 1 in place and returns its old length. A zero quaternion becomes the
identity.
Parameters
- q: *Quaternion
- the quaternion to normalize.
Returns
- float