Skip to main content

brepkit_math/nurbs/intersection/
mod.rs

1//! Surface-surface and curve-surface intersection routines.
2//!
3//! These are the geometric foundations for boolean operations on NURBS solids.
4//!
5//! ## Algorithms
6//!
7//! - **Plane-NURBS**: Sample the NURBS surface on a grid, find sign changes of the
8//!   signed distance to the plane, trace zero-crossings via linear interpolation,
9//!   then refine with Newton iteration.
10//! - **NURBS-NURBS**: Subdivision + marching method in (u1,v1,u2,v2) parameter space.
11//! - **Line-surface**: Newton iteration from grid-based seed points.
12
13#![allow(
14    clippy::many_single_char_names,
15    clippy::similar_names,
16    clippy::suboptimal_flops,
17    clippy::needless_range_loop,
18    clippy::cast_precision_loss,
19    clippy::doc_markdown,
20    clippy::missing_const_for_fn,
21    clippy::manual_let_else
22)]
23
24mod chaining;
25mod curve_surface;
26mod line;
27mod plane;
28mod surface_marching;
29mod surface_seeding;
30
31use crate::nurbs::curve::NurbsCurve;
32use crate::vec::Point3;
33
34pub use chaining::chain_intersection_points;
35pub use curve_surface::{CurveSurfaceHit, intersect_curve_surface};
36pub use line::intersect_line_nurbs;
37pub use plane::intersect_plane_nurbs;
38pub use surface_seeding::intersect_nurbs_nurbs;
39
40/// Maximum work-queue entries for the branch-aware SSI marcher.
41const MAX_QUEUE_SIZE: usize = 100;
42
43/// Maximum traced curve segments before stopping branch exploration.
44const MAX_SEGMENTS: usize = 50;
45
46/// Maximum branch points detected per march direction.
47const MAX_BRANCHES_PER_DIRECTION: usize = 10;
48
49/// Maximum iterations for Newton-type solvers.
50///
51/// 20 iterations is sufficient for quadratic convergence from reasonable seeds
52/// (quadratic convergence achieves ~1e-12 in ~6 iterations from a 1e-1 seed).
53/// The limit is generous to handle near-singular cases where convergence slows.
54const MAX_NEWTON_ITER: usize = 20;
55
56/// A point on an intersection curve, with parameter values on both surfaces.
57#[derive(Debug, Clone, Copy)]
58pub struct IntersectionPoint {
59    /// 3D position of the intersection.
60    pub point: Point3,
61    /// Parameter on the first surface (u1, v1) or the curve parameter.
62    pub param1: (f64, f64),
63    /// Parameter on the second surface (u2, v2).
64    pub param2: (f64, f64),
65}
66
67/// Result of a surface-surface intersection: a list of intersection curves.
68#[derive(Debug, Clone)]
69pub struct IntersectionCurve {
70    /// The 3D intersection curve as a NURBS.
71    pub curve: NurbsCurve,
72    /// Sampled points along the curve with parameter values.
73    pub points: Vec<IntersectionPoint>,
74}
75
76#[cfg(test)]
77mod tests;