Sketch corners: a corner cut is refused where two lines lie in line, as rounding is (#8802)

Chamfer at a corner of two lines lying on each other cut both back and
added a line of no length between their ends; lines in line with each
other have no corner either. chamfer now refuses a corner angle of 0 or
180 degrees with Fillet's message, "the lines are parallel" (found by a
local trim fuzzer).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-10-29 11:49:31 +00:00
committed by GitHub
parent dd6a91533d
commit 6a183cce02
2 changed files with 26 additions and 0 deletions
@@ -97,6 +97,26 @@ fn fillet_and_chamfer_corners() {
assert!((area(&s) - (a0 - 8.0)).abs() < 1e-6, "{}", area(&s));
}
/// A chamfer where the two lines have no corner is refused, as a fillet there is: two lines
/// lying on each other made a chamfer line of no length between their cut-back ends (found by a
/// local trim fuzzer), and two lines in line with each other have no corner either.
#[test]
fn a_chamfer_where_two_lines_lie_in_line_is_refused() {
for far in [[0, 10], [0, 30]] {
let mut s = new_sketch();
let a = curves(&run(&mut s, "sketch.line", json!({"points": [[0, 0], [0, 20]], "infer": false})))[0].clone();
let b = curves(&run(&mut s, "sketch.line", json!({"points": [far, [0, 20]], "infer": false, "connect": false})))[0].clone();
run(&mut s, "sketch.constraint.coincident", json!({"a": format!("{a}.end"), "b": format!("{b}.end")}));
let n = sk(&s).curves.len();
for cmd in ["sketch.chamfer.equal_distance", "sketch.fillet"] {
let p = if cmd == "sketch.fillet" { json!({"a": a, "b": b, "radius": 2}) } else { json!({"a": a, "b": b, "distance": 2}) };
let e = s.execute(cmd, &p).unwrap_err().to_string();
assert!(e.contains("parallel"), "{cmd} at {far:?}: {e}");
assert_eq!(sk(&s).curves.len(), n, "{cmd} at {far:?}");
}
}
}
/// The ids of the constraints driven by the model parameter `name`.
fn driven_by(s: &Session, name: &str) -> Vec<String> {
sk(s).constraints.iter().filter(|c| c.param.as_deref() == Some(name)).map(|c| c.id.clone()).collect()
+6
View File
@@ -1789,6 +1789,12 @@ fn chamfer(s: &mut Session, p: &Value, cmd: &str, dists: impl FnOnce(f64) -> Res
let (pc, pa, pb) = (sk.point(c).unwrap_or_default(), sk.point(fa).unwrap_or_default(), sk.point(fb).unwrap_or_default());
let (u, v) = ((pa - pc).normalized().unwrap_or(Vec2::X), (pb - pc).normalized().unwrap_or(Vec2::Y));
let corner_angle = u.cross(v).atan2(u.dot(v)).abs();
// Lines in line with each other, or lying on each other, have no corner to cut, as a
// fillet refuses them: on two lines lying on each other the chamfer was a line of no
// length between their cut-back ends.
if !(2e-6..=std::f64::consts::PI - 2e-9).contains(&corner_angle) {
return Err(bad(cmd, "the lines are parallel"));
}
let (da, db) = dists(corner_angle)?;
let (ta, tb, _, kept) = cut_corner(sk, la, lb, c, fa, fb, da, db, cmd)?;
let l = sk.add_line_pts(ta, tb, None)?;