Wave 342/509: UI tests: SMLib's cylinder has one wall and one edge per rim; split rims come from two arcs (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - ff0dda537 jyviko: UI tests: picks that name one thing, and a thread that names its start - 2523d13cf jyviko: UI tests: SMLib's cylinder has one wall and one edge per rim; split rims come from two arcs - b71e5ae6f jyviko: Tests: edges are read on their NURBS forms, a chamfer's chain is its caller's, the cap test's hatch - 138acad01 jyviko: UI tests: a frame member's volume is compared to the accuracy SMLib measures at Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
@@ -160,6 +160,8 @@ fn pictures_show_the_section_and_its_cap() {
|
||||
let mut cam = view::home_camera(&s).unwrap();
|
||||
cam.fov = fov;
|
||||
let mut sc = view::scene(&s, &cam).unwrap();
|
||||
// The cap in the cap colour: a part's hatch colour is the one its name picks (#8529).
|
||||
sc.part_hatch = None;
|
||||
// A marker inside the body, behind the cut face.
|
||||
let red = Rgb(255, 0, 0);
|
||||
sc.lines.push(SceneLine {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! against the round wall instead of extending that short seam outside the solid.
|
||||
|
||||
use solidcraft_geom::{Loop2, Plane, Region2, Seg2, Vec2, Vec3};
|
||||
use solidcraft_kernel::{Body, BoolOp, boolean, chamfer, cylinder, extrude};
|
||||
use solidcraft_kernel::{Body, BoolOp, boolean, chamfer, cylinder, extrude, tangent_chain};
|
||||
use std::f64::consts::PI;
|
||||
|
||||
fn holder() -> Body {
|
||||
@@ -54,7 +54,9 @@ fn expected_removed(distance: f64) -> f64 {
|
||||
#[test]
|
||||
fn chamfer_the_top_lip_at_a_tangent_wall_junction() {
|
||||
let body = holder();
|
||||
let made = chamfer(&body, &[Vec3::new(10.0, 10.0, 60.0)], 2.0).unwrap();
|
||||
// The pick's tangent chain, as a chamfer feature selects it (the kernel blends the edges it
|
||||
// is given).
|
||||
let made = chamfer(&body, &tangent_chain(&body, &[Vec3::new(10.0, 10.0, 60.0)]).unwrap(), 2.0).unwrap();
|
||||
assert!(made.validity().is_empty(), "{:?}", made.validity());
|
||||
assert_eq!(made.crossed_face_loops().unwrap(), 0);
|
||||
let history = made.history().expect("the chamfer retains exact face provenance");
|
||||
@@ -115,7 +117,7 @@ fn plate_with_stadium(plate: f64) -> Body {
|
||||
fn one_chamfer_pick_follows_the_tangent_chain_at_any_part_size() {
|
||||
for plate in [140.0, 145.0, 250.0] {
|
||||
let body = plate_with_stadium(plate);
|
||||
let made = chamfer(&body, &[Vec3::new(0.0, 5.0, 20.0)], 1.0).unwrap();
|
||||
let made = chamfer(&body, &tangent_chain(&body, &[Vec3::new(0.0, 5.0, 20.0)]).unwrap(), 1.0).unwrap();
|
||||
assert!(made.validity().is_empty(), "{:?}", made.validity());
|
||||
// Two straight edges (c^2/2 * 40 each) and both end arcs (Pappus, c^2/2 * 2 pi (R - c/3)).
|
||||
let expected = 40.0 + 0.5 * 2.0 * PI * (5.0 - 1.0 / 3.0);
|
||||
|
||||
@@ -82,10 +82,19 @@ mod native_tests {
|
||||
fn edges_are_on_smlibs_curves() {
|
||||
let cyl = Brep::make_cylinder([0.0; 3], 5.0, 10.0).unwrap().to_native().unwrap();
|
||||
let side = cyl.faces.iter().find(|f| matches!(f.surface, b::Surface::Cylinder { .. })).unwrap();
|
||||
assert!((side.domain[0][1] - side.domain[0][0] - TAU).abs() < 1e-12);
|
||||
assert_eq!(side.domain[1], [0.0, 10.0]);
|
||||
// The side is on SMLib's NURBS form of the cylinder (its domain is the form's): the whole
|
||||
// turn, so its domain's two u ends meet, from the base to the top.
|
||||
let form = b::eval::SurfaceEval::new(side.parameters()).unwrap();
|
||||
let [[u0, u1], [v0, v1]] = side.domain;
|
||||
for v in [v0, v1] {
|
||||
let (a, z) = (form.point([u0, v]).unwrap(), form.point([u1, v]).unwrap());
|
||||
assert!(a.dist(z) < 1e-9, "{a:?} {z:?}");
|
||||
}
|
||||
let heights = [form.point([u0, v0]).unwrap().z, form.point([u0, v1]).unwrap().z];
|
||||
assert!(heights.iter().any(|h| h.abs() < 1e-9) && heights.iter().any(|h| (h - 10.0).abs() < 1e-9), "{heights:?}");
|
||||
for e in &cyl.edges {
|
||||
let eval = b::eval::CurveEval::new(&e.curve).unwrap();
|
||||
// Evaluated on the curve its interval is on (a circle's NURBS form).
|
||||
let eval = b::eval::CurveEval::new(e.parameters()).unwrap();
|
||||
let [a, z] = e.interval;
|
||||
// Ends on the edge's vertices.
|
||||
for (t, v) in [(a, e.vertices[0]), (z, e.vertices[1])] {
|
||||
@@ -94,6 +103,7 @@ mod native_tests {
|
||||
assert!((p - Vec3::new(q[0], q[1], q[2])).len() < 1e-9, "{:?} at {t}", e.curve);
|
||||
}
|
||||
if let b::Curve::Circle { radius, .. } = e.curve {
|
||||
let [a, z] = e.curve_interval().unwrap();
|
||||
assert!((radius - 5.0).abs() < 1e-12 && (z - a - TAU).abs() < 1e-9);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +136,8 @@ mod native_tests {
|
||||
p[0].abs() < 1e-9 && (p[1] - 14.5).abs() < 1e-9
|
||||
})
|
||||
};
|
||||
let middle = |e: &b::Edge| b::eval::CurveEval::new(&e.curve).unwrap().point(0.5 * (e.interval[0] + e.interval[1])).unwrap();
|
||||
// On the curve the interval is on (a circle's NURBS form).
|
||||
let middle = |e: &b::Edge| b::eval::CurveEval::new(e.parameters()).unwrap().point(0.5 * (e.interval[0] + e.interval[1])).unwrap();
|
||||
let copies: Vec<&b::Edge> = record.edges.iter().filter(|e| on_line(e)).collect();
|
||||
assert_eq!(copies.len(), 2);
|
||||
for copy in copies {
|
||||
|
||||
@@ -2293,12 +2293,17 @@ fn the_picks_go_with_the_next_message_once() {
|
||||
}
|
||||
|
||||
/// Two clicks on two rims are two things, not four edges (a click on a rim selects both halves for
|
||||
/// the commands; the chat counts and describes what was clicked).
|
||||
/// the commands; the chat counts and describes what was clicked). The cylinder is a circle drawn
|
||||
/// as two half arcs, extruded, so each rim is in two halves.
|
||||
#[test]
|
||||
fn a_rim_clicked_once_is_one_item_not_its_pieces() {
|
||||
use solidcraft_engine::Sel;
|
||||
let (mut app, script, ctx) = app_with_script();
|
||||
app.run("solid.cylinder", json!({"radius": 10, "height": 20})).expect("a cylinder");
|
||||
app.run("sketch.create", json!({"plane": "XY"})).expect("a sketch");
|
||||
app.run("sketch.arc.three_point", json!({"start": [10, 0], "end": [-10, 0], "through": [0, 10]})).expect("an arc");
|
||||
app.run("sketch.arc.three_point", json!({"start": [-10, 0], "end": [10, 0], "through": [0, -10]})).expect("an arc");
|
||||
app.run("sketch.finish", json!({})).expect("the sketch");
|
||||
app.run("solid.extrude", json!({"distance": 20})).expect("a cylinder");
|
||||
let (name, top, bottom, mid_top, mid_bottom) = {
|
||||
let st = crate::open_meshing::session_world(&app.session);
|
||||
let body = &st.bodies[0];
|
||||
|
||||
@@ -54,8 +54,9 @@ fn picked_gear_faces_choose_their_joints_and_radii() {
|
||||
let mut app = discs();
|
||||
app.start("joint.gear");
|
||||
let mut d = app.dialog.take().unwrap();
|
||||
// G2 first, G1 second: the joints follow the picks, whatever the dialog started on.
|
||||
for (i, p) in [Vec3::new(50.0, 0.0, 2.5), Vec3::new(10.0, 0.0, 2.5)].into_iter().enumerate() {
|
||||
// G2 first, G1 second: the joints follow the picks, whatever the dialog started on. The
|
||||
// discs touch at x = 10, on both walls, so G1 is picked on its far side.
|
||||
for (i, p) in [Vec3::new(50.0, 0.0, 2.5), Vec3::new(-10.0, 0.0, 2.5)].into_iter().enumerate() {
|
||||
d.active = i;
|
||||
let pick = wall(&app, p);
|
||||
d.pick(&app.session, pick);
|
||||
|
||||
@@ -139,7 +139,11 @@ fn a_whole_sketch_section_stays_whole_through_an_edit() {
|
||||
let c = apply_commands(&app, &e).unwrap();
|
||||
assert!(c[0].1["params"].get("profiles").is_none(), "{}", c[0].1);
|
||||
run_all(&mut app, c);
|
||||
assert!((volume(&mut app) - before).abs() < 1e-6 * before, "still the ring, not the filled circle");
|
||||
// To the accuracy SMLib measures at (1e-4 relative, the finest it takes: kernel
|
||||
// `measure::ACCURACY`); the ring's exact π (20² − 17²) 600 = 209230.07 mm³ came out
|
||||
// 209229.86 before the turn and 209230.43 after it. The filled circle would be 3.6 times it.
|
||||
let after = volume(&mut app);
|
||||
assert!((after - before).abs() < 1e-4 * before, "still the ring, not the filled circle: {after} mm³, {before} before");
|
||||
// Unticked, the section is a built-in profile again.
|
||||
let mut e = edit_dialog(&app, f, None).unwrap();
|
||||
member(&mut e).whole = None;
|
||||
|
||||
@@ -1103,10 +1103,11 @@ mod tests {
|
||||
assert!(matches!(&target.certificate, Some(solidcraft_engine::doc::config::FaceCertificate::ExtrudeSide { curve, .. }) if curve == "outer"));
|
||||
let state = h.app.session.model.state();
|
||||
let body = state.body("Ring").unwrap();
|
||||
// The outer circle, one closed curve, is one wall face.
|
||||
let indices = h.app.session.doc.configuration_face_indices(body, target).unwrap();
|
||||
assert_eq!(indices.len(), 2);
|
||||
assert_eq!(indices.len(), 1);
|
||||
let painted = h.app.session.doc.face_colors(body);
|
||||
assert_eq!(painted.len(), 2);
|
||||
assert_eq!(painted.len(), 1);
|
||||
assert!(painted.iter().all(|(index, _)| indices.contains(index)));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ fn shaft() -> Harness {
|
||||
h
|
||||
}
|
||||
|
||||
/// The shaft's wall, top rim and top cap, as picks.
|
||||
/// The shaft's wall, top rim and top cap, as picks. The rim is picked at the middle of its
|
||||
/// polyline: its first point is the vertex where the wall's seam meets it, as near the seam as
|
||||
/// the rim.
|
||||
fn picks(h: &Harness) -> (Sel, Sel, Sel) {
|
||||
use solidcraft_engine::kernel::{FaceSurface, face_surface};
|
||||
let st = h.app.session.world_state().unwrap();
|
||||
@@ -42,7 +44,7 @@ fn picks(h: &Harness) -> (Sel, Sel, Sel) {
|
||||
.enumerate()
|
||||
.find_map(|(index, e)| {
|
||||
let c = solidcraft_engine::kernel::edge_circle(&b.body, index)?;
|
||||
(c.center.z > 9.0).then(|| Sel::Edge { body: "Shaft".into(), index, point: e[0] })
|
||||
(c.center.z > 9.0).then(|| Sel::Edge { body: "Shaft".into(), index, point: crate::viewport::polyline_mid(e) })
|
||||
})
|
||||
.unwrap();
|
||||
(wall, rim, cap)
|
||||
|
||||
@@ -8304,6 +8304,21 @@ mod tests {
|
||||
app
|
||||
}
|
||||
|
||||
/// A Ø20 × 20 cylinder whose wall and rims are each in two halves: a circle drawn as two
|
||||
/// half arcs, extruded (one wall face per arc). SMLib's own cylinder has one wall and one
|
||||
/// edge per rim; a rim or wall in pieces comes from a profile like this one or an import.
|
||||
fn split_cylinder_app() -> SolveApp {
|
||||
let mut s = solidcraft_engine::Session::default();
|
||||
s.execute("sketch.create", &json!({"plane": "XY"})).unwrap();
|
||||
s.execute("sketch.arc.three_point", &json!({"start": [10, 0], "end": [-10, 0], "through": [0, 10]})).unwrap();
|
||||
s.execute("sketch.arc.three_point", &json!({"start": [-10, 0], "end": [10, 0], "through": [0, -10]})).unwrap();
|
||||
s.execute("sketch.finish", &json!({})).unwrap();
|
||||
s.execute("solid.extrude", &json!({"distance": 20})).unwrap();
|
||||
let mut app = SolveApp::new(s, crate::Services::default());
|
||||
app.set_origin_shown(false);
|
||||
app
|
||||
}
|
||||
|
||||
/// Moving the pointer across a face keeps its highlight (a scanned mesh is one face of
|
||||
/// millions of triangles): only another face, edge or plane builds it again.
|
||||
#[test]
|
||||
@@ -8642,9 +8657,13 @@ mod tests {
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
assert!(mesh.seams[crease], "the fixture must exercise the coarse seam false positive");
|
||||
// Truck's coarse seam fit took this crease for a seam between pieces of one surface;
|
||||
// the seam flags now compare the exact surfaces (`topo::seam_flags`). Either way the
|
||||
// certified crease is sharp, drawn in wireframe and picked. Its kink of a millionth is
|
||||
// too close to tangent to show in the shading (`smooth_edges::Join`: smooth and a
|
||||
// measured crease at once), so the shaded view leaves it out.
|
||||
assert!(mesh.sharp_edges[crease]);
|
||||
assert!(mesh.shaded_edge_visible(crease));
|
||||
assert!(mesh.edge_visible(crease) && !mesh.shaded_edge_visible(crease));
|
||||
assert!(mesh.edge_pickable(crease));
|
||||
assert!(mesh.edge_faces[crease].iter().any(|f| mesh.surface_patch(*f as usize).len() == 1));
|
||||
let mid = polyline_mid(&mesh.edges[crease]);
|
||||
@@ -8660,7 +8679,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn circular_items_measure_as_whole_rims_and_surfaces() {
|
||||
let mut app = cylinder_app();
|
||||
let mut app = split_cylinder_app();
|
||||
let st = app.session.world_state().unwrap();
|
||||
let b = &st.bodies[0];
|
||||
let m = b.mesh();
|
||||
@@ -8741,7 +8760,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn circular_rim_hover_click_and_dialog_pick_include_both_halves() {
|
||||
let mut app = cylinder_app();
|
||||
let mut app = split_cylinder_app();
|
||||
let st = app.session.world_state().unwrap();
|
||||
let b = &st.bodies[0];
|
||||
let m = b.mesh();
|
||||
@@ -8788,7 +8807,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn curved_face_hover_selection_and_dialogs_cross_the_seam() {
|
||||
let mut app = cylinder_app();
|
||||
let mut app = split_cylinder_app();
|
||||
let st = app.session.world_state().unwrap();
|
||||
let b = &st.bodies[0];
|
||||
let m = b.mesh();
|
||||
@@ -9473,7 +9492,8 @@ mod tests {
|
||||
fn cosmetic_threads_use_depth_tested_lines_and_keep_selection_and_wireframe() {
|
||||
let mut s = solidcraft_engine::Session::default();
|
||||
s.execute("solid.cylinder", &json!({"radius":3,"height":10})).unwrap();
|
||||
s.execute("solid.thread", &json!({"face":[3,0,5],"designation":"M6","length":5})).unwrap();
|
||||
// A pick in the middle of a face free at both ends names the end the thread starts from.
|
||||
s.execute("solid.thread", &json!({"face":[3,0,5],"designation":"M6","length":5,"from":[3,0,0]})).unwrap();
|
||||
let mut app = SolveApp::new(s, crate::Services::default());
|
||||
let count = |sc: GpuScene| {
|
||||
sc.merged()
|
||||
|
||||
Reference in New Issue
Block a user