Skip to content

Commit

Permalink
[test_scenes} Stroke cap variants of longpathdash
Browse files Browse the repository at this point in the history
Added a butt cap and round cap variant of the pathological longpathdash
test case. The round caps exhibit the expected increase in the number of
line segments post-flattening, and hence a significant increase in
required GPU memory.

Also added a new `scene!` macro variant for custom test names and
factory functions that return a test function.
  • Loading branch information
armansito committed Oct 11, 2023
1 parent 87b2703 commit 6c8ce4e
Showing 1 changed file with 48 additions and 50 deletions.
98 changes: 48 additions & 50 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{ExampleScene, SceneConfig, SceneParams, SceneSet};
use vello::kurbo::{Affine, BezPath, Ellipse, PathEl, Point, Rect, Stroke};
use vello::kurbo::{Affine, BezPath, Cap, Ellipse, PathEl, Point, Rect, Stroke};
use vello::peniko::*;
use vello::*;

Expand All @@ -21,29 +21,23 @@ macro_rules! scene {
function: Box::new($name),
}
};
($func:expr, $name: expr, $animated: literal) => {
ExampleScene {
config: SceneConfig {
animated: $animated,
name: $name.to_owned(),
},
function: Box::new($func),
}
};
}

pub fn test_scenes() -> SceneSet {
let splash_scene = ExampleScene {
config: SceneConfig {
animated: false,
name: "splash_with_tiger".to_owned(),
},
function: Box::new(splash_with_tiger()),
};
let mmark_scene = ExampleScene {
config: SceneConfig {
animated: false,
name: "mmark".to_owned(),
},
function: Box::new(crate::mmark::MMark::new(80_000)),
};
let scenes = vec![
splash_scene,
mmark_scene,
scene!(splash_with_tiger(), "splash_with_tiger", false),
scene!(crate::mmark::MMark::new(80_000), "mmark", false),
scene!(funky_paths),
scene!(cardioid_and_friends),
scene!(longpathdash),
scene!(animated_text: animated),
scene!(gradient_extend),
scene!(two_point_radial),
Expand All @@ -53,6 +47,8 @@ pub fn test_scenes() -> SceneSet {
scene!(labyrinth),
scene!(base_color_test: animated),
scene!(clip_test: animated),
scene!(longpathdash(Cap::Butt), "longpathdash (butt caps)", false),
scene!(longpathdash(Cap::Round), "longpathdash (round caps)", false),
];

SceneSet { scenes }
Expand Down Expand Up @@ -108,44 +104,46 @@ fn cardioid_and_friends(sb: &mut SceneBuilder, _: &mut SceneParams) {
//render_tiger(sb, false);
}

fn longpathdash(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn longpathdash(cap: Cap) -> impl FnMut(&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(
move |sb, _| {
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),
(
pts[0].0 * (1.0 - i) + pts[1].0 * i,
pts[0].1 * (1.0 - i) + pts[1].1 * i,
)
.into(),
));
i += 0.05;
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;
}
a += PI * 0.01;
x += 16;
}
x += 16;
sb.stroke(
&Stroke::new(1.0).with_caps(cap).with_dashes(0.0, [1.0, 1.0]),
Affine::translate((50.0, 50.0)),
Color::rgb8(255, 255, 0),
None,
&path,
);
}
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) {
Expand Down

0 comments on commit 6c8ce4e

Please sign in to comment.