Sketch: dragging a constrained centre point of a centre rectangle moves it, not resizes it (#10510) (#10535)

* claim: #10510

Signed-off-by: Maurizio Monticelli <maurizio@whatwedo.ch>

* Sketch: dragging a centre rectangle's constrained centre point keeps the rectangle's size

A centre rectangle's centre sits on the middle of its diagonal, and a
press there picked the diagonal's midpoint before the centre point. The
drag then took the diagonal by its middle: with the centre free the
rectangle moved along, but with the centre held (on the origin, on a
line) the diagonal turned and stretched about it, and the rectangle
grew or shrank with the pointer, many times its size.

A drag that starts on a line's middle where a point is held by a
Midpoint constraint now drags that point, as a drag that starts on the
point does. A centre held on the origin stays there and the rectangle
keeps its size; a centre on a line slides the whole rectangle along it;
a free centre still moves the rectangle. Clicking the middle still
selects the line's midpoint for constraints.

Fixes #10510

Signed-off-by: Maurizio Monticelli <maurizio@whatwedo.ch>

---------

Signed-off-by: Maurizio Monticelli <maurizio@whatwedo.ch>
This commit is contained in:
rugbymauri
2026-11-02 00:04:38 +00:00
committed by GitHub
parent cea07cbc66
commit 7d86a8cfd3
2 changed files with 53 additions and 0 deletions
@@ -461,3 +461,34 @@ fn a_freed_circle_centre_on_the_origin_drags_instead_of_the_origin() {
assert!(point(&h, "c1.center").dist(Vec2::new(15.0, 10.0)) < 0.05, "{:?}", point(&h, "c1.center"));
assert!(point(&h, "origin").dist(Vec2::new(0.0, 0.0)) < 1e-9);
}
/// A centre rectangle's centre held on the origin stays there when dragged, and the rectangle
/// keeps its size. The press lands on the middle of the rectangle's diagonal as well as on the
/// centre; the drag took the diagonal by its middle and turned and stretched it about the held
/// centre, resizing the rectangle (#10510).
#[test]
fn a_centre_rectangles_centre_held_on_the_origin_keeps_the_rectangle_when_dragged() {
let mut h = Harness::new();
run(&mut h, "sketch.create", json!({"plane": "XY"}));
run(&mut h, "sketch.rectangle.center", json!({"center": [3, 2], "corner": [13, 9]}));
run(&mut h, "sketch.constraint.coincident", json!({"a": "p5", "b": "origin"}));
run(&mut h, "sketch.options", json!({"snap": false, "show_dimensions": false, "show_constraints": false}));
h.call("ui.view", json!({"view": "top"}));
h.app.cam.distance = 150.0;
h.frames(3);
let corners = ["p1", "p2", "p3", "p4"].map(|p| point(&h, p));
assert!(point(&h, "p5").len() < 1e-9, "{:?}", point(&h, "p5"));
// A press a little off the centre, as a hand presses.
let a = screen(&mut h, 0.3, 0.2);
let b = screen(&mut h, 12.0, 8.0);
let mut path = vec![a];
path.extend(steps(a, b, 6));
press_and_move(&mut h, &path);
assert_eq!(h.app.viewport.point_drag.as_ref().map(|(id, _, _)| id.as_str()), Some("p5"), "grabbed the centre, not the diagonal");
h.frames(4);
release(&mut h, b);
assert!(point(&h, "p5").len() < 1e-6, "the centre left the origin: {:?}", point(&h, "p5"));
for (p, was) in ["p1", "p2", "p3", "p4"].into_iter().zip(corners) {
assert!(point(&h, p).dist(was) < 1e-6, "{p} moved from {was:?} to {:?}", point(&h, p));
}
}
+22
View File
@@ -4817,6 +4817,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
// the text, also from the space between its letters (#8835).
let own = matches!(&hit, Some(Hit::SketchPoint { sketch, .. } | Hit::SketchMidpoint { sketch, .. } | Hit::SketchCurve { sketch, .. }) if Some(*sketch) == active);
let hit = if own { hit } else { crate::sketch_text_handles::grab_inside(app, &proj, a).or(hit) };
let hit = hit.map(|hit| point_at_midpoint(app, hit));
match hit {
Some(Hit::SketchPoint { sketch, id, .. }) if Some(sketch) == active => {
// A point dragged with the rest of a selection slides with it, from where it
@@ -5816,6 +5817,27 @@ pub(crate) fn select(app: &mut SolveApp, sel: Option<Sel>, add: bool, toggle: bo
/// The rest of the selected sketch geometry when the point or curve `id` is part of it (#2621):
/// a drag that starts on a selected entity moves the whole selection with it.
/// A drag that starts on a line's middle where a point is held (a centre rectangle's centre on
/// its diagonal) drags that point, as a drag that starts on the point does. Dragging the line by
/// its middle instead moved its ends: with the point constrained (on the origin, on a line) the
/// line turned and stretched about it, and the rectangle round it changed size (#10510).
fn point_at_midpoint(app: &SolveApp, hit: Hit) -> Hit {
let Hit::SketchMidpoint { sketch, id, .. } = &hit else { return hit };
let st = app.session.world_state();
let held = st.sketch(*sketch).and_then(|ss| {
let sk = &ss.sketch;
let line = sk.curve_index(id)?;
sk.constraints.iter().filter(|c| !c.driven).find_map(|c| match c.kind {
solidcraft_engine::sketch::ConstraintKind::Midpoint { p, l } if l == line => sk.points.get(p).map(|q| (q.id.clone(), q.pos)),
_ => None,
})
});
match held {
Some((id, at)) => Hit::SketchPoint { sketch: *sketch, id, at },
None => hit,
}
}
fn dragged_with(app: &SolveApp, id: &str) -> Vec<String> {
fn geometry(s: &Sel) -> Option<&str> {
match s {