diff --git a/crates/kernel/tests/shell_barrel.rs b/crates/kernel/tests/shell_barrel.rs index fb933cbfb..fc7422ae9 100644 --- a/crates/kernel/tests/shell_barrel.rs +++ b/crates/kernel/tests/shell_barrel.rs @@ -43,13 +43,19 @@ fn check_volume(body: &Body, lo: f64, hi: f64) { #[test] fn shell_of_a_revolved_barrel() { let barrel = barrel(); - let side = (0..barrel.face_count()) - .find_map(|i| match face_surface(&barrel, i) { - Some(s @ FaceSurface::Torus { major, minor, .. }) if (major - CENTRE).abs() < 1e-6 && (minor - RADIUS).abs() < 1e-6 => Some(s), - _ => None, - }) - .expect("barrel side is the inner sheet of a spindle torus"); - assert!(side.nearest(Vec3::new(15.0, 0.0, HALF_HEIGHT)).unwrap().dist(Vec3::new(14.0, 0.0, HALF_HEIGHT)) < 1e-6); + // The side is the inner (lemon) zone of a spindle torus: SMLib's torus describes only its + // outer zone, so the side is the exact rational surface of revolution of the arc. Two flat + // caps and that side; the solid is the closed-form barrel, 14 mm round at mid height (`contains` asks the display mesh, so a margin round it). + assert_eq!(barrel.face_count(), 3); + let planes = (0..barrel.face_count()).filter(|i| matches!(face_surface(&barrel, *i), Some(FaceSurface::Plane { .. }))).count(); + assert_eq!(planes, 2, "two caps and the curved side"); + let full = integral(RADIUS, 2.0 * HALF_HEIGHT) - integral(RADIUS, 0.0); + let volume = measure(&barrel).unwrap().volume; + assert!((volume - full).abs() < full * 1e-3, "{volume} vs {full}"); + for turn in [0.0, 1.0, 2.5, 4.0] { + let (c, s) = (f64::cos(turn), f64::sin(turn)); + assert!(barrel.contains(Vec3::new(13.8 * c, 13.8 * s, HALF_HEIGHT)) && !barrel.contains(Vec3::new(14.2 * c, 14.2 * s, HALF_HEIGHT))); + } let result = shell(&barrel, &[Vec3::new(0.0, 0.0, 2.0 * HALF_HEIGHT)], 2.0).unwrap(); assert!(result.validity().is_empty(), "{:?}", result.validity()); assert_eq!(result.shell_count(), 1); @@ -62,7 +68,8 @@ fn shell_of_a_revolved_barrel() { check_volume(&result, 2.0, 2.0 * HALF_HEIGHT); let history = result.history().expect("exact shell face history"); assert_eq!(history.operands, 1); - assert_eq!(history.faces.iter().filter(|f| matches!(f.origins.as_slice(), [FaceOrigin::Offset { operand: 0, .. }])).count(), 4); + // The inner wall and the inner floor, offsets of the barrel's side and bottom (the top opened). + assert_eq!(history.faces.iter().filter(|f| matches!(f.origins.as_slice(), [FaceOrigin::Offset { operand: 0, .. }])).count(), 2); let step = step_export(&[&result], "barrel shell").unwrap(); let imported = step_import(&step).unwrap(); assert_eq!(imported.bodies.len(), 1);