From 4b9f31542246706e0d90827d60b1b289cf011b26 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Tue, 12 Nov 2024 17:36:53 -0500 Subject: [PATCH] Add test for wide rendering --- fidget/src/render/render2d.rs | 76 +++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/fidget/src/render/render2d.rs b/fidget/src/render/render2d.rs index 132b328b..d007ad74 100644 --- a/fidget/src/render/render2d.rs +++ b/fidget/src/render/render2d.rs @@ -485,16 +485,18 @@ mod test { shape: Shape, expected: &'static str, camera: Camera<2>, + wide: bool, ) { + let width = if wide { 64 } else { 32 }; let cfg = RenderConfig::<2> { - image_size: ImageSize::from(32), + image_size: ImageSize::new(width, 32), camera, ..RenderConfig::default() }; let out = cfg.run::<_, BitRenderMode>(shape).unwrap(); let mut img_str = String::new(); for (i, b) in out.iter().enumerate() { - if i % 32 == 0 { + if i % width as usize == 0 { img_str += "\n "; } img_str.push(if *b { 'X' } else { '.' }); @@ -514,7 +516,19 @@ mod test { shape: Shape, expected: &'static str, ) { - render_and_compare_with_camera(shape, expected, Camera::default()) + render_and_compare_with_camera( + shape, + expected, + Camera::default(), + false, + ) + } + + fn render_and_compare_wide( + shape: Shape, + expected: &'static str, + ) { + render_and_compare_with_camera(shape, expected, Camera::default(), true) } fn check_hi() { @@ -556,6 +570,45 @@ mod test { render_and_compare(shape, EXPECTED); } + fn check_hi_wide() { + let (ctx, root) = Context::from_text(HI.as_bytes()).unwrap(); + let shape = Shape::::new(&ctx, root).unwrap(); + const EXPECTED: &str = " + .................................X.............................. + .................................X.............................. + .................................X.............................. + .................................X..........XX.................. + .................................X..........XX.................. + .................................X.............................. + .................................X.............................. + .................................XXXXXX.....XX.................. + .................................XXX..XX....XX.................. + .................................XX....XX...XX.................. + .................................X......X...XX.................. + .................................X......X...XX.................. + .................................X......X...XX.................. + .................................X......X...XX.................. + .................................X......X...XX.................. + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................ + ................................................................"; + render_and_compare_wide(shape, EXPECTED); + } + fn check_hi_transformed() { let (ctx, root) = Context::from_text(HI.as_bytes()).unwrap(); let shape = Shape::::new(&ctx, root).unwrap(); @@ -642,6 +695,7 @@ mod test { nalgebra::Vector2::new(0.5, 0.5), 0.5, ), + false, ); } @@ -700,6 +754,22 @@ mod test { check_hi::(); } + #[test] + fn render_hi_wide_vm() { + check_hi_wide::(); + } + + #[test] + fn render_hi_wide_vm3() { + check_hi_wide::>(); + } + + #[cfg(feature = "jit")] + #[test] + fn render_hi_wide_jit() { + check_hi_wide::(); + } + #[test] fn render_hi_transformed_vm() { check_hi_transformed::();