Skip to content

Commit 730f6f5

Browse files
committed
fix: tolerance for aspect ratio to catch near-standard resolutions
1 parent 492fccd commit 730f6f5

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Classes/Utils/Helpers.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,14 @@ public static string GetAspectRatio(int width, int height) {
702702
}
703703

704704
public static bool IsValidAspectRatio(int width, int height) {
705-
return new[] { "64:27", "43:18", "21:9", "16:10", "16:9", "4:3", "32:9", "3:2" }.Contains(GetAspectRatio(width, height));
705+
if (width <= 0 || height <= 0)
706+
return false;
707+
708+
// standard gaming aspect ratios: 5:4, 4:3, 3:2, 16:10, 16:9, 21:9 variants (64:27, 43:18, 12:5), 32:9
709+
double[] validRatios = { 5 / 4d, 4 / 3d, 3 / 2d, 16 / 10d, 16 / 9d, 64 / 27d, 43 / 18d, 12 / 5d, 32 / 9d };
710+
double ratio = width / (double)height;
711+
// tolerance catches near-standard resolutions (e.g. 1366x768, 1360x768) that don't reduce to an exact ratio
712+
return validRatios.Any(valid => Math.Abs(ratio - valid) < 0.01);
706713
}
707714

708715
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> source) {

0 commit comments

Comments
 (0)