Skip to main content

brepkit_math/
lib.rs

1//! # brepkit-math
2//!
3//! Vector math, matrix transforms, NURBS geometry, and exact geometric
4//! predicates for the brepkit CAD kernel.
5//!
6//! This is the foundation layer (L0) with no workspace dependencies.
7
8/// Errors from math operations.
9#[derive(Debug, thiserror::Error)]
10pub enum MathError {
11    /// Knot vector length does not match control points and degree.
12    #[error("invalid knot vector: expected {expected} knots, got {got}")]
13    InvalidKnotVector {
14        /// Expected number of knots.
15        expected: usize,
16        /// Actual number of knots.
17        got: usize,
18    },
19
20    /// Weights vector length does not match control points.
21    #[error("invalid weights: expected {expected} weights, got {got}")]
22    InvalidWeights {
23        /// Expected number of weights.
24        expected: usize,
25        /// Actual number of weights.
26        got: usize,
27    },
28
29    /// Control point grid dimensions are inconsistent.
30    #[error(
31        "invalid control point grid: expected {expected_rows}x{expected_cols}, got inconsistent dimensions"
32    )]
33    InvalidControlPointGrid {
34        /// Expected number of rows.
35        expected_rows: usize,
36        /// Expected number of columns.
37        expected_cols: usize,
38    },
39
40    /// Cannot normalize a zero-length vector.
41    #[error("cannot normalize zero vector")]
42    ZeroVector,
43
44    /// Matrix is singular and cannot be inverted.
45    #[error("singular matrix cannot be inverted")]
46    SingularMatrix,
47
48    /// Input collection is empty where at least one element is required.
49    #[error("empty input where at least one element is required")]
50    EmptyInput,
51
52    /// Parameter is outside the valid range.
53    #[error("parameter {value} out of range [{min}, {max}]")]
54    ParameterOutOfRange {
55        /// The out-of-range value.
56        value: f64,
57        /// Lower bound of the valid range.
58        min: f64,
59        /// Upper bound of the valid range.
60        max: f64,
61    },
62
63    /// Newton iteration did not converge within the allowed iterations.
64    #[error("Newton iteration did not converge after {iterations} iterations")]
65    ConvergenceFailure {
66        /// Number of iterations attempted.
67        iterations: usize,
68    },
69}
70
71pub mod aabb;
72pub mod analytic_intersection;
73pub mod bvh;
74pub mod cdt;
75pub mod chord;
76pub mod convex_hull;
77pub mod curves;
78pub mod curves2d;
79pub mod det_hash;
80pub mod filtered;
81pub mod frame;
82pub mod mat;
83pub mod nurbs;
84pub mod obb;
85pub mod plane;
86pub mod polygon2d;
87pub mod polygon_boolean;
88pub mod polygon_offset;
89pub mod predicates;
90pub mod quadrature;
91pub mod ray_triangle;
92pub mod surfaces;
93pub mod tolerance;
94pub mod traits;
95pub mod vec;
96
97#[cfg(feature = "simd")]
98pub mod simd;