Transform: Perspective side-handle slides stop before the box folds

A Perspective side handle slides its edge along itself through
apply_drag's edge branch, which doesn't check convexity. On a
parallelogram that's harmless. Once the opposite edge isn't parallel
(after a corner pair on the other axis, say), the turns at the far
corners change with the slide, so a long drag turned the box concave
and then folded it, and the preview and commit used that quad.

Clamp the slid quad with keep_convex, as the Perspective corner and
Distort side-handle paths already do, and carry the reference point to
the clamped box. Skew mode's edge path is unchanged.

Regression test: perspective_mode_edge_slide_stops_before_the_box_folds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ljkxandClaude Opus 5.5 committed 2026-11-03 15:39:32 +01:00
1 parent c2acddae8c
commit abb8558815
2 files changed
+33 -3

No files matched your search

@@ -171,13 +171,22 @@ pub(crate) fn apply_mode_drag(s: &mut TransformSession, g: Gesture, p: [f64; 2],
s.quad = keep_convex(q0, q);
s.pivot = carry_pivot(q0, s.quad, g.pivot0);
}
// Skew, and Perspective's side handles, as in Photoshop: an edge slides only along itself
// (⌘⇧ in Free Transform).
(TransformMode::Skew | TransformMode::Perspective, Hit::Edge(_)) => {
// Skew: an edge slides only along itself (⌘⇧ in Free Transform).
(TransformMode::Skew, Hit::Edge(_)) => {
mods.command = true;
mods.shift = true;
apply_drag(s, g, p, mods);
}
// Perspective's side handles, as in Photoshop: the edge slides along itself, stopping
// before the box folds over (#1323). That happens once the opposite edge isn't parallel,
// as after a corner drag on the other axis.
(TransformMode::Perspective, Hit::Edge(_)) => {
mods.command = true;
mods.shift = true;
apply_drag(s, g, p, mods);
s.quad = keep_convex(g.quad0, s.quad);
s.pivot = carry_pivot(g.quad0, s.quad, g.pivot0);
}
_ => apply_drag(s, g, p, mode_mods(mode, g.hit, mods)),
}
}
@@ -1650,6 +1650,27 @@ fn perspective_mode_edge_slides_along_itself() {
assert_eq!(drag_in(persp, [50.0, 0.0], [62.0, 7.0], egui::Modifiers::ALT), [[12.0, 0.0], [112.0, 0.0], [88.0, 50.0], [-12.0, 50.0]]);
}
/// A Perspective side handle on a box whose opposite edge isn't parallel (here its right side
/// already pulled out by a vertical corner pair) stops before the box folds over, as its
/// corners do (#1323): a long slide along the top edge turned it concave.
#[test]
fn perspective_mode_edge_slide_stops_before_the_box_folds() {
let mut s = session();
s.quad = [[0.0, 0.0], [100.0, -20.0], [100.0, 70.0], [0.0, 50.0]];
let start = turns(&s.quad);
// Along the top edge, (5, -1), 100 steps the other way.
let g = Gesture { hit: Hit::Edge(0), start: [50.0, -10.0], quad0: s.quad, pivot0: s.pivot };
apply_mode_drag(&mut s, g, [-450.0, 90.0], TransformMode::Perspective, false, egui::Modifiers::NONE);
let q = s.quad;
assert!(turns(&q).iter().zip(start).all(|(t, t0)| t * t0.signum() > 0.0), "still convex: {q:?}");
assert!(q.iter().flatten().all(|v| v.is_finite()), "{q:?}");
assert_eq!((q[2], q[3]), (g.quad0[2], g.quad0[3]), "the other corners stay");
// The top edge only slid along itself, and some way.
assert!(((q[0][0] - g.quad0[0][0]) + (q[0][1] - g.quad0[0][1]) * 5.0).abs() < 1e-9, "{q:?}");
assert!(([q[1][0] - q[0][0] - 100.0, q[1][1] - q[0][1] + 20.0]).iter().all(|v| v.abs() < 1e-9), "{q:?}");
assert!(q[0][0] < -1.0, "it still slid: {q:?}");
}
/// #3941: Edit › Transform › Rotate must rotate from a corner handle, not scale.
#[test]
fn rotate_mode_turns_the_box_from_a_corner_handle() {