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) 472 B
import { magnitude3D } from "./magnitude-3d.js"; /** * Limits the maximum magnitude of a 3D vector. * @param {ArrayVector3D} xyz - Vector as `[x, y, z]` * @param {number} max - Maximum magnitude * @param {number} [m] - Optional current magnitude (default: `magnitude3D(xyz)`) * @returns {ArrayVector3D} The adjusted vector */ export const limitMax3D = (xyz, max, m = magnitude3D(xyz)) => m > max ? [(xyz[0] / m) * max, (xyz[1] / m) * max, (xyz[2] / m) * max] : xyz;