Merge PR #18396 at its new head (its centre fix matches the batch fix-up; takes its test and overflow-safe centre)

This commit is contained in:
David Mann committed 2026-12-01 02:41:39 +01:00
commit 2ca6667b06
2 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -217,7 +217,7 @@ pub fn fill(s: &mut Session, p: &Value) -> Result<Value> {
// 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 {
@@ -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();