From f30d267acae4bee82dd372671b8f3d7bebeb5282 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 23:34:11 -0800 Subject: [PATCH] Effects: test that a pan by part of a pixel filters a width-capped whole-object raster again A 2000 x 1 pt bar with Torn Edges at 6400% has a whole-object raster capped at the widest raster side, so a vertical pan by part of a pixel can leave its scale, size and rounded origin unchanged. Only the whole-pixel pan check then keeps the raster from being drawn on a moved sampling grid; the new test covers it. The PixelEntry::view doc now says which lower-resolution rasters keep a view tag: those of an image kept for one placement and those a drag keeps. --- crates/render/src/fx/raster.rs | 10 ++++++---- crates/render/src/fx/tests.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/render/src/fx/raster.rs b/crates/render/src/fx/raster.rs index 5b9d8ca120..7cd2dc9916 100644 --- a/crates/render/src/fx/raster.rs +++ b/crates/render/src/fx/raster.rs @@ -90,10 +90,12 @@ pub(crate) struct PixelEntry { pub(super) rel: (f64, f64), pub(super) k: f64, pub(crate) image: std::sync::Arc, - /// For a raster of the content's whole reach, `None`: it draws after a pan too. For one - /// cropped to the view, the view and the rect it was made for: it draws only there, so - /// dragging other art over the object keeps it (a wide blur, or any blur zoomed in, reaches - /// past the pixel budget). + /// For a raster of the content's whole reach at full size, or at a lower resolution with its + /// pans kept in [`Self::pan`], `None`: it draws after a pan too. For one cropped to the view, + /// or another raster made at a lower resolution (of an image kept for one placement, or kept + /// by a drag), the view and the rect it was made for: it draws only there, so dragging other + /// art over the object keeps it (a wide blur, or any blur zoomed in, reaches past the pixel + /// budget). pub(super) view: Option, /// For a raster a drag's frame kept of content cropped to the view, the device pixels (against /// the anchor's view position) whose pixels the effects decided with all they look at: the diff --git a/crates/render/src/fx/tests.rs b/crates/render/src/fx/tests.rs index 8a4580f327..0b1da35bd7 100644 --- a/crates/render/src/fx/tests.rs +++ b/crates/render/src/fx/tests.rs @@ -2003,6 +2003,28 @@ fn pans_draw_the_lower_resolution_raster_of_the_whole_object_again() { assert!(pixels == Renderer::new().render(&d, 1280, 800, view(48.0, 40.5), &opts).pixels, "after a pan by part of a pixel"); } +/// At 6400% a 2000 × 1 pt bar with Torn Edges is 128000 px wide, so its whole-object raster is +/// capped at the widest raster side and its scale stays the same across vertical pans. A vertical +/// pan by part of a pixel that leaves the raster's rounded origin and size unchanged moves the +/// sampling grid, so it filters the content again. +#[test] +fn a_pan_by_part_of_a_pixel_filters_a_width_capped_whole_object_raster_again() { + let d = doc_with(Rect::new(100.0, 100.0, 2100.0, 101.0), Color::rgb(0.9, 0.4, 0.1), vec![("sketch.tornEdges", json!({}))]); + let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() }; + let view = |y: f64| Affine::translate((640.0, y)) * Affine::scale(64.0) * Affine::translate((-1100.0, -100.5)); + for (start, pan) in [(400.1, 40.2), (400.3, 40.7)] { + let mut r = Renderer::new(); + let _ = r.render(&d, 1280, 800, view(start), &opts); + let kept = r.pixel_fx.values().next().unwrap(); + assert!(kept.k < 1.0 && kept.view.is_none(), "a raster of the whole object at a lower resolution"); + assert_eq!(u32::from(kept.image.width()), crate::MAX_RASTER_SIDE, "the raster is as wide as a raster can be"); + let image = kept.image.clone(); + let pixels = r.render(&d, 1280, 800, view(start + pan), &opts).pixels; + assert!(!r.pixel_fx.values().any(|e| Arc::ptr_eq(&e.image, &image)), "a pan of {pan} px from {start} filters the content again"); + assert!(pixels == Renderer::new().render(&d, 1280, 800, view(start + pan), &opts).pixels, "after a pan of {pan} px from {start}"); + } +} + /// Hiding a member of a group filters its whole-object raster again after a pan by whole pixels. #[test] fn hiding_a_member_filters_the_whole_object_raster_again_after_a_pan() {