Skip to main content

aspect_fit_factor

Function aspect_fit_factor 

Source
fn aspect_fit_factor(
    source_w: u32,
    source_h: u32,
    canvas_w: u32,
    canvas_h: u32,
) -> (f64, f64)
Expand description

Per-axis screen shrink that fits a source_w × source_h frame inside a canvas_w × canvas_h output canvas without stretch (AUT-513). The screen sprite’s base transform fills NDC [-1, 1]² (the whole canvas), so when the canvas aspect differs from the source aspect the source would stretch; this factor shrinks the over-long axis so the source keeps its shape and the remainder becomes a matte (letterbox / pillarbox).

r = source_aspect / canvas_aspect: r > 1 (source relatively wider) fits to width and shrinks height (1/r) → letterbox top/bottom; r < 1 (source relatively taller) fits to height and shrinks width (r) → pillarbox sides; r == 1 (same aspect) is (1, 1) (full fill, unchanged behaviour). Pure.