UNPKG

@fimbul-works/vec

Version:

A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.

13 lines (12 loc) 528 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalize2D = void 0; const magnitude_2d_js_1 = require("./magnitude-2d.js"); /** * Normalize a 2D vector. * @param {ArrayVector2D} xy - Vector as `[x, y]` * @param {number} [m] - Optional current magnitude (default: `magnitude2D(xy)`) * @returns {ArrayVector2D} The normalized vector */ const normalize2D = (xy, m = (0, magnitude_2d_js_1.magnitude2D)(xy)) => m === 0 ? [0, 0] : [xy[0] / m, xy[1] / m]; exports.normalize2D = normalize2D;