MCPcopy
hub / github.com/spritejs/spritejs / normalize

Function normalize

docs/demo/spritejs.esm.js:5152–5167  ·  view source on GitHub ↗

* Normalize a vec3 * * @param {vec3} out the receiving vector * @param {ReadonlyVec3} a vector to normalize * @returns {vec3} out

(out, a)

Source from the content-addressed store, hash-verified

5150 */
5151
5152function normalize(out, a) {
5153 var x = a[0];
5154 var y = a[1];
5155 var z = a[2];
5156 var len = x * x + y * y + z * z;
5157
5158 if (len > 0) {
5159 //TODO: evaluate use of glm_invsqrt here?
5160 len = 1 / Math.sqrt(len);
5161 }
5162
5163 out[0] = a[0] * len;
5164 out[1] = a[1] * len;
5165 out[2] = a[2] * len;
5166 return out;
5167}
5168/**
5169 * Calculates the dot product of two vec3's
5170 *

Callers 3

spritejs.esm.jsFile · 0.70
computeMiterFunction · 0.70
directionFunction · 0.70

Calls 3

squaredLengthFunction · 0.70
quadraticFunction · 0.70
lineFunction · 0.70

Tested by

no test coverage detected