| // Copyright 2024 the Vello Authors |
| // SPDX-License-Identifier: Apache-2.0 OR MIT |
| |
| //! Tests to ensure that certain issues which don't deserve a test scene don't regress |
| |
| use scenes::ImageCache; |
| use scenes::SimpleText; |
| use vello::{ |
| AaConfig, Scene, |
| kurbo::{Affine, Rect, RoundedRect, Stroke}, |
| peniko::{Extend, ImageQuality, color::palette}, |
| }; |
| use vello_tests::{TestParams, smoke_snapshot_test_sync, snapshot_test_sync}; |
| |
| /// Test created from <https://github.com/linebender/vello/issues/616> |
| #[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, palette::css::WHITE, None, &rect); |
| let mut params = TestParams::new("rounded_rectangle_watertight", 70, 30); |
| params.anti_aliasing = AaConfig::Msaa16; |
| snapshot_test_sync(scene, ¶ms) |
| .unwrap() |
| .assert_mean_less_than(0.001); |
| } |
| |
| const DATA_IMAGE_PNG: &[u8] = include_bytes!("../snapshots/smoke/data_image_roundtrip.png"); |
| |
| /// Test for <https://github.com/linebender/vello/issues/972> |
| #[test] |
| #[cfg_attr(skip_gpu_tests, ignore)] |
| fn test_data_image_roundtrip_extend_pad() { |
| let mut scene = Scene::new(); |
| let mut images = ImageCache::new(); |
| let image = images |
| .from_bytes(0, DATA_IMAGE_PNG) |
| .unwrap() |
| .with_quality(ImageQuality::Low) |
| .with_extend(Extend::Pad); |
| scene.draw_image(&image, Affine::IDENTITY); |
| let mut params = TestParams::new( |
| "data_image_roundtrip", |
| image.image.width, |
| image.image.height, |
| ); |
| params.anti_aliasing = AaConfig::Area; |
| smoke_snapshot_test_sync(scene, ¶ms) |
| .unwrap() |
| .assert_mean_less_than(0.001); |
| } |
| |
| /// Test created from <https://github.com/linebender/vello/issues/662> |
| #[test] |
| #[cfg_attr(skip_gpu_tests, ignore)] |
| fn stroke_width_zero() { |
| let mut scene = Scene::new(); |
| let stroke = Stroke::new(0.0); |
| let rect = Rect::new(10.0, 10.0, 40.0, 40.0); |
| let rect_stroke_color = palette::css::PEACH_PUFF; |
| scene.stroke(&stroke, Affine::IDENTITY, rect_stroke_color, None, &rect); |
| let mut params = TestParams::new("stroke_width_zero", 50, 50); |
| params.anti_aliasing = AaConfig::Msaa16; |
| snapshot_test_sync(scene, ¶ms) |
| .unwrap() |
| .assert_mean_less_than(0.001); |
| } |
| |
| #[test] |
| #[cfg_attr(skip_gpu_tests, ignore)] |
| #[expect(clippy::cast_possible_truncation, reason = "Test code")] |
| fn text_stroke_width_zero() { |
| let font_size = 12.; |
| let mut scene = Scene::new(); |
| let mut simple_text = SimpleText::new(); |
| simple_text.add_run( |
| &mut scene, |
| None, |
| font_size, |
| palette::css::WHITE, |
| Affine::translate((0., f64::from(font_size))), |
| None, |
| &Stroke::new(0.), |
| "Testing text", |
| ); |
| let params = TestParams::new( |
| "text_stroke_width_zero", |
| (font_size * 6.) as _, |
| (font_size * 1.25).ceil() as _, |
| ); |
| snapshot_test_sync(scene, ¶ms) |
| .unwrap() |
| .assert_mean_less_than(0.001); |
| } |