@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) • 775 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clamp3D = void 0;
const magnitude_3d_js_1 = require("./magnitude-3d.js");
/**
* Clamps the magnitude of a vector between min and max.
* @param {ArrayVector3D} xyz - Vector as `[x, y, z]`
* @param {number} min - Minimum magnitude
* @param {number} max - Maximum magnitude
* @param {number} [m] - Optional current magnitude (default: `magnitude3D(xyz)`)
* @returns {ArrayVector3D} The clamped vector
*/
const clamp3D = (xyz, min, max, m = (0, magnitude_3d_js_1.magnitude3D)(xyz)) => m > max
? [(xyz[0] / m) * max, (xyz[1] / m) * max, (xyz[2] / m) * max]
: m < min
? [(xyz[0] / m) * min, (xyz[1] / m) * min, (xyz[2] / m) * min]
: xyz;
exports.clamp3D = clamp3D;