egui icon indicating copy to clipboard operation
egui copied to clipboard

Add pixel_threshold and improve threshold docs

Open lucasmerlin opened this issue 10 months ago • 5 comments

Sometimes visual threshold isn't enough and it would be nice to just allow x pixels to be different

lucasmerlin avatar Feb 05 '25 10:02 lucasmerlin

Workaround we use right now:

    let broken_percent_threshold = 0.003;
    let num_pixels = (size.x * size.y).ceil() as f64;

    use re_viewer_context::external::egui_kittest;
    match harness.try_snapshot(name) {
        Ok(_) => {}

        Err(err) => match err {
            egui_kittest::SnapshotError::Diff {
                name,
                diff: num_broken_pixels,
                diff_path,
            } => {
                let broken_percent = num_broken_pixels as f64 / num_pixels;
                re_log::debug!(num_pixels, num_broken_pixels, broken_percent);
                assert!(
                    broken_percent <= broken_percent_threshold,
                    "{name} failed because {broken_percent} > {broken_percent_threshold}\n{diff_path:?}"
                )
            }

            _ => panic!("{name} failed: {err}"),
        },
    }

teh-cmc avatar Feb 05 '25 10:02 teh-cmc

@Wumpf Do we still need this after mergning

  • https://github.com/rerun-io/rerun/pull/8971 ?

emilk avatar Feb 11 '25 10:02 emilk

Yes absolutely. Even with AA disabled, we still have one (down from several) test where this is needed and there is many reasons why we may run into problems that need this.

Wumpf avatar Feb 11 '25 12:02 Wumpf

The problem with the workaround we're using right now is that whenever we react to a egui_kittest::SnapshotError::Diff { and discard its error as passing, the image has already been updated. I.e. if I'm on a machine that didn't produce the original and run all tests with UPDATE_SNAPSHOTS=1, I end up having a git diff with this despite passing the test.

@lucasmerlin would you be up for incorporating this in?

Wumpf avatar May 20 '25 16:05 Wumpf

@Wumpf I started developing a solution and created a PR today

bircni avatar May 26 '25 19:05 bircni

@emilk thank you for helping me out :-)

bircni avatar Jul 05 '25 11:07 bircni