Skip to content

Commit

Permalink
Add a regression test for linebender#616
Browse files Browse the repository at this point in the history
This was contributed in linebender#616 (comment)

Co-Authored-By: TimTom <[email protected]>
  • Loading branch information
DJMcNab and timtom-dev committed Sep 23, 2024
1 parent 4433203 commit 95481d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vello_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use vello::wgpu::{
self, BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer,
TextureDescriptor, TextureFormat, TextureUsages,
};
use vello::{block_on_wgpu, util::RenderContext, RendererOptions, Scene};
use vello::{block_on_wgpu, util::RenderContext, AaConfig, RendererOptions, Scene};

mod compare;
mod snapshot;
Expand All @@ -32,6 +32,7 @@ pub struct TestParams {
pub base_colour: Option<Color>,
pub use_cpu: bool,
pub name: String,
pub anti_aliasing: AaConfig,
}

impl TestParams {
Expand All @@ -42,6 +43,7 @@ impl TestParams {
base_colour: None,
use_cpu: false,
name: name.into(),
anti_aliasing: AaConfig::Area,
}
}
}
Expand Down Expand Up @@ -87,7 +89,7 @@ pub async fn get_scene_image(params: &TestParams, scene: &Scene) -> Result<Image
surface_format: None,
use_cpu: params.use_cpu,
num_init_threads: NonZeroUsize::new(1),
antialiasing_support: vello::AaSupport::area_only(),
antialiasing_support: std::iter::once(params.anti_aliasing).collect(),
},
)
.or_else(|_| bail!("Got non-Send/Sync error from creating renderer"))?;
Expand All @@ -97,7 +99,7 @@ pub async fn get_scene_image(params: &TestParams, scene: &Scene) -> Result<Image
base_color: params.base_colour.unwrap_or(Color::BLACK),
width,
height,
antialiasing_method: vello::AaConfig::Area,
antialiasing_method: params.anti_aliasing,
debug: vello::DebugLayers::none(),
};
let size = Extent3d {
Expand Down
20 changes: 20 additions & 0 deletions vello_tests/tests/regression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use vello::{
kurbo::{Affine, RoundedRect, Stroke},
peniko::Color,
AaConfig, Scene,
};
use vello_tests::{snapshot_test_sync, TestParams};

#[test]
#[cfg_attr(skip_gpu_tests, ignore)]
fn rounded_rectangle_watertight() {
let mut scene = Scene::new();
let rect = RoundedRect::new(60.0, 10.0, 80.0, 30.0, 10.0);
let stroke = Stroke::new(2.0);
scene.stroke(&stroke, Affine::IDENTITY, Color::WHITE, None, &rect);
let mut params = TestParams::new("rounded_rectangle_watertight", 70, 30);
params.anti_aliasing = AaConfig::Msaa16;
snapshot_test_sync(scene, &params)
.unwrap()
.assert_mean_less_than(0.001);
}

0 comments on commit 95481d8

Please sign in to comment.