Sketch: points tied only through a removed curve's end stay tied (#8640)
* Sketch: points tied only through a removed curve's end stay tied Removing a curve removed its orphaned end points with their constraints, so two points made coincident with such an end lost their tie although they still met: two rectangles' corners on one arc end came apart when the arc was trimmed. They are now tied to each other before the point goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sketch: keep the tie test with the other trim tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2468,6 +2468,30 @@ fn several_texts_edit_in_one_rebuild() {
|
||||
assert!((v1 / v0 - 2.0).abs() < 0.05, "two bars per label now: {v0} -> {v1}");
|
||||
}
|
||||
|
||||
/// Two ends tied to each other only through a third curve's end stay tied when a trim takes
|
||||
/// that curve away: they still meet there (found by a local trim fuzzer: two rectangles'
|
||||
/// corners made coincident with one arc end came apart when the arc was trimmed).
|
||||
#[test]
|
||||
fn ends_tied_through_a_trimmed_away_end_stay_tied() {
|
||||
let mut s = new_sketch();
|
||||
for (a, b) in [([0, 0], [10, 0]), ([10, 0], [10, 10]), ([10, 0], [20, 5])] {
|
||||
run(&mut s, "sketch.line", json!({"points": [a, b], "infer": false, "connect": false}));
|
||||
}
|
||||
run(&mut s, "sketch.constraint.coincident", json!({"a": "l1.end", "b": "l3.start"}));
|
||||
run(&mut s, "sketch.constraint.coincident", json!({"a": "l2.start", "b": "l3.start"}));
|
||||
assert!(solidcraft_sketch::loose_ends(&sketch(&s)).untied.is_empty());
|
||||
let r = run(&mut s, "sketch.trim", json!({"curve": "l3", "at": [15, 2.5]}));
|
||||
assert_eq!(r["result"]["deleted"], "l3");
|
||||
let sk = sketch(&s);
|
||||
let ends = solidcraft_sketch::loose_ends(&sk);
|
||||
assert!(ends.untied.is_empty(), "l1 and l2 still meet at (10, 0): {ends:?}");
|
||||
// Tied, not merely touching: dragging one end takes the other along.
|
||||
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("l2.start")) < 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).
|
||||
|
||||
@@ -1603,11 +1603,52 @@ impl Sketch {
|
||||
let mut orphans: Vec<usize> = owned.into_iter().filter(|p| *p != 0 && !self.point_used_by_curve(*p)).collect();
|
||||
orphans.sort_unstable();
|
||||
orphans.dedup();
|
||||
self.keep_ties_through(&orphans);
|
||||
self.remove_points(&orphans);
|
||||
self.prune_links();
|
||||
self.prune_patterns();
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn keep_ties_through(&mut self, gone: &[usize]) {
|
||||
if gone.is_empty() {
|
||||
return;
|
||||
}
|
||||
let gone: std::collections::BTreeSet<usize> = gone.iter().copied().collect();
|
||||
let n = self.points.len();
|
||||
// Coincident groups with every point, and with the points that stay only.
|
||||
let (mut all, mut kept): (Vec<usize>, Vec<usize>) = ((0..n).collect(), (0..n).collect());
|
||||
for c in &self.constraints {
|
||||
if let ConstraintKind::Coincident { p, q } = c.kind {
|
||||
union(&mut all, p, q);
|
||||
if !gone.contains(&p) && !gone.contains(&q) {
|
||||
union(&mut kept, p, q);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut first = std::collections::BTreeMap::<usize, usize>::new();
|
||||
let mut ties = Vec::new();
|
||||
for x in (0..n).filter(|x| !gone.contains(x)) {
|
||||
let group = find(&mut all, x);
|
||||
match first.get(&group).copied() {
|
||||
None => {
|
||||
first.insert(group, x);
|
||||
}
|
||||
Some(f) if find(&mut kept, f) != find(&mut kept, x) => {
|
||||
union(&mut kept, f, x);
|
||||
ties.push((f, x));
|
||||
}
|
||||
Some(_) => {}
|
||||
}
|
||||
}
|
||||
for (p, q) in ties {
|
||||
// Only a full sketch refuses one more; the points then come apart as before.
|
||||
let _ = self.add_constraint(ConstraintKind::Coincident { p, q }, None);
|
||||
}
|
||||
}
|
||||
|
||||
fn point_used_by_curve(&self, p: usize) -> bool {
|
||||
self.curves.iter().any(|c| c.kind.uses(p))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user