rhb-server/mes-ui/rhb-app/node_modules/gl-vec2/normalize.js

21 lines
431 B
JavaScript
Raw Normal View History

2025-10-20 11:14:41 +08:00
module.exports = normalize
/**
* Normalize a vec2
*
* @param {vec2} out the receiving vector
* @param {vec2} a vector to normalize
* @returns {vec2} out
*/
function 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
}