From e1d4cb433c63a4dbbf95e247c8f28b8f97be983b Mon Sep 17 00:00:00 2001 From: cronos Date: Sun, 1 Nov 2026 20:19:16 +0000 Subject: [PATCH] Cover sketch line-arc fillets in both selection orders (#10242) --- crates/engine/src/cmd/sketch_modify_tests.rs | 34 +++++++++++++++++- crates/ui-egui/src/sketch_corner_ui_tests.rs | 38 ++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rs index 7d5b1b8da..4a5c66894 100644 --- a/crates/engine/src/cmd/sketch_modify_tests.rs +++ b/crates/engine/src/cmd/sketch_modify_tests.rs @@ -1875,7 +1875,7 @@ fn fillet_a_line_and_an_arc() { fn fillet_a_line_and_an_arc_drawn_to_meet_at_a_point() { // #1208: the arc starts at the line's end by coordinates, so the corner is two points held // together by a Coincident constraint. By point and by naming the two curves. - for how in [json!({"point": "l1.end"}), json!({"a": "l1", "b": "a1"})] { + for how in [json!({"point": "l1.end"}), json!({"a": "l1", "b": "a1"}), json!({"a": "a1", "b": "l1"})] { let mut s = new_sketch(); run(&mut s, "sketch.line", json!({"points": [[0, 0], [40, 0]], "ids": ["l1"]})); run(&mut s, "sketch.arc.center_point", json!({"center": [50, 0], "start": [60, 0], "end": [40, 0], "id": "a1"})); @@ -1941,6 +1941,38 @@ fn fillet_a_coincident_corner_that_a_dimension_measures_to() { } } +#[test] +fn fillet_coincident_line_and_arc_selection_order() { + for held in ["l1.end", "a1.end"] { + for (a, b) in [("l1", "a1"), ("a1", "l1")] { + let mut s = new_sketch(); + run(&mut s, "sketch.line", json!({"points": [[0, 0], [40, 0]], "ids": ["l1"]})); + run(&mut s, "sketch.arc.center_point", json!({"center": [50, 0], "start": [60, 0], "end": [40, 0], "id": "a1"})); + // Keep the fixed sharp corner in place, whichever endpoint is fixed or picked + // first when rounding the same corner. + run(&mut s, "sketch.constraint.fix", json!({"entity": held})); + let before = serde_json::to_value(sketch(&s)).unwrap(); + let f = run(&mut s, "sketch.fillet", json!({"a": a, "b": b, "radius": 3})); + let sk = sketch(&s); + let ai = sk.curve_index(&ids(&f["curves"])[0]).unwrap(); + let want = Vec2::new(50.0 - 160f64.sqrt(), 3.0); + assert!((sk.radius(ai).unwrap() - 3.0).abs() < 1e-7, "{held}: {a}, {b}"); + assert!(sk.center(ai).unwrap().dist(want) < 1e-6, "{held}: {a}, {b}"); + let fixed = sk + .constraints + .iter() + .find_map(|c| match c.kind { + ConstraintKind::Fix { p } => Some(p), + _ => None, + }) + .unwrap(); + assert!(sk.point(fixed).unwrap().dist(Vec2::new(40.0, 0.0)) < 1e-6); + assert_eq!(run(&mut s, "sketch.inspect", json!({}))["status"], "solved"); + run(&mut s, "edit.undo", json!({})); + assert_eq!(serde_json::to_value(sketch(&s)).unwrap(), before); + } + } +} #[test] fn chamfer_two_lines_drawn_to_meet_at_a_point() { let mut s = new_sketch(); diff --git a/crates/ui-egui/src/sketch_corner_ui_tests.rs b/crates/ui-egui/src/sketch_corner_ui_tests.rs index b556232d1..b51f486ed 100644 --- a/crates/ui-egui/src/sketch_corner_ui_tests.rs +++ b/crates/ui-egui/src/sketch_corner_ui_tests.rs @@ -958,3 +958,41 @@ fn corner_candidates_agree_with_engine_spatial_curve_filter() { h.app.dialog = None; } } + +#[test] +fn line_arc_fillet_preview_and_apply_work_in_both_pick_orders() { + for reverse in [false, true] { + let mut h = crate::scenario::Harness::new(); + h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); + h.app.run("sketch.line", json!({"points":[[0,0],[40,0]],"ids":["l1"]})).unwrap(); + h.app.run("sketch.arc.center_point", json!({"center":[50,0],"start":[60,0],"end":[40,0],"id":"a1"})).unwrap(); + h.app.run("sketch.constraint.fix", json!({"entity":"l1.end"})).unwrap(); + h.app.run("view.fit", json!({})).unwrap(); + h.settle(); + let undo = h.app.session.undo.len(); + h.step(&json!({"start":"sketch.fillet"})).unwrap(); + h.frames(2); + let mut picks = [[32, 0, 0], [50, 10, 0]]; + if reverse { + picks.reverse(); + } + for point in picks { + h.step(&json!({"click":{"world":point}})).unwrap(); + h.frames(2); + } + assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items.len(), 2); + set_size(&mut h.app, "3 mm"); + h.step(&json!({"until":{"count":{"name":"sketch_preview_curves","value":3}}})).unwrap(); + apply(&mut h); + assert!(h.app.dialog.is_none(), "reverse {reverse}: {:?}", h.app.status); + assert_eq!(h.app.session.undo.len(), undo + 1); + let st = h.app.session.world_state(); + let ss = st.sketch(h.app.session.active_sketch.unwrap()).unwrap(); + assert!(ss.report.ok()); + assert_eq!(ss.sketch.curves.len(), 3); + let want = Vec2::new(50.0 - 160f64.sqrt(), 3.0); + assert!(ss.sketch.curves.iter().enumerate().any(|(i, _)| { + ss.sketch.radius(i).is_some_and(|r| (r - 3.0).abs() < 1e-7) && ss.sketch.center(i).is_some_and(|c| c.dist(want) < 1e-6) + })); + } +}