Struct stroke::cubic_bezier::CubicBezier
source · 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,
impl<P> CubicBezier<P>where P: Point,
pub fn new(start: P, ctrl1: P, ctrl2: P, end: P) -> Self
sourcepub fn eval(&self, t: P::Scalar) -> P
pub fn eval(&self, t: P::Scalar) -> P
Evaluate a CubicBezier curve at t by direct evaluation of the polynomial (not numerically stable)
sourcepub fn eval_casteljau(&self, t: P::Scalar) -> P
pub fn eval_casteljau(&self, t: P::Scalar) -> P
Evaluate a CubicBezier curve at t using the numerically stable De Casteljau algorithm
pub fn control_points(&self) -> [P; 4]
sourcepub fn axis(&self, t: P::Scalar, axis: usize) -> P::Scalar
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()
sourcepub fn arclen(&self, nsteps: usize) -> P::Scalar
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
pub fn split(&self, t: P::Scalar) -> (Self, Self)
sourcepub fn derivative(&self) -> QuadraticBezier<P>
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
sourcepub fn dd(&self, t: P::Scalar, axis: usize) -> P::Scalar
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
sourcepub fn distance_to_point(&self, point: P) -> P::Scalar
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:
- coarse search over the whole curve
- fine search around the minimum yielded by the coarse search
pub fn baseline(&self) -> LineSegment<P>
pub fn is_linear(&self, tolerance: P::Scalar) -> bool
pub fn is_a_point(&self, tolerance: P::Scalar) -> bool
sourcepub fn bounding_box(&self) -> [(P::Scalar, P::Scalar); P::DIM]
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>
impl<P: Clone> Clone for CubicBezier<P>
source§fn clone(&self) -> CubicBezier<P>
fn clone(&self) -> CubicBezier<P>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<P: Debug> Debug for CubicBezier<P>
impl<P: Debug> Debug for CubicBezier<P>
source§impl<P> From<CubicBezier<P>> for BezierSegment<P>where
P: Point,
impl<P> From<CubicBezier<P>> for BezierSegment<P>where P: Point,
source§fn from(s: CubicBezier<P>) -> Self
fn from(s: CubicBezier<P>) -> Self
source§impl<P: PartialEq> PartialEq<CubicBezier<P>> for CubicBezier<P>
impl<P: PartialEq> PartialEq<CubicBezier<P>> for CubicBezier<P>
source§fn eq(&self, other: &CubicBezier<P>) -> bool
fn eq(&self, other: &CubicBezier<P>) -> bool
self
and other
values to be equal, and is used
by ==
.