fix aspect ratio matching

This commit is contained in:
Brandon Thomas committed 2026-04-10 08:53:04 -04:00
1 parent a332e25681
commit 77be2ab6aa
2 files changed
+38 -8

No files matched your search

@@ -118,11 +118,27 @@ fn plan_aspect_ratio(
value: format!("{:?}", unsupported),
}))
}
_ => Ok(Some(Ar::Auto)),
_ => Ok(Some(nearest_aspect_ratio(unsupported))),
},
}
}
/// Pick the nearest supported aspect ratio for unsupported inputs.
fn nearest_aspect_ratio(aspect_ratio: CommonAspectRatio) -> FalSeedance1p5ProAspectRatio {
use FalSeedance1p5ProAspectRatio as Ar;
match aspect_ratio {
// Wide unsupported → nearest wide
CommonAspectRatio::WideFiveByFour => Ar::FourByThree, // 1.25 → 1.33
CommonAspectRatio::WideThreeByTwo => Ar::FourByThree, // 1.50 → 1.33
// Tall unsupported → nearest tall
CommonAspectRatio::TallFourByFive => Ar::ThreeByFour, // 0.80 → 0.75
CommonAspectRatio::TallTwoByThree => Ar::ThreeByFour, // 0.67 → 0.75
CommonAspectRatio::TallNineByTwentyOne => Ar::NineBySixteen, // 0.43 → 0.56
// Anything else → Square
_ => Ar::Square,
}
}
fn plan_resolution(
resolution: Option<CommonResolution>,
strategy: RequestMismatchMitigationStrategy,
@@ -359,26 +359,40 @@ mod tests {
});
}
// ── Unsupported aspect ratios fall back under PayMoreUpgrade ──────────
// ── Unsupported aspect ratios fall back to nearest under PayMoreUpgrade
#[test]
fn wide_5x4_falls_back_to_auto() {
fn wide_5x4_falls_back_to_four_by_three() {
with_text_plan(&make_request(Some("p"), Some(CommonAspectRatio::WideFiveByFour), None, None, None, None, None), |plan| {
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::Auto)));
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::FourByThree)));
});
}
#[test]
fn wide_3x2_falls_back_to_auto() {
fn wide_3x2_falls_back_to_four_by_three() {
with_text_plan(&make_request(Some("p"), Some(CommonAspectRatio::WideThreeByTwo), None, None, None, None, None), |plan| {
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::Auto)));
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::FourByThree)));
});
}
#[test]
fn tall_4x5_falls_back_to_auto() {
fn tall_4x5_falls_back_to_three_by_four() {
with_text_plan(&make_request(Some("p"), Some(CommonAspectRatio::TallFourByFive), None, None, None, None, None), |plan| {
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::Auto)));
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::ThreeByFour)));
});
}
#[test]
fn tall_2x3_falls_back_to_three_by_four() {
with_text_plan(&make_request(Some("p"), Some(CommonAspectRatio::TallTwoByThree), None, None, None, None, None), |plan| {
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::ThreeByFour)));
});
}
#[test]
fn tall_9x21_falls_back_to_nine_by_sixteen() {
with_text_plan(&make_request(Some("p"), Some(CommonAspectRatio::TallNineByTwentyOne), None, None, None, None, None), |plan| {
assert!(matches!(plan.aspect_ratio, Some(FalSeedance1p5ProAspectRatio::NineBySixteen)));
});
}