normalize function

List<double> normalize(
  1. dynamic out,
  2. dynamic a
)

Normalize a vec2

@param {vec2} out the receiving vector @param {ReadonlyVec2} a vector to normalize @returns {vec2} out

Implementation

List<double> normalize(out, a) {
  var x = a[0], y = a[1];
  var len = x * x + y * y;
  if (len > 0) {
    // TODO: evaluate use of glm_invsqrt here?
    len = 1 / math.sqrt(len);
  }
  out[0] = a[0] * len;
  out[1] = a[1] * len;
  return out;
}