use super::{DegenerateReason, IntersectionSolid, intersection_solid};
use crate::world_frame_fixture::{
WorldFrameCase, normal_projected_noise_bound, placed_box_mesh,
};
const OVERLAP_M: f64 = 0.005;
fn overlapping_pair(case: WorldFrameCase) -> (crate::mesh::Mesh, crate::mesh::Mesh) {
let a = placed_box_mesh(case, [0.0, 0.0, 0.0], [1.0, 1.0, 0.3]);
let b = placed_box_mesh(case, [0.0, 0.0, 0.3 - OVERLAP_M], [1.0, 1.0, 0.6]);
(a, b)
}
#[test]
fn the_overlap_is_provably_above_the_z_noise_bound_in_every_case() {
for case in crate::world_frame_fixture::WORLD_FRAME_CASES {
let (a, b) = overlapping_pair(case);
let bound = normal_projected_noise_bound([0.0, 0.0, 1.0], &[&a, &b]);
assert!(
OVERLAP_M > 10_000.0 * bound,
"corpus premise broken for {case:?}: overlap {OVERLAP_M} vs z-noise bound {bound}"
);
}
}
#[test]
fn counter_case_a_5mm_overlap_at_the_origin_is_a_solid() {
let (a, b) = overlapping_pair(WorldFrameCase::AtOrigin);
let solid = intersection_solid(&a, &b);
let volume = solid
.volume_m3()
.unwrap_or_else(|| panic!("expected a Solid at the origin, got {solid:?}"));
let expected = 1.0 * 1.0 * OVERLAP_M;
assert!(
(volume - expected).abs() < 1e-4,
"volume {volume} vs expected {expected}"
);
}
#[test]
fn counter_case_a_sub_band_overlap_at_the_origin_stays_withheld() {
let a = placed_box_mesh(WorldFrameCase::AtOrigin, [0.0, 0.0, 0.0], [1.0, 1.0, 0.3]);
let b = placed_box_mesh(
WorldFrameCase::AtOrigin,
[0.0, 0.0, 0.3 - 0.0002],
[1.0, 1.0, 0.6],
);
assert!(
matches!(
intersection_solid(&a, &b),
IntersectionSolid::Degenerate(DegenerateReason::BelowKernelResolution { .. })
),
"a 0.2 mm overlap sits inside the kernel's near band and must stay withheld"
);
}
#[test]
fn a_5mm_overlap_10km_out_in_x_must_still_be_a_solid() {
let (a, b) = overlapping_pair(WorldFrameCase::FarBaked);
let solid = intersection_solid(&a, &b);
let volume = solid.volume_m3().unwrap_or_else(|| {
panic!(
"the SAME genuine 5 mm overlap that is a Solid at the origin must be a \
Solid 10 km out in X (offset axis X, contact normal Z); got {solid:?}"
)
});
let expected = 1.0 * 1.0 * OVERLAP_M;
assert!(
(volume - expected).abs() < 1e-4,
"the gate returned a Solid 10 km out, but its far-placement volume {volume} \
does not match the expected {expected}"
);
}