SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Accept a leading = in expressions, so a fillet radius can be =d3 (#4681) (#4686)
Steve Jasona9c3c8bb8a1e
diff --git a/crates/doc/src/expr.rs b/crates/doc/src/expr.rsindex d8419b1290..b135c2db13 100644--- a/crates/doc/src/expr.rs+++ b/crates/doc/src/expr.rs@@ -341,6 +341,12 @@ fn lex_spans(s: &str) -> Result<Vec<(Tok, usize, usize)>, DocError> {let mut out = Vec::new();// Parentheses open at this point: a comma outside them can only be a decimal comma.let mut depth = 0usize;+ // A single leading `=` marks the text as a formula (`=d3`, #4681) and is not part of it.+ if let Some(k) = cs.iter().position(|(_, c)| !c.is_whitespace())+ && cs.get(k).is_some_and(|(_, c)| *c == '=')+ {+ i = k + 1;+ }while let Some(&(_, c)) = cs.get(i) {if c.is_whitespace() {i += 1;@@ -564,7 +570,9 @@ fn is_name_shaped(s: &str) -> bool {pub fn definition(s: &str) -> Option<(&str, &str)> {let (name, rhs) = s.split_once('=')?;let name = name.trim();- is_name_shaped(name).then(|| (name, rhs.trim()))+ let rhs = rhs.trim();+ // `w == 3` is not a definition: a second `=` would read as a formula marker (#4681).+ (is_name_shaped(name) && !rhs.starts_with('=')).then_some((name, rhs))}/// The length unit of a design with these units: `mm` unless they name another length unit.@@ -1252,8 +1260,6 @@ mod tests {("szerokość = 20", "szerokość", "20"),// Reserved names split too: the parameter check names the reason.("mm = 5", "mm", "5"),- // A second `=` stays in the expression, which then fails to evaluate.- ("w == 3", "w", "= 3"),("w = a = 3", "w", "a = 3"),// An empty expression is the caller's error to report.("w =", "w", ""),@@ -1262,7 +1268,7 @@ mod tests {for (text, name, rhs) in splits {assert_eq!(definition(text), Some((name, rhs)), "{text:?}");}- for text in ["20", "20 mm", "width / 2", "= 20", "=", "", "2w = 3", "a b = 3", "a-b = 3", "w.x = 3", "(w) = 3", "-w = 3"] {+ for text in ["20", "20 mm", "width / 2", "= 20", "=", "", "2w = 3", "a b = 3", "a-b = 3", "w.x = 3", "(w) = 3", "-w = 3", "w == 3"] {assert_eq!(definition(text), None, "{text:?}");}}diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rsindex c9dc74e023..d5b5f57c4e 100644--- a/crates/engine/src/cmd/sketch_modify_tests.rs+++ b/crates/engine/src/cmd/sketch_modify_tests.rs@@ -1871,3 +1871,25 @@ fn fillet_refuses_an_offsets_corners_until_its_association_is_broken() {assert!((sk.radius(ai).unwrap() - 2.0).abs() < 1e-7);}}++/// #4681: a fillet radius typed as `=name` (a leading equals sign, as in a spreadsheet) is the+/// expression after the sign, so it can follow a parameter.+#[test]+fn fillet_radius_accepts_a_leading_equals_sign() {+ let mut s = new_sketch();+ run(&mut s, "sketch.line", json!({"points": [[0, 0], [50, 0], [50, 30], [0, 30]], "closed": true, "ids": ["a", "b", "c", "d"]}));+ let first = run(&mut s, "sketch.fillet", json!({"point": "a.end", "radius": 4}));+ let pname = first["param"].as_str().unwrap().to_string();+ let second = run(&mut s, "sketch.fillet", json!({"point": "b.end", "radius": format!("={pname}")}));+ let sk = sketch(&s);+ let arc = ids(&second["curves"])[0].clone();+ let ai = sk.curve_index(&arc).unwrap();+ assert!((sk.radius(ai).unwrap() - 4.0).abs() < 1e-7);+ // Changing the parameter moves both fillets.+ run(&mut s, "parameters.change", json!({"name": pname, "expression": "6 mm"}));+ let sk = sketch(&s);+ let ai = sk.curve_index(&arc).unwrap();+ assert!((sk.radius(ai).unwrap() - 6.0).abs() < 1e-7);+ let plain = run(&mut s, "sketch.fillet", json!({"point": "c.end", "radius": "= 2 mm"}));+ assert!(plain["curves"].is_array());+}