Merge develop 74001e53 into solidcore

This commit is contained in:
Brett Lawson committed 2026-10-30 10:47:31 +01:00
commit 41491734af
12 files changed
+2262 -2480

No files matched your search

+10 -16
View File
@@ -139,21 +139,14 @@ fn a_parameter_edit_rebuilds_like_a_fresh_build_and_reverts_exactly() {
assert!(problems.is_empty(), "{}", problems.join("\n"));
}
/// The README demo's Raspberry Pi case (`examples/demo/enclosure_ui_mcp.py --story pi`): its
/// face count after each feature, and each outer side (the four walls and the bottom) one face
/// throughout: (a) built at height 24, (b) built at 24 and changed to 32 in Parameters, (c)
/// built at 32. The port cut-outs and the floor vents used to split the long wall (or the end
/// wall at 24) into strips along the openings' tops and bottoms.
/// The README demo's Raspberry Pi case (`examples/demo/enclosure_ui_mcp.py --story pi`): after
/// each feature, each outer side (the four walls and the bottom) is one face and the case is as
/// tall as its height, and a height changed in Parameters rebuilds the same topology as one
/// built at that height: (a) built at height 24, (b) built at 24 and changed to 32, (c) built at
/// 32. The port cut-outs and the floor vents used to split the long wall (or the end wall at 24)
/// into strips along the openings' tops and bottoms.
#[test]
fn pi_case_faces_per_step_at_both_heights() {
// Sketch1 (1) .. RectangularPattern2 (14): the faces once features 1..=k are built. The box
// (6), its four corner rounds (10), shelled open at the top (outside 9, inside 9, rim 1:
// 19); each standoff (a ring, Ø6 round a Ø2.5 hole) adds its outer and inner wall (each one
// cylinder, closed along its seam), its top and the floor inside its hole (4, so 23, and 35
// for four); the three port openings through a wall 4 walls each (47); the end cut-out 4
// (51); each of five floor vents 4 (55, 71).
const FACES: [(usize, usize); 13] =
[(2, 6), (3, 10), (4, 19), (5, 19), (6, 23), (7, 35), (8, 35), (9, 47), (10, 47), (11, 51), (12, 51), (13, 55), (14, 71)];
fn pi_case_sides_stay_whole_at_both_heights() {
let dir = scratch_dir("pi");
let design: Value = serde_json::from_slice(&std::fs::read(root().join("tests/action_matrix/designs/pi-case.solidcraft")).unwrap()).unwrap();
let at = |height: &str, file: &str| {
@@ -176,12 +169,13 @@ fn pi_case_faces_per_step_at_both_heights() {
for (case, s, h) in [("(a) at 24", a, 24.), ("(b) 24 changed to 32", b, 32.), ("(c) at 32", c, 32.)] {
assert!(errors(&s).is_empty(), "{case}: features fail: {:?}", errors(&s));
let mut steps = Vec::new();
for (k, want) in FACES {
// Sketch1 (1) is no body; the box (2) .. RectangularPattern2 (14).
for k in 2..=14 {
let mut t = s.scratch();
t.execute("timeline.rollback", &json!({"position": k})).unwrap();
let st = t.world_state().unwrap();
let body = st.bodies.iter().find(|b| b.name == "Body1").unwrap();
assert_eq!(body.body.face_count(), want, "{case}: faces after feature {k}");
assert!(body.body.validity().is_empty(), "{case}: after feature {k}: {:?}", body.body.validity());
// Each outer side: the faces in its plane.
for (n, d) in [([0., -1., 0.], 33.), ([0., 1., 0.], 33.), ([-1., 0., 0.], 47.5), ([1., 0., 0.], 47.5), ([0., 0., -1.], 0.)] {
let on = (0..body.body.face_count())
+22 -70
View File
@@ -309,7 +309,6 @@ fn saved_former_strip_projection_reports_lost_without_expanding_healthy_material
#[test]
fn saved_curved_strip_projection_is_lost_after_exact_wall_coalescence() {
use solidcraft_kernel::{FacePaint, Paint};
use solidcraft_sketch::{LinkKind, LinkSource, Sketch};
let mut doc = Document::new("saved curved strip");
doc.set_param("width", "80", Some("mm"), None).unwrap();
@@ -327,86 +326,39 @@ fn saved_curved_strip_projection_is_lost_after_exact_wall_coalescence() {
Some("Corners"),
)
.unwrap();
let shell = doc
.add_feature(
FeatureKind::Shell {
faces: vec![crate::FacePick(Vec3::new(0., 0., 30.))],
thickness: "wall".into(),
body: Some("Case".into()),
direction: "inside".into(),
tangent_chain: false,
},
Some("Shell"),
)
.unwrap();
doc.add_feature(
FeatureKind::Shell {
faces: vec![crate::FacePick(Vec3::new(0., 0., 30.))],
thickness: "wall".into(),
body: Some("Case".into()),
direction: "inside".into(),
tangent_chain: false,
},
Some("Shell"),
)
.unwrap();
let mut model = Model::new();
model.evaluate(&doc);
assert!(model.results.iter().all(|r| r.error.is_none()), "{:?}", model.results);
let before = model.state_before(shell);
// Per-face paint disables the construction optimization: this control keeps
// the real pre-repair slab faces without forging a name or source witness.
let old_source = before
.body("Case")
.unwrap()
.body
.clone()
.with_paint(Some(Paint { opacity: 1., faces: vec![FacePaint { face: 0, color: [1., 0., 0.], opacity: 1. }] }));
let cavity_box = solidcraft_kernel::box_solid(Vec3::new(-38., -28., 2.), Vec3::new(38., 28., 35.)).unwrap();
let cavity = solidcraft_kernel::fillet(
&cavity_box,
&[Vec3::new(38., 28., 15.), Vec3::new(-38., 28., 15.), Vec3::new(-38., -28., 15.), Vec3::new(38., -28., 15.)],
4.,
)
.unwrap();
let raw = solidcraft_kernel::boolean(&old_source, &cavity, solidcraft_kernel::BoolOp::Cut).unwrap().unwrap();
let mut old_body = ModelBody::new("Case".into(), raw, shell);
old_body.names = crate::naming::NameCell::new(Some(std::sync::Arc::new(crate::naming::NamingOrigin {
feature: doc.feature(shell).unwrap().clone(),
before,
depth: 1,
mats: vec![],
sheets: vec![],
})));
// A point low on the outer round of the +x+y corner (radius 6 about (34, 24)), below the
// cavity's floor at z = 2.
let t = std::f64::consts::FRAC_1_SQRT_2;
let at = Vec3::new(34. + 6. * t, 24. + 6. * t, 1.);
let former = crate::naming::face_name_at_body(&old_body, at).unwrap();
let stem = crate::naming::strip_piece(&former).to_string();
assert_ne!(former, stem, "actual old cylindrical strip must have a piece suffix");
let state = model.state();
let current = state.body("Case").unwrap();
let names = crate::naming::face_names(current);
let stem = crate::naming::face_name_at_body(current, at).unwrap();
assert_eq!(crate::naming::strip_piece(&stem), stem, "the shelled wall's round is one exact face, floor to rim");
let index = names.iter().position(|name| name == &stem).unwrap();
assert!(current.body.face_was_coalesced(index));
assert!(current.body.face_plane(index).is_none(), "witness grants no planar attachment authority");
assert!(old_body.body.face_sources().is_none_or(|sources| sources.iter().enumerate().all(|(index, _)| !old_body.body.face_was_coalesced(index))));
let mut old_state = (*model.state()).clone();
old_state.bodies = vec![old_body];
// What a build that sewed the cut slab by slab saved: the round in two pieces split at the
// cavity's floor, the projection made on the lower one, `#1` (pieces numbered up their
// longest spread), from z = 0 to 2. Projected on YZ, the quarter round from (40, 24) to
// (34, 30) is the rectangle y 24..30, z 0..2: its two arcs and its two straight sides.
let former = format!("{stem}#1");
let source = LinkSource::Face { body: "Case".into(), at };
// Recover the saved projection from the old face's complete raw topology.
// Display seam suppression must not discard a historical strip boundary.
let old_body = old_state.body("Case").unwrap();
let old_index = crate::naming::face_on_body(old_body, &former, at).unwrap().0;
let mesh = old_body.mesh();
let mut geometry = Vec::new();
for (index, faces) in mesh.edge_faces.iter().enumerate() {
if !faces.contains(&(old_index as u32)) {
continue;
}
let points = &mesh.edges[index];
let a = solidcraft_geom::Plane::YZ.to_local(*points.first().unwrap());
let b = solidcraft_geom::Plane::YZ.to_local(*points.last().unwrap());
let (a, b) = (Vec2::new(a.x, a.y), Vec2::new(b.x, b.y));
assert!(a.dist(b) > 1e-6);
for point in points {
let q = solidcraft_geom::Plane::YZ.to_local(*point);
let q = Vec2::new(q.x, q.y);
let direction = b - a;
let t = ((q - a).dot(direction) / direction.dot(direction)).clamp(0., 1.);
assert!(q.dist(a + direction * t) < 1e-7, "exact cylindrical quadrant projects to a straight support");
}
geometry.push(solidcraft_sketch::LinkGeom::Line(a, b));
}
assert_eq!(geometry.len(), 4, "historical curved strip has a complete four-edge rectangular projection");
let (a, b, c, d) = (Vec2::new(24., 0.), Vec2::new(30., 0.), Vec2::new(30., 2.), Vec2::new(24., 2.));
let geometry: Vec<_> = [(a, b), (b, c), (c, d), (d, a)].into_iter().map(|(p, q)| solidcraft_sketch::LinkGeom::Line(p, q)).collect();
let mut sketch = Sketch::new();
sketch.add_link(LinkKind::Project, source, &geometry).unwrap();
sketch.links[0].face_name = Some(former);
@@ -1060,8 +1060,15 @@ fn cut_keeps_posts_joined_while_apart_in_one_body() {
// A cut through the middle of the case still leaves two bodies, and says it made the second.
s.execute("solid.box", &json!({"length": 2, "width": 80, "height": 80, "center": [0, 0, 20], "operation": "new", "body_name": "Saw"})).unwrap();
let saw = s.execute("solid.combine", &json!({"target": "Case", "tools": ["Saw"], "operation": "cut"})).unwrap();
assert_eq!(saw["bodies"], json!(["Case", "Case (1)"]), "{saw}");
// `bodies` lists them in the kernel's order. The piece whose least face name sorts first keeps
// the name (`lineage::order_lumps`): the +x half, whose `F1:+x` sorts before the -x half's
// least, its piece of the case's `F1:+y`.
let mut bodies: Vec<&str> = saw["bodies"].as_array().unwrap().iter().filter_map(Value::as_str).collect();
bodies.sort_unstable();
assert_eq!(bodies, ["Case", "Case (1)"], "{saw}");
assert_eq!(saw["created_bodies"], json!(["Case (1)"]), "{saw}");
let low_x = |name: &str| s.model.state().body(name).unwrap().mesh().bounds().min.x;
assert!((low_x("Case") - 1.0).abs() < 1e-9 && (low_x("Case (1)") + 30.0).abs() < 1e-9);
let half = (60.0 - 2.0) / 2.0 * 40.0 * 10.0 + posts / 2.0;
for name in ["Case", "Case (1)"] {
assert!((volume(&s, name) - half).abs() < 1e-6 * half, "{name}: {} vs {half}", volume(&s, name));
@@ -15,6 +15,8 @@ fn paint(session: &mut Session, body: &str, point: Value) {
run(session, "config.row", json!({"name":"Painted","values":{key:"ABS - Red"}}));
run(session, "config.activate", json!({"row":"Painted"}));
}
/// Every painted face of `name` lies on the cylinder of `radius` round its axis; how many faces
/// are painted, to compare a copy with its original.
fn painted_radius(session: &Session, name: &str, radius: f64) -> usize {
let state = session.model.state();
let body =
@@ -30,7 +32,7 @@ fn painted_radius(session: &Session, name: &str, radius: f64) -> usize {
}
}
}
assert!(!painted.is_empty());
assert!(!painted.is_empty(), "{name}: nothing painted");
painted.len()
}
@@ -49,22 +51,22 @@ fn certified_annulus_side_rows_follow_radius_edits_and_clone() {
run(&mut s, "sketch.finish", json!({}));
run(&mut s, "solid.extrude", json!({"distance":10,"profiles":[{"point":[9.5,0]}],"body_name":"Ring"}));
paint(&mut s, "Ring", json!([10, 0, 5]));
assert_eq!(painted_radius(&s, "Ring", 10.), 2, "both constructed arc pieces share outer curve");
let pieces = painted_radius(&s, "Ring", 10.);
let Column::FaceAppearance(target) = &s.doc.configs.columns[0] else { panic!() };
assert_eq!(target.certificate, Some(FaceCertificate::ExtrudeSide { sketch, curve: "outer".into() }));
run(&mut s, "parameters.change", json!({"name":dimensions[0],"expression":"12 mm"}));
run(&mut s, "parameters.change", json!({"name":dimensions[1],"expression":"9.25 mm"}));
run(&mut s, "config.activate", json!({"row":"Painted"}));
assert_eq!(painted_radius(&s, "Ring", 12.), 2);
assert_eq!(painted_radius(&s, "Ring", 12.), pieces);
run(&mut s, "component.paste_new", json!({"component":part,"translate":[30,0,0]}));
assert_eq!(s.doc.configs.columns.len(), 2);
run(&mut s, "config.activate", json!({"row":"Painted"}));
assert_eq!(painted_radius(&s, "Ring (2)", 12.), 2);
assert_eq!(painted_radius(&s, "Ring (2)", 12.), pieces);
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
let mut reopened = Session::new(reopened);
run(&mut reopened, "config.activate", json!({"row":"Painted"}));
assert_eq!(painted_radius(&reopened, "Ring", 12.), 2);
assert_eq!(painted_radius(&reopened, "Ring (2)", 12.), 2);
assert_eq!(painted_radius(&reopened, "Ring", 12.), pieces);
assert_eq!(painted_radius(&reopened, "Ring (2)", 12.), pieces);
run(&mut reopened, "config.activate", json!({"row":"Default"}));
assert!(reopened.doc.appearances.faces.is_empty());
}
@@ -227,11 +229,11 @@ fn certified_side_transfer_preserves_geometry_and_unsupported_taper_refuses_atom
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,0],"angle":90,"axis":[0,0,1],"capture":false}));
run(&mut s, "component.move_bodies", json!({"component":destination,"bodies":["Round"]}));
run(&mut s, "config.activate", json!({"row":"Painted"}));
assert_eq!(painted_radius(&s, "Round", 10.), 2);
let pieces = painted_radius(&s, "Round", 10.);
let before = s.world_state().unwrap().body("Round").unwrap().mesh().bounds();
let mut s = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
run(&mut s, "config.activate", json!({"row":"Painted"}));
assert_eq!(painted_radius(&s, "Round", 10.), 2);
assert_eq!(painted_radius(&s, "Round", 10.), pieces);
assert!(
s.world_state().unwrap().body("Round").unwrap().mesh().bounds().min.dist(before.min) < 1e-8,
"before {before:?}, reopened {:?}",
+8 -2
View File
@@ -1870,8 +1870,14 @@ fn fillets_on_tapered_bosses_saved_before_still_find_their_edges() {
let r = s.model.result(id).unwrap();
assert!(r.error.is_none() && r.warning.is_none(), "{name}: {:?} {:?}", r.error, r.warning);
}
// The build that saved it measured 69454.885209 mm³.
assert!((volume - 69454.8852092132).abs() < 1e-3, "{volume}");
// In closed form: the 80 × 40 × 20 block, the 20 × 20 boss 10 high tapered 5° in (a frustum,
// top 20 − 20 tan 5° square: 3660.251034), the Ø16 boss tapered alike (a cone frustum, top
// radius 8 − 10 tan 5°: 1798.751833); less the R1 round along a sloping corner (the corner's
// section, r²(cot φ/2 − (π − φ)/2) at its dihedral angle φ = 90.435°, times its length
// between z = 20 and 30: 2.124401) and the R0.5 round all round the cone's top (the section
// at the rim's 95°, turned about the axis by Pappus: 1.928463). The build that saved it,
// with truck, measured 69454.885209.
assert!((volume - 69454.950004).abs() < 1e-3, "{volume}");
assert_eq!(s.world_state().unwrap().bodies.len(), 1);
}
+8 -9
View File
@@ -1091,9 +1091,9 @@ mod tests {
}
}
/// Offset Surface: a cylinder's side picked once with its chain (both halves) moved out to
/// radius 12; a box top moved up exactly; a zero distance copies; past the axis refused, the
/// design left as it was; undo, redo and reopening.
/// Offset Surface: a cylinder's side (one face, closed along its seam) picked with its chain
/// moved out to radius 12; a box top moved up exactly; a zero distance copies; past the axis
/// refused, the design left as it was; undo, redo and reopening.
#[test]
fn offset_surface_of_a_cylinder_and_a_box_top() {
let mut s = Session::default();
@@ -1101,7 +1101,7 @@ mod tests {
run(&mut s, "surface.offset", json!({"faces": [[10, 0, 10]], "chain": true, "distance": 2, "body": "Can", "body_name": "Sleeve"}));
let st = s.world_state().unwrap();
let sleeve = &st.body("Sleeve").unwrap().body;
assert!(sleeve.is_surface() && sleeve.face_count() == 2);
assert!(sleeve.is_surface());
let want = 2.0 * std::f64::consts::PI * 12.0 * 20.0;
assert!((area(&s, "Sleeve") - want).abs() < want * 1e-3, "{} vs {want}", area(&s, "Sleeve")); // (measured on meshes)
assert!(st.body("Can").is_some(), "the source body stays");
@@ -1293,9 +1293,10 @@ mod tests {
/// Extend a cylinder strip: naturally 5 along its axis (10 · π/2 · 25, one face, still a
/// cylinder), up to the plane z = 30 (10 · π/2 · 30), and by tangent and curvature run-offs
/// (a second face along a straight edge, 20 long: the tangent one a flat 5 × 20, the
/// curvature one the parabola s ↦ s·R + ½κs²·n with the cylinder's κ = 1/10, its section
/// ∫₀⁵ √(1 + κ²s²) ds long). Undo, redo and reopening; the default saves nothing new.
/// along a straight edge, 20 long: each SMLib's G1 or G2 extension of the surface, so the
/// strip stays one face (the tangent one a flat 5 × 20, the curvature one the parabola
/// s ↦ s·R + ½κs²·n with the cylinder's κ = 1/10, its section ∫₀⁵ √(1 + κ²s²) ds long).
/// Undo, redo and reopening; the default saves nothing new.
#[test]
fn extend_a_cylinder_strip_every_way() {
let pi = std::f64::consts::PI;
@@ -1325,8 +1326,6 @@ mod tests {
let parabola = 2.5 * (1.0 + 25.0 * k * k).sqrt() + (5.0 * k).asinh() / (2.0 * k);
for (mode, run_off) in [("tangent", 5.0), ("curvature", parabola)] {
run(&mut s, "surface.extend", json!({"body": "Strip", "edges": [side], "distance": 5, "mode": mode}));
let st = s.world_state().unwrap();
assert_eq!(st.body("Strip").unwrap().body.face_count(), 2, "{mode}");
let want = 10.0 * pi / 2.0 * 20.0 + run_off * 20.0;
assert!((area(&s, "Strip") - want).abs() < want * 1e-3, "{mode}: {} vs {want}", area(&s, "Strip")); // (measured on meshes)
let cold = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
+9 -4
View File
@@ -371,10 +371,15 @@ fn the_round_sides_of_a_thin_ring_are_named_by_the_circle_they_run_beside() {
run(&mut s, "solid.extrude", json!({"sketch": "Outline", "thin": true, "thickness": 2, "distance": 5, "name": "Ring"}));
let world = s.world_state().unwrap();
let names = solidcraft_doc::naming::face_names(world.bodies.first().unwrap());
// Each round side is two half cylinders, told apart by their numbers.
// Each round side is one cylinder, closed along its seam, so its name needs no number.
let walls: Vec<_> = names.iter().filter(|name| name.contains(":wall:")).collect();
assert_eq!(walls.len(), 4, "{names:?}");
for side in ["left", "right"] {
assert_eq!(walls.iter().filter(|name| name.contains(&format!(":wall:c1:{side}#"))).count(), 2, "{walls:?}");
assert_eq!(walls.len(), 2, "{names:?}");
// The wall is 2 thick about the circle (radius 9 to 11). The circle runs counter-clockwise,
// so its left is the inner side; each name is found again at a point on its own wall.
for (side, radius) in [("left", 9.0), ("right", 11.0)] {
let name = format!("F2:wall:c1:{side}");
assert!(walls.contains(&&name), "{walls:?}");
let at = solidcraft_geom::Vec3::new(0.0, radius, 2.5);
assert_eq!(solidcraft_doc::naming::face_names_at(&s.model.state(), &[at]), vec![name.clone()]);
}
}
+3 -3
View File
@@ -34,9 +34,9 @@ fn intersection_curves(body: &Body) -> Vec<Curve> {
fn a_small_hole_in_a_large_spline_face_cuts_cleanly() {
let (block, cut) = holed();
assert!(cut.validity().is_empty(), "{:?}", cut.validity());
// The hole adds its wall (two half cylinders) and splits nothing: the bottom and the wave
// each gain a loop.
assert_eq!(cut.face_count(), block.face_count() + 2);
// The hole adds its wall (one cylinder, closed along its seam) and splits nothing: the
// bottom and the wave each gain a loop.
assert_eq!(cut.face_count(), block.face_count() + 1);
let curves = intersection_curves(&cut);
assert!(!curves.is_empty(), "the hole's rim on the wave is an intersection edge");
// The wave is within a few tenths of a millimetre of flat across a Ø1 hole, so the hole
+9 -2
View File
@@ -478,7 +478,14 @@ mod tests {
})
.collect();
assert_eq!(fit_loop(&points, 0.001, 1e-6).segs.len(), 16);
assert_eq!(fit_loop(&points, 0.2, 1e-6).segs.len(), 2);
assert_exact_circle(&fit_loop(&points, 0.2, 1e-6), Vec2::ZERO, 10.);
}
/// The loop is the exact circle: one full turn of an arc round `center` at `radius`.
fn assert_exact_circle(fitted: &Loop2, center: Vec2, radius: f64) {
let [solidcraft_geom::Seg2::Arc { center: c, radius: r, sweep, .. }] = fitted.segs.as_slice() else { panic!("not one arc: {fitted:?}") };
assert!(c.dist(center) < 1e-9 && (r - radius).abs() < 1e-9, "centre {c:?}, radius {r}");
assert!((sweep.abs() - std::f64::consts::TAU).abs() < 1e-9, "sweep {sweep}");
}
#[test]
@@ -549,7 +556,7 @@ mod tests {
.collect();
let inner = Loop2::polygon(&points);
let fitted = fit_loop(&points, 0.05, 1e-6);
assert_eq!(fitted.segs.len(), 2);
assert_exact_circle(&fitted, Vec2::ZERO, 1.02);
assert!(certify_nesting(&[outer.clone(), inner], &[outer, fitted], 1e-6, 3.).is_err());
}
File diff suppressed because it is too large. Load diff
@@ -62,13 +62,15 @@ fn smlib_results_go_back_into_smlib() {
}
/// Extruded circles go into SMLib as its cylinder, so a boolean with one intersects a plane with
/// a cylinder, not with a spline.
/// a cylinder, not with a spline. The record holds the wall as the cylinder it is (one face,
/// closed along its seam).
#[test]
fn extruded_circles_go_as_cylinders() {
use solidcraft_smlib::flat;
let body = cylinder(v(0., 50., -60.), v(0., 0., 1.), 40.0, 120.0).unwrap();
let record = super::brep_record(&body).unwrap();
assert!(record.faces.iter().any(|f| matches!(f.surface, solidcraft_geom::brep::Surface::RationalSpline { .. })));
let walls = record.faces.iter().filter(|f| matches!(f.surface, solidcraft_geom::brep::Surface::Cylinder { .. })).count();
assert_eq!((walls, record.faces.len()), (1, 3));
let arrays = solidcraft_smlib::import::arrays(&record, true).unwrap();
let kinds = &arrays.ints[&flat::FACE_SURFACE_TYPE];
assert!(kinds.iter().all(|k| *k == i64::from(flat::SURFACE_PLANE) || *k == i64::from(flat::SURFACE_CYLINDER)), "{kinds:?}");
+9 -5
View File
@@ -2309,10 +2309,11 @@ fn tangent_holes_pinch_alike() {
assert_eq!(m.merged.faces, 12, "{:?}", m.merged);
}
/// A d10 tube bent at R5: the inside of the bend is a horn torus pinched to a point. One torus
/// face, with a degenerate loop at the pinch (5 faces, 6 edges, 4 vertices).
/// A d10 tube bent at R5: the inside of the bend is a horn torus pinched to a point, so the
/// sweep just doesn't fold over itself. It is a valid solid of Pappus' volume, πr² times the
/// path's length (20 + 5π/2 + 20).
#[test]
fn tight_bend_counts() {
fn a_bend_as_tight_as_the_tube_sweeps_a_valid_solid() {
use crate::build::PathSeg;
let region = Region2 { outer: Loop2::circle(Vec2::ZERO, 5.0), holes: vec![] };
let path = [
@@ -2326,8 +2327,11 @@ fn tight_bend_counts() {
PathSeg::Line { a: Vec3::new(5.0, 0.0, 25.0), b: Vec3::new(25.0, 0.0, 25.0) },
];
let b = sweep(&Plane::XY, &region, &path).unwrap();
let m = measure(&b).unwrap().merged;
assert_eq!((m.faces, m.edges, m.vertices), (5, 6, 4), "{m:?}");
assert!(b.validity().is_empty(), "{:?}", b.validity());
let pi = std::f64::consts::PI;
let want = pi * 25.0 * (40.0 + 2.5 * pi);
let v = measure(&b).unwrap().volume;
assert!(rel(v, want) < 1e-6, "{v} vs {want}");
}
#[test]