perf: Simplify normalizeRadians function (#9572)

Co-authored-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Muhammad Khuzaima Umair 2025-05-28 18:58:42 +05:00 committed by GitHub
parent 5921ebc416
commit 7cad3645a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,16 +8,10 @@ import type {
Radians, Radians,
} from "./types"; } from "./types";
// TODO: Simplify with modulo and fix for angles beyond 4*Math.PI and - 4*Math.PI export const normalizeRadians = (angle: Radians): Radians =>
export const normalizeRadians = (angle: Radians): Radians => { angle < 0
if (angle < 0) { ? (((angle % (2 * Math.PI)) + 2 * Math.PI) as Radians)
return (angle + 2 * Math.PI) as Radians; : ((angle % (2 * Math.PI)) as Radians);
}
if (angle >= 2 * Math.PI) {
return (angle - 2 * Math.PI) as Radians;
}
return angle;
};
/** /**
* Return the polar coordinates for the given cartesian point represented by * Return the polar coordinates for the given cartesian point represented by