Wave 85/509: kernel: a body's record for SMLib takes a larger tolerance where an edge needs it (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- e35b4d744 jyviko: kernel: revolutions of a line square to the axis go into SMLib as planes
- 00e43aacc jyviko: kernel: an operand SMLib's check refuses goes through SMLib's healer
- 94c159825 jyviko: kernel: SMLib's round faces decode as truck's own revolutions are laid out
- ff0f7ccfa jyviko: kernel: a body's record for SMLib takes a larger tolerance where an edge needs it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-21 06:30:20 -04:00
parent ffc289d7d8
commit f4e6dbd1d0
6 changed files with 133 additions and 26 deletions
+44 -6
View File
@@ -98,10 +98,33 @@ pub fn brep_record(body: &Body) -> Result<solidcraft_geom::brep::Brep> {
/// 9e-7 where the record as given is exact to 1e-7.
#[cfg(feature = "smlib")]
pub fn smlib_body(body: &Body) -> Result<solidcraft_smlib::Brep> {
let record = brep_record(body)?;
let record = tolerant_record(body)?;
solidcraft_smlib::Brep::from_record(&record, true).map_err(|e| KernelError::Failed(format!("SMLib: {e}")))
}
/// [`brep_record`] for another kernel: where an edge lies a little farther from a face it bounds
/// than the body's working tolerance (truck's offsets leave edges some 3e-5 mm off their faces),
/// the record takes a tolerance ten, then a hundred times as large for the body, its edges and
/// vertices, as the kernel it goes to works to tolerances (SMLib's own are far larger). Past
/// that it is refused.
#[cfg(feature = "smlib")]
fn tolerant_record(body: &Body) -> Result<solidcraft_geom::brep::Brep> {
guard("B-rep record", || {
if body.mesh.is_some() {
return Err(invalid("mesh bodies are source blobs, not B-rep"));
}
let working = crate::fill::face_tolerance(body);
let mut last = None;
for factor in [1.0, 10.0, 100.0] {
match adapter::encode_within(body, working * factor)? {
Ok(record) => return Ok(record),
Err(e) => last = Some(e),
}
}
Err(last.unwrap_or_else(|| invalid("no record")))
})
}
/// The truck solid of a schema 4 record, as a saved body's is built: tests compare records
/// made elsewhere (the STEP reader's) with truck's own import.
#[cfg(test)]
@@ -174,13 +197,28 @@ pub(crate) fn body_from_smlib_ordered(brep: &solidcraft_smlib::Brep) -> Result<(
})
}
/// `body` in SMLib ([`smlib_body`]), with where each of SMLib's faces and edges is in the body's
/// face and edge order: SMLib's export of the imported body, checked to number every face,
/// edge and vertex as the body's record does. `None` where it does not.
/// `body` in SMLib ([`smlib_body`], healed where SMLib's check refuses it as given), with where
/// each of SMLib's faces and edges is in the body's face and edge order: SMLib's export of the
/// imported body, checked to number every face, edge and vertex as the body's record does.
/// `None` where it does not.
#[cfg(feature = "smlib")]
pub(crate) fn smlib_body_ordered(body: &Body) -> Result<(solidcraft_smlib::Brep, Option<solidcraft_smlib::history::Order>)> {
let record = brep_record(body)?;
let brep = solidcraft_smlib::Brep::from_record(&record, true).map_err(|e| KernelError::Failed(format!("SMLib: {e}")))?;
use solidcraft_smlib::{Brep, CheckLevel};
let record = tolerant_record(body)?;
let import = |trusted: bool| Brep::from_record(&record, trusted).map_err(|e| KernelError::Failed(format!("SMLib: {e}")));
let valid = |b: &Brep| b.check(CheckLevel::All).is_ok_and(|c| c.is_valid());
// A record SMLib's check refuses as given (a gap a little over the record's tolerance, a
// hole listed before its face's outer loop) goes through SMLib's healer; healed, it is kept
// only where SMLib then finds it valid.
let trusted = import(true)?;
let brep = if valid(&trusted) {
trusted
} else {
match import(false) {
Ok(healed) if valid(&healed) => healed,
_ => trusted,
}
};
let order = match brep.to_native_ordered() {
Ok((back, order)) => same_numbering(&record, &back).then_some(order),
Err(e) => {