Trait Curve

Source
pub trait Curve: Into<Segment> {
Show 17 methods // Required methods fn flatness(&self) -> Scalar; fn transform(&self, tr: Transform) -> Self; fn start(&self) -> Point; fn end(&self) -> Point; fn at(&self, t: Scalar) -> Point; fn split_at(&self, t: Scalar) -> (Self, Self); fn cut(&self, a: Scalar, b: Scalar) -> Self; fn bbox(&self, init: Option<BBox>) -> BBox; fn offset(&self, dist: Scalar, out: &mut impl Extend<Segment>); fn deriv(&self) -> Segment; fn reverse(&self) -> Self; fn roots(&self) -> CurveRoots; fn extremities(&self) -> CurveExtremities; fn length(&self, t0: Scalar, t1: Scalar) -> Scalar; // Provided methods fn flatten(&self, tr: Transform, flatness: Scalar) -> CurveFlattenIter { ... } fn split(&self) -> (Self, Self) { ... } fn param_at_length(&self, l: Scalar, error: Option<Scalar>) -> Scalar { ... }
}
Expand description

Set of operations common to all bezier curves.

Required Methods§

Source

fn flatness(&self) -> Scalar

Correspond to maximum deviation of the curve from the straight line f = max |curve(t) - line(curve_start, curve_end)(t)|. This function actually returns 16.0 * f^2 to avoid unneeded division and square root.

Source

fn transform(&self, tr: Transform) -> Self

Apply affine transformation to the curve

Source

fn start(&self) -> Point

Point at which curve starts

Source

fn end(&self) -> Point

Point at which curve ends

Source

fn at(&self, t: Scalar) -> Point

Evaluate curve at parameter value t in (0.0..=1.0)

Source

fn split_at(&self, t: Scalar) -> (Self, Self)

Split the curve at parameter value t

Source

fn cut(&self, a: Scalar, b: Scalar) -> Self

Create sub-curve specified starting at parameter value a and ending at value b

Source

fn bbox(&self, init: Option<BBox>) -> BBox

Extend provided init bounding box with the bounding box of the curve

Source

fn offset(&self, dist: Scalar, out: &mut impl Extend<Segment>)

Offset the curve by distance dist, result is inserted into out container

Source

fn deriv(&self) -> Segment

Derivative with respect to t, deriv(t) = [curve'(t)_x, curve'(t)_y]

Source

fn reverse(&self) -> Self

Identical curve but directed from end to start, instead of start to end.

Source

fn roots(&self) -> CurveRoots

Find roots of the equation curve(t)_y = 0. Values of the parameter at which curve crosses y axis.

Source

fn extremities(&self) -> CurveExtremities

Find all extremities of the curve curve'(t)_x = 0 || curve'(t)_y = 0

Source

fn length(&self, t0: Scalar, t1: Scalar) -> Scalar

Calculate length of the curve from t0 to t1

Provided Methods§

Source

fn flatten(&self, tr: Transform, flatness: Scalar) -> CurveFlattenIter

Convert curve to an iterator over line segments with desired flatness

Source

fn split(&self) -> (Self, Self)

Optimized version of Curve::split_at(0.5)

Source

fn param_at_length(&self, l: Scalar, error: Option<Scalar>) -> Scalar

Find value of parameter t given desired l length of the segment

This method is not particularly fast, parameter value is found by solving f(t) = self.length(0.0, t) - l == 0 using Newton’s method with fallback to bisection if next iteration will produce out of bound value.

Reference: https://www.geometrictools.com/Documentation/MovingAlongCurveSpecifiedSpeed.pdf

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§