diff --git a/crates/thing-core/tests/render.rs b/crates/thing-core/tests/render.rs index 3fd0a5e..06daa24 100644 --- a/crates/thing-core/tests/render.rs +++ b/crates/thing-core/tests/render.rs @@ -674,7 +674,7 @@ fn random_documents_render_without_panic_balanced_and_equal() { } // A round that layout refuses renders nothing: keep them few enough that render is exercised. eprintln!("random documents: {refused} of {ROUNDS} refused"); - assert!(refused * 10 <= ROUNDS as u32, "{refused} of {ROUNDS} rounds were refused"); + assert!(refused * 20 <= ROUNDS as u32, "{refused} of {ROUNDS} rounds were refused"); } #[test] @@ -803,29 +803,29 @@ fn fit_table() { let provider = ProviderId::new(PROVIDER); let run = |asset: &str, fit: ImageFit| { let mut state = MemState::new(); - state.put(&provider, &catalog(&[("wide", 400, 200), ("tall", 100, 400)])); - // A clipping 100x100 row squeezes the image to its height and width, so its rect is not its ratio. - let row = BoxStyle { overflow: Overflow::Clip, ..sized(100.0, 100.0) }; - let rendered = with_state(&mut state, flat("root", row, vec![image("pic", asset, fit)]), &pixels(1.0)); - assert_eq!(placed(&rendered, "pic").rect, rect(0.0, 0.0, 100.0, 100.0), "the image fills the row"); - let all = rendered.commands; - all[1..all.len() - 1].to_vec() + state.put(&provider, &catalog(&[("wide", 400, 200), ("tall", 100, 400), ("small", 40, 20)])); + // A row 100 high stretches the image to 100 high and leaves it its 400 wide extent width: + // a 400x100 rect, which is the ratio of none of the three assets. + let rendered = with_state(&mut state, flat("root", sized(100.0, 100.0), vec![image("pic", asset, fit)]), &pixels(1.0)); + assert_eq!(placed(&rendered, "pic").rect, rect(0.0, 0.0, 400.0, 100.0), "the image's rect"); + rendered.commands }; let img = |r: Rect, uri: &str| RenderCommand::Image { rect: r, uri: format!("asset://{uri}"), alt: "alt".into() }; - let clip = |inner: Vec| { - let mut out = vec![RenderCommand::ClipPush { rect: rect(0.0, 0.0, 100.0, 100.0), radius: 0.0 }]; - out.extend(inner); - out.push(RenderCommand::ClipPop); - out + let clip = |inner: RenderCommand| { + [RenderCommand::ClipPush { rect: rect(0.0, 0.0, 400.0, 100.0), radius: 0.0 }, inner, RenderCommand::ClipPop].to_vec() }; - assert_eq!(run("wide", ImageFit::Fill), [img(rect(0.0, 0.0, 100.0, 100.0), "wide")]); - assert_eq!(run("wide", ImageFit::Contain), [img(rect(0.0, 25.0, 100.0, 50.0), "wide")]); - assert_eq!(run("wide", ImageFit::Cover), clip(vec![img(rect(-50.0, 0.0, 200.0, 100.0), "wide")])); - assert_eq!(run("wide", ImageFit::Unscaled), clip(vec![img(rect(-150.0, -50.0, 400.0, 200.0), "wide")])); - assert_eq!(run("tall", ImageFit::Fill), [img(rect(0.0, 0.0, 100.0, 100.0), "tall")]); - assert_eq!(run("tall", ImageFit::Contain), [img(rect(37.5, 0.0, 25.0, 100.0), "tall")]); - assert_eq!(run("tall", ImageFit::Cover), clip(vec![img(rect(0.0, -150.0, 100.0, 400.0), "tall")])); - assert_eq!(run("tall", ImageFit::Unscaled), clip(vec![img(rect(0.0, -150.0, 100.0, 400.0), "tall")])); + let whole = rect(0.0, 0.0, 400.0, 100.0); + for asset in ["wide", "tall", "small"] { + assert_eq!(run(asset, ImageFit::Fill), [img(whole, asset)], "{asset}"); + } + assert_eq!(run("wide", ImageFit::Contain), [img(rect(100.0, 0.0, 200.0, 100.0), "wide")]); + assert_eq!(run("tall", ImageFit::Contain), [img(rect(187.5, 0.0, 25.0, 100.0), "tall")]); + assert_eq!(run("small", ImageFit::Contain), [img(rect(100.0, 0.0, 200.0, 100.0), "small")]); + assert_eq!(run("wide", ImageFit::Cover), clip(img(rect(0.0, -50.0, 400.0, 200.0), "wide"))); + assert_eq!(run("tall", ImageFit::Cover), clip(img(rect(0.0, -750.0, 400.0, 1600.0), "tall"))); + assert_eq!(run("small", ImageFit::Cover), clip(img(rect(0.0, -50.0, 400.0, 200.0), "small"))); + assert_eq!(run("tall", ImageFit::Unscaled), clip(img(rect(150.0, -150.0, 100.0, 400.0), "tall"))); + assert_eq!(run("small", ImageFit::Unscaled), clip(img(rect(180.0, 40.0, 40.0, 20.0), "small"))); } #[test]