Sketch: a fillet stays the arc of its corner when the corner mirrors or a line is dragged through it (#5677)

A line tangent to an arc at the arc's end had no sense: the tangency held
with the line on either side of its touch point, so pinning a line's far
end across the corner left the line cutting back through its fillet, and
when the solver found the mirrored corner the arc kept its stored
direction and became its three-quarter complement, inside out.

The solver now keeps each fillet an arc of its corner. A line tangent at an
arc's end keeps its sense there (it leaves the arc as it did) and the arc
its side of its chord, compared with the positions before an interactive
move or the stored ones. A corner that mirrored gets its arc on the
mirrored side: its ends swapped where the solve ran the arc round the
other way with the lines following, or the arc reflected across the line
that stayed and solved again where a line cut back through. A solve that
would loop the arc the other way round, or fold a line onto it, is refused
as a fold is. A drag's cursor-following steps keep the fillets too, so a
line dragged through its own fillet stops at the arc.
This commit is contained in:
Kai Evans
2026-10-26 10:42:41 +00:00
committed by GitHub
parent 9d0b509961
commit 41a938e731
5 changed files with 399 additions and 8 deletions
+1 -1
View File
@@ -294,7 +294,7 @@ pub(super) fn drag_entity(
let valid = |before: &Sketch, after: &Sketch| {
let mut geometry = Geometry::default();
geometry.take(before);
!geometry.sweep_wrapped(after)
!geometry.sweep_wrapped(after) && solidcraft_sketch::fillets_kept(before, after)
};
let followed = match (e, line_grab) {
(Ent::Point(q), _) => solidcraft_sketch::move_point_towards(sk, q, to, max_step, frame.as_mut(), valid),
@@ -2492,3 +2492,50 @@ fn freeform_chain_offsets_take_the_straight_pieces_of_the_chain_along() {
assert!(!curves.is_empty(), "{out}");
certified(&s, &curves);
}
/// The arc's counter-clockwise sweep from its stored start to its end, degrees, from `sketch.inspect`.
fn arc_sweep_deg(si: &Value, id: &str) -> f64 {
let c = si["curves"].as_array().unwrap().iter().find(|c| c["id"] == id).unwrap();
let at = |k: &str| Vec2::new(c[k][0].as_f64().unwrap(), c[k][1].as_f64().unwrap());
let (centre, a, b) = (at("center_at"), at("start_at"), at("end_at"));
((b - centre).angle() - (a - centre).angle()).rem_euclid(std::f64::consts::TAU).to_degrees()
}
#[test]
fn a_fillet_stays_a_quarter_arc_when_its_corner_is_pinned_or_dragged_to_the_other_side() {
let mut s = new_sketch();
run(&mut s, "sketch.line", json!({"points": [[10, 10], [40, 10], [40, 30]]}));
let f = run(&mut s, "sketch.fillet", json!({"point": "l1.end", "radius": 5}));
let arc = ids(&f["curves"])[0].clone();
run(&mut s, "sketch.constraint.horizontal_vertical", json!({"line": "l1"}));
run(&mut s, "sketch.constraint.horizontal_vertical", json!({"line": "l2"}));
let curve = |si: &Value, id: &str| si["curves"].as_array().unwrap().iter().find(|c| c["id"] == id).unwrap().clone();
// Pin the vertical line's far end below the horizontal line: the corner mirrors, and the
// fillet is the quarter arc inside the mirrored corner (its lines leave it, none cuts
// through it).
run(&mut s, "sketch.point", json!({"point": [40, -20], "id": "q"}));
run(&mut s, "sketch.constraint.fix", json!({"entity": "q"}));
run(&mut s, "sketch.constraint.coincident", json!({"a": "l2.end", "b": "q"}));
let si = run(&mut s, "sketch.inspect", json!({}));
assert!((arc_sweep_deg(&si, &arc) - 90.0).abs() < 1e-6, "{}", arc_sweep_deg(&si, &arc));
assert_eq!(curve(&si, &arc)["center_at"], json!([35.0, 5.0]), "{}", curve(&si, &arc));
assert_eq!(curve(&si, "l2")["start_at"], json!([40.0, 5.0]), "{}", curve(&si, "l2"));
// Dragging the horizontal line's far end through the corner would push the line through its
// fillet: the drag stops at the arc.
let d = run(&mut s, "sketch.drag", json!({"entity": "l1.start", "from": [10, 10], "to": [70, 10]}));
assert!(d["reached"].as_f64().unwrap() < 0.5, "{d}");
let si = run(&mut s, "sketch.inspect", json!({}));
let l1 = curve(&si, "l1");
assert!(l1["start_at"][0].as_f64().unwrap() <= 35.0 + 1e-6, "{l1}");
assert!((arc_sweep_deg(&si, &arc) - 90.0).abs() < 1e-6, "{}", arc_sweep_deg(&si, &arc));
assert_eq!(curve(&si, &arc)["center_at"], json!([35.0, 5.0]), "{}", curve(&si, &arc));
// Pinned on the far side instead, the corner mirrors again and the fillet follows.
run(&mut s, "sketch.point", json!({"point": [70, 10], "id": "r"}));
run(&mut s, "sketch.constraint.fix", json!({"entity": "r"}));
run(&mut s, "sketch.constraint.coincident", json!({"a": "l1.start", "b": "r"}));
let si = run(&mut s, "sketch.inspect", json!({}));
assert!((arc_sweep_deg(&si, &arc) - 90.0).abs() < 1e-6, "{}", arc_sweep_deg(&si, &arc));
assert_eq!(curve(&si, &arc)["center_at"], json!([45.0, 5.0]), "{}", curve(&si, &arc));
assert_eq!(curve(&si, "l1")["end_at"], json!([45.0, 10.0]), "{}", curve(&si, "l1"));
assert_eq!(curve(&si, "l2")["start_at"], json!([40.0, 5.0]), "{}", curve(&si, "l2"));
}