SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: dragging one of several selected sides no longer runs ahead of the pointer (#11324)
sommerper1cf7ae8e5c79
diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rsindex a6c0130b93..e14110f474 100644--- a/crates/engine/src/cmd/sketch.rs+++ b/crates/engine/src/cmd/sketch.rs@@ -3776,10 +3776,10 @@ fn drag_frame(s: &mut Session, p: &Value, live: bool) -> Result<(Value, Option<c// its degrees of freedom.Ok((d, if live && last.is_some() { left } else { left.solve_again() }))})?;- // Lines retain the grabbed material point through rotation. Other entities report the- // average displacement of their moving points, as before.+ // Lines retain the grabbed material point through rotation. Other entities report how the+ // moving point that got furthest toward `to` moved (`Dragged::at`).let sk = sketch_store::read(&s.doc, id)?;- let at = d.at(sk, from);+ let at = d.at(sk, from, to);let rep = rep.or_else(|| last.map(|ss| SolveReport { status: solidcraft_sketch::SolveStatus::Solved, failing: Vec::new(), ..ss.report.clone() }));let out = json!({"sketch": rep.as_ref().map(report_json), "reached": d.reached, "at": [at.x, at.y], "retry": d.retry});Ok((out, rep.filter(|_| live).map(|report| crate::LiveEdit { sketch: id, report })))diff --git a/crates/engine/src/cmd/sketch_drag.rs b/crates/engine/src/cmd/sketch_drag.rsindex d868808593..1d987bd048 100644--- a/crates/engine/src/cmd/sketch_drag.rs+++ b/crates/engine/src/cmd/sketch_drag.rs@@ -592,12 +592,17 @@ pub(super) struct Dragged {}impl Dragged {- pub(super) fn at(&self, sk: &Sketch, from: Vec2) -> Vec2 {+ /// Where the grab went on its way from `from` to `to`: moved as the moving point that got+ /// furthest toward `to` moved. A selection part of which is held back (a rectangle with a+ /// corner on the origin) has its free part follow the pointer; the average of all its points+ /// lagged the grab, and the next frame's catch-up took the free part past the pointer.+ pub(super) fn at(&self, sk: &Sketch, from: Vec2, to: Vec2) -> Vec2 {if let Some(at) = self.line_grab.and_then(|g| g.point(sk)) {return at;}- let moves: Vec<_> = self.moving.iter().filter_map(|&(q, was)| Some(sk.point(q)? - was)).collect();- from + moves.iter().fold(Vec2::ZERO, |a, m| a + *m) * (1.0 / moves.len().max(1) as f64)+ let d = to - from;+ let furthest = self.moving.iter().filter_map(|&(q, was)| Some(sk.point(q)? - was)).max_by(|a, b| a.dot(d).total_cmp(&b.dot(d)));+ from + furthest.unwrap_or(Vec2::ZERO)}}diff --git a/crates/ui-egui/src/sketch_drag_ui_tests.rs b/crates/ui-egui/src/sketch_drag_ui_tests.rsindex e215c93d6a..3a2cccc9eb 100644--- a/crates/ui-egui/src/sketch_drag_ui_tests.rs+++ b/crates/ui-egui/src/sketch_drag_ui_tests.rs@@ -493,3 +493,36 @@ fn a_centre_rectangles_centre_held_on_the_origin_keeps_the_rectangle_when_draggeassert!(point(&h, p).dist(was) < 1e-6, "{p} moved from {was:?} to {:?}", point(&h, p));}}++/// A selected rectangle with a corner on the origin, dragged by its right side or its top,+/// stretches as far as the pointer goes. The grab followed the average of the moving corners,+/// one of which the origin held back, and each frame's catch-up took the side nearly twice as+/// far as the pointer.+#[test]+fn a_selected_rectangle_held_at_a_corner_stretches_with_the_pointer() {+ for (grab, to) in [(Vec2::new(30.0, 10.0), Vec2::new(40.0, 10.0)), (Vec2::new(15.0, 20.0), Vec2::new(15.0, 30.0))] {+ let mut h = Harness::new();+ run(&mut h, "sketch.create", json!({"plane": "XY"}));+ run(&mut h, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [30, 20]}));+ let sid = h.app.session.active_sketch.expect("sketch mode");+ let corner =+ h.app.session.doc.sketch(sid).expect("the sketch").points.iter().find(|p| p.id != "origin" && p.pos.len() < 1e-9).map(|p| p.id.clone());+ run(&mut h, "sketch.constraint.coincident", json!({"a": corner.expect("a corner on the origin"), "b": "origin"}));+ run(&mut h, "sketch.options", json!({"show_dimensions": false, "show_constraints": false}));+ h.app.session.selection = ["l1", "l2", "l3", "l4"].iter().map(|l| Sel::SketchCurve { id: (*l).into(), sketch: None }).collect();+ h.call("ui.view", json!({"view": "top"}));+ h.app.cam.distance = 150.0;+ h.frames(3);+ let a = screen(&mut h, grab.x, grab.y);+ let b = screen(&mut h, to.x, to.y);+ let mut path = vec![a];+ path.extend(steps(a, b, 6));+ press_and_move(&mut h, &path);+ release(&mut h, b);+ let st = h.app.session.world_state().unwrap();+ let sk = &st.sketch(sid).expect("the sketch").sketch;+ let far = sk.points.iter().map(|p| p.pos).fold(Vec2::ZERO, |m, p| Vec2::new(m.x.max(p.x), m.y.max(p.y)));+ let want = Vec2::new(30.0, 20.0) + (to - grab);+ assert!(far.dist(want) < 0.05, "dragged {:?}: the far corner went to {far:?}, not {want:?}", to - grab);+ }+}