1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//! A pure, standalone geometric kernel for CAD-grade curves and surfaces.
//!
//! `geomcore` provides parametric evaluation of elementary curves and
//! surfaces (lines, circles, ellipses, parabolas, hyperbolas, B-splines;
//! planes, cylinders, cones, spheres, tori, B-spline surfaces), rigid
//! transformations, and analytic curve-on-surface parametrization: computing
//! the exact 2D representation of a 3D curve in a surface's parameter space
//! wherever a closed form exists.
//!
//! # Namespace layout
//!
//! - The crate root re-exports the placement and value types shared by
//! everything else: [`Point`]/[`Point2D`], [`Vector`]/[`Vector2D`],
//! [`Axis`]/[`Axis2D`], [`Frame`]/[`Frame2D`], and [`Transform`].
//! - [`curves`] holds the 3D and 2D curve types ([`curves::Line`],
//! [`curves::Circle`], [`curves::Ellipse`], [`curves::Parabola`],
//! [`curves::Hyperbola`], [`curves::BSplineCurve`],
//! [`curves::Line2D`], [`curves::Circle2D`]), the [`curves::Curve`]/
//! [`curves::Curve2D`] enum adaptors, the
//! [`curves::TrimmedCurve`]/[`curves::TrimmedCurve2D`] pieces of a
//! curve over a parameter range (segments, arcs), and the
//! [`curves::ParametricCurve`]/[`curves::ParametricCurve2D`] traits.
//! - [`surfaces`] holds the five elementary surfaces
//! ([`surfaces::Plane`], [`surfaces::Cylinder`], [`surfaces::Cone`],
//! [`surfaces::Sphere`], [`surfaces::Torus`]) plus
//! [`surfaces::BSplineSurface`], the [`surfaces::Surface`] enum adaptor,
//! and the [`surfaces::ParametricSurface`] trait.
//! - [`bounding_box`] holds [`BoundingBox`] and the [`HasBoundingBox`] trait,
//! through which curves and surfaces report the axis-aligned box
//! bounding them.
//!
//! # Quick start
//!
//! ```
//! use geomcore::{Cylinder, Point, Tolerance, Vector};
//! use geomcore::curves::Circle;
//!
//! // Evaluate a circle at a single parameter, and over a batch of parameters.
//! let circle = Circle::new(Point::ORIGIN, Vector::Z, 2.0).unwrap();
//! let point = circle.eval_point(std::f64::consts::PI / 4.0);
//! let points = circle.eval_points(&[0.0, 1.0, 2.0]);
//! assert_eq!(points[0], circle.eval_point(0.0));
//!
//! // Curve-on-surface parametrization: this circle is coaxial with the
//! // cylinder, so it has an exact 2D image, a horizontal line in (u, v).
//! let cylinder = Cylinder::new(Point::ORIGIN, Vector::Z, 2.0).unwrap();
//! let pcurve = circle.parametrize_on(&cylinder, Tolerance::DEFAULT).unwrap();
//! # let _ = point;
//! ```
//!
//! # Intersections
//!
//! `a.intersect(&b, tol)` ([`Intersect`]) is the entry point. It works for
//! every supported pair of curves and surfaces, in either order: it solves
//! the pair exactly when a closed form exists and runs a numeric search
//! otherwise, and the result says which method ran and whether it found
//! every hit.
//!
//! ```
//! use geomcore::curves::TrimmedCurve;
//! use geomcore::{
//! BSplineCurve, Completeness, Intersect, IntersectionMethod, Line, Point, Sphere,
//! Tolerance, Vector,
//! };
//!
//! let tol = Tolerance::DEFAULT;
//! let sphere = Sphere::new(Point::ORIGIN, 2.0).unwrap();
//!
//! // A line through a sphere has a closed form: exact, and so complete.
//! let line = Line::new(Point::new(0.0, 0.0, -5.0), Vector::Z).unwrap();
//! let result = line.intersect(&sphere, tol);
//! assert_eq!(result.method(), IntersectionMethod::Exact);
//! assert_eq!(result.completeness(), &Completeness::Complete);
//! let parameters: Vec<Option<f64>> = result.hits().iter().map(|h| h.curve_parameter).collect();
//! assert_eq!(parameters, [Some(3.0), Some(7.0)]);
//! // A parameter the solver did not compute is `None`: the caller reads it
//! // from the point, here the sphere's.
//! assert_eq!(result.hits()[0].surface_parameters, None);
//! let (_, latitude) = sphere.parameters_of(result.hits()[0].point);
//! assert!((latitude + std::f64::consts::FRAC_PI_2).abs() < 1e-12);
//!
//! // A segment keeps only the hits in its range.
//! let segment = TrimmedCurve::new(line, 0.0, 5.0).unwrap();
//! assert_eq!(segment.intersect(&sphere, tol).hits().len(), 1);
//!
//! // A B-spline has no closed form: the numeric search runs.
//! let poles = vec![Point::new(0.0, 0.0, -5.0), Point::new(0.0, 0.0, 5.0)];
//! let spline = BSplineCurve::new(1, poles, vec![0.0, 1.0], vec![2, 2], false).unwrap();
//! let result = spline.intersect(&sphere, tol);
//! assert_eq!(result.method(), IntersectionMethod::Numeric);
//! assert_eq!(result.hits().len(), 2);
//! ```
//!
//! [`IntersectExact::intersect_exact`] is the typed fast path: between two
//! concrete types it returns the pair's own exact result. It recovers no
//! parameters it does not need and never falls back to a numeric search.
//!
//! ```
//! use geomcore::{IntersectExact, PlaneSphereIntersection, Point, Vector};
//! use geomcore::surfaces::{Plane, Sphere};
//!
//! let plane = Plane::new(Point::ORIGIN, Vector::Z).unwrap();
//! let sphere = Sphere::new(Point::ORIGIN, 2.0).unwrap();
//! let tol = geomcore::Tolerance::default();
//! let PlaneSphereIntersection::Circle(circle) = plane.intersect_exact(&sphere, tol) else {
//! panic!("expected a circle");
//! };
//! assert_eq!(sphere.intersect_exact(&plane, tol), PlaneSphereIntersection::Circle(circle));
//! ```
//!
//! Between [`surfaces::Surface`] or [`curves::Curve`] values it returns
//! a general result such as [`ExactSurfaceIntersection`], which reports
//! `NotAnalytic` for a B-spline or a pair without a closed form, where
//! [`Intersect::intersect`] runs the numeric search. Two surfaces without
//! a closed form are traced numerically by the same call.
//!
//! # Extending the kernel
//!
//! New curve or surface types are added by implementing
//! [`curves::ParametricCurve`] (or [`curves::ParametricCurve2D`]) and
//! [`surfaces::ParametricSurface`] respectively, without touching the
//! existing dispatch code in [`curves::Curve`]/[`surfaces::Surface`].
//! Such types are intersected by [`intersect_curve_curve`] and
//! [`intersect_curve_surface`], which run the numeric search on any
//! curve and surface and return the same result types as
//! [`Intersect::intersect`], solved numerically.
pub
/// Axis-aligned bounding boxes of curves and surfaces.
/// Internal analytic curve evaluation math.
pub
/// Public curve types: lines, conics, and B-spline curves.
/// Discretization of curves into points joined by straight segments, with
/// proven chord and angle deviations.
/// Axis and frame placement types.
/// Intersections of curves and surfaces: the routed [`Intersect`], the
/// typed exact [`IntersectExact`], and their results.
/// Internal numerical toolbox (polynomial roots, Newton, Brent).
pub
/// Points in 2D and 3D space.
/// Point-projection result types.
/// Internal analytic surface evaluation math.
pub
/// Public surface types: planes, cylinders, cones, spheres, tori, and
/// B-spline surfaces.
/// Distance and angle tolerances shared by all geometric queries.
/// Rigid and affine transformations.
/// Vectors in 2D and 3D space.
pub use ;
pub use ;
pub use ;
pub use ;
pub use curve_curve_extrema;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Tolerance;
pub use Transform;
pub use ;
// The 0.36 names, deprecated in 0.37 (ADR 0013): kept for one release so
// callers migrate with warnings instead of errors.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Point3D;
pub use Vector3D;