mirror of
https://github.com/bherbruck/solidcraft.git
synced 2026-11-04 11:05:56 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017itGh5fpMEousnZ91cYcVt
This commit is contained in:
@@ -1 +1 @@
|
||||
2152a2cbbb12ee2c0990caf3e85621f7552d5198
|
||||
4a81dd9ca9a7bbd41c5125e4cc7b026f6abae5e5
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Handle, i32> {
|
||||
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<Handle, i32> {
|
||||
Err(NOT_BUILT)
|
||||
}
|
||||
@@ -24,6 +24,7 @@ pub mod import;
|
||||
mod measure;
|
||||
mod ops;
|
||||
mod split;
|
||||
mod sheets;
|
||||
pub mod ssi;
|
||||
pub mod sweeps;
|
||||
pub mod trim;
|
||||
|
||||
@@ -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<Brep> {
|
||||
init()?;
|
||||
ffi::sheets::offset_sheet(&self.0, distance).map(Brep).map_err(error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user