Files
makeCAD/crates/ui-egui/src/blend_dialog_tests.rs
T
Irakli Kourtis 37a8402cae surface.blend: seam alignment, chain-topology refusal and a dialog (#764) (#2488)
* kernel: a blend runs along chains of several faces and lines closed rims up (#764)

A blend's chain may run along the boundaries of several faces (a tube's rim
along the halves of its wall): each edge continues from its own best-facing
face, read station by station. Before, a chain had to be the edges of one face,
so every rim of a revolved or cylindrical surface was refused.

Two closed chains blend from matching seams: the second chain's start (searched
by arclength, then narrowed) and direction are the ones that put each station
closest to its partner, so rims whose seams sit apart no longer twist. A
picked `seam` point on each chain fixes the start instead. A closed chain
against an open one is refused. Closed chains leave towards each other's
centroid, not a point on the rim.

Stations are read on the edges' own curves, not on the chords of the length
table (they sat up to the chord's sagitta inside a curved edge), and the
reported gap is measured to the curves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* kernel: closed blend chains run round the same way; Hermite strip and seam tests (#764)

The second of two closed chains runs round the same way as the first (by
their area vectors), so a picked seam turns the blend by just the angle
between the seams instead of folding it over. The nearer pairing decides only
when the loops stand almost at right angles.

Tests for the issue's gates: the blend between two offset box rims is the
analytic cubic Hermite strip (control points from the chord) and keeps the
top faces' normal along both seams; picked seams a quarter apart turn the
blend a quarter round.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* surface.blend: `seam` picks where each chain's stations start (#764)

A point on each chain, saved with the feature (one pending format change),
moved with the design like `align`, and refused when it is not two points.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* surface.blend: a test between two tube rims, their seams picked and saved (#764)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* Blend dialog: edges at each end, continuity and bulge per end, stitch (#764)

SURFACE › CREATE › Blend Surface opens a dialog: the edges the blend leaves
and the ones it arrives at, each end's continuity (G0–G3) and bulge, and
Stitch to both bodies. Edit Feature brings it back and keeps what the dialog
does not show (align and seam points). Labels in every locale catalog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* ROADMAP: M8 Blend runs along several faces, pairs closed rims and has a dialog (#764)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* kernel: a blend station on the vertex between two support faces is read on the neighbour (#764)

A station where a tube wall's two halves meet sits at a corner of one half's
parameters; with a leave direction that turns round the wall (tubes off each
other's axis) the shape could not be read there and the blend was refused. The
neighbouring chain edge's face holds the same point and reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

* blend: review clean-ups (#764)

- ChainLine keeps one list of samples instead of four parallel lists.
- frames_on and boundary_gap take the chain's ChainLine instead of rebuilding it.
- A station is read on the neighbouring face only when it sits on the vertex the two edges
  share, each face once, and each face keeps its own walk.
- The seam rule (a closed chain starts at it, an open one runs from the nearer end) lives in
  ChainLine::start_at_seam; pair_with reuses the start of its both-ways search.
- support_faces projects with curveblend::project; loop_area sits with plane_through.
- surface.blend parses `align` and `seam` through one point_pair; the Blend and Ruled dialogs
  share body_and_edges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM

---------

Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 04:26:12 +00:00

83 lines
4.1 KiB
Rust

//! The Blend Surface dialog (#764): edges at each end, the continuity and bulge of each end and
//! the stitch toggle become `surface.blend`, and Edit Feature brings them back with what the
//! dialog does not show (the seams) kept as they were.
use crate::dialogs::Kind;
use crate::dialogs_surface::Surf;
use crate::scenario::Harness;
use serde_json::json;
use solidcraft_engine::doc::{FeatureKind, kernel::Continuity};
use solidcraft_engine::geom::Vec3;
fn ok(h: &mut Harness) {
h.frames(2);
h.step(&json!({"widget":"OK"})).unwrap();
// An edit is applied off the UI thread: give it the frames it takes.
for _ in 0..200 {
if h.app.dialog.is_none() {
break;
}
h.frames(1);
}
assert!(h.app.dialog.is_none(), "{:?} {:?} {:?}", h.app.preview.error, h.app.dialog.as_ref().map(|d| (&d.error, &d.inputs)), h.app.session.log);
}
/// What the blend feature `name` was made with: the bodies at each end, continuity, bulge, seams
/// and stitch.
#[allow(clippy::type_complexity)]
fn blend(h: &Harness, name: &str) -> (String, String, [Continuity; 2], [f64; 2], Option<[Vec3; 2]>, bool) {
match &h.app.session.doc.find_feature(name).unwrap().kind {
FeatureKind::SurfaceBlend { from, to, continuity, bulge, seam, stitch, .. } => {
(from.body.to_string(), to.body.to_string(), *continuity, *bulge, seam.map(|[p, q]| [p.0, q.0]), *stitch)
}
k => panic!("{k:?}"),
}
}
#[test]
fn edges_at_each_end_make_a_blend_and_come_back_in_an_edit() {
let mut h = Harness::new();
h.app.run("solid.box", json!({"length": 40, "width": 10, "height": 10, "corner": [0, 0, 0], "body_name": "A"})).unwrap();
h.app.run("solid.box", json!({"length": 40, "width": 10, "height": 10, "corner": [0, 20, 5], "body_name": "B"})).unwrap();
let from = crate::dialogs::edge_sel(&h.app.session, Vec3::new(20.0, 10.0, 10.0)).unwrap();
let to = crate::dialogs::edge_sel(&h.app.session, Vec3::new(20.0, 20.0, 15.0)).unwrap();
h.step(&json!({"call":"ui.start","params":{"command":"surface.blend"}})).unwrap();
h.frames(3);
assert!(h.widget("From edges").is_some() && h.widget("Start continuity").is_some() && h.widget("End bulge").is_some());
let d = h.app.dialog.as_mut().unwrap();
d.inputs[0].items = vec![from];
d.inputs[1].items = vec![to];
let Kind::Surface(Surf::Blend { continuity, bulge, .. }) = &mut d.kind else { panic!("{:?}", d.kind) };
*continuity = [2, 1];
*bulge = [0.5, 0.0];
ok(&mut h);
let name = h.app.session.doc.features.last().unwrap().name.clone();
let (a, b, continuity, bulge, seam, stitch) = blend(&h, &name);
assert_eq!((a.as_str(), b.as_str()), ("A", "B"));
assert_eq!(continuity, [Continuity::G2, Continuity::G1]);
assert_eq!((bulge, seam, stitch), ([0.5, 0.0], None, false));
assert_eq!(h.app.session.world_state().bodies.len(), 3, "a new surface body beside the boxes");
// A blend made by the command with a seam the dialog does not show: an edit keeps it.
h.app.session.execute("edit.undo", &json!({})).unwrap();
h.app
.run(
"surface.blend",
json!({"from": {"body": "A", "edges": [[20, 10, 10]]}, "to": {"body": "B", "edges": [[20, 20, 15]]},
"continuity": ["g2", "g1"], "seam": [[0, 10, 10], [0, 20, 15]]}),
)
.unwrap();
let name = h.app.session.doc.features.last().unwrap().name.clone();
h.step(&json!({"call":"ui.editFeature","params":{"feature":name}})).unwrap();
h.frames(8);
let d = h.app.dialog.as_mut().unwrap();
assert!(matches!(d.kind, Kind::Surface(Surf::Blend { continuity: [2, 1], stitch: false, .. })), "{:?}", d.kind);
assert_eq!((d.inputs[0].items.len(), d.inputs[1].items.len()), (1, 1), "{:?}", d.inputs);
let Kind::Surface(Surf::Blend { stitch, .. }) = &mut d.kind else { panic!() };
*stitch = true;
ok(&mut h);
let (_, _, continuity, _, seam, stitch) = blend(&h, &name);
assert_eq!(continuity, [Continuity::G2, Continuity::G1]);
assert_eq!(seam, Some([Vec3::new(0.0, 10.0, 10.0), Vec3::new(0.0, 20.0, 15.0)]));
assert!(stitch);
assert_eq!(h.app.session.world_state().bodies.len(), 1, "stitched onto both boxes");
}