UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

21 lines (20 loc) 636 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeAngle = void 0; /** * Normalizes an angle to [0, 360) or [-π, π). * @author @dailker * @param {number} angle - The angle to normalize. * @param {'deg'|'rad'} [unit='deg'] - Unit: 'deg' or 'rad'. * @returns {number} Normalized angle. */ function normalizeAngle(angle, unit = 'deg') { if (unit === 'deg') { return ((angle % 360) + 360) % 360; } else { const pi = Math.PI; return ((angle + pi) % (2 * pi) + 2 * pi) % (2 * pi) - pi; } } exports.normalizeAngle = normalizeAngle;