Sketch: an end held on a removed curve where another curve ends stays tied (#8779)

A trimmed circle ended on a line exactly where an arc started on that
line, held there by a point-on-curve tie. Trimming the line away dropped
the tie and left the two ends on one spot, untied. remove_curves now ties
each point held on a removed curve at one of its ends to that end before
the curve goes (found by a local trim fuzzer, 15 -> 12 cases in 2000
seeds).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-10-29 11:07:28 +00:00
committed by GitHub
parent 63f053e4fe
commit cf86f18c11
2 changed files with 55 additions and 0 deletions
@@ -2492,6 +2492,26 @@ fn ends_tied_through_a_trimmed_away_end_stay_tied() {
assert!(at("l1.end").dist(at("l2.start")) < 1e-9);
}
/// An end held on a line exactly where that line meets another curve stays tied to it when a
/// trim takes the line away (found by the local trim fuzzer: a trimmed circle ended on a line
/// where a fillet started, and trimming the line left the circle's end loose on the fillet's).
#[test]
fn an_end_held_on_a_trimmed_away_line_at_its_end_stays_tied() {
let mut s = new_sketch();
run(&mut s, "sketch.line", json!({"points": [[0, 0], [10, 0], [10, 10]], "infer": false}));
run(&mut s, "sketch.line", json!({"points": [[20, 5], [10, 0]], "infer": false, "connect": false}));
run(&mut s, "sketch.constraint.coincident", json!({"a": "l3.end", "b": "l2"}));
assert!(solidcraft_sketch::loose_ends(&sketch(&s)).untied.is_empty());
let r = run(&mut s, "sketch.trim", json!({"curve": "l2", "at": [10, 5]}));
assert_eq!(r["result"]["deleted"], "l2");
let ends = solidcraft_sketch::loose_ends(&sketch(&s));
assert!(ends.untied.is_empty(), "l1 and l3 still meet at (10, 0): {ends:?}");
run(&mut s, "sketch.drag", json!({"entity": "l1.end", "from": [10, 0], "to": [12, 1]}));
let sk = sketch(&s);
let at = |r: &str| sk.point(sk.resolve_point(r).unwrap()).unwrap();
assert!(at("l1.end").dist(at("l3.end")) < 1e-9);
}
#[test]
fn trim_keeps_the_rest_of_a_dimensioned_line_where_it_was() {
// A 40 x 40 square, its right side dimensioned with the Dimension tool (a line length).
+35
View File
@@ -1599,7 +1599,12 @@ impl Sketch {
owned.extend(c.kind.point_ids());
}
}
let on_ends = self.points_on_ends_of(which);
self.drop_curves(which);
for (p, q) in on_ends {
// Only a full sketch refuses one more; the point then comes loose as before.
let _ = self.add_constraint(ConstraintKind::Coincident { p, q }, None);
}
let mut orphans: Vec<usize> = owned.into_iter().filter(|p| *p != 0 && !self.point_used_by_curve(*p)).collect();
orphans.sort_unstable();
orphans.dedup();
@@ -1609,6 +1614,36 @@ impl Sketch {
self.prune_patterns();
}
/// Points held on one of the curves `which` exactly at one of its ends, and that end: a point
/// on a curve at its end meets whatever else ends there, so when the curve goes the two are
/// tied instead of coming apart (a trimmed circle ending on a line where a fillet starts kept
/// its end there only through the line). Pairs already in one coincident group are left out.
fn points_on_ends_of(&self, which: &[usize]) -> Vec<(usize, usize)> {
let mut groups: Vec<usize> = (0..self.points.len()).collect();
for c in &self.constraints {
if let ConstraintKind::Coincident { p, q } = c.kind
&& p < groups.len()
&& q < groups.len()
{
union(&mut groups, p, q);
}
}
let mut pairs = Vec::new();
for k in &self.constraints {
let ConstraintKind::PointOnCurve { p, c } = k.kind else { continue };
let Some((a, b)) = which.contains(&c).then(|| self.curves.get(c).and_then(|k| k.kind.ends())).flatten() else { continue };
let Some(at) = self.point(p) else { continue };
for end in [a, b] {
let Some(e) = self.point(end) else { continue };
if end != p && at.dist(e) <= crate::END_TOL && find(&mut groups, p) != find(&mut groups, end) {
union(&mut groups, p, end);
pairs.push((p, end));
}
}
}
pairs
}
/// Points held together only through points about to go stay together: two rectangles'
/// corners made coincident with one arc end are tied to each other when a trim takes that
/// end away, instead of coming apart where they still meet.