axiolid_curve/spline.rs
1//! B-spline and rational B-spline curve data.
2
3use axiolid_core::{Point2, Point3, Scalar};
4
5/// How the knot vector was specified by the source representation.
6#[non_exhaustive]
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum KnotSpec {
9 /// Uniform spacing, not necessarily clamped.
10 Uniform,
11 /// Quasi-uniform spacing with clamped ends.
12 QuasiUniform,
13 /// Piecewise Bezier knot multiplicities.
14 PiecewiseBezier,
15 /// Explicit knots and multiplicities.
16 Unspecified,
17}
18
19/// Exact B-spline data. Rational curves carry one weight per control point.
20#[derive(Debug, Clone, PartialEq)]
21pub struct BSplineCurve<P> {
22 /// Polynomial degree.
23 pub degree: u16,
24 /// Ordered control points.
25 pub control_points: Vec<P>,
26 /// Distinct knot values.
27 pub knots: Vec<Scalar>,
28 /// Multiplicity for each distinct knot.
29 pub multiplicities: Vec<u32>,
30 /// Optional rational weights, one per control point.
31 pub weights: Option<Vec<Scalar>>,
32 /// Whether the source declares the curve closed.
33 pub closed: bool,
34 /// Whether the source declares self intersection.
35 pub self_intersect: Option<bool>,
36 /// Source knot convention.
37 pub knot_spec: KnotSpec,
38}
39
40/// Two-dimensional B-spline curve.
41pub type BSplineCurve2 = BSplineCurve<Point2>;
42/// Three-dimensional B-spline curve.
43pub type BSplineCurve3 = BSplineCurve<Point3>;