Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Wave 86/509: kernel: one switch, SOLIDCRAFT_KERNEL, picks the kernel for every operation (and 3 more)

jyviko5f743c46b79d
diff --git a/apps/solidcraft-cli/src/kernel_cases.rs b/apps/solidcraft-cli/src/kernel_cases.rs
index 6d01d51db2..49d5f0e092 100644
--- a/apps/solidcraft-cli/src/kernel_cases.rs
+++ b/apps/solidcraft-cli/src/kernel_cases.rs
@@ -9,9 +9,9 @@ use serde_json::{Value, json};
use crate::oracle::{ABS_FRAC, Checks, REL_TOL, totals, v3};
use crate::{read_json, recipe};
-/// The kernel this process runs booleans with (`SOLIDCRAFT_BOOLEANS`, set by the caller).
+/// The kernel this process runs on (`SOLIDCRAFT_KERNEL`, set by the caller).
fn kernel() -> String {
- std::env::var("SOLIDCRAFT_BOOLEANS").ok().filter(|k| !k.is_empty()).unwrap_or_else(|| "default".into())
+ std::env::var("SOLIDCRAFT_KERNEL").ok().filter(|k| !k.is_empty()).unwrap_or_else(|| "default".into())
}
/// How many cases a chain of `base` recipes may go through (a ladder case builds on the one
diff --git a/apps/solidcraft-cli/src/main.rs b/apps/solidcraft-cli/src/main.rs
index a73856567b..4fffaff44d 100644
--- a/apps/solidcraft-cli/src/main.rs
+++ b/apps/solidcraft-cli/src/main.rs
@@ -82,7 +82,7 @@ const USAGE_RECIPE: &str = " solidcraft-cli recipe <recipe.json>\n";
/// `oracle`'s lines in the usage.
const USAGE_ORACLE: &str = " solidcraft-cli oracle <case-dir>... [--json]\n";
/// `kernel-cases`'s lines in the usage.
-const USAGE_KERNEL_CASES: &str = " solidcraft-cli kernel-cases <case-dir>... [--json]\n (the kernel regression rig, tests/kernel-cases; SOLIDCRAFT_BOOLEANS picks the kernel)\n";
+const USAGE_KERNEL_CASES: &str = " solidcraft-cli kernel-cases <case-dir>... [--json]\n (the kernel regression rig, tests/kernel-cases; SOLIDCRAFT_KERNEL picks the kernel)\n";
/// `fuzz`'s lines in the usage.
const USAGE_FUZZ: &str =
" solidcraft-cli fuzz [--from N] [--count N] [--jobs J] [--timeout S] [--steps N] [--minimise] [--out DIR] [--report FILE]\n";
diff --git a/crates/kernel/src/backend.rs b/crates/kernel/src/backend.rs
new file mode 100644
index 0000000000..8ff0b40d67
--- /dev/null
+++ b/crates/kernel/src/backend.rs
@@ -0,0 +1,51 @@
+//! Which kernel this process runs its operations on: truck (the default) or SMLib.
+//!
+//! The setting is the environment variable `SOLIDCRAFT_KERNEL`, read once per process: `truck`
+//! (or unset) or `smlib`. Every operation that has an SMLib path asks [`backend`]. SMLib needs a
+//! build with the kernel's `smlib` feature; set without it, or set to anything else, every such
+//! operation fails with an error that says so rather than quietly running truck, so a comparison
+//! run can never compare truck with itself.
+
+use crate::{KernelError, Result};
+
+/// The environment variable that picks the kernel.
+pub const KERNEL_ENV: &str = "SOLIDCRAFT_KERNEL";
+
+/// A kernel operations run on.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum Backend {
+ Truck,
+ Smlib,
+}
+
+impl Backend {
+ /// The backend a setting names; `None` (unset) is truck.
+ pub fn parse(setting: Option<&str>) -> std::result::Result<Backend, String> {
+ match setting.map(str::trim) {
+ None | Some("") | Some("truck") => Ok(Backend::Truck),
+ Some("smlib") if cfg!(feature = "smlib") => Ok(Backend::Smlib),
+ Some("smlib") => Err(format!("{KERNEL_ENV}=smlib: not supported yet: this build has no SMLib (feature `smlib`)")),
+ Some(other) => Err(format!("{KERNEL_ENV}={other}: expected `truck` or `smlib`")),
+ }
+ }
+}
+
+/// The kernel this process runs on ([`KERNEL_ENV`], read on first use).
+pub fn backend() -> Result<Backend> {
+ static SETTING: std::sync::OnceLock<std::result::Result<Backend, String>> = std::sync::OnceLock::new();
+ SETTING.get_or_init(|| Backend::parse(std::env::var(KERNEL_ENV).ok().as_deref())).clone().map_err(KernelError::Invalid)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn the_setting_names_a_backend_or_is_refused() {
+ assert_eq!(Backend::parse(None), Ok(Backend::Truck));
+ assert_eq!(Backend::parse(Some("truck")), Ok(Backend::Truck));
+ assert_eq!(Backend::parse(Some(" ")), Ok(Backend::Truck));
+ assert_eq!(Backend::parse(Some("smlib")).is_ok(), cfg!(feature = "smlib"));
+ assert!(Backend::parse(Some("occt")).is_err());
+ }
+}
diff --git a/crates/kernel/src/boolean_history_tests.rs b/crates/kernel/src/boolean_history_tests.rs
index 7635f2b423..4f0d26f8bf 100644
--- a/crates/kernel/src/boolean_history_tests.rs
+++ b/crates/kernel/src/boolean_history_tests.rs
@@ -531,7 +531,7 @@ fn stacked_pieces_of_one_cylinder_keep_their_walls() {
#[cfg(feature = "smlib")]
mod smlib {
use super::*;
- use crate::boolean_backend::smlib_boolean;
+ use crate::smlib_boolean::smlib_boolean;
fn through_smlib(a: &Body, b: &Body, op: BoolOp) -> Body {
smlib_boolean(a, b, op).unwrap().expect("a result")
diff --git a/crates/kernel/src/lib.rs b/crates/kernel/src/lib.rs
index 8e0921db7d..5debee6442 100644
--- a/crates/kernel/src/lib.rs
+++ b/crates/kernel/src/lib.rs
@@ -12,6 +12,7 @@
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
#![forbid(unsafe_code)]
+mod backend;
mod blend;
mod blend_corner;
mod blend_fit;
@@ -20,7 +21,6 @@ mod blend_vertex;
#[cfg(test)]
mod blend_wrong_way_tests;
mod body;
-mod boolean_backend;
mod boolean_diagnostics;
mod boolean_guard;
mod boolean_record;
@@ -121,6 +121,8 @@ pub mod provenance;
mod record;
mod seam_faces;
mod sew;
+#[cfg(feature = "smlib")]
+mod smlib_boolean;
mod smooth_edges;
mod sphere_lens;
mod spline_conv;
@@ -157,11 +159,11 @@ mod validity;
pub mod watch;
mod whole_face;
+pub use backend::{Backend, KERNEL_ENV, backend};
pub use blend::{ChamferSide, chamfer, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_max, fillet_max_each};
pub use blend_corner::fillet_radii;
pub use blend_variable::{RadiusSpline, Taper, fillet_chord, fillet_tapered, fillet_variable, fillet_variable_points, fillet_variable_spline, taper};
pub use body::{Body, CapSignature, DISPLAY_ANGLE, DisplayShare, EdgeInfo, FaceInfo, FacePaint, FaceSource, Paint};
-pub use boolean_backend::{BOOLEANS_ENV, BooleanBackend, boolean_backend};
pub use boolean_diagnostics::{BooleanDiagnostics, BooleanFallback, BooleanStrategy, capture_boolean_diagnostics};
pub use boundary::{Boundary, boundary_patch};
pub use boundary_network::{BoundaryCurve, CurveSource, MAX_CHAIN_CURVES, MAX_EDGE_PICKS, boundary_join, boundary_surface};
diff --git a/crates/kernel/src/ops.rs b/crates/kernel/src/ops.rs
index 0df1d95032..34abd4d116 100644
--- a/crates/kernel/src/ops.rs
+++ b/crates/kernel/src/ops.rs
@@ -918,18 +918,18 @@ fn take_attempt() -> bool {
/// The result carries its exact history ([`Body::history`]) over the operands `[a, b]`,
/// whichever way it was made, or none where a step it took does not report one.
///
-/// Truck runs it unless [`crate::BOOLEANS_ENV`] picks SMLib ([`crate::boolean_backend`]).
+/// Truck runs it unless [`crate::KERNEL_ENV`] picks SMLib ([`crate::backend`]).
pub fn boolean(a: &Body, b: &Body, op: BoolOp) -> Result<Option<Body>> {
- crate::profile::timed(crate::profile::Kind::Boolean, || match crate::boolean_backend()? {
- crate::BooleanBackend::Truck => boolean_untimed(a, b, op),
- crate::BooleanBackend::Smlib => smlib_boolean(a, b, op),
+ crate::profile::timed(crate::profile::Kind::Boolean, || match crate::backend()? {
+ crate::Backend::Truck => boolean_untimed(a, b, op),
+ crate::Backend::Smlib => smlib_boolean(a, b, op),
})
}
/// [`boolean`] through SMLib, its result given the operands' roles as truck's is.
#[cfg(feature = "smlib")]
fn smlib_boolean(a: &Body, b: &Body, op: BoolOp) -> Result<Option<Body>> {
- let r = guard("SMLib boolean", || crate::boolean_backend::smlib_boolean(a, b, op));
+ let r = guard("SMLib boolean", || crate::smlib_boolean::smlib_boolean(a, b, op));
with_operand_roles(a, b, op, r)
}
diff --git a/crates/kernel/src/boolean_backend.rs b/crates/kernel/src/smlib_boolean.rs
similarity index 50%
rename from crates/kernel/src/boolean_backend.rs
rename to crates/kernel/src/smlib_boolean.rs
index 4b2ad5beab..789dfdc45c 100644
--- a/crates/kernel/src/boolean_backend.rs
+++ b/crates/kernel/src/smlib_boolean.rs
@@ -1,51 +1,12 @@
-//! Which kernel runs [`crate::boolean`]: truck (the default) or SMLib.
-//!
-//! The setting is the environment variable `SOLIDCRAFT_BOOLEANS`, read once per process:
-//! `truck` (or unset) or `smlib`. SMLib needs a build with the kernel's `smlib` feature; set
-//! without it, or set to anything else, every boolean fails with an error that says so rather
-//! than quietly running truck, so a comparison run can never compare truck with itself.
-//!
-//! Through SMLib a boolean is: each operand's schema 4 record built in SMLib and tagged as
-//! operand 0 or 1, `SmBrep` boolean, the result exported to schema 4 and decoded as a kernel
-//! body. The result's history is SMLib's own (its tags carried through the operation),
-//! renumbered from SMLib's face and edge order into the operands' and the result's ([`History`]'s
-//! contract). A result SMLib's own check or the record's geometry check refuses is an error,
-//! never a body.
+//! Booleans through SMLib ([`crate::backend`] picks them): each operand's schema 4 record built
+//! in SMLib and tagged as operand 0 or 1, `SmBrep` boolean, the result exported to schema 4 and
+//! decoded as a kernel body. The result's history is SMLib's own (its tags carried through the
+//! operation), renumbered from SMLib's face and edge order into the operands' and the result's
+//! ([`crate::history::History`]'s contract). A result SMLib's own check or the record's geometry
+//! check refuses is an error, never a body.
-use crate::{KernelError, Result};
-
-/// The environment variable that picks the boolean kernel.
-pub const BOOLEANS_ENV: &str = "SOLIDCRAFT_BOOLEANS";
-
-/// A kernel that runs booleans.
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum BooleanBackend {
- Truck,
- Smlib,
-}
-
-impl BooleanBackend {
- /// The backend a setting names; `None` (unset) is truck.
- pub fn parse(setting: Option<&str>) -> std::result::Result<BooleanBackend, String> {
- match setting.map(str::trim) {
- None | Some("") | Some("truck") => Ok(BooleanBackend::Truck),
- Some("smlib") if cfg!(feature = "smlib") => Ok(BooleanBackend::Smlib),
- Some("smlib") => Err(format!("{BOOLEANS_ENV}=smlib: not supported yet: this build has no SMLib (feature `smlib`)")),
- Some(other) => Err(format!("{BOOLEANS_ENV}={other}: expected `truck` or `smlib`")),
- }
- }
-}
-
-/// The boolean kernel this process uses ([`BOOLEANS_ENV`], read on first use).
-pub fn boolean_backend() -> Result<BooleanBackend> {
- static SETTING: std::sync::OnceLock<std::result::Result<BooleanBackend, String>> = std::sync::OnceLock::new();
- SETTING.get_or_init(|| BooleanBackend::parse(std::env::var(BOOLEANS_ENV).ok().as_deref())).clone().map_err(KernelError::Invalid)
-}
-
-#[cfg(feature = "smlib")]
pub(crate) use smlib::boolean as smlib_boolean;
-#[cfg(feature = "smlib")]
mod smlib {
use solidcraft_smlib::{BooleanOp, CheckLevel};
@@ -105,17 +66,3 @@ mod smlib {
body.with_checked_history(history, &record::counts(&[a, b]))
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn the_setting_names_a_backend_or_is_refused() {
- assert_eq!(BooleanBackend::parse(None), Ok(BooleanBackend::Truck));
- assert_eq!(BooleanBackend::parse(Some("truck")), Ok(BooleanBackend::Truck));
- assert_eq!(BooleanBackend::parse(Some(" ")), Ok(BooleanBackend::Truck));
- assert_eq!(BooleanBackend::parse(Some("smlib")).is_ok(), cfg!(feature = "smlib"));
- assert!(BooleanBackend::parse(Some("occt")).is_err());
- }
-}
diff --git a/crates/kernel/src/validity.rs b/crates/kernel/src/validity.rs
index 943335927d..d07c4ed9fc 100644
--- a/crates/kernel/src/validity.rs
+++ b/crates/kernel/src/validity.rs
@@ -65,10 +65,13 @@ pub fn smlib_built() -> bool {
cfg!(feature = "smlib")
}
-/// The kernel booleans run on in this process: `"default"` or `"smlib"`. The regression rig
-/// refuses to grade a kernel the process isn't running. The SMLib boolean switch
-/// (`SOLIDCRAFT_BOOLEANS=smlib`) answers here once it lands; until then this is always
-/// `"default"`.
+/// The kernel this process runs on ([`crate::backend`]): `"default"` (truck) or `"smlib"`, and
+/// `"invalid"` where [`crate::KERNEL_ENV`] names neither or names SMLib in a build without it.
+/// The regression rig refuses to grade a kernel the process isn't running.
pub fn boolean_kernel() -> &'static str {
- "default"
+ match crate::backend() {
+ Ok(crate::Backend::Truck) => "default",
+ Ok(crate::Backend::Smlib) => "smlib",
+ Err(_) => "invalid",
+ }
}
diff --git a/crates/smlib/SMLIB_REV b/crates/smlib/SMLIB_REV
index 21013f033f..03e44b16f2 100644
--- a/crates/smlib/SMLIB_REV
+++ b/crates/smlib/SMLIB_REV
@@ -1 +1 @@
-14996818bedacc057cf35f296b29876df022faa7
+1f4d4a173e9fae1f149d5457b2e1cb0a8d62d005
diff --git a/crates/smlib/src/ffi/ops.rs b/crates/smlib/src/ffi/ops.rs
index 4262bd5580..c91d705887 100644
--- a/crates/smlib/src/ffi/ops.rs
+++ b/crates/smlib/src/ffi/ops.rs
@@ -1,5 +1,6 @@
//! The operations block of `capi/include/smlib.h` (`smlib_boolean`, `smlib_fillet`,
-//! `smlib_chamfer`, `smlib_shell`, `smlib_brep_solid_count`; the fork's `capi/src/smlib_ops.cpp`),
+//! `smlib_chamfer`, `smlib_shell`, `smlib_offset_faces`, `smlib_thicken`,
+//! `smlib_brep_solid_count`; the fork's `capi/src/smlib_ops.cpp`),
//! declared by hand. Part of the FFI boundary, like its parent: called only through
//! [`crate::ops`].
@@ -14,6 +15,7 @@ use super::{ERR_ARG, OK, RawBrep, new_brep};
pub const ERR_NOT_SOLID: i32 = -1100;
pub const ERR_PICK_NONE: i32 = -1101;
pub const ERR_PICK_AMBIGUOUS: i32 = -1102;
+pub const ERR_NO_ROOM: i32 = -1103;
pub const BOOLEAN_UNION: i32 = 0;
pub const BOOLEAN_SUBTRACT: i32 = 1;
@@ -25,6 +27,7 @@ pub enum Pick {
Fillet,
Chamfer,
Shell,
+ OffsetFaces,
}
/// A failed selection operation: the status, and the index of the point that selected nothing
@@ -65,6 +68,16 @@ unsafe extern "C" {
out: *mut *mut RawBrep,
out_failed_point: *mut i64,
) -> i32;
+ fn smlib_offset_faces(
+ brep: *const RawBrep,
+ points: *const f64,
+ n_points: i64,
+ tolerance: f64,
+ distance: f64,
+ out: *mut *mut RawBrep,
+ out_failed_point: *mut i64,
+ ) -> i32;
+ fn smlib_thicken(brep: *const RawBrep, thickness: f64, symmetric: i32, out: *mut *mut RawBrep) -> i32;
}
#[cfg(feature = "native")]
@@ -89,6 +102,7 @@ pub fn pick_op(kind: Pick, b: &Handle, points: &[[f64; 3]], tolerance: f64, size
Pick::Fillet => smlib_fillet,
Pick::Chamfer => smlib_chamfer,
Pick::Shell => smlib_shell,
+ Pick::OffsetFaces => smlib_offset_faces,
};
let flat = points.as_ptr().cast::<f64>();
let mut failed = -1i64;
@@ -98,6 +112,16 @@ pub fn pick_op(kind: Pick, b: &Handle, points: &[[f64; 3]], tolerance: f64, size
})
}
+#[cfg(feature = "native")]
+pub fn thicken(b: &Handle, thickness: f64, symmetric: bool) -> Result<Handle, i32> {
+ new_brep(|out| unsafe { smlib_thicken(b.raw(), thickness, i32::from(symmetric), out) })
+}
+
+#[cfg(not(feature = "native"))]
+pub fn thicken(_: &Handle, _: f64, _: bool) -> Result<Handle, i32> {
+ Err(NOT_BUILT)
+}
+
#[cfg(not(feature = "native"))]
pub fn boolean(_: &Handle, _: &Handle, _: i32) -> Result<Handle, i32> {
Err(NOT_BUILT)
diff --git a/crates/smlib/src/import/analytic.rs b/crates/smlib/src/import/analytic.rs
index 8eaeed53ff..075411901f 100644
--- a/crates/smlib/src/import/analytic.rs
+++ b/crates/smlib/src/import/analytic.rs
@@ -9,8 +9,9 @@
//! domain; where the analytic surface's natural normal is the other way round, the face is turned
//! over (its loops reversed, its uses in the shells flipped), which leaves the solid as it was.
//!
-//! A revolution of any other profile, or one placed by a matrix that is not a rigid motion, is
-//! refused; any other spline stays a spline.
+//! A revolution of any other profile, or one placed by a matrix that is not a rigid motion,
+//! stays a revolution, which the import sends as its exact rational B-spline; any other spline
+//! stays a spline.
use std::borrow::Cow;
use std::f64::consts::{FRAC_PI_2, TAU};
@@ -32,8 +33,14 @@ pub(super) fn analytic(brep: &b::Brep) -> R<Cow<'_, b::Brep>> {
let mut turned = Vec::new();
for (i, f) in brep.faces.iter().enumerate() {
let found = match &f.surface {
+ // One that is none of the analytic kinds goes as its exact rational B-spline
+ // (`super::revolution`).
b::Surface::PlacedRevolution { profile, origin, axis, matrix, forward } => {
- Some(Revolution::new(profile, *origin, *axis, matrix, *forward)?.analytic(f.domain)?)
+ match Revolution::new(profile, *origin, *axis, matrix, *forward).and_then(|r| r.analytic(f.domain)) {
+ Ok(found) => Some(found),
+ Err(Unsupported::NotYet(_)) => None,
+ Err(e) => return Err(e),
+ }
}
b::Surface::RationalSpline { u_knots, v_knots, homogeneous } => {
extruded_circle(u_knots, v_knots, homogeneous, f.domain, 1e-9 * size.max(1.0))
diff --git a/crates/smlib/src/lib.rs b/crates/smlib/src/lib.rs
index 5dda74a1c3..e200b62a6f 100644
--- a/crates/smlib/src/lib.rs
+++ b/crates/smlib/src/lib.rs
@@ -44,6 +44,8 @@ pub enum Error {
NoMatch { point: usize },
/// Selection point `point` is equally near to two edges (faces).
Ambiguous { point: usize },
+ /// An inward offset (a shell's wall, faces moved in) leaves no room inside the body.
+ NoRoom,
/// A C++ exception (most likely out of memory) was caught at the boundary.
Exception,
/// The C API is a different version from the one this crate was written against.
@@ -64,6 +66,7 @@ impl std::fmt::Display for Error {
Error::NotSolid => write!(f, "SMLib's result is not a closed solid"),
Error::NoMatch { point } => write!(f, "selection point {} is not near any edge or face", point + 1),
Error::Ambiguous { point } => write!(f, "selection point {} is equally near to two edges or faces", point + 1),
+ Error::NoRoom => write!(f, "the offset leaves no room inside the body"),
Error::Exception => write!(f, "SMLib raised an internal exception"),
Error::Version(v) => write!(f, "SMLib C API version {v}, expected {}", ffi::ABI_VERSION),
Error::NotBuilt => write!(f, "not supported yet: this build has no SMLib"),
@@ -81,6 +84,7 @@ fn error(s: i32) -> Error {
ffi::ERR_ARG | ffi::ERR_BUFFER => Error::Argument,
ffi::ERR_EMPTY => Error::Empty,
ffi::ops::ERR_NOT_SOLID => Error::NotSolid,
+ ffi::ops::ERR_NO_ROOM => Error::NoRoom,
ffi::ERR_EXCEPTION => Error::Exception,
ffi::NOT_BUILT => Error::NotBuilt,
s => Error::Status(s),
diff --git a/crates/smlib/src/ops.rs b/crates/smlib/src/ops.rs
index a25361a60e..e5c1acc967 100644
--- a/crates/smlib/src/ops.rs
+++ b/crates/smlib/src/ops.rs
@@ -1,4 +1,5 @@
-//! SMLib's modelling operations: booleans, fillet, chamfer and shell. Each returns a new body
+//! SMLib's modelling operations: booleans, fillet, chamfer, shell, offset faces and thicken.
+//! Each returns a new body
//! and leaves its inputs unchanged.
//!
//! Edges and faces are chosen by points, never by SMLib's internal order: each point selects the
@@ -66,11 +67,27 @@ impl Brep {
/// Hollowed to a wall of `thickness` (negative: inside the original surface, positive:
/// outside), open at the faces nearest to `open_faces` (each within `tolerance`); none gives
- /// a closed hollow body.
+ /// a closed hollow body. An inward wall that leaves no room inside is [`Error::NoRoom`].
pub fn shell(&self, open_faces: &[[f64; 3]], tolerance: f64, thickness: f64) -> Result<Brep> {
self.pick_op(ffi::ops::Pick::Shell, open_faces, tolerance, thickness, true)
}
+ /// The solid with the faces nearest to `faces` (each within `tolerance`) moved `distance`
+ /// along their outward normals (negative: into the body), onto their surfaces' offsets, the
+ /// faces around them extended or trimmed to meet them. Faces moved in past all of the body
+ /// behind them are [`Error::NoRoom`].
+ pub fn offset_faces(&self, faces: &[[f64; 3]], tolerance: f64, distance: f64) -> Result<Brep> {
+ self.pick_op(ffi::ops::Pick::OffsetFaces, faces, tolerance, distance, false)
+ }
+
+ /// A sheet thickened into a solid by `thickness` along its surfaces' normals (negative:
+ /// against them), or by half each way when `symmetric`, with ruled walls along its open
+ /// edges. A closed solid is [`Error::Argument`].
+ pub fn thicken(&self, thickness: f64, symmetric: bool) -> Result<Brep> {
+ init()?;
+ ffi::ops::thicken(&self.0, thickness, symmetric).map(Brep).map_err(error)
+ }
+
fn pick_op(&self, kind: ffi::ops::Pick, points: &[[f64; 3]], tolerance: f64, size: f64, allow_none: bool) -> Result<Brep> {
init()?;
if points.len() > MAX_POINTS || (points.is_empty() && !allow_none) {
diff --git a/crates/smlib/src/ops_tests.rs b/crates/smlib/src/ops_tests.rs
index c816fad962..0778a43859 100644
--- a/crates/smlib/src/ops_tests.rs
+++ b/crates/smlib/src/ops_tests.rs
@@ -206,16 +206,16 @@ fn hostile_inputs_are_errors() {
assert_eq!(c.shell(&[[10.0, 10.0, 20.0]], 0.1, t).unwrap_err(), Error::Argument, "thickness {t}");
}
// Sizes SMLib cannot build fail as errors, whatever SMLib says.
- for (what, r) in [
- ("radius larger than the cube", c.fillet(&mid, 0.1, 50.0)),
- ("chamfer past the faces", c.chamfer(&mid, 0.1, 30.0)),
- ("wall thicker than the box", c.shell(&[[10.0, 10.0, 20.0]], 0.1, -15.0)),
- ] {
+ for (what, r) in [("radius larger than the cube", c.fillet(&mid, 0.1, 50.0)), ("chamfer past the faces", c.chamfer(&mid, 0.1, 30.0))] {
match r {
Ok(b) => panic!("{what}: SMLib built a body of volume {:?}, counts {:?}", b.volume(ACC), b.counts()),
Err(e) => eprintln!("{what}: {e:?}"),
}
}
+ // A wall with no room inside it never reaches SMLib's offset.
+ assert_eq!(c.shell(&[[10.0, 10.0, 20.0]], 0.1, -15.0).unwrap_err(), Error::NoRoom);
+ assert_eq!(c.offset_faces(&[[10.0, 10.0, 20.0]], 0.1, -20.0).unwrap_err(), Error::NoRoom);
+ assert_eq!(c.thicken(1.0, false).unwrap_err(), Error::Argument, "a solid is no sheet");
assert_untouched(&c, 8000.0, [6, 12, 8]);
}
diff --git a/tests/kernel-cases/README.md b/tests/kernel-cases/README.md
index ca7e73ead4..67733cf247 100644
--- a/tests/kernel-cases/README.md
+++ b/tests/kernel-cases/README.md
@@ -11,7 +11,7 @@ cargo run -p solidcraft-cli -- kernel-cases tests/kernel-cases/booleans/<id>
```
For the `smlib` column, build `solidcraft-cli` with `--features smlib` (after
-`scripts/fetch-smlib.sh`). The rig sets `SOLIDCRAFT_BOOLEANS=smlib` for those runs.
+`scripts/fetch-smlib.sh`). The rig sets `SOLIDCRAFT_KERNEL=smlib` for those runs.
## Rules
diff --git a/xtask/src/kernel_cases.rs b/xtask/src/kernel_cases.rs
index edb87615f4..aa74dc8690 100644
--- a/xtask/src/kernel_cases.rs
+++ b/xtask/src/kernel_cases.rs
@@ -87,9 +87,9 @@ fn run_case(o: &Options, kernel: &str, case: &Path) -> Value {
};
cmd.current_dir(root()).args(["kernel-cases", "--json"]).arg(&rel).stdout(Stdio::piped()).stderr(Stdio::piped());
if kernel == "default" {
- cmd.env_remove("SOLIDCRAFT_BOOLEANS");
+ cmd.env_remove("SOLIDCRAFT_KERNEL");
} else {
- cmd.env("SOLIDCRAFT_BOOLEANS", kernel);
+ cmd.env("SOLIDCRAFT_KERNEL", kernel);
}
let base = |status: &str, error: String| {
let area = case.parent().and_then(|p| p.file_name()).map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
@@ -278,7 +278,7 @@ fn write_report(o: &Options, dir: &Path, list: &[PathBuf], results: &[Value]) ->
);
}
let mut md = String::from(
- "# Kernel regression rig\n\nGenerated by `cargo xtask kernel-cases`. Every geometry case the old kernel (truck) got wrong, as an issue, a PR or a crash report recorded it, is a use case in [`tests/kernel-cases/`](../tests/kernel-cases/) with its own right answer: numbers from analysis or a hand calculation (**analytic**) where the geometry has them, and otherwise the invariants (**invariants**): the operation succeeds, or refuses cleanly where that is the right answer; each body is one closed shell that passes the record's structure and geometry checks and, in builds with SMLib, SMLib's own check; the expected face, edge and vertex counts. Never a kernel's output, and never a commercial kernel's.\n\nEach kernel is graded against the case, never against the other kernel. **default** is the kernel SolidCraft ships today; **smlib** runs with `SOLIDCRAFT_BOOLEANS=smlib`. A failing case stays failing until its kernel is fixed; there is no workaround on SolidCraft's side. See [`tests/kernel-cases/README.md`](../tests/kernel-cases/README.md) for the format.\n\n",
+ "# Kernel regression rig\n\nGenerated by `cargo xtask kernel-cases`. Every geometry case the old kernel (truck) got wrong, as an issue, a PR or a crash report recorded it, is a use case in [`tests/kernel-cases/`](../tests/kernel-cases/) with its own right answer: numbers from analysis or a hand calculation (**analytic**) where the geometry has them, and otherwise the invariants (**invariants**): the operation succeeds, or refuses cleanly where that is the right answer; each body is one closed shell that passes the record's structure and geometry checks and, in builds with SMLib, SMLib's own check; the expected face, edge and vertex counts. Never a kernel's output, and never a commercial kernel's.\n\nEach kernel is graded against the case, never against the other kernel. **default** is the kernel SolidCraft ships today; **smlib** runs with `SOLIDCRAFT_KERNEL=smlib`. A failing case stays failing until its kernel is fixed; there is no workaround on SolidCraft's side. See [`tests/kernel-cases/README.md`](../tests/kernel-cases/README.md) for the format.\n\n",
);
md += "## Coverage\n\n| Area | Cases |";
for k in &o.kernels {