pub struct CubicBezier<P> { /* private fields */ }
Expand description

A 2d cubic Bezier curve defined by four points: the starting point, two successive control points and the ending point. The curve is defined by equation: ∀ t ∈ [0..1], P(t) = (1 - t)³ * start + 3 * (1 - t)² * t * ctrl1 + 3 * t² * (1 - t) * ctrl2 + t³ * end

Implementations§

source§

impl<P> CubicBezier<P>where P: Point,

source

pub fn new(start: P, ctrl1: P, ctrl2: P, end: P) -> Self

source

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

Evaluate a CubicBezier curve at t by direct evaluation of the polynomial (not numerically stable)

source

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

Evaluate a CubicBezier curve at t using the numerically stable De Casteljau algorithm

source

pub fn control_points(&self) -> [P; 4]

source

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

Returns the x coordinate of the curve evaluated at t Convenience shortcut for bezier.eval(t).x()

source

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

Approximates the arc length of the curve by flattening it with straight line segments. Remember arclen also works by linear approximation, not the integral, so we have to accept error! This approximation is unfeasable if desired accuracy is greater than 2 decimal places

source

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

source

pub fn derivative(&self) -> QuadraticBezier<P>

Return the derivative curve. The derivative is also a bezier curve but of degree n-1 (cubic->quadratic) Since it returns the derivative function, eval() needs to be called separately

source

pub fn dd(&self, t: P::Scalar, axis: usize) -> P::Scalar

Direct Derivative - Sample the axis coordinate at ‘axis’ of the curve’s derivative at t without creating a new curve. This is a convenience function for .derivative().eval(t).axis(n)
Parameters: t: the sampling parameter on the curve interval [0..1] axis: the index of the coordinate axis [0..N] Returns: Scalar value of the points own type type F
May be deprecated in the future.
This function can cause out of bounds panic when axis is larger than dimension of P

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 baseline(&self) -> LineSegment<P>

source

pub fn is_linear(&self, tolerance: P::Scalar) -> bool

source

pub fn is_a_point(&self, tolerance: P::Scalar) -> bool

source

pub fn bounding_box(&self) -> [(P::Scalar, P::Scalar); P::DIM]

Return the bounding box of the curve as an array of (min, max) tuples for each dimension (its index)

Trait Implementations§

source§

impl<P: Clone> Clone for CubicBezier<P>

source§

fn clone(&self) -> CubicBezier<P>

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<P: Debug> Debug for CubicBezier<P>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<P> From<CubicBezier<P>> for BezierSegment<P>where P: Point,

source§

fn from(s: CubicBezier<P>) -> Self

Converts to this type from the input type.
source§

impl<P: PartialEq> PartialEq<CubicBezier<P>> for CubicBezier<P>

source§

fn eq(&self, other: &CubicBezier<P>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<P: Copy> Copy for CubicBezier<P>

source§

impl<P> StructuralPartialEq for CubicBezier<P>

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for CubicBezier<P>where P: RefUnwindSafe,

§

impl<P> Send for CubicBezier<P>where P: Send,

§

impl<P> Sync for CubicBezier<P>where P: Sync,

§

impl<P> Unpin for CubicBezier<P>where P: Unpin,

§

impl<P> UnwindSafe for CubicBezier<P>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.