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.

10 lines (9 loc) 514 B
import { magnitude4D } from "./magnitude-4d.js"; /** * Limits the maximum magnitude of a 4D vector. * @param {ArrayVector4D} xyzw - Vector as `[x, y, z, w]` * @param {number} max - Maximum magnitude * @param {number} [m] - Optional current magnitude (default: `magnitude4D(xyzw)`) * @returns {ArrayVector4D} Vector with limited magnitude */ export const limitMax4D = (xyzw, max, m = magnitude4D(xyzw)) => m > max ? [(xyzw[0] / m) * max, (xyzw[1] / m) * max, (xyzw[2] / m) * max, (xyzw[3] / m) * max] : xyzw;