Skip to main content

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)]
8#[cfg_attr(
9    feature = "serde",
10    derive(serde::Serialize, serde::Deserialize),
11    serde(deny_unknown_fields)
12)]
13pub enum KnotSpec {
14    /// Uniform spacing, not necessarily clamped.
15    Uniform,
16    /// Quasi-uniform spacing with clamped ends.
17    QuasiUniform,
18    /// Piecewise Bezier knot multiplicities.
19    PiecewiseBezier,
20    /// Explicit knots and multiplicities.
21    Unspecified,
22}
23
24/// Exact B-spline data. Rational curves carry one weight per control point.
25#[derive(Debug, Clone, PartialEq)]
26#[cfg_attr(
27    feature = "serde",
28    derive(serde::Serialize, serde::Deserialize),
29    serde(deny_unknown_fields)
30)]
31pub struct BSplineCurve<P> {
32    /// Polynomial degree.
33    pub degree: u16,
34    /// Ordered control points.
35    pub control_points: Vec<P>,
36    /// Distinct knot values.
37    pub knots: Vec<Scalar>,
38    /// Multiplicity for each distinct knot.
39    pub multiplicities: Vec<u32>,
40    /// Optional rational weights, one per control point.
41    pub weights: Option<Vec<Scalar>>,
42    /// Whether the source declares the curve closed.
43    pub closed: bool,
44    /// Whether the source declares self intersection.
45    pub self_intersect: Option<bool>,
46    /// Source knot convention.
47    pub knot_spec: KnotSpec,
48}
49
50/// Two-dimensional B-spline curve.
51pub type BSplineCurve2 = BSplineCurve<Point2>;
52/// Three-dimensional B-spline curve.
53pub type BSplineCurve3 = BSplineCurve<Point3>;