Struct stroke::bspline::BSpline

source ·
pub struct BSpline<P, const K: usize, const C: usize, const D: usize>where
    P: Point,{ /* private fields */ }
Expand description

General Implementation of a BSpline with choosable degree, control points and knots. Generic parameters: P: const generic points array ‘P’ as defined by the Point trait F: Any float value used for the knots and interpolation (usually the same as the internal generic parameter within P). const generic parameters: C: Number of control points K: Number of Knots D: Degree of the piecewise function used for interpolation degree = order - 1 While C, K, O relate to each other in the following manner K = C + O where O = D + 1

Implementations§

source§

impl<P, const K: usize, const C: usize, const D: usize> BSpline<P, { K }, { C }, { D }>where P: Point,

source

pub fn new( knots: [P::Scalar; K], control_points: [P; C] ) -> Result<BSpline<P, { K }, { C }, { D }>, BSplineError>

Create a new B-spline curve that interpolates the control_points using a piecewise polynomial of degree within intervals specified by the knots. The knots must be sorted in non-decreasing order, the constructor enforces this which may yield undesired results. The degree is defined as curve_order - 1. Desired curve must have a valid number of control points and knots in relation to its degree or the constructor will return None. A B-Spline curve requires at least one more control point than the degree (control_points.len() > degree) and the number of knots should be equal to control_points.len() + degree + 1.

source

pub fn eval(&self, t: P::Scalar) -> Result<P, BSplineError>where [(); { _ }]: Sized,

Compute a point on the curve at t using iterative de boor algorithm. The parameter must be in the inclusive range of values returned by knot_domain(). If t is out of bounds a KnotDomainViolation error is returned.

source

pub fn control_points(&self) -> Iter<'_, P>

Returns an iterator over the control points.

source

pub fn knots(&self) -> Iter<'_, P::Scalar>

Returns an iterator over the knots.

source

pub fn knot_domain(&self) -> (P::Scalar, P::Scalar)

Returns the knot domain of the B-Spline. The knot domain is the range of values over which the B-Spline is defined. The knot domain is defined as the minimum and maximum knot values. For a clamped B-Spline the first and last knot has multiplicity D+1. For an unclamped B-Spline the first and last knot has multiplicity 1.

source

pub fn distance_to_point(&self, point: P) -> P::Scalar

Calculates the minimum distance between given ‘point’ and the curve. Uses two passes with the same amount of steps in t:

  1. coarse search over the whole curve
  2. fine search around the minimum yielded by the coarse search
source

pub fn arclen(&self, nsteps: usize) -> P::Scalarwhere [(); { _ }]: Sized,

Approximates the arc length of the curve by flattening it with straight line segments. This approximation is unfeasable if desired accuracy is greater than ~2 decimal places

source

pub fn derivative(&self) -> BSpline<P, K, { _ }, { _ }>

Returns the derivative curve of self which has N-1 control points. The derivative of an nth degree B-Spline curve is an (n-1)th degree (d) B-Spline curve, with the same knot vector, and new control points Q0…Qn-1 derived from the original control points Pi as: d Qi = —————– (P[i+1]-P[i]) k[i+d+1] - k[i+1]. with degree = curve_order - 1 TODO test & verify!

Trait Implementations§

source§

impl<P, const K: usize, const C: usize, const D: usize> Clone for BSpline<P, K, C, D>where P: Point + Clone, P::Scalar: Clone,

source§

fn clone(&self) -> BSpline<P, K, C, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<P, const K: usize, const C: usize, const D: usize> RefUnwindSafe for BSpline<P, K, C, D>where P: RefUnwindSafe, <P as Point>::Scalar: RefUnwindSafe,

§

impl<P, const K: usize, const C: usize, const D: usize> Send for BSpline<P, K, C, D>where P: Send, <P as Point>::Scalar: Send,

§

impl<P, const K: usize, const C: usize, const D: usize> Sync for BSpline<P, K, C, D>where P: Sync, <P as Point>::Scalar: Sync,

§

impl<P, const K: usize, const C: usize, const D: usize> Unpin for BSpline<P, K, C, D>where P: Unpin, <P as Point>::Scalar: Unpin,

§

impl<P, const K: usize, const C: usize, const D: usize> UnwindSafe for BSpline<P, K, C, D>where P: UnwindSafe, <P as Point>::Scalar: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.