Skip to content

Commit 464c285

Browse files
Merge pull request #387 from observerly/feature/optics/getFocalRatio
feat: add getFocalRatio() utility to optics module in @observerly/astrometry
2 parents 2e1b9dd + 476c850 commit 464c285

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/optics.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77
/*****************************************************************************************************************/
88

9-
export {}
9+
type FocalRatio = `f/${number}`
10+
11+
/*****************************************************************************************************************/
12+
13+
/**
14+
*
15+
* getFocalRatio()
16+
*
17+
* @param apertureWidth - the aperture of the optics
18+
* @param focalLength - the focal length of the optics
19+
* @returns the focal ratio as a string formatted in the standard focal ratio, e.g., f/x.
20+
*/
21+
export function getFocalRatio(apertureWidth: number, focalLength: number): FocalRatio {
22+
// Check that the aperterure is a sensible number, e.g., > 0:
23+
if (apertureWidth < 0) {
24+
throw new Error(`Invalid focal ratio as aperture is negative`)
25+
}
26+
27+
if (focalLength < 0) {
28+
throw new Error(`Invalid focal ratio as focal length is negative`)
29+
}
30+
31+
return `f/${focalLength / apertureWidth}`
32+
}
1033

1134
/*****************************************************************************************************************/

0 commit comments

Comments
 (0)