Skip to content

Commit

Permalink
Add test for wide rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Nov 12, 2024
1 parent 5e192dc commit 4b9f315
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions fidget/src/render/render2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,18 @@ mod test {
shape: Shape<F>,
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 { '.' });
Expand All @@ -514,7 +516,19 @@ mod test {
shape: Shape<F>,
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<F: Function>(
shape: Shape<F>,
expected: &'static str,
) {
render_and_compare_with_camera(shape, expected, Camera::default(), true)
}

fn check_hi<F: Function + MathFunction>() {
Expand Down Expand Up @@ -556,6 +570,45 @@ mod test {
render_and_compare(shape, EXPECTED);
}

fn check_hi_wide<F: Function + MathFunction>() {
let (ctx, root) = Context::from_text(HI.as_bytes()).unwrap();
let shape = Shape::<F>::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<F: Function + MathFunction>() {
let (ctx, root) = Context::from_text(HI.as_bytes()).unwrap();
let shape = Shape::<F>::new(&ctx, root).unwrap();
Expand Down Expand Up @@ -642,6 +695,7 @@ mod test {
nalgebra::Vector2::new(0.5, 0.5),
0.5,
),
false,
);
}

Expand Down Expand Up @@ -700,6 +754,22 @@ mod test {
check_hi::<crate::jit::JitFunction>();
}

#[test]
fn render_hi_wide_vm() {
check_hi_wide::<VmFunction>();
}

#[test]
fn render_hi_wide_vm3() {
check_hi_wide::<GenericVmFunction<3>>();
}

#[cfg(feature = "jit")]
#[test]
fn render_hi_wide_jit() {
check_hi_wide::<crate::jit::JitFunction>();
}

#[test]
fn render_hi_transformed_vm() {
check_hi_transformed::<VmFunction>();
Expand Down

0 comments on commit 4b9f315

Please sign in to comment.