Struct stroke::bezier::Bezier

source ·
pub struct Bezier<P, const N: usize>where
    P: Point,{ /* private fields */ }
Expand description

General implementation of a Bezier curve of arbitrary degree (= number of control points - 1). The curve is solely defined by an array of ‘control_points’. The degree is defined as degree = control_points.len() - 1. Points on the curve can be evaluated with an interpolation parameter ‘t’ in interval [0,1] using the eval() and eval_casteljau() methods. Generic parameters: P: Generic points ‘P’ as defined by there Point trait const generic parameters: N: Number of control points

Implementations§

source§

impl<P, const N: usize> Bezier<P, { N }>where P: Point,

source

pub fn new(control_points: [P; N]) -> Bezier<P, { N }>

Create a new Bezier curve that interpolates the control_points. The degree is defined as degree = control_points.len() - 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 control_points(&self) -> [P; N]

source

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

Evaluate a point on the curve at point ‘t’ which should be in the interval [0,1] This is implemented using De Casteljau’s algorithm (over a temporary array with const generic sizing)

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 split(&self, t: P::Scalar) -> (Self, Self)

source

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

Returns the derivative curve of self which has N-1 control points. The derivative of an nth degree Bézier curve is an (n-1)th degree Bézier curve, with one fewer term, and new weights w0…wn-1 derived from the original weights as n(wi+1 - wi). So for a 3rd degree curve, with four weights, the derivative has three new weights: w0 = 3(w1-w0), w’1 = 3(w2-w1) and w’2 = 3(w3-w2).

source

pub fn arclen(&self, nsteps: usize) -> P::Scalar

Approximates the arc length of the curve by flattening it with straight line segments. This works quite well, at ~32 segments it should already provide an error in the decimal places The accuracy gain falls off with more steps so this approximation is unfeasable if desired accuracy is greater than 1-2 decimal places

Trait Implementations§

source§

impl<P, const N: usize> Clone for Bezier<P, N>where P: Point + Clone,

source§

fn clone(&self) -> Bezier<P, N>

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
source§

impl<'a, P: Point, const N: usize> IntoIterator for &'a mut Bezier<P, { N }>

§

type Item = &'a mut P

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, P>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IterMut<'a, P>

Creates an iterator from a value. Read more
source§

impl<P: Point, const N: usize> IntoIterator for Bezier<P, { N }>

§

type Item = P

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<Bezier<P, N> as IntoIterator>::Item, N>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<P, const N: usize> Spline<P> for Bezier<P, { N }>where P: Point,

source§

fn eval(&self, t: P::Scalar) -> P

source§

impl<P, const N: usize> Copy for Bezier<P, N>where P: Point + Copy,

Auto Trait Implementations§

§

impl<P, const N: usize> RefUnwindSafe for Bezier<P, N>where P: RefUnwindSafe,

§

impl<P, const N: usize> Send for Bezier<P, N>where P: Send,

§

impl<P, const N: usize> Sync for Bezier<P, N>where P: Sync,

§

impl<P, const N: usize> Unpin for Bezier<P, N>where P: Unpin,

§

impl<P, const N: usize> UnwindSafe for Bezier<P, N>where P: 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.