diff --git a/crates/engine-paint/src/cmd/fill_cmds.rs b/crates/engine-paint/src/cmd/fill_cmds.rs index 3febb40037..6ecdf693ce 100644 --- a/crates/engine-paint/src/cmd/fill_cmds.rs +++ b/crates/engine-paint/src/cmd/fill_cmds.rs @@ -217,7 +217,7 @@ pub fn fill(s: &mut Session, p: &Value) -> Result { // A symmetry turns about the selection's own centre (also where it reaches past the canvas), the canvas // centre without one. let centre = sel.as_ref().map_or(doc_bounds, |m| m.content_bounds()); - let centre = (f64::from(centre.x0 + centre.x1) / 2.0, f64::from(centre.y0 + centre.y1) / 2.0); + 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, canvas: doc_bounds, centre, path: path.as_deref() }; 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();