Files
makeCAD/crates/smlib/src/split.rs
T
jyviko 9c65a30265 Kernel rig: export each case's kernel operations as a corpus for solidcore's rig
`cargo xtask kernel-cases [--ladder] --export DIR` runs the rig with the kernel's
operations traced (`smlib::trace`) and writes one entry per case: the operation, or
chain of operations, that made the bodies the case ends with; each operand that came
in as a record, as that record; the parameters, with every pick by points also given
as the topology index it picked; the fix set; the case's expected values and the
rig's result. A case no kernel operation alone accounts for is written too, marked
not expressible with its reasons. DIR/manifest.json counts them per area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
2026-11-03 06:05:18 -05:00

60 lines
3.1 KiB
Rust

//! Split Face and Split Body (`capi/include/smlib.h`, "Split"): faces cut where tool surfaces
//! meet them, and a solid cut in two by a surface. Tools are [`crate::ssi::Surface`]s, each
//! taken over its whole domain.
use crate::ssi::Surface;
use serde_json::json;
use crate::trace;
use crate::{Brep, Error, Result, core};
impl Brep {
/// `self` with faces `faces` (indices in SMLib's face order, distinct) cut where each of
/// `tools` meets them, the tools in turn, each cutting the pieces the earlier ones left; and
/// for each face how many faces it became besides itself (0: no tool split it). `None` when
/// no face is split. Tagged operands ([`Brep::tagged`]) give the pieces' history.
pub fn split_faces(&self, faces: &[usize], tools: &[&Surface]) -> Result<Option<(Brep, Vec<usize>)>> {
if faces.is_empty() || faces.len() > core::split::MAX_FACES || tools.is_empty() || tools.len() > core::split::MAX_TOOLS {
return Err(Error::Argument);
}
let specs: Vec<&crate::ssi::Spec> = tools.iter().map(|t| t.spec()).collect();
let r = core::split::split_faces(self.core(), faces, &specs).map(|r| r.map(|(b, made)| (Brep::made_core(b), made)));
trace::call(
"split_faces",
&[self],
&r,
|o| o.iter().map(|(b, _)| b.id).collect(),
|| json!({"faces": faces, "tools": specs.iter().map(|s| trace::surface(s)).collect::<Vec<_>>()}),
);
r
}
/// The manifold solid `self` cut in two by `tool` (whose domain must reach past it): the
/// part behind the surface (its normal points away) and the part in front, each closed by
/// the tool's piece inside the body and each possibly several solids. A tool that misses
/// leaves both parts the whole body, with no face from the tool (tag `self` to tell); `None`
/// when a side is left empty.
pub fn split_body(&self, tool: &Surface) -> Result<Option<(Brep, Brep)>> {
let r = core::split::split_body(self.core(), tool.spec()).map(|r| r.map(|(b, f)| (Brep::made_core(b), Brep::made_core(f))));
trace::call(
"split_body",
&[self],
&r,
|o| o.iter().flat_map(|(b, f)| [b.id, f.id]).collect(),
|| json!({"tool": trace::surface(tool.spec())}),
);
r
}
/// The manifold solid `self` cut in two by the sheet `sheet` as it is (its faces joined edge
/// to edge; it must cross the body to cut it), as [`Brep::split_body`] cuts it: its faces'
/// surfaces turned to agree with face `face`'s (in SMLib's face order), the part behind that
/// normal and the part in front. A `sheet` that is no sheet, or a `face` it does not have, is
/// [`Error::Argument`].
pub fn split_body_by_sheet(&self, sheet: &Brep, face: usize) -> Result<Option<(Brep, Brep)>> {
let r = core::split::split_body_by_sheet(self.core(), sheet.core(), face).map(|r| r.map(|(b, f)| (Brep::made_core(b), Brep::made_core(f))));
trace::call("split_body_by_sheet", &[self, sheet], &r, |o| o.iter().flat_map(|(b, f)| [b.id, f.id]).collect(), || json!({"face": face}));
r
}
}