Crop: a move of a turned document crop may take the frame past its bounds

A turned frame stopped at the image's edge on a move (photocraft#16460);
the reference application lets it go past and fills the area there, as for
an upright frame (photocraft#16404). Only the turn itself still keeps the
frame inside the turned image (photocraft#10869).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Mann
2026-11-22 22:25:17 +01:00
co-authored by Claude Opus 5.5
parent 8d436f486a
commit 269c33ea55
2 changed files with 22 additions and 7 deletions
+5 -5
View File
@@ -70,8 +70,8 @@ pub(super) struct Rules {
pub image: bool,
pub auto_center: bool,
pub fills_uncovered: bool,
/// An edge or corner drag, and a move of an upright frame, may take the frame past `bounds`: the crop grows the
/// canvas there, as in the reference application (a document crop, not one bounded by a placed picture's source).
/// An edge or corner drag, and a move, may take the frame past `bounds`, turned or not: the crop grows the canvas
/// there, as in the reference application (a document crop, not one bounded by a placed picture's source).
pub resize_grows: bool,
/// The canvas's snapping, with this pass's tolerance.
pub snap: Option<Snap>,
@@ -110,9 +110,9 @@ impl Rules {
(CropBox::upright(drawn(*anchor, *cur, self.ratio, mods)), true, self.ratio.is_some() || mods.shift)
}
Kind::Move => {
// A moved document crop may take in the area past the canvas, as an edge drag does (photocraft#16404);
// a turned frame stays inside the image it turns over (#10869).
grows = self.resize_grows && at.angle == 0.0;
// A moved document crop may take in the area past the canvas, as an edge drag does (photocraft#16404),
// also once turned (photocraft#16460): only the turn itself keeps the frame inside the image (#10869).
grows = self.resize_grows;
let by = if self.image { drag.from - to } else { to - drag.from };
(at.moved(by), false, false)
}
+17 -2
View File
@@ -862,13 +862,28 @@ fn a_document_crop_moved_past_its_bounds_takes_in_the_area_there() {
"image mode, auto centre {auto_center}: the frame moves past the canvas: {r:?}"
);
}
// A turned frame keeps inside the canvas.
// A turned frame moves past the canvas too (photocraft#16460): in Classic Mode past the right edge, in image mode
// (the image turned under an upright frame on screen) past the left edge.
let mut setup = Setup::new();
setup.bounds = Some(canvas);
let mut rig = Rig::new(CropBox::new(RECT, 10.0), setup);
rig.drag(rig.at(200.0, 150.0), rig.at(300.0, 150.0), Modifiers::NONE);
let b = rig.crop().turned_bounds();
assert!(b.x1 <= canvas.x1 + 1e-6, "a turned frame's move stays inside: {b:?}");
assert!(b.x1 > canvas.x1 + 1.0, "classic: a turned frame moves past the canvas: {b:?}");
assert!((rig.rect().width() - RECT.width()).abs() < 1e-6, "classic: a turned frame keeps its size: {:?}", rig.rect());
for auto_center in [false, true] {
let mut setup = Setup::image(10.0, auto_center);
setup.bounds = Some(canvas);
let mut rig = Rig::new(CropBox::new(RECT, 10.0), setup);
rig.drag(rig.at(200.0, 150.0), rig.at(300.0, 150.0), Modifiers::NONE);
let b = rig.crop().turned_bounds();
assert!(b.x0 < canvas.x0 - 1.0, "image mode, auto centre {auto_center}: a turned frame moves past the canvas: {b:?}");
assert!(
(rig.rect().width() - RECT.width()).abs() < 1e-6,
"image mode, auto centre {auto_center}: a turned frame keeps its size: {:?}",
rig.rect()
);
}
}
#[trial]