Skip to content

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

fix(#5505): a zero length dimension keeps constraining the sketch (#10790)

Homero Thompson9e30ff58782c
diff --git a/crates/sketch/src/solver.rs b/crates/sketch/src/solver.rs
index 8f74c2887e..87213765d4 100644
--- a/crates/sketch/src/solver.rs
+++ b/crates/sketch/src/solver.rs
@@ -609,6 +609,13 @@ fn residuals(s: &State, k: &ConstraintKind, out: &mut Vec<f64>) {
LineCircleDistance { l, c, value, inside } => out.push(s.line_circle_gap(l, c, inside) - value),
PointCircleDistance { p, c, value, inside } => out.push(s.point_circle_gap(p, c, inside) - value),
CircleCircleDistance { a, b, value, circles } => out.push(s.circle_circle_gap(a, b, circles) - value),
+ // A length within convergence tolerance of zero means the line's two ends meet:
+ // the component rows keep both directions constrained even when they do, the way a
+ // coincidence does (the same treatment a distance of zero gets above).
+ Length { l, value } if value.abs() <= TOL => {
+ let (a, b) = s.line(l);
+ out.extend([b.x - a.x, b.y - a.y]);
+ }
Length { l, value } => {
let (a, b) = s.line(l);
out.push(a.dist(b) - value);
diff --git a/crates/sketch/src/tests.rs b/crates/sketch/src/tests.rs
index 26c6933449..feaa87cad8 100644
--- a/crates/sketch/src/tests.rs
+++ b/crates/sketch/src/tests.rs
@@ -210,6 +210,27 @@ fn zero_distance_edits_preserve_dimension_rank() {
}
}
+/// A length dimension of zero still constrains the sketch: the two ends of the line meet, and
+/// the dimension holds them together instead of leaving a degree of freedom behind (#5505).
+#[test]
+fn zero_length_keeps_the_line_constrained() {
+ for seed in [false, true] {
+ seeded(seed, || {
+ let mut sk = Sketch::new();
+ let a = sk.add_point(v(0.0, 0.0), None).unwrap();
+ let b = sk.add_point(v(10.0, 0.0), None).unwrap();
+ let l = sk.add_line_pts(a, b, None).unwrap();
+ sk.add_constraint(ConstraintKind::Fix { p: a }, None).unwrap();
+ let id = sk.add_constraint(ConstraintKind::Length { l, value: 0.0 }, None).unwrap();
+ let report = solve(&mut sk);
+ assert!(report.ok(), "{report:?}");
+ assert_eq!(report.dof, 0, "a zero length holds the line's ends together: {report:?}");
+ assert!(!report.redundant.contains(&id), "a zero length is not redundant: {report:?}");
+ assert!(sk.point(b).unwrap().dist(v(0.0, 0.0)) < 1e-6, "{:?}", sk.point(b));
+ });
+ }
+}
+
#[test]
fn under_constrained_reports_dof() {
let mut sk = Sketch::new();