SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: an old edge-on projection keeps its line when it is re-resolved (#9025) (#9097)
Logan Night5a24d4095ab3
diff --git a/crates/sketch/src/link.rs b/crates/sketch/src/link.rsindex 994f73350b..dbdb8cc5fc 100644--- a/crates/sketch/src/link.rs+++ b/crates/sketch/src/link.rs@@ -1063,6 +1063,26 @@ impl Sketch {}return Ok(false);}+ // A face seen edge-on was once saved as two lines on the same two points, one each way;+ // it is one line now. Keep the first line (an offset or a constraint may name it) and+ // drop only the second, instead of rebuilding both under new ids.+ if let Some([LCurve::Line(0, 1), LCurve::Line(1, 0)]) = cur.as_deref()+ && let [LCurve::Line(0, 1)] = new.as_slice()+ && let [_, second] = curves[..]+ && let [p0, p1] = points[..]+ && lay.lone.is_empty()+ && let Some(a) = order.first().and_then(|li| lay.pts.get(*li)).copied()+ && let Some(b) = order.get(1).and_then(|li| lay.pts.get(*li)).copied()+ {+ if let Some(p) = self.points.get_mut(p0) {+ p.pos = a;+ }+ if let Some(p) = self.points.get_mut(p1) {+ p.pos = b;+ }+ self.remove_curves(&[second]);+ return Ok(true);+ }// Rebuild: drop the old entities (constraints on them go too) and make new ones.self.drop_link_entities(id);self.build_link(id, &lay)?;diff --git a/crates/sketch/src/link_identity_tests.rs b/crates/sketch/src/link_identity_tests.rsindex 9240bbaf91..bfa5118543 100644--- a/crates/sketch/src/link_identity_tests.rs+++ b/crates/sketch/src/link_identity_tests.rs@@ -374,3 +374,52 @@ fn linked_conic_curves_take_the_n_prefix_not_the_constraints_k() {let ids: Vec<String> = sk.link_curves(&link).iter().map(|c| sk.curves[*c].id.clone()).collect();assert_eq!(ids, vec!["l1".to_string(), "n1".to_string()], "linked curve ids");}++/// A face seen edge-on was saved as two lines on the same two points, one each way, and is one+/// line now. Re-resolving it must not give the first line a new id: an offset names it as its+/// source, and lost it ("an offset source vanished or changed shape").+#[test]+fn edge_on_face_saved_as_a_line_pair_keeps_the_line_an_offset_follows() {+ let (a, b) = (Vec2::new(5.0, 5.0), Vec2::new(15.0, 5.0));+ let mut sk = Sketch::new();+ // `add_link` makes one line of a reversed pair, so lay the pair out the way a saved file has it.+ let link = "j1".to_string();+ let (pa, pb) = (sk.add_point(a, None).unwrap(), sk.add_point(b, None).unwrap());+ for (from, to, id) in [(pa, pb, "l1"), (pb, pa, "l2")] {+ let c = sk.add_line_pts(from, to, Some(id)).unwrap();+ sk.curves[c].link = Some(link.clone());+ }+ for point in [pa, pb] {+ sk.points[point].link = Some(link.clone());+ }+ sk.links.push(Link {+ id: link.clone(),+ kind: LinkKind::Project,+ source: face(),+ face_name: None,+ edge_name: None,+ auto_face: false,+ lost: false,+ });+ let ids: Vec<String> = sk.link_curves(&link).iter().map(|c| sk.curves[*c].id.clone()).collect();+ assert_eq!(ids.len(), 2, "the saved link holds the pair");+ let (p, q) = (sk.add_point(Vec2::new(5.0, 3.0), None).unwrap(), sk.add_point(Vec2::new(15.0, 3.0), None).unwrap());+ let out = sk.add_line_pts(p, q, None).unwrap();+ let out_id = sk.curves[out].id.clone();+ sk.offsets.push(crate::offset::OffsetChain {+ sources: vec![(ids[0].clone(), true)],+ outputs: vec![out_id],+ distance: -2.0,+ closed: false,+ topology: None,+ });+ sk.refresh_offsets().unwrap();++ sk.update_link(&link, &[LinkGeom::Line(a, Vec2::new(17.0, 5.0))]).unwrap();++ let kept: Vec<String> = sk.link_curves(&link).iter().map(|c| sk.curves[*c].id.clone()).collect();+ assert_eq!(kept, vec![ids[0].clone()], "the first line keeps its id");+ sk.refresh_offsets().unwrap();+ let end = sk.points[sk.link_points(&link)[1]].pos;+ assert_eq!(end, Vec2::new(17.0, 5.0), "the line moved to the new geometry");+}