Sketch Fillet: 3D sketch lines are not offered and say they can't be filleted yet (#4160) (#4177)

* claim: #4160

* Sketch Fillet: 3D sketch lines are not offered, and say they can't be filleted (#4160)

The Fillet tool offered 3D sketch lines as picks, and sketch.fillet then
refused them with "`a` must be a line". The tool no longer offers them, and
the command refuses them with "not supported yet: filleting 3D sketch lines".

* Sketch Fillet and Chamfer: refuse all spatial sketch curves (#4160)

* Sketch corner test: give the picked curve its point (#4160)

main added a point to sketch-curve hits after this branch was written.
This commit is contained in:
raykholo
2026-10-29 07:22:53 +00:00
committed by GitHub
parent d2fcab8432
commit aee57875f5
5 changed files with 86 additions and 0 deletions
+10
View File
@@ -1404,6 +1404,14 @@ fn weld_corner(sk: &mut Sketch, p: &Value) {
}
}
fn refuse_spatial_corner(sk: &Sketch, p: &Value, cmd: &str) -> Result<()> {
if ["a", "b"].iter().any(|key| str_(p, key).is_some_and(|id| sk.is_spatial_corner_curve(id))) {
let action = if cmd == "sketch.fillet" { "filleting" } else { "chamfering" };
return Err(bad(cmd, format!("not supported yet: {action} 3D or linked sketch curves")));
}
Ok(())
}
/// Fillets and chamfers refuse a corner on an infinite line (#1359): it has no end there.
fn refuse_infinite_corner(sk: &Sketch, p: &Value, cmd: &str) -> Result<()> {
let infinite = |c: Option<usize>| c.and_then(|c| sk.curves.get(c)).is_some_and(|c| c.infinite);
@@ -1661,6 +1669,7 @@ fn kept_json(kept: Vec<CornerKept>) -> (Vec<String>, Vec<String>) {
/// Round one corner (`point` or `a`, `b`) with an arc of radius `r` tangent to both curves:
/// the arc, the tangent constraints and what became of the corner point.
fn fillet_corner(sk: &mut Sketch, p: &Value, r: f64, cmd: &str) -> Result<(usize, Vec<String>, CornerKept)> {
refuse_spatial_corner(sk, p, cmd)?;
refuse_infinite_corner(sk, p, cmd)?;
refuse_offset_corner(sk, p, cmd)?;
weld_corner(sk, p);
@@ -1772,6 +1781,7 @@ fn round_corner(sk: &mut Sketch, p: &Value, r: f64, cmd: &str) -> Result<Option<
fn chamfer(s: &mut Session, p: &Value, cmd: &str, dists: impl FnOnce(f64) -> Result<(f64, f64)>) -> Result<Value> {
let (out, info) = edit(s, p, cmd, false, |sk, _| {
refuse_spatial_corner(sk, p, cmd)?;
refuse_infinite_corner(sk, p, cmd)?;
refuse_offset_corner(sk, p, cmd)?;
weld_corner(sk, p);
@@ -3238,3 +3238,31 @@ fn mirror_origin_axis_in_rotated_plane_reuses_projection_and_rejects_invalid_lin
assert_eq!(s.doc.to_json(), before);
}
}
#[test]
fn corner_tools_refuse_all_spatial_curves_with_an_unsupported_message() {
let mut s = Session::default();
run(&mut s, "solid.sphere", json!({"radius":20}));
run(&mut s, "sketch.create", json!({"plane":"XY", "offset":50}));
run(&mut s, "sketch.line", json!({"points":[[-10,0],[10,0]],"ids":["source"]}));
run(&mut s, "sketch.finish", json!({}));
let src = s.doc.features.last().unwrap().id;
run(&mut s, "sketch.create", json!({"plane":"XY"}));
let projected = run(&mut s, "sketch.project_to_surface", json!({"curves":[{"sketch":src,"curve":"source"}],"face":[0,0,20]}));
let linked = projected["links"][0]["wires"][0].as_str().unwrap().to_owned();
run(&mut s, "sketch.options", json!({"sketch_3d":true}));
let line = ids(&run(&mut s, "sketch.line3d", json!({"points":[[0,0,0],[20,0,20]]}))["curves"])[0].clone();
let spline = ids(&run(&mut s, "sketch.spline3d", json!({"points":[[0,0,0],[10,5,10],[20,0,20]]}))["curves"])[0].clone();
run(&mut s, "sketch.line", json!({"points":[[0,0],[0,20]],"ids":["side"]}));
let before = s.doc.to_json();
for cmd in ["sketch.fillet", "sketch.chamfer.equal_distance", "sketch.chamfer.two_distance", "sketch.chamfer.distance_angle"] {
let action = if cmd == "sketch.fillet" { "filleting" } else { "chamfering" };
for wire in [&line, &spline, &linked] {
for (a, b) in [(wire.as_str(), "side"), ("side", wire.as_str())] {
let error = s.execute(cmd, &json!({"a":a,"b":b,"radius":2,"distance":2,"distance2":3,"angle":45})).unwrap_err().to_string();
assert!(error.contains(&format!("not supported yet: {action} 3D or linked sketch curves")), "{cmd}: {error}");
assert_eq!(s.doc.to_json(), before);
}
}
}
}
+6
View File
@@ -267,6 +267,12 @@ impl Sketch {
WireSpace::from_legacy_link(link)
}
/// Whether a curve is reference geometry that planar corner tools cannot modify.
/// Shared by command validation and the Fillet/Chamfer pick filters.
pub fn is_spatial_corner_curve(&self, id: &str) -> bool {
self.wire_index(id).is_some()
}
pub fn wire_index(&self, id: &str) -> Option<usize> {
self.wires.iter().position(|w| w.id == id)
}
@@ -925,3 +925,36 @@ fn centre_circle_on_an_existing_point_is_tied_by_a_coincident() {
.any(|k| matches!(k.kind, ConstraintKind::Coincident { p, q } if (p, q) == (corner, centre) || (p, q) == (centre, corner)));
assert!(tied, "a Coincident ties the centre to the corner: {:?}", sk.constraints);
}
#[test]
fn corner_candidates_agree_with_engine_spatial_curve_filter() {
use crate::sketch_modify_ui::candidate;
use crate::viewport::Hit;
let mut h = crate::scenario::Harness::new();
h.app.run("solid.sphere", json!({"radius":20})).unwrap();
h.app.run("sketch.create", json!({"plane":"XY", "offset":50})).unwrap();
h.app.run("sketch.line", json!({"points":[[-10,0],[10,0]],"ids":["source"]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
let src = h.app.session.doc.features.last().unwrap().id;
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
let projected = h.app.run("sketch.project_to_surface", json!({"curves":[{"sketch":src,"curve":"source"}],"face":[0,0,20]})).unwrap();
let linked = projected["links"][0]["wires"][0].as_str().unwrap().to_owned();
h.app.run("sketch.options", json!({"sketch_3d":true})).unwrap();
let line = h.app.run("sketch.line3d", json!({"points":[[0,0,0],[20,0,20]]})).unwrap()["curves"][0].as_str().unwrap().to_owned();
let spline = h.app.run("sketch.spline3d", json!({"points":[[0,0,0],[10,5,10],[20,0,20]]})).unwrap()["curves"][0].as_str().unwrap().to_owned();
h.app.run("sketch.line", json!({"points":[[0,0],[0,20]],"ids":["side"]})).unwrap();
let sketch = h.app.session.active_sketch.unwrap();
for cmd in ["sketch.fillet", "sketch.chamfer.equal_distance", "sketch.chamfer.two_distance", "sketch.chamfer.distance_angle"] {
h.app.start(cmd);
for id in [&line, &spline, &linked, &"side".to_owned()] {
let state = h.app.session.world_state();
let sk = &state.sketch(sketch).unwrap().sketch;
let hit = Hit::SketchCurve { sketch, id: id.clone(), straight: true, point: solidcraft_engine::geom::Vec3::ZERO };
let offered = candidate(h.app.dialog.as_ref().unwrap(), &h.app.session, &hit).is_some();
assert_eq!(offered, !sk.is_spatial_corner_curve(id), "{cmd}: {id}");
assert_eq!(offered, id == "side", "{cmd}: {id}");
}
h.app.dialog = None;
}
}
+9
View File
@@ -256,6 +256,15 @@ pub fn candidate(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) ->
let active = session.active_sketch?;
match hit {
Hit::SketchCurve { sketch, .. } | Hit::SketchPoint { sketch, .. } if *sketch != active => None,
Hit::SketchCurve { id, .. } if matches!(d.kind, Kind::SketchModify(Mod::Corner { .. })) => {
let state = session.world_state();
let sk = &state.sketch(active)?.sketch;
if sk.is_spatial_corner_curve(id) {
return None;
}
sk.curve_index(id)?;
d.active_input()?.accepts(hit, Some(active), |_, _| false)
}
_ => d.active_input()?.accepts(hit, Some(active), |_, _| false),
}
}