* Normalize a vec2 * * @param {vec2} out the receiving vector * @param {vec2} a vector to normalize * @returns {vec2} out
(out, a)
| 16333 | |
| 16334 | |
| 16335 | function normalize(out, a) { |
| 16336 | var x = a[0], |
| 16337 | y = a[1]; |
| 16338 | var len = x * x + y * y; |
| 16339 | |
| 16340 | if (len > 0) { |
| 16341 | //TODO: evaluate use of glm_invsqrt here? |
| 16342 | len = 1 / Math.sqrt(len); |
| 16343 | } |
| 16344 | |
| 16345 | out[0] = a[0] * len; |
| 16346 | out[1] = a[1] * len; |
| 16347 | return out; |
| 16348 | } |
| 16349 | /** |
| 16350 | * Calculates the dot product of two vec2's |
| 16351 | * |
no test coverage detected