From c3a299d6645aa05508a6050e98b4729138b1e129 Mon Sep 17 00:00:00 2001 From: michealroberts Date: Thu, 10 Oct 2024 09:01:58 +0100 Subject: [PATCH] feat: add getFocalRation() utility to optics module in @observerly/astrometry feat: add getFocalRation() utility to optics module in @observerly/astrometry --- src/optics.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/optics.ts b/src/optics.ts index 703412d..bc13f21 100644 --- a/src/optics.ts +++ b/src/optics.ts @@ -6,6 +6,29 @@ /*****************************************************************************************************************/ -export {} +type FocalRatio = `f/${number}` + +/*****************************************************************************************************************/ + +/** + * + * getFocalRatio() + * + * @param apertureWidth - the aperture of the optics + * @param focalLength - the focal length of the optics + * @returns the focal ratio as a string formatted in the standard focal ratio, e.g., f/x. + */ +export function getFocalRatio(apertureWidth: number, focalLength: number): FocalRatio { + // Check that the aperterure is a sensible number, e.g., > 0: + if (apertureWidth < 0) { + throw new Error(`Invalid focal ratio as aperture is negative`) + } + + if (focalLength < 0) { + throw new Error(`Invalid focal ratio as focal length is negative`) + } + + return `f/${focalLength / apertureWidth}` +} /*****************************************************************************************************************/