B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Generates a unit vector of the same direction as the provided vec3.
   * If vector length is 0, returns [0, 0, 0].
   *
   * @param {Array} aVec
   *                vec3 to normalize
   * @param {Array} aDest
   *                optional, vec3 receiving operation result
   *                if not specified result is written to the first operand
   *
   * @return {Array} the destination vec3 if specified, first operand otherwise
   */
Generates a unit vector of the same direction as the provided vec3.

@param {Array} aVec
vec3 to normalize
@param {Array} aDest
optional, vec3 receiving operation result
if not specified result is written to the first operand

@return {Array} the destination vec3 if specified, first operand otherwise
Generates a unit vector of the same direction as the provided vec3 . @param { Array } aVec vec3 to normalize @param { Array } aDest optional vec3 receiving operation result if not specified result is written to the first operand @return { Array } the destination vec3 if specified first operand otherwise
function V3_normalize(aVec, aDest)
  {
    if (!aDest) {
      aDest = aVec;
    }
    let x = aVec[0];
    let y = aVec[1];
    let z = aVec[2];
    let len = Math.sqrt(x * x + y * y + z * z);
    if (Math.abs(len) < EPSILON) {
      aDest[0] = 0;
      aDest[1] = 0;
      aDest[2] = 0;
      return aDest;
    }
    len = 1 / len;
    aDest[0] = x * len;
    aDest[1] = y * len;
    aDest[2] = z * len;
    return aDest;
  }
function V3_normalize ( aVec , aDest ) { if ( ! aDest ) { aDest = aVec ; } let x = aVec [ 0 ] ; let y = aVec [ 1 ] ; let z = aVec [ 2 ] ; let len = Math . sqrt ( x * x + y * y + z * z ) ; if ( Math . abs ( len ) < EPSILON ) { aDest [ 0 ] = 0 ; aDest [ 1 ] = 0 ; aDest [ 2 ] = 0 ; return aDest ; } len = 1 / len ; aDest [ 0 ] = x * len ; aDest [ 1 ] = y * len ; aDest [ 2 ] = z * len ; return aDest ; }
Generates a unit vector of the same direction as the provided vec3.
Generates a unit vector of the same direction as the provided vec3 .