Add copy, clone, and debug derives to cubic spline structs (#13293)
# Objective Fixes #13190 --------- Co-authored-by: Ben Harper <ben@tukom.org>
This commit is contained in:
parent
dc0fdd6ad9
commit
6f641e9f9b
@ -40,6 +40,7 @@ use thiserror::Error;
|
|||||||
/// let bezier = CubicBezier::new(points).to_curve();
|
/// let bezier = CubicBezier::new(points).to_curve();
|
||||||
/// let positions: Vec<_> = bezier.iter_positions(100).collect();
|
/// let positions: Vec<_> = bezier.iter_positions(100).collect();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct CubicBezier<P: VectorSpace> {
|
pub struct CubicBezier<P: VectorSpace> {
|
||||||
control_points: Vec<[P; 4]>,
|
control_points: Vec<[P; 4]>,
|
||||||
}
|
}
|
||||||
@ -111,6 +112,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicBezier<P> {
|
|||||||
/// let hermite = CubicHermite::new(points, tangents).to_curve();
|
/// let hermite = CubicHermite::new(points, tangents).to_curve();
|
||||||
/// let positions: Vec<_> = hermite.iter_positions(100).collect();
|
/// let positions: Vec<_> = hermite.iter_positions(100).collect();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct CubicHermite<P: VectorSpace> {
|
pub struct CubicHermite<P: VectorSpace> {
|
||||||
control_points: Vec<(P, P)>,
|
control_points: Vec<(P, P)>,
|
||||||
}
|
}
|
||||||
@ -177,6 +179,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicHermite<P> {
|
|||||||
/// let cardinal = CubicCardinalSpline::new(0.3, points).to_curve();
|
/// let cardinal = CubicCardinalSpline::new(0.3, points).to_curve();
|
||||||
/// let positions: Vec<_> = cardinal.iter_positions(100).collect();
|
/// let positions: Vec<_> = cardinal.iter_positions(100).collect();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct CubicCardinalSpline<P: VectorSpace> {
|
pub struct CubicCardinalSpline<P: VectorSpace> {
|
||||||
tension: f32,
|
tension: f32,
|
||||||
control_points: Vec<P>,
|
control_points: Vec<P>,
|
||||||
@ -264,6 +267,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicCardinalSpline<P> {
|
|||||||
/// let b_spline = CubicBSpline::new(points).to_curve();
|
/// let b_spline = CubicBSpline::new(points).to_curve();
|
||||||
/// let positions: Vec<_> = b_spline.iter_positions(100).collect();
|
/// let positions: Vec<_> = b_spline.iter_positions(100).collect();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct CubicBSpline<P: VectorSpace> {
|
pub struct CubicBSpline<P: VectorSpace> {
|
||||||
control_points: Vec<P>,
|
control_points: Vec<P>,
|
||||||
}
|
}
|
||||||
@ -303,7 +307,7 @@ impl<P: VectorSpace> CubicGenerator<P> for CubicBSpline<P> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Error during construction of [`CubicNurbs`]
|
/// Error during construction of [`CubicNurbs`]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Clone, Debug, Error)]
|
||||||
pub enum CubicNurbsError {
|
pub enum CubicNurbsError {
|
||||||
/// Provided the wrong number of knots.
|
/// Provided the wrong number of knots.
|
||||||
#[error("Wrong number of knots: expected {expected}, provided {provided}")]
|
#[error("Wrong number of knots: expected {expected}, provided {provided}")]
|
||||||
@ -381,6 +385,7 @@ pub enum CubicNurbsError {
|
|||||||
/// .to_curve();
|
/// .to_curve();
|
||||||
/// let positions: Vec<_> = nurbs.iter_positions(100).collect();
|
/// let positions: Vec<_> = nurbs.iter_positions(100).collect();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct CubicNurbs<P: VectorSpace> {
|
pub struct CubicNurbs<P: VectorSpace> {
|
||||||
control_points: Vec<P>,
|
control_points: Vec<P>,
|
||||||
weights: Vec<f32>,
|
weights: Vec<f32>,
|
||||||
@ -585,6 +590,7 @@ impl<P: VectorSpace> RationalGenerator<P> for CubicNurbs<P> {
|
|||||||
///
|
///
|
||||||
/// ### Continuity
|
/// ### Continuity
|
||||||
/// The curve is C0 continuous, meaning it has no holes or jumps.
|
/// The curve is C0 continuous, meaning it has no holes or jumps.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct LinearSpline<P: VectorSpace> {
|
pub struct LinearSpline<P: VectorSpace> {
|
||||||
points: Vec<P>,
|
points: Vec<P>,
|
||||||
}
|
}
|
||||||
@ -624,7 +630,7 @@ pub trait CubicGenerator<P: VectorSpace> {
|
|||||||
/// Can be evaluated as a parametric curve over the domain `[0, 1)`.
|
/// Can be evaluated as a parametric curve over the domain `[0, 1)`.
|
||||||
///
|
///
|
||||||
/// Segments can be chained together to form a longer compound curve.
|
/// Segments can be chained together to form a longer compound curve.
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||||
pub struct CubicSegment<P: VectorSpace> {
|
pub struct CubicSegment<P: VectorSpace> {
|
||||||
coeff: [P; 4],
|
coeff: [P; 4],
|
||||||
}
|
}
|
||||||
@ -685,7 +691,7 @@ impl CubicSegment<Vec2> {
|
|||||||
pub fn new_bezier(p1: impl Into<Vec2>, p2: impl Into<Vec2>) -> Self {
|
pub fn new_bezier(p1: impl Into<Vec2>, p2: impl Into<Vec2>) -> Self {
|
||||||
let (p0, p3) = (Vec2::ZERO, Vec2::ONE);
|
let (p0, p3) = (Vec2::ZERO, Vec2::ONE);
|
||||||
let bezier = CubicBezier::new([[p0, p1.into(), p2.into(), p3]]).to_curve();
|
let bezier = CubicBezier::new([[p0, p1.into(), p2.into(), p3]]).to_curve();
|
||||||
bezier.segments[0].clone()
|
bezier.segments[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maximum allowable error for iterative Bezier solve
|
/// Maximum allowable error for iterative Bezier solve
|
||||||
@ -914,7 +920,7 @@ pub trait RationalGenerator<P: VectorSpace> {
|
|||||||
/// Can be evaluated as a parametric curve over the domain `[0, knot_span)`.
|
/// Can be evaluated as a parametric curve over the domain `[0, knot_span)`.
|
||||||
///
|
///
|
||||||
/// Segments can be chained together to form a longer compound curve.
|
/// Segments can be chained together to form a longer compound curve.
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||||
pub struct RationalSegment<P: VectorSpace> {
|
pub struct RationalSegment<P: VectorSpace> {
|
||||||
/// The coefficients matrix of the cubic curve.
|
/// The coefficients matrix of the cubic curve.
|
||||||
coeff: [P; 4],
|
coeff: [P; 4],
|
||||||
|
Loading…
Reference in New Issue
Block a user