use crate::csg::ClippingProcessor;
use crate::world_frame_fixture::{
WORLD_FRAME_CASES, WorldFrameCase, mesh_volume, normal_projected_noise_bound,
placed_box_mesh,
};
fn recess_volume(case: WorldFrameCase, depth: f64) -> f64 {
let host = placed_box_mesh(case, [0.0, 0.0, 0.0], [1.0, 1.0, 0.3]);
let cutter = placed_box_mesh(case, [0.3, 0.3, 0.3 - depth], [0.7, 0.7, 0.5]);
let processor = ClippingProcessor::new();
let result = processor
.subtract_mesh(&host, &cutter)
.expect("subtract must succeed");
mesh_volume(&result)
}
const THIN_DEPTH: f64 = 0.002;
const EXPECTED_THIN: f64 = 0.3 - 0.4 * 0.4 * THIN_DEPTH;
#[test]
fn the_thin_recess_is_provably_above_the_z_noise_bound_in_every_case() {
for case in WORLD_FRAME_CASES {
let host = placed_box_mesh(case, [0.0, 0.0, 0.0], [1.0, 1.0, 0.3]);
let cutter = placed_box_mesh(case, [0.3, 0.3, 0.3 - THIN_DEPTH], [0.7, 0.7, 0.5]);
let bound = normal_projected_noise_bound([0.0, 0.0, 1.0], &[&host, &cutter]);
assert!(
THIN_DEPTH > 1_000.0 * bound,
"corpus premise broken for {case:?}: depth {THIN_DEPTH} vs z-noise bound {bound}"
);
}
}
#[test]
fn a_deep_recess_is_placement_invariant() {
let near = recess_volume(WorldFrameCase::AtOrigin, 0.1);
let far = recess_volume(WorldFrameCase::FarBaked, 0.1);
let expected = 0.3 - 0.4 * 0.4 * 0.1;
assert!((near - expected).abs() < 1e-4, "near {near} vs {expected}");
assert!((far - expected).abs() < 1e-4, "far {far} vs {expected}");
}
#[test]
fn a_2mm_recess_cuts_at_the_origin() {
let near = recess_volume(WorldFrameCase::AtOrigin, THIN_DEPTH);
assert!(
(near - EXPECTED_THIN).abs() < 1e-4,
"near {near} vs {EXPECTED_THIN}"
);
}
#[test]
fn a_2mm_recess_cuts_identically_10km_out_in_x() {
let far = recess_volume(WorldFrameCase::FarBaked, THIN_DEPTH);
assert!(
(far - EXPECTED_THIN).abs() < 1e-4,
"world-frame corpus: the SAME 2 mm recess that cuts at the origin must cut \
10 km out in X (offset axis X, cut normal Z); far volume {far} vs expected \
{EXPECTED_THIN}"
);
}