Wave 464/509: Sketch: a control spline can carry its own knots and weights (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - b16e8a542 jyviko: Sketch: a control spline can carry its own knots and weights - e6abea809 jyviko: Sketch projection: a free-form edge comes in as the one exact spline it is - f61f25c7f jyviko: Fillet rig: blends past an outer rim of their faces build, on SMLib smlib-blends-past-rims - 09bc14dbd jyviko: Naming: test that a round of a round's end has no seam with that round's faces Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
@@ -186,7 +186,17 @@ fn sketch_json(s: &Session, world: &solidcraft_doc::ModelState, id: u64) -> Opti
|
||||
CurveKind::Circle { c: cc, r } => json!({"id": c.id, "type": "circle", "center": pid(cc), "center_at": sk.point(cc), "radius": r, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Arc { c: cc, a, b } => json!({"id": c.id, "type": "arc", "center": pid(cc), "start": pid(a), "end": pid(b), "center_at": sk.point(cc), "start_at": sk.point(a), "end_at": sk.point(b), "radius": sk.radius(i), "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Ellipse { c: cc, m, r } => json!({"id": c.id, "type": "ellipse", "center": pid(cc), "major": pid(m), "center_at": sk.point(cc), "major_at": sk.point(m), "minor_radius": r, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Spline { ref pts, control, degree, periodic } => json!({"id": c.id, "type": "spline", "points": pts.iter().map(|q| pid(*q)).collect::<Vec<_>>(), "points_at": pts.iter().map(|q| sk.point(*q)).collect::<Vec<_>>(), "control": control, "degree": degree, "periodic": periodic, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
CurveKind::Spline { ref pts, control, degree, periodic, ref nurbs } => {
|
||||
let mut v = json!({"id": c.id, "type": "spline", "points": pts.iter().map(|q| pid(*q)).collect::<Vec<_>>(), "points_at": pts.iter().map(|q| sk.point(*q)).collect::<Vec<_>>(), "control": control, "degree": degree, "periodic": periodic, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det});
|
||||
// A control spline with its own knots (a projected free-form edge) says them.
|
||||
if let (Some(n), Some(o)) = (nurbs, v.as_object_mut()) {
|
||||
o.insert("knots".into(), json!(n.knots));
|
||||
if !n.weights.is_empty() {
|
||||
o.insert("weights".into(), json!(n.weights));
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
CurveKind::Conic { a, b, apex, rho } => json!({"id": c.id, "type": "conic", "start": pid(a), "end": pid(b), "apex": pid(apex), "start_at": sk.point(a), "end_at": sk.point(b), "apex_at": sk.point(apex), "rho": rho, "construction": c.construction, "fixed": sk.curve_locked(i), "fully_constrained": det}),
|
||||
};
|
||||
if let (Some(l), Some(o)) = (&c.link, v.as_object_mut()) {
|
||||
|
||||
@@ -505,7 +505,7 @@ fn blend(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (sp, cons) = if order <= 1 {
|
||||
let c1 = sk.add_point(qa + ta * (l / 3.0), None)?;
|
||||
let c2 = sk.add_point(qb + tb * (l / 3.0), None)?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts: vec![pa, c1, c2, pb], control: true, degree: 3, periodic: false }, None)?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts: vec![pa, c1, c2, pb], control: true, degree: 3, periodic: false, nurbs: None }, None)?;
|
||||
let cons = vec![add_c(sk, ConstraintKind::Tangent { a: ca, b: sp })?, add_c(sk, ConstraintKind::Tangent { a: cb, b: sp })?];
|
||||
(sp, cons)
|
||||
} else {
|
||||
@@ -527,7 +527,7 @@ fn blend(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
});
|
||||
}
|
||||
let degree = u8::try_from(cps.len().saturating_sub(1)).map_err(|_| bad(cmd, "the blend curve needs too many control points"))?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts, control: true, degree, periodic: false }, None)?;
|
||||
let sp = sk.add_curve(CurveKind::Spline { pts, control: true, degree, periodic: false, nurbs: None }, None)?;
|
||||
(sp, Vec::new())
|
||||
};
|
||||
solve_new_only(sk, first_new);
|
||||
@@ -655,7 +655,7 @@ fn spline(s: &mut Session, p: &Value, cmd: &str, control: bool, degree: u8) -> R
|
||||
{
|
||||
pts.push(*pts.first().ok_or_else(|| bad(cmd, "missing first point"))?);
|
||||
}
|
||||
let c = sk.add_curve(CurveKind::Spline { pts, control, degree, periodic }, None)?;
|
||||
let c = sk.add_curve(CurveKind::Spline { pts, control, degree, periodic, nurbs: None }, None)?;
|
||||
mark_construction(sk, &[c], p);
|
||||
Ok((ids_of(sk, &[c]), Vec::new()))
|
||||
})?;
|
||||
@@ -1344,13 +1344,13 @@ mod blend_tests {
|
||||
let mut broken = solidcraft_sketch::Sketch::new();
|
||||
let p0 = broken.add_point(Vec2::new(1.0, 1.0), None).unwrap();
|
||||
let p1 = broken.add_point(Vec2::ZERO, None).unwrap();
|
||||
let l = broken.add_curve(CurveKind::Spline { pts: vec![p1, p0], control: true, degree: 1, periodic: false }, None).unwrap();
|
||||
let l = broken.add_curve(CurveKind::Spline { pts: vec![p1, p0], control: true, degree: 1, periodic: false, nurbs: None }, None).unwrap();
|
||||
broken.points[p0].pos = Vec2::new(f64::NAN, 4.0);
|
||||
assert!(super::joint_derivatives(&broken, l, p1, 2, true, "a", "sketch.blend_curve").is_err(), "non-finite geometry");
|
||||
let mut flat = solidcraft_sketch::Sketch::new();
|
||||
let q0 = flat.add_point(Vec2::new(3.0, 3.0), None).unwrap();
|
||||
let q1 = flat.add_point(Vec2::new(3.0, 3.0), None).unwrap();
|
||||
let d = flat.add_curve(CurveKind::Spline { pts: vec![q0, q1], control: true, degree: 1, periodic: false }, None).unwrap();
|
||||
let d = flat.add_curve(CurveKind::Spline { pts: vec![q0, q1], control: true, degree: 1, periodic: false, nurbs: None }, None).unwrap();
|
||||
let e = super::joint_derivatives(&flat, d, q0, 2, true, "a", "sketch.blend_curve").unwrap_err().to_string();
|
||||
assert!(e.contains("no tangent"), "{e}");
|
||||
assert!(solidcraft_geom::hermite_bezier(Vec2::ZERO, Vec2::X, &[Vec2::Y; 5], &[Vec2::Y; 5]).is_none(), "no order above g4");
|
||||
|
||||
@@ -156,7 +156,7 @@ fn add_pieces(sk: &mut Sketch, segs: &[Seg2], start: Option<usize>, end: Option<
|
||||
Seg2::Line { .. } => CurveKind::Line { a: prev, b: to },
|
||||
Seg2::Cubic { p1, p2, .. } => {
|
||||
let (c1, c2) = (sk.add_point(p1, None)?, sk.add_point(p2, None)?);
|
||||
CurveKind::Spline { pts: vec![prev, c1, c2, to], control: true, degree: 3, periodic: false }
|
||||
CurveKind::Spline { pts: vec![prev, c1, c2, to], control: true, degree: 3, periodic: false, nurbs: None }
|
||||
}
|
||||
Seg2::Conic { apex, w, .. } => {
|
||||
let x = sk.add_point(apex, None)?;
|
||||
@@ -169,7 +169,7 @@ fn add_pieces(sk: &mut Sketch, segs: &[Seg2], start: Option<usize>, end: Option<
|
||||
pts.push(sk.add_point(*q, None)?);
|
||||
}
|
||||
pts.push(to);
|
||||
CurveKind::Spline { pts, control: true, degree: n, periodic: false }
|
||||
CurveKind::Spline { pts, control: true, degree: n, periodic: false, nurbs: None }
|
||||
}
|
||||
Seg2::Arc { .. } => return Err(bad("trim", "unexpected arc piece")),
|
||||
};
|
||||
|
||||
@@ -101,7 +101,7 @@ pub(super) fn add_geometry(sk: &mut Sketch, geom: &[Geom2], f: &dyn Fn(Vec2) ->
|
||||
idx.push(i);
|
||||
}
|
||||
}
|
||||
(idx.len() >= 2).then_some(CurveKind::Spline { pts: idx, control: *control, degree: *degree, periodic: false })
|
||||
(idx.len() >= 2).then_some(CurveKind::Spline { pts: idx, control: *control, degree: *degree, periodic: false, nurbs: None })
|
||||
}
|
||||
Geom2::Conic { a, apex, b, rho } => {
|
||||
let (a, x, b) = (pt(sk, *a)?, pt(sk, *apex)?, pt(sk, *b)?);
|
||||
|
||||
@@ -1764,7 +1764,7 @@ fn offset_side(sk: &mut Sketch, cmd: &str, order: &[(usize, bool)], sources: &[(
|
||||
idx.push(pb);
|
||||
idx.dedup();
|
||||
if idx.len() >= 2 {
|
||||
made.push(sk.add_curve(CurveKind::Spline { pts: idx, control: false, degree: 3, periodic: false }, None)?);
|
||||
made.push(sk.add_curve(CurveKind::Spline { pts: idx, control: false, degree: 3, periodic: false, nurbs: None }, None)?);
|
||||
}
|
||||
}
|
||||
Piece::Line(..) => {
|
||||
|
||||
@@ -936,3 +936,38 @@ fn intersect_on_a_top_face_gives_its_outline() {
|
||||
let ends = outline(&intersect_curves(&block, json!({"plane": "XY", "offset": 20})).unwrap());
|
||||
assert_eq!(ends, vec![[0.0, 0.0, 0.0, 30.0], [0.0, 0.0, 40.0, 0.0], [0.0, 30.0, 40.0, 30.0], [40.0, 0.0, 40.0, 30.0]]);
|
||||
}
|
||||
|
||||
/// A free-form edge projects as the one exact spline it is, its knots and weights its own: the
|
||||
/// bottom face of a 40 x 20 x 10 box whose upright edges have G2 rounds (each round's bottom
|
||||
/// edge a B-spline of several spans) comes into its sketch as four lines and four splines, one a
|
||||
/// corner, each meeting the lines at their ends (#3604, where each span was a curve of its own).
|
||||
/// The profile they bound, extruded the box's height, is the box: its sides are upright.
|
||||
#[test]
|
||||
fn a_free_form_edge_projects_as_one_spline_with_its_own_knots() {
|
||||
use solidcraft_sketch::CurveKind;
|
||||
let volume = |s: &Session, body: &str| solidcraft_kernel::measure(&s.world_state().unwrap().body(body).unwrap().body).unwrap().volume;
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"corner":[0,0,0],"length":40,"width":20,"height":10,"body_name":"B"}));
|
||||
run(&mut s, "solid.fillet", json!({"body":"B","edges":[[0,0,5],[40,0,5],[40,20,5],[0,20,5]],"radius":5,"type":"g2"}));
|
||||
let id = run(&mut s, "sketch.create", json!({"plane":{"face":[20,10,0]},"project_edges":true,"name":"Bottom"}))["sketch"].as_u64().unwrap();
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
let st = s.model.state();
|
||||
let sketch = &st.sketch(id).unwrap().sketch;
|
||||
let lines = sketch.curves.iter().filter(|c| matches!(c.kind, CurveKind::Line { .. })).count();
|
||||
let splines: Vec<_> = sketch.curves.iter().filter(|c| matches!(c.kind, CurveKind::Spline { .. })).collect();
|
||||
assert_eq!((lines, splines.len(), sketch.curves.len()), (4, 4, 8), "{:?}", sketch.curves);
|
||||
for c in &splines {
|
||||
let CurveKind::Spline { pts, control: true, nurbs: Some(nurbs), .. } = &c.kind else { panic!("{:?}", c.kind) };
|
||||
assert_eq!(nurbs.knots.len(), pts.len() + 4, "a cubic's knots");
|
||||
let (a, b) = c.kind.ends().unwrap();
|
||||
for end in [a, b] {
|
||||
let meets = sketch.curves.iter().filter(|o| matches!(o.kind, CurveKind::Line { a, b } if a == end || b == end)).count();
|
||||
assert_eq!(meets, 1, "{} end {end}", c.id);
|
||||
}
|
||||
}
|
||||
drop(st);
|
||||
let rounded = volume(&s, "B");
|
||||
run(&mut s, "solid.extrude", json!({"sketch":"Bottom","distance":10,"operation":"new","body_name":"P"}));
|
||||
let prism = volume(&s, "P");
|
||||
assert!((prism - rounded).abs() < rounded * 1e-6, "{prism} vs {rounded}");
|
||||
}
|
||||
|
||||
@@ -375,6 +375,34 @@ fn blend_seams_are_a_rounds_contacts_and_the_blends_beside_it() {
|
||||
assert!(corner.iter().all(|x| x.kind == BlendSeamKind::Blend), "{seams:?}");
|
||||
}
|
||||
|
||||
/// A round along a chain onto an earlier round's end has that round for one of its faces, and
|
||||
/// that round's own faces are not its own: where it runs into the cylinder the earlier round
|
||||
/// rolls on, its end face, is no seam of it (a block's arc at a cylinder rounded r2, then the
|
||||
/// block's top edge with the round's end curve on its side face rounded r1; the earlier round's
|
||||
/// name holds a `|` of its own, `F3:blend:F1:+z|F2:side`).
|
||||
#[test]
|
||||
fn a_round_of_a_round_s_end_has_no_seam_with_that_round_s_faces() {
|
||||
use solidcraft_doc::naming::{blend_seams, face_names};
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 40, "width": 10, "height": 15, "corner": [0, -5, 0], "body_name": "Block"}));
|
||||
run(&mut s, "solid.cylinder", json!({"radius": 10, "height": 30, "base": [0, 0, 0], "operation": "join", "targets": ["Block"]}));
|
||||
run(&mut s, "solid.fillet", json!({"edges": [[10, 0, 15]], "radius": 2}));
|
||||
run(&mut s, "solid.fillet", json!({"edges": [[30, 5, 15]], "radius": 1}));
|
||||
let state = s.model.state();
|
||||
let body = &state.bodies[0];
|
||||
let names = face_names(body);
|
||||
let mesh = body.mesh();
|
||||
let sides = |edge: usize| -> Vec<&str> { mesh.edge_faces[edge].iter().filter_map(|f| names.get(*f as usize).map(String::as_str)).collect() };
|
||||
let seams = blend_seams(body);
|
||||
assert!(!seams.is_empty());
|
||||
for seam in &seams {
|
||||
let faces = sides(seam.edge);
|
||||
if faces.iter().any(|n| n.starts_with("F2:side")) {
|
||||
assert!(faces.iter().any(|n| n.starts_with("F3:blend:")), "a seam of the r2 round only: {faces:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A fillet of a shell's inner corners names those edges. Thinning the wall past the outer
|
||||
/// round removes them. The fillet must say the names are gone, not blend the seam nearest
|
||||
/// the old pick, which now sits on the axis of the inner round (#775).
|
||||
|
||||
Reference in New Issue
Block a user