Trait rasterize::Curve[][src]

pub trait Curve: Sized + Into<Segment> {
Show 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; fn flatten(&self, tr: Transform, flatness: Scalar) -> CurveFlattenIter

Notable traits for CurveFlattenIter

impl Iterator for CurveFlattenIter type Item = Line;
{ ... }
fn split(&self) -> (Self, Self) { ... }
fn from_length(&self, l: Scalar, error: Option<Scalar>) -> Scalar { ... }
}

Set of operations common to all bezier curves.

Required methods

fn flatness(&self) -> Scalar[src]

Correspond to maximum diviation 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.

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

Apply affine transformation to the curve

fn start(&self) -> Point[src]

Point at which curve starts

fn end(&self) -> Point[src]

Point at which curve ends

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

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

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

Split the curve at prameter value t

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

Create subcurve specified starting at parameter value a and ending at value b

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

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

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

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

fn deriv(&self) -> Segment[src]

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

fn reverse(&self) -> Self[src]

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

fn roots(&self) -> CurveRoots[src]

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

fn extremities(&self) -> CurveExtremities[src]

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

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

Calculate length of the curve from t0 to t1

Loading content...

Provided methods

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

Notable traits for CurveFlattenIter

impl Iterator for CurveFlattenIter type Item = Line;
[src]

Convert curve to an iterator over line segments with desired flatness

fn split(&self) -> (Self, Self)[src]

Optimized version of Curve::split_at(0.5)

fn from_length(&self, l: Scalar, error: Option<Scalar>) -> Scalar[src]

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

This method is not particulary fast, parmeter 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

Loading content...

Implementors

impl Curve for Segment[src]

impl Curve for Cubic[src]

fn flatness(&self) -> Scalar[src]

Flattness criteria for the cubic curve This function actually returns 16 * flatness^2

It is equal to f = max d(t) where d(t) = |c(t) - l(t)|, l(t) = (1 - t) * c0 + t * c3 for c(t) bezier3 curve with c{0..3} control points, in other words maximum distance from parametric line to bezier3 curve for the same parameter t. It is shown in the article that: f^2 <= 1/16 (max{u_x^2, v_x^2} + max{u_y^2, v_y^2}) where: u = 3 * b1 - 2 * b0 - b3 v = 3 * b2 - b0 - 2 * b3 f == 0 means completely flat so estimating upper bound is sufficient as spliting more than needed is not a problem for rendering.

Linear Approximation of Bezier Curve

fn split(&self) -> (Self, Self)[src]

Optimized version of split_at(0.5)

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

Offset cubic bezier curve with a list of cubic curves

Offset bezier curve using Tiller-Hanson method. In short, it will just offset line segment corresponding to control points, then find intersection of this lines and treat them as new control points.

impl Curve for Line[src]

impl Curve for Quad[src]

fn flatness(&self) -> Scalar[src]

Flattness criteria for the cubic curve

It is equal to f = max d(t) where d(t) = |q(t) - l(t)|, l(t) = (1 - t) * p0 + t * p2 for q(t) bezier2 curve with p{0..2} control points, in other words maximum distance from parametric line to bezier2 curve for the same parameter t.

Line can be represented as bezier2 curve, if p1 = (p0 + p2) / 2.0. Grouping polynomial coofficients:

    q(t) = t^2 p2 + 2 (1 - t) t p1 + (1 - t)^2 p0
    l(t) = t^2 p2 + (1 - t) t (p0 + p2) + (1 - t)^2 p0
    d(t) = |q(t) - l(t)| = (1 - t) t |2 * p1 - p0 - p2|
    f    = 1 / 4 * | 2 p1 - p0 - p2 |
    f^2  = 1/16 |2 * p1 - p0 - p2|^2

fn split(&self) -> (Self, Self)[src]

Optimized version of split_at(0.5)

Loading content...