use super::*;
use crate::clash_contact_axes::dot3;
use crate::kernel::arrangement::Tri;
use crate::kernel::near_band::NearBand;
use clash_solid_geom::component_groups;
#[test]
fn an_axis_below_its_own_band_is_caught_even_when_a_different_axis_is_the_argmin() {
let axes: [[f64; 3]; 3] = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];
let mut band = NearBand::default();
for p in [
[10000.0, 0.0, 0.0],
[10001.0, 1.0, 1.0],
[10000.998, 0.0, 0.9994],
[10002.0, 1.0, 2.0],
] {
band.observe_point(&p);
}
let overlap_lo = [10000.998, 0.0, 0.9994];
let overlap_hi = [10001.0, 1.0, 1.0];
let tris: Vec<Tri> = vec![[overlap_lo, overlap_hi, overlap_lo]];
let mut old_thickness = f64::INFINITY;
let mut old_required = 0.0;
for axis in &axes {
let (mut lo, mut hi) = (f64::INFINITY, f64::NEG_INFINITY);
for v in &tris[0] {
let p = dot3(*v, *axis);
lo = lo.min(p);
hi = hi.max(p);
}
let t = hi - lo;
if t < old_thickness {
old_thickness = t;
old_required = TRUST_BAND_MULTIPLE * band.scaled_band2(*axis, 1.0).sqrt();
}
}
assert!(
old_thickness >= old_required,
"premise: the old argmin-only shape must wrongly trust this pair (argmin {old_thickness} \
>= its own required {old_required}) for this test to demonstrate the fix"
);
let reason = trust_gate_reason(&tris, &axes, &band, TRUST_BAND_MULTIPLE);
assert!(
reason.is_some(),
"the 2 mm X overlap sits inside the X-normal near band at 10 km and must be caught, \
even though the 0.6 mm Z overlap alone would clear the Z-axis band and used to be the \
only axis checked"
);
}
#[test]
fn two_triangles_sharing_only_one_vertex_are_still_pooled_into_one_component_a_known_limitation() {
let tri_a: Tri = [[0.0, 0.0, 0.0], [0.0001, 0.0, 0.0], [0.0, 0.0001, 0.0]]; let tri_b: Tri = [[0.0, 0.0, 0.0], [10.0, 0.0, 0.0], [10.0, 10.0, 0.0]];
let groups = component_groups(&[tri_a, tri_b]);
assert_eq!(
groups.len(),
1,
"documented limitation: a shared vertex (no shared edge) still pools these into one \
component; if this now returns 2, see this test's doc comment before updating it"
);
}
#[test]
fn two_disjoint_triangles_with_no_shared_geometry_are_two_components() {
let tri_a: Tri = [[0.0, 0.0, 0.0], [0.0001, 0.0, 0.0], [0.0, 0.0001, 0.0]];
let tri_b: Tri = [[20.0, 0.0, 0.0], [30.0, 0.0, 0.0], [30.0, 10.0, 0.0]];
let groups = component_groups(&[tri_a, tri_b]);
assert_eq!(groups.len(), 2);
}