@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.
17 lines (16 loc) • 650 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setMagnitude2D = void 0;
const magnitude_2d_js_1 = require("./magnitude-2d.js");
/**
* Sets the magnitude (length) of a 2D vector, maintaining its direction.
* @param {ArrayVector2D} xy - Vector as `[x, y]`
* @param {number} newMag - New magnitude
* @param {number} [m] - Optional current magnitude (default: `magnitude2D(xy)`)
* @returns {ArrayVector2D} The adjusted vector
*/
const setMagnitude2D = (xy, newMag, m = (0, magnitude_2d_js_1.magnitude2D)(xy)) => [
(xy[0] / m) * newMag,
(xy[1] / m) * newMag,
];
exports.setMagnitude2D = setMagnitude2D;