From e1326f37f1fb748b4e0f81609f34a8a17a925360 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Thu, 22 Oct 2026 00:45:07 -0400 Subject: [PATCH] solidcraft-smlib: Brep::stitch and Brep::offset_sheet, and the fork pinned at e3d478d The safe wrappers of the fork's smlib_stitch (a body's faces sewn at a tolerance, oriented, with whether it closed) and smlib_offset_sheet (a sheet's faces onto their offsets), for the kernel's Stitch and Offset Surface. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017itGh5fpMEousnZ91cYcVt --- crates/smlib/SMLIB_REV | 2 +- crates/smlib/src/ffi.rs | 1 + crates/smlib/src/ffi/sheets.rs | 40 ++++++++++++++++++++++++++++++++++ crates/smlib/src/lib.rs | 1 + crates/smlib/src/sheets.rs | 23 +++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 crates/smlib/src/ffi/sheets.rs create mode 100644 crates/smlib/src/sheets.rs diff --git a/crates/smlib/SMLIB_REV b/crates/smlib/SMLIB_REV index a57d774f9..d5a51ab3a 100644 --- a/crates/smlib/SMLIB_REV +++ b/crates/smlib/SMLIB_REV @@ -1 +1 @@ -2152a2cbbb12ee2c0990caf3e85621f7552d5198 +4a81dd9ca9a7bbd41c5125e4cc7b026f6abae5e5 diff --git a/crates/smlib/src/ffi.rs b/crates/smlib/src/ffi.rs index 1254d7c04..2d69a594a 100644 --- a/crates/smlib/src/ffi.rs +++ b/crates/smlib/src/ffi.rs @@ -192,6 +192,7 @@ pub mod history; pub mod measure; pub mod ops; pub mod split; +pub mod sheets; pub mod ssi; pub mod sweeps; pub mod trim; diff --git a/crates/smlib/src/ffi/sheets.rs b/crates/smlib/src/ffi/sheets.rs new file mode 100644 index 000000000..61f23eda8 --- /dev/null +++ b/crates/smlib/src/ffi/sheets.rs @@ -0,0 +1,40 @@ +//! The sheets block of `capi/include/smlib.h` (`smlib_stitch`, `smlib_offset_sheet`; the fork's +//! `capi/src/smlib_sheets.cpp`), declared by hand. Part of the FFI boundary, like its parent: +//! called only through [`crate::sheets`]. + +#![allow(unsafe_code)] + +use super::Handle; +#[cfg(not(feature = "native"))] +use super::NOT_BUILT; +#[cfg(feature = "native")] +use super::{RawBrep, new_brep}; + +#[cfg(feature = "native")] +unsafe extern "C" { + fn smlib_stitch(brep: *const RawBrep, tolerance: f64, out_closed: *mut i32, out: *mut *mut RawBrep) -> i32; + fn smlib_offset_sheet(sheet: *const RawBrep, distance: f64, out: *mut *mut RawBrep) -> i32; +} + +/// The stitched body and whether it closed into a solid. +#[cfg(feature = "native")] +pub fn stitch(b: &Handle, tolerance: f64) -> Result<(Handle, bool), i32> { + let mut closed = 0i32; + let h = new_brep(|out| unsafe { smlib_stitch(b.raw(), tolerance, &mut closed, out) })?; + Ok((h, closed != 0)) +} + +#[cfg(feature = "native")] +pub fn offset_sheet(b: &Handle, distance: f64) -> Result { + new_brep(|out| unsafe { smlib_offset_sheet(b.raw(), distance, out) }) +} + +#[cfg(not(feature = "native"))] +pub fn stitch(_: &Handle, _: f64) -> Result<(Handle, bool), i32> { + Err(NOT_BUILT) +} + +#[cfg(not(feature = "native"))] +pub fn offset_sheet(_: &Handle, _: f64) -> Result { + Err(NOT_BUILT) +} diff --git a/crates/smlib/src/lib.rs b/crates/smlib/src/lib.rs index 91f2b98c1..eac683135 100644 --- a/crates/smlib/src/lib.rs +++ b/crates/smlib/src/lib.rs @@ -24,6 +24,7 @@ pub mod import; mod measure; mod ops; mod split; +mod sheets; pub mod ssi; pub mod sweeps; pub mod trim; diff --git a/crates/smlib/src/sheets.rs b/crates/smlib/src/sheets.rs new file mode 100644 index 000000000..f05306f44 --- /dev/null +++ b/crates/smlib/src/sheets.rs @@ -0,0 +1,23 @@ +//! SMLib's sheet operations: sewing a body's faces along the edges that coincide, and a sheet's +//! offset along its faces' normals. Each returns a new body and leaves its input unchanged; +//! tagged inputs ([`Brep::tagged`]) give results whose [`Brep::history`] says where each face and +//! edge came from. + +use crate::{Brep, Result, error, ffi, init}; + +impl Brep { + /// The faces sewn along the vertices and edges that coincide within `tolerance` mm, oriented + /// outward where they close into a solid, else only made to agree across their shared edges; + /// with whether the result is a closed solid. + pub fn stitch(&self, tolerance: f64) -> Result<(Brep, bool)> { + init()?; + ffi::sheets::stitch(&self.0, tolerance).map(|(h, closed)| (Brep(h), closed)).map_err(error) + } + + /// This sheet with every face moved onto its surface's offset by `distance` along its normal + /// (negative: against it). A closed solid is [`crate::Error::Argument`]. + pub fn offset_sheet(&self, distance: f64) -> Result { + init()?; + ffi::sheets::offset_sheet(&self.0, distance).map(Brep).map_err(error) + } +}