From 87b2703a53e3c274acf02e661180ba700c4057b9 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Fri, 6 Oct 2023 16:14:43 -0700 Subject: [PATCH] [test_scenes] Port longpathdash test case from Skia This is a single very long path that results in a large number of line segments when dashing is applied. This demonstrates rendering artifacts. --- examples/scenes/src/test_scenes.rs | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/examples/scenes/src/test_scenes.rs b/examples/scenes/src/test_scenes.rs index 48d70d33f..bde55e084 100644 --- a/examples/scenes/src/test_scenes.rs +++ b/examples/scenes/src/test_scenes.rs @@ -43,6 +43,7 @@ pub fn test_scenes() -> SceneSet { mmark_scene, scene!(funky_paths), scene!(cardioid_and_friends), + scene!(longpathdash), scene!(animated_text: animated), scene!(gradient_extend), scene!(two_point_radial), @@ -107,6 +108,46 @@ fn cardioid_and_friends(sb: &mut SceneBuilder, _: &mut SceneParams) { //render_tiger(sb, false); } +fn longpathdash(sb: &mut SceneBuilder, _: &mut SceneParams) { + use std::f64::consts::PI; + use PathEl::*; + let mut path = BezPath::new(); + let mut x = 32; + while x < 256 { + let mut a: f64 = 0.0; + while a < PI * 2.0 { + let pts = [ + (256.0 + a.sin() * x as f64, 256.0 + a.cos() * x as f64), + ( + 256.0 + (a + PI / 3.0).sin() * (x + 64) as f64, + 256.0 + (a + PI / 3.0).cos() * (x + 64) as f64, + ), + ]; + path.push(MoveTo(pts[0].into())); + let mut i: f64 = 0.0; + while i < 1.0 { + path.push(LineTo( + ( + pts[0].0 * (1.0 - i) + pts[1].0 * i, + pts[0].1 * (1.0 - i) + pts[1].1 * i, + ) + .into(), + )); + i += 0.05; + } + a += PI * 0.01; + } + x += 16; + } + sb.stroke( + &Stroke::new(1.0).with_dashes(0.0, [1.0, 1.0]), + Affine::translate((50.0, 50.0)), + Color::rgb8(255, 255, 0), + None, + &path, + ); +} + fn animated_text(sb: &mut SceneBuilder, params: &mut SceneParams) { // Uses the static array address as a cache key for expedience. Real code // should use a better strategy.