Skip to content

Commit

Permalink
[test_scenes] fill_type scene
Browse files Browse the repository at this point in the history
Added a test scene specifically for fill rules, drawing a star shape
and intersecting arcs with opposite winding.
  • Loading branch information
armansito committed Oct 22, 2023
1 parent 9d1010a commit 958d1cd
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ macro_rules! scene {
pub fn test_scenes() -> SceneSet {
let scenes = vec![
scene!(splash_with_tiger(), "splash_with_tiger", false),
scene!(crate::mmark::MMark::new(80_000), "mmark", false),
scene!(funky_paths),
scene!(stroke_styles),
scene!(tricky_strokes),
scene!(fill_types),
scene!(cardioid_and_friends),
scene!(animated_text: animated),
scene!(gradient_extend),
Expand All @@ -48,6 +48,7 @@ pub fn test_scenes() -> SceneSet {
scene!(clip_test: animated),
scene!(longpathdash(Cap::Butt), "longpathdash (butt caps)", false),
scene!(longpathdash(Cap::Round), "longpathdash (round caps)", false),
scene!(crate::mmark::MMark::new(80_000), "mmark", false),
];

SceneSet { scenes }
Expand Down Expand Up @@ -287,6 +288,54 @@ fn tricky_strokes(sb: &mut SceneBuilder, _: &mut SceneParams) {
}
}

fn fill_types(sb: &mut SceneBuilder, params: &mut SceneParams) {
use PathEl::*;
let rect = Rect::from_origin_size(Point::new(0., 0.), (500., 500.));
let star = [
MoveTo((250., 0.).into()),
LineTo((105., 450.).into()),
LineTo((490., 175.).into()),
LineTo((10., 175.).into()),
LineTo((395., 450.).into()),
ClosePath,
];
let arcs = [
MoveTo((0., 480.).into()),
CurveTo((500., 480.).into(), (500., -10.).into(), (0., -10.).into()),
ClosePath,
MoveTo((500., -10.).into()),
CurveTo((0., -10.).into(), (0., 480.).into(), (500., 480.).into()),
ClosePath,
];
let scale = Affine::scale(0.6);
let t = Affine::translate((10., 25.));
let rules = [
(Fill::NonZero, "Non-Zero", star.as_slice()),
(Fill::EvenOdd, "Even-Odd", &star),
(Fill::NonZero, "Non-Zero", &arcs),
(Fill::EvenOdd, "Even-Odd", &arcs),
];
for (i, rule) in rules.iter().enumerate() {
let t = Affine::translate(((i % 2) as f64 * 306., (i / 2) as f64 * 340.)) * t;
params.text.add(sb, None, 24., None, t, rule.1);
let t = Affine::translate((0., 5.)) * t * scale;
sb.fill(
Fill::NonZero,
t,
&Brush::Solid(Color::rgb8(128, 128, 128)),
None,
&rect,
);
sb.fill(
rule.0,
Affine::translate((0., 10.)) * t,
Color::BLACK,
None,
&rule.2,
);
}
}

fn cardioid_and_friends(sb: &mut SceneBuilder, _: &mut SceneParams) {
render_cardioid(sb);
render_clip_test(sb);
Expand Down

0 comments on commit 958d1cd

Please sign in to comment.