index/vec2.js
function(returnNew) {
      var length = this.length();

      // Collect a ratio to shrink the x and y coords
      var invertedLength = (length < Number.MIN_VALUE) ? 0 : 1/length;

      if (!returnNew) {
        // Convert the coords to be greater than zero
        // but smaller than or equal to 1.0
        return this.set(this.x * invertedLength, this.y * invertedLength);
      } else {
        return new Vec2(this.x * invertedLength, this.y * invertedLength);
      }
    }
function(returnNew) {
      var length = this.length();

      // Collect a ratio to shrink the x and y coords
      var invertedLength = (length < Number.MIN_VALUE) ? 0 : 1/length;

      if (!returnNew) {
        // Convert the coords to be greater than zero
        // but smaller than or equal to 1.0
        return this.set(this.x * invertedLength, this.y * invertedLength);
      } else {
        return new Vec2(this.x * invertedLength, this.y * invertedLength);
      }
    }
function ( returnNew ) { var length = this . length ( ) ; // Collect a ratio to shrink the x and y coords var invertedLength = ( length < Number . MIN_VALUE ) ? 0 : 1 / length ; if ( ! returnNew ) { // Convert the coords to be greater than zero // but smaller than or equal to 1.0 return this . set ( this . x * invertedLength , this . y * invertedLength ) ; } else { return new Vec2 ( this . x * invertedLength , this . y * invertedLength ) ; } }
Convert this vector into a unit vector. Returns the length.
Convert this vector into a unit vector . Returns the length .