@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.
19 lines (18 loc) • 734 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setMagnitude4D = void 0;
const magnitude_4d_js_1 = require("./magnitude-4d.js");
/**
* Sets the magnitude of a 4D vector while maintaining its direction.
* @param {ArrayVector4D} xyzw - Vector as `[x, y, z, w]`
* @param {number} newMag - The new magnitude
* @param {number} [m] - Optional current magnitude (default: `magnitude4D(xyzw)`)
* @returns {ArrayVector4D} Vector with the new magnitude
*/
const setMagnitude4D = (xyzw, newMag, m = (0, magnitude_4d_js_1.magnitude4D)(xyzw)) => [
(xyzw[0] / m) * newMag,
(xyzw[1] / m) * newMag,
(xyzw[2] / m) * newMag,
(xyzw[3] / m) * newMag,
];
exports.setMagnitude4D = setMagnitude4D;