Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Sketch Fillet: a corner held by Coincident takes a fillet when a dimension measures to it (#7507) (#7778)

semmelrinde99f8cff45450
diff --git a/crates/engine/src/cmd/sketch_modify.rs b/crates/engine/src/cmd/sketch_modify.rs
index b041cb8681..5c37aa04f1 100644
--- a/crates/engine/src/cmd/sketch_modify.rs
+++ b/crates/engine/src/cmd/sketch_modify.rs
@@ -1409,21 +1409,31 @@ fn weld_corner(sk: &mut Sketch, p: &Value) {
let Some(mut q) = q else { return };
// Each pass welds one partner; a pass removes a constraint, so this ends.
for _ in 0..sk.constraints.len() {
- let partner = sk.constraints.iter().enumerate().find_map(|(i, k)| {
+ let partner = sk.constraints.iter().find_map(|k| {
let o = match k.kind {
ConstraintKind::Coincident { p, q: r } if p == q && r != q => r,
ConstraintKind::Coincident { p, q: r } if r == q && p != q => p,
_ => return None,
};
- let held_elsewhere = sk.constraints.iter().enumerate().any(|(j, k)| j != i && k.kind.refers_to_point(o));
+ // What else holds the partner (a dimension measuring to the corner, #7507) holds
+ // the corner instead: the two are one place. Not where that would name the corner
+ // twice in one constraint (other than a repeat of this coincidence).
+ let twice = sk.constraints.iter().any(|other| {
+ let points = other.kind.indices().0;
+ !matches!(other.kind, ConstraintKind::Coincident { .. }) && points.contains(&o) && points.contains(&q)
+ });
let linked = (0..sk.curves.len()).any(|c| sk.is_linked_curve(c) && sk.curves.get(c).is_some_and(|x| x.kind.uses(o)));
- (o != 0 && !held_elsewhere && !linked).then_some((i, o))
+ (o != 0 && !twice && !linked).then_some(o)
});
- let Some((i, o)) = partner else { return };
+ let Some(o) = partner else { return };
for c in sk.curves.iter_mut() {
c.kind.map_points(&|x| if x == o { q } else { x });
}
- sk.constraints.remove(i);
+ for k in sk.constraints.iter_mut() {
+ k.kind.remap(&|x| Some(if x == o { q } else { x }), &Some);
+ }
+ // The coincidence, and any repeat of it, now joins the corner to itself.
+ sk.constraints.retain(|k| !matches!(k.kind, ConstraintKind::Coincident { p, q: r } if p == r));
sk.remove_points(&[o]);
if o < q {
q -= 1;
diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rs
index aa29a3c9ad..526a70a801 100644
--- a/crates/engine/src/cmd/sketch_modify_tests.rs
+++ b/crates/engine/src/cmd/sketch_modify_tests.rs
@@ -1715,6 +1715,45 @@ fn fillet_a_line_and_an_arc_drawn_to_meet_at_a_point() {
}
}
+/// #7507: a line drawn on from another line's end by coordinates meets it through a Coincident
+/// constraint, and a dimension measures to the second line's own end at that corner. The corner
+/// is still rounded, by point and by naming the two lines, and the dimension keeps measuring to
+/// the sharp corner.
+#[test]
+fn fillet_a_coincident_corner_that_a_dimension_measures_to() {
+ for how in [json!({"point": "l1.end"}), json!({"a": "l1", "b": "l2"})] {
+ let mut s = new_sketch();
+ run(&mut s, "sketch.line", json!({"points": [[0, 0], [40, 0]]}));
+ run(&mut s, "sketch.line", json!({"points": [[40, 0], [100, -30]]}));
+ run(&mut s, "sketch.dimension", json!({"entities": ["origin", "l2.start"], "type": "horizontal", "value": "40"}));
+ let mut p = how.clone();
+ p["radius"] = json!(5);
+ let f = run(&mut s, "sketch.fillet", p);
+ let made = ids(&f["curves"]);
+ assert_eq!(made.len(), 1, "{how}: {f}");
+ let sk = sketch(&s);
+ let ai = sk.curve_index(&made[0]).unwrap();
+ assert!((sk.radius(ai).unwrap() - 5.0).abs() < 1e-7, "{how}");
+ // Tangent to both lines: 5 below the first and 5 from the second's line.
+ let c = sk.center(ai).unwrap();
+ let along = Vec2::new(60.0, -30.0).normalized().unwrap();
+ assert!((c.y + 5.0).abs() < 1e-6 && ((c - Vec2::new(40.0, 0.0)).cross(along).abs() - 5.0).abs() < 1e-6, "{how}: {c:?}");
+ // The dimension still measures 40 to the sharp corner, and the sketch solves.
+ let info = run(&mut s, "sketch.inspect", json!({}));
+ assert_eq!(info["status"], "solved", "{how}: {info}");
+ let (p, q) = sk
+ .constraints
+ .iter()
+ .find_map(|k| match k.kind {
+ ConstraintKind::DistanceX { p, q, .. } => Some((p, q)),
+ _ => None,
+ })
+ .unwrap();
+ assert!((sk.point(q).unwrap().x - sk.point(p).unwrap().x - 40.0).abs() < 1e-6, "{how}");
+ assert!(sk.point(q).unwrap().dist(Vec2::new(40.0, 0.0)) < 1e-6, "{how}");
+ }
+}
+
#[test]
fn chamfer_two_lines_drawn_to_meet_at_a_point() {
let mut s = new_sketch();