mod common;
use common::*;
#[test]
fn push_transform_rotates_fill_rect() {
let red_color = Color::srgb(255, 0, 0, 255);
let mut rotated = Scene::new(100.0, 100.0);
rotated.commands.push(SceneCommand::PushClip {
x: 0.0,
y: 0.0,
w: 100.0,
h: 100.0,
});
rotated.commands.push(SceneCommand::PushTransform {
angle_deg: 45.0,
cx: 50.0,
cy: 50.0,
});
rotated.commands.push(SceneCommand::FillRect {
x: 25.0,
y: 25.0,
w: 50.0,
h: 50.0,
paint: Paint::solid(red_color),
});
rotated.commands.push(SceneCommand::PopTransform);
rotated.commands.push(SceneCommand::PopClip);
let mut plain = Scene::new(100.0, 100.0);
plain.commands.push(SceneCommand::PushClip {
x: 0.0,
y: 0.0,
w: 100.0,
h: 100.0,
});
plain.commands.push(SceneCommand::FillRect {
x: 25.0,
y: 25.0,
w: 50.0,
h: 50.0,
paint: Paint::solid(red_color),
});
plain.commands.push(SceneCommand::PopClip);
let backend = TinySkiaBackend;
let provider = default_provider();
let rot1 = backend
.rasterize(&rotated, &provider, &no_assets())
.expect("rotated rasterize 1");
let rot2 = backend
.rasterize(&rotated, &provider, &no_assets())
.expect("rotated rasterize 2");
let base = backend
.rasterize(&plain, &provider, &no_assets())
.expect("plain rasterize");
assert_eq!(
rot1.rgba, rot2.rgba,
"two rasterizes of the rotated scene must be byte-identical"
);
let any_red = (0..rot1.height).any(|py| {
(0..rot1.width).any(|px| {
let (r, g, b, a) = pixel(&rot1.rgba, rot1.width, px, py);
a > 0 && r > g && r > b
})
});
assert!(
any_red,
"rotated FillRect must produce at least one red pixel"
);
assert_ne!(
rot1.rgba, base.rgba,
"rotation must change the inked pixels versus the unrotated FillRect"
);
let (_, _, _, a_outside_bbox) = pixel(&rot1.rgba, rot1.width, 20, 50);
assert!(
a_outside_bbox > 0,
"pixel (20,50) is outside the unrotated bbox but inside the rotated diamond; must be inked"
);
let (_, _, _, a_base) = pixel(&base.rgba, base.width, 20, 50);
assert_eq!(
a_base, 0,
"pixel (20,50) must be transparent in the unrotated baseline"
);
}