From 8f8d03b771d0d673ed7b3ec9613749f4bf11e128 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 22 Nov 2026 15:46:51 +0100 Subject: [PATCH] Crop shield: one unfeathered mesh, no seam between its pieces `paint_outside` filled each convex piece of the area outside the frame on its own, feathered on all its edges, so along an edge two pieces share both faded out and the translucent shield left a thin strip less covered than the rest: a light line from the frame's corner to the window's edge. The pieces are now one mesh without feathering (`Draw::data_fill_tiled`), whose triangles meet with no gap and no overlap. Crop and Perspective Crop both paint through it. Fixes storytold/photocraft#16410. Co-Authored-By: Claude Opus 5.5 --- crates/ui-canvas/src/canvas/crop/shield.rs | 16 ++++++------ crates/ui-canvas/tests/it/canvas/crop.rs | 29 ++++++++++++++++++++++ crates/ui-contract/src/primitives/draw.rs | 15 +++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/crates/ui-canvas/src/canvas/crop/shield.rs b/crates/ui-canvas/src/canvas/crop/shield.rs index f2f300a26..3437a443d 100644 --- a/crates/ui-canvas/src/canvas/crop/shield.rs +++ b/crates/ui-canvas/src/canvas/crop/shield.rs @@ -1,7 +1,7 @@ //! The crop shield: the options that dim the area outside the frame. use crate::canvas::CanvasSpace; -use crate::primitives::{Draw, PaintShape}; +use crate::primitives::Draw; use crate::style::DataColor; use craft_behavior::geometry::outside_pieces; use craft_behavior::kurbo::Point; @@ -63,15 +63,17 @@ impl Default for CropShield { } } -/// Paints `fill` over the canvas quad outside the convex `hole`, in screen points: one polygon per convex piece of -/// [`outside_pieces`]. The one shield painter for both crops. +/// Paints `fill` over the canvas quad outside the convex `hole`, in screen points: the convex pieces of +/// [`outside_pieces`] as one unfeathered mesh, so the translucent shield shows no seam where two pieces meet +/// (photocraft#16410). The one shield painter for both crops. pub fn paint_outside(draw: &Draw<'_>, canvas: [Pos2; 4], hole: &[Pos2], fill: DataColor) { let point = |p: Pos2| Point::new(f64::from(p.x), f64::from(p.y)); let hole: Vec = hole.iter().copied().map(point).collect(); - for piece in outside_pieces(canvas.map(point), &hole) { - let piece = piece.into_iter().map(|p| Pos2::new(p.x as f32, p.y as f32)).collect(); - draw.data_fill(&PaintShape::Polygon(piece), fill); - } + let pieces: Vec> = outside_pieces(canvas.map(point), &hole) + .into_iter() + .map(|piece| piece.into_iter().map(|p| Pos2::new(p.x as f32, p.y as f32)).collect()) + .collect(); + draw.data_fill_tiled(&pieces, fill); } impl CropShield { diff --git a/crates/ui-canvas/tests/it/canvas/crop.rs b/crates/ui-canvas/tests/it/canvas/crop.rs index 0c1cbd219..a59d6ecb9 100644 --- a/crates/ui-canvas/tests/it/canvas/crop.rs +++ b/crates/ui-canvas/tests/it/canvas/crop.rs @@ -248,6 +248,20 @@ impl Rig { (!points.is_empty()).then(|| egui::Rect::from_points(&points)) } + /// The shield's meshes this frame: those with a translucent vertex. + fn shield_meshes(&mut self) -> Vec { + let room = egui::Rect::from_min_size(Pos2::ZERO, ROOM); + let show = &mut self.show; + let shapes = self.frames.frame_shapes(|ui| layout::in_region(ui, room, |ui| show(ui))); + shapes + .into_iter() + .filter_map(|shape| match shape { + egui::Shape::Mesh(mesh) if mesh.vertices.iter().any(|v| (1..255).contains(&v.color.a())) => Some((*mesh).clone()), + _ => None, + }) + .collect() + } + fn view(&self) -> CanvasView { self.setup.borrow().view } @@ -889,3 +903,18 @@ fn an_object_crop_is_bounded_by_its_source_and_a_press_outside_it_reaches_what_l rig.frame(vec![input::key_press(egui::Key::Escape, Modifiers::NONE)]); assert!(rig.seen.borrow().discarded, "Escape discards"); } + +/// photocraft#16410: the shield is one unfeathered mesh. Its pieces used to be feathered one by one, so each faded +/// out along the edges it shares with the next and the canvas showed through as a line under the translucent shield, +/// from the frame's corners to the canvas's edges. +#[trial] +fn the_shield_is_one_unfeathered_mesh_with_no_seam_between_its_pieces() { + for (what, setup) in [("classic", Setup::new()), ("image mode", Setup::image(0.0, false)), ("turned", Setup::image(10.0, false))] { + let angle = if what == "turned" { 10.0 } else { 0.0 }; + let mut rig = Rig::new(CropBox::new(RECT, angle), setup); + let meshes = rig.shield_meshes(); + assert_eq!(meshes.len(), 1, "{what}: the shield is one mesh: {} meshes", meshes.len()); + let alpha = meshes[0].vertices[0].color.a(); + assert!(meshes[0].vertices.iter().all(|v| v.color.a() == alpha), "{what}: no vertex of the shield fades out (a feathered edge)"); + } +} diff --git a/crates/ui-contract/src/primitives/draw.rs b/crates/ui-contract/src/primitives/draw.rs index 1e976bd76..3408e3581 100644 --- a/crates/ui-contract/src/primitives/draw.rs +++ b/crates/ui-contract/src/primitives/draw.rs @@ -554,6 +554,21 @@ impl<'a> Draw<'a> { self.paint(shape, Some(fill), None); } + /// Fills the polygons `pieces`, which tile one area edge to edge, as one mesh with no feathered edges, in a colour + /// from data as `data_fill` paints it. Feathered pieces would each fade out along the edges they share, so a + /// translucent fill would show a seam of what lies beneath along every shared edge; unfeathered triangles meet + /// with no gap and no overlap. + pub fn data_fill_tiled(&self, pieces: &[Vec], color: DataColor) { + let fill = self.data_color(color); + let mut mesh = egui::Mesh::default(); + for piece in pieces { + mesh.append(super::kit::fill_polygon(piece, fill, 0.0)); + } + if !mesh.is_empty() { + self.painter.add(Shape::mesh(mesh)); + } + } + /// Paints the part `uv` of `texture` (from `TextureCache` or a `TextureStore`) into `rect`, untinted. The picture /// is data: a disabled component paints it at `Opacity::DISABLED`, and a `Draw` for an inactive part fills `rect` /// with the theme's disabled fill instead, as `data_fill` does.