vec2-fn
    Preparing search index...

    Function normalize

    • Normalize a vector to unit length. A zero vector is returned unchanged.

      Type Parameters

      Parameters

      • target: T

        Target can be vec object or array.

      Returns T

      • The modified target object.

      Error - When a computed component is NaN or non-finite.

      normalize({ x: 0, y: 5 }); // -> { x: 0, y: 1 }
      
    • Normalize a vector to unit length. A zero vector is returned unchanged.

      Type Parameters

      Parameters

      • target: Vec2Param

        Target can be vec object or array.

      • Optionaldest: D

        destination object to store the result.

      Returns D

      • A reference to the destination object.

      Error - When a computed component is NaN or non-finite.

      const result = { x: 0, y: 0 };
      normalize({ x: 0, y: 5 }, result); // result -> { x: 0, y: 1 }