d69ebbee1b
One numbered loop type (crate::numbered) carries each segment's profile numbers through orientation, snapping, circle re-seaming, re-sampling and rotation; every builder orients its regions through it once. Builders that make their own side faces pair each face with its provenance as it is made (ruled walls by the wire edges each face holds, smooth lofts, coils and path sweeps by segment), and cap_and_close appends the caps itself. Column following is kept only for faces truck sweeps internally (rsweep, tsweep along paths, cones, where an apex vertex stays put). Extrude derives face sources and history in one topology pass. One attach entry point takes operands with their edges already indexed. Geometry, face order, face sources and recorded origins are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J53sR6gEaVt56soFDpTck8
124 lines
4.5 KiB
Rust
124 lines
4.5 KiB
Rust
//! The B-rep kernel boundary.
|
|
//!
|
|
//! Everything SolveCraft does with solids goes through this crate: building bodies from planar
|
|
//! regions (extrude, revolve) and primitives, booleans, fillets and chamfers, tessellation,
|
|
//! measurement and STEP export and import. The implementation uses the `truck` crates (Apache-2.0; see
|
|
//! `plan/adr/0001-geometry-kernel.md`) plus our own local operations (edge fillets and
|
|
//! chamfers in `blend.rs`), but no truck type appears in the public API, so the kernel can be
|
|
//! replaced without touching the rest of the workspace.
|
|
//!
|
|
//! Every call into the third-party kernel runs under [`guard`]: a panic inside it becomes a
|
|
//! [`KernelError::Internal`] instead of taking the application down.
|
|
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
|
#![forbid(unsafe_code)]
|
|
|
|
mod blend;
|
|
mod blend_corner;
|
|
mod blend_variable;
|
|
mod body;
|
|
mod boolean_diagnostics;
|
|
mod bore_guard;
|
|
mod build;
|
|
mod coplanar;
|
|
mod curveblend;
|
|
mod delete_face;
|
|
mod emboss;
|
|
#[cfg(test)]
|
|
mod face_source_tests;
|
|
mod freeform;
|
|
pub mod fuzz;
|
|
mod heal;
|
|
mod helix;
|
|
pub mod history;
|
|
mod iges_in;
|
|
mod iges_out;
|
|
#[cfg(test)]
|
|
mod intersection_curve_tests;
|
|
mod lip;
|
|
mod loopblend;
|
|
mod measure;
|
|
mod mesh_convert;
|
|
mod meshbody;
|
|
mod numbered;
|
|
mod offset;
|
|
mod ops;
|
|
mod polybool;
|
|
mod polyhedron;
|
|
mod prism;
|
|
mod prism_curve;
|
|
mod prism_measure;
|
|
pub mod provenance;
|
|
mod record;
|
|
mod sew;
|
|
mod smooth_edges;
|
|
mod splitface;
|
|
mod step;
|
|
mod step_in;
|
|
mod step_out;
|
|
mod surface_kind;
|
|
mod surfaces;
|
|
mod sweep_path;
|
|
#[cfg(test)]
|
|
mod thread_tests;
|
|
mod topo;
|
|
|
|
pub use blend::{ChamferSide, chamfer, chamfer_sides, fillet};
|
|
pub use blend_corner::fillet_radii;
|
|
pub use blend_variable::{fillet_chord, fillet_variable, fillet_variable_points};
|
|
pub use body::{Body, CapSignature, EdgeInfo, FaceInfo, FacePaint, FaceSource, Paint};
|
|
pub use boolean_diagnostics::{BooleanDiagnostics, BooleanFallback, BooleanStrategy, capture_boolean_diagnostics};
|
|
pub use build::{PathSeg, box_solid, canonical_revolve_axis, cylinder, extrude, extrude_tapered, loft, revolve, sphere, sweep, torus};
|
|
pub use delete_face::delete_faces;
|
|
pub use emboss::{cylinder_emboss_anchor, emboss_cylinder, emboss_cylinder_at, has_cylinder_emboss_wall, infer_cylinder_emboss};
|
|
pub use helix::{loft_to_point, sweep_helix, sweep_helix_mesh};
|
|
pub use iges_in::{MAX_IGES_BYTES, iges_import, iges_to_step};
|
|
pub use iges_out::iges_export_bodies;
|
|
pub use lip::raise_band;
|
|
pub use measure::{BodyMeasure, measure};
|
|
pub use mesh_convert::convert_prismatic_mesh;
|
|
pub use meshbody::{MAX_TRIANGLES, mesh_body};
|
|
pub use offset::with_same_surface;
|
|
pub use ops::{BoolOp, boolean, can_join_touching_faces, split_by_plane, transform, transform_matrix, union_apart};
|
|
pub use polybool::{faceted_boolean, planar_boolean};
|
|
pub use polyhedron::{HalfSpace, convex_polyhedron, draft, offset_faces, shell};
|
|
pub use prism::{extrude_planar_regions, planar_regions_boolean};
|
|
pub use prism_measure::certified_prism_equivalent;
|
|
pub use sew::{EdgeSpec, FaceSpec, SurfSpec, sew};
|
|
pub use splitface::{SplitTool, split_body, split_faces, split_faces_with_map};
|
|
pub use step::step_export;
|
|
pub use step_in::{ImportedBody, StepImport, StepNode, step_import, step_import_shared, step_orientation_errors, step_validate};
|
|
pub use step_out::{ExportBody, ExportProduct, StepHeader, step_export_bodies, step_export_products};
|
|
pub use surface_kind::{FaceSurface, face_surface};
|
|
pub use surfaces::{copy_faces, extend, patch_edges, patch_region, stitch, thicken, trim};
|
|
pub use sweep_path::sweep_path;
|
|
pub use topo::{CylinderFace, cylinder_face_at};
|
|
pub use topo::{TopoCounts, merged_topology, seam_flags};
|
|
|
|
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
|
|
pub enum KernelError {
|
|
#[error("invalid input: {0}")]
|
|
Invalid(String),
|
|
#[error("the operation failed: {0}")]
|
|
Failed(String),
|
|
/// The third-party kernel panicked; the model is unchanged.
|
|
#[error("kernel internal error: {0}")]
|
|
Internal(String),
|
|
}
|
|
|
|
pub type Result<T> = std::result::Result<T, KernelError>;
|
|
|
|
/// Run third-party kernel code, converting a panic into an error.
|
|
pub fn guard<T>(what: &str, f: impl FnOnce() -> Result<T>) -> Result<T> {
|
|
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
|
|
Ok(r) => r,
|
|
Err(p) => {
|
|
let msg = p.downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| p.downcast_ref::<String>().cloned()).unwrap_or_default();
|
|
log::warn!("kernel panic in {what}: {msg}");
|
|
Err(KernelError::Internal(format!("{what}: {msg}")))
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|