test: failing regression test for #268: Panic from truck-topology lib.rs:186 when joining struts that end on a bore wall (#283)

* test: reproduce #268 (Panic from truck-topology lib.rs:186 when joining struts that end on a bore wall)

* Sew refuses edges whose ends weld to one vertex (#268)

The sewer welds vertices on a 1e-6 grid but only rejected edges shorter than
1e-9, so a sliver edge between the two welded its ends into one vertex and
truck-topology panicked ("Two same vertices cannot construct an edge") inside
the guard. Such an edge is now a degenerate-edge error before any truck call,
and the boolean takes its usual fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: bherbruck <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-12 11:18:24 -04:00
1 parent db6ecaf446
commit f525704192
3 files changed
+36 -1

No files matched your search

@@ -64,3 +64,27 @@ fn oblique_cut_through_a_small_arc_matches_a_split() {
assert!((got - above).abs() < 1e-6 * above, "{got} vs {above}");
}
}
/// Joining struts that end on a bore wall reached a truck-topology panic (#268). The guard caught it,
/// but no kernel call should panic at all (wasm aborts on a panic).
#[test]
fn struts_ending_on_a_bore_wall_join_without_a_panic() {
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
let me = std::thread::current().id();
let count = Arc::new(AtomicUsize::new(0));
let c2 = count.clone();
let prev = std::panic::take_hook();
std::panic::set_hook(Box::new(move |_| {
if std::thread::current().id() == me {
c2.fetch_add(1, Ordering::SeqCst);
}
}));
let mut s = Session::default();
let script: Value = serde_json::from_str(include_str!("../../../examples/regressions/join_struts_on_bore_wall.json")).unwrap();
let result = s.run_script(&script);
std::panic::set_hook(prev);
assert_eq!(count.load(Ordering::SeqCst), 0, "kernel panics during the join");
result.unwrap();
assert_eq!(s.model.state().bodies.len(), 1);
}
+2 -1
View File
@@ -363,7 +363,8 @@ fn sew_impl(faces: &[FaceSpec], touching: bool, sources: Option<&[Option<crate::
}
for e in l {
let (a, b) = e.ends();
if !a.is_finite() || !b.is_finite() || a.dist(b) < 1e-9 {
// Ends that weld to one vertex would make truck panic on a zero-length edge (#268).
if !a.is_finite() || !b.is_finite() || a.dist(b) < 1e-9 || key(a) == key(b) {
return Err(KernelError::Invalid("sew: a degenerate edge".into()));
}
}
@@ -0,0 +1,10 @@
{
"description": "A 25 x 140 x 140 fan frame with an R68 bore and two crossing 4 x 4 struts whose ends lie on the bore wall, joined into the frame. truck-topology panicked twice (lib.rs:186 'Two same vertices cannot construct an edge'); the kernel guard caught it, but the panic hook printed it. Issue #268.",
"commands": [
{"command": "solid.box", "params": {"corner": [438, 50, 42], "length": 25, "width": 140, "height": 140, "operation": "new_body", "body_name": "Frame"}},
{"command": "solid.cylinder", "params": {"base": [438, 120, 112], "axis": "X", "radius": 68, "height": 25, "operation": "cut"}},
{"command": "solid.box", "params": {"corner": [459, 52, 110], "length": 4, "width": 136, "height": 4, "operation": "new_body", "body_name": "StrutH"}},
{"command": "solid.box", "params": {"corner": [459, 118, 44], "length": 4, "width": 4, "height": 136, "operation": "new_body", "body_name": "StrutV"}},
{"command": "solid.combine", "params": {"target": "Frame", "tools": ["StrutH", "StrutV"], "operation": "join"}}
]
}