Skip to main content

brepkit_geometry/
lib.rs

1//! # brepkit-geometry
2//!
3//! Curve and surface sampling, extrema, and analytic/NURBS conversion.
4//! Layer L1, depending only on `brepkit-math`.
5//!
6//! Three subsystems:
7//!
8//! - [`sampling`]: uniform, deflection-adaptive, arc-length-uniform, and
9//!   curvature-adaptive curve sampling, plus surface grids.
10//! - [`extrema`]: point-to-curve projection, curve-to-curve and
11//!   point-to-surface distance, segment-segment distance, and a Lipschitz
12//!   global optimizer.
13//! - [`convert`]: analytic geometry to NURBS, and recognition of NURBS back
14//!   into analytic curves and surfaces.
15//!
16//! # Stability
17//!
18//! This crate is internal. It is published so that `brepkit-operations`
19//! resolves from crates.io, not because its API is meant to be called
20//! directly. Depend on `brepkit-operations` instead and expect breakage here
21//! on any release.
22//!
23//! # Example
24//!
25//! Adaptive sampling refines only where the curve bends. The deflection
26//! sampler splits an interval while the curve at its midpoint sits further
27//! than the requested deflection from the chord, which concentrates points in
28//! the tight regions and leaves the flat ones alone.
29//!
30//! It is a midpoint test rather than a proven bound. A curve whose largest
31//! excursion falls away from the midpoint, or an interval that reaches the
32//! recursion limit, can still exceed the requested deflection.
33//!
34//! ```
35//! use brepkit_geometry::sampling::deflection::sample_deflection;
36//! use brepkit_math::curves::Circle3D;
37//! use brepkit_math::vec::{Point3, Vec3};
38//!
39//! let circle = Circle3D::new(Point3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 1.0), 10.0)?;
40//!
41//! let coarse = sample_deflection(&circle, 0.0, std::f64::consts::TAU, 1.0);
42//! let fine = sample_deflection(&circle, 0.0, std::f64::consts::TAU, 0.01);
43//!
44//! // A tighter deflection budget buys more points on the same arc.
45//! assert!(fine.len() > coarse.len());
46//! # Ok::<(), brepkit_math::MathError>(())
47//! ```
48//!
49//! # Choosing a sampler
50//!
51//! The four curve samplers answer different questions, and picking by habit
52//! rather than by need is a common source of either ugly output or wasted
53//! points:
54//!
55//! | Sampler | Spaces points by | Use when |
56//! |---------|------------------|----------|
57//! | [`sampling::uniform`] | parameter | You need a fixed count, or the curve is a line |
58//! | [`sampling::deflection`] | midpoint chord error | You are tessellating, and want points placed by geometric error rather than by parameter |
59//! | [`sampling::arc_length`] | distance along the curve | Points must be evenly spaced in space, as for a sweep or a dashed line |
60//! | [`sampling::curvature`] | local curvature | A NURBS curve has tight and flat regions and you want detail only where it bends |
61//!
62//! Uniform parameter spacing is not uniform spatial spacing. On a NURBS curve
63//! with a non-uniform knot vector the two diverge sharply, which is why a
64//! sweep built on `uniform` can bunch its sections at one end.
65//!
66//! # See also
67//!
68//! - [`brepkit_math`](https://docs.rs/brepkit-math): the curves and surfaces
69//!   these algorithms operate on.
70//! - [`brepkit_operations`](https://docs.rs/brepkit-operations): the crate to
71//!   depend on instead of this one.
72
73pub mod convert;
74pub mod error;
75pub mod extrema;
76pub mod sampling;
77
78pub use error::GeomError;