summaryrefslogtreecommitdiff
path: root/apps/web/src/utils/geometry.ts
blob: b5c5058486fdf8819bc0bb96159d1915d1be54f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export function dimensionToAspectRatio({
	width,
	height,
}: {
	width: number;
	height: number;
}): string {
	const gcd = ({
		a,
		b,
	}: {
		a: number;
		b: number;
	}): number => (b === 0 ? a : gcd({ a: b, b: a % b }));
	const divisor = gcd({ a: width, b: height });
	const aspectWidth = width / divisor;
	const aspectHeight = height / divisor;
	return `${aspectWidth}:${aspectHeight}`;
}