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.

19 lines (18 loc) 834 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clamp4D = void 0; const magnitude_4d_js_1 = require("./magnitude-4d.js"); /** * Clamps the magnitude of a 4D vector between min and max. * @param {ArrayVector4D} xyzw - Vector as `[x, y, z, w]` * @param {number} min - Minimum magnitude * @param {number} max - Maximum magnitude * @param {number} [m] - Optional current magnitude (default: `magnitude4D(xyzw)`) * @returns {ArrayVector4D} The clamped vector */ const clamp4D = (xyzw, min, max, m = (0, magnitude_4d_js_1.magnitude4D)(xyzw)) => m > max ? [(xyzw[0] / m) * max, (xyzw[1] / m) * max, (xyzw[2] / m) * max, (xyzw[3] / m) * max] : m < min ? [(xyzw[0] / m) * min, (xyzw[1] / m) * min, (xyzw[2] / m) * min, (xyzw[3] / m) * min] : xyzw; exports.clamp4D = clamp4D;