From d11671267747c6e3132b75413f5a52902ac63172 Mon Sep 17 00:00:00 2001 From: David Mann Date: Mon, 30 Nov 2026 23:47:05 +0100 Subject: [PATCH] Fill: Symmetry Fill turns about the selection's own centre (#17433) A selection that reaches past the canvas kept the centre of its visible part; it now turns about the centre of the whole selection, while the fill stays clipped to the canvas. The centre is summed in f64 so a far-off selection pixel cannot overflow. Co-Authored-By: Claude Opus 5.5 --- crates/engine-paint/src/cmd/fill_cmds.rs | 7 ++++--- .../src/fill_script_symmetry_tests.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/engine-paint/src/cmd/fill_cmds.rs b/crates/engine-paint/src/cmd/fill_cmds.rs index c2dfb4f98a..5d6965cbbc 100644 --- a/crates/engine-paint/src/cmd/fill_cmds.rs +++ b/crates/engine-paint/src/cmd/fill_cmds.rs @@ -139,9 +139,10 @@ pub fn fill(s: &mut Session, p: &Value) -> Result { // With a script the pattern is laid out tile by tile instead of repeated. if let Some(script) = script(p)? { out["script"] = json!(script); - // A symmetry turns about the selection's centre, the canvas centre without one. - let centre = if sel.is_some() { area } else { doc_bounds }; - let centre = (f64::from(centre.x0 + centre.x1) / 2.0, f64::from(centre.y0 + centre.y1) / 2.0); + // A symmetry turns about the selection's own centre, also where it reaches past the canvas, and the + // canvas centre without one. + let centre = sel.as_ref().map_or(doc_bounds, |m| m.content_bounds()); + let centre = ((f64::from(centre.x0) + f64::from(centre.x1)) / 2.0, (f64::from(centre.y0) + f64::from(centre.y1)) / 2.0); let place = photocraft_compose::scripted_pattern::Area { rect: area, centre }; Source::Pixels(area, scripted(p, script, &tile, &pat, place)?) } else { diff --git a/crates/engine-paint/src/fill_script_symmetry_tests.rs b/crates/engine-paint/src/fill_script_symmetry_tests.rs index 28afa6dc40..7b9b9f2c12 100644 --- a/crates/engine-paint/src/fill_script_symmetry_tests.rs +++ b/crates/engine-paint/src/fill_script_symmetry_tests.rs @@ -142,6 +142,21 @@ fn a_selection_moves_the_centre_to_its_own() { assert_eq!(rgb8(pixel(&s, 85, 90)), RED); } +#[test] +fn a_selection_past_the_canvas_edge_keeps_its_own_centre() { + let mut s = session(); + // A selection from x -100 to 200 (left of the canvas too): its centre is x 50, not the 100 of its visible part. + s.edit("selection", |doc, _| { + let mut sel = photocraft_raster::Surface::new(photocraft_color::PixelFormat::GRAY8); + sel.fill_rect(photocraft_geom::Rect::new(-100, 0, 200, 150), &[1.0]); + doc.selection = Some(sel); + Ok(()) + }) + .unwrap(); + s.execute("edit.fill", symmetry(json!({"symmetryType": 1}))).unwrap(); + assert_eq!(painted_bounds(&s, 600, 400), Some((0, 82, 100, 112)), "mirrored about x 50"); +} + #[test] fn fill_mode_and_opacity_apply_to_the_copies() { let mut s = session();