Struct rasterize::Cubic

source ·
pub struct Cubic(pub [Point; 4]);
Expand description

Cubic bezier curve

Polynomial form: (1 - t) ^ 3 * p0 + 3 * (1 - t) ^ 2 * t * p1 + 3 * (1 - t) * t ^ 2 * p2 + t ^ 3 * p3 Matrix from:

                ┌             ┐ ┌    ┐
┌             ┐ │  1  0  0  0 │ │ p0 │
│ 1 t t^2 t^3 │ │ -3  3  0  0 │ │ p1 │
└             ┘ │  3 -6  3  0 │ │ p2 │
                │ -1  3 -3  1 │ │ p3 │
                └             ┘ └    ┘

Tuple Fields§

§0: [Point; 4]

Implementations§

source§

impl Cubic

source

pub fn new( p0: impl Into<Point>, p1: impl Into<Point>, p2: impl Into<Point>, p3: impl Into<Point> ) -> Self

Create new cubic bezier curve

source

pub fn points(&self) -> [Point; 4]

Points defining cubic bezier curve

source

pub fn ends(&self) -> (Line, Line)

Tangent lines at the ends of cubic bezier curve

source

pub fn smooth(&self) -> Point

Find smooth point used by SVG parser

Trait Implementations§

source§

impl Clone for Cubic

source§

fn clone(&self) -> Cubic

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 Curve for Cubic

source§

fn flatness(&self) -> Scalar

Flatness 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 splitting more than needed is not a problem for rendering.

Linear Approximation of Bezier Curve

source§

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

Optimized version of split_at(0.5)

source§

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

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.

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 deriv(&self) -> Segment

Derivative with respect to t, deriv(t) = [curve'(t)_x, curve'(t)_y]
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 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
source§

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

Convert curve to an iterator over line segments with desired flatness
source§

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

Find value of parameter t given desired l length of the segment Read more
source§

impl Debug for Cubic

source§

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

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

impl Display for Cubic

source§

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

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

impl From<Cubic> for Segment

source§

fn from(cubic: Cubic) -> Self

Converts to this type from the input type.
source§

impl From<Quad> for Cubic

source§

fn from(quad: Quad) -> Self

Converts to this type from the input type.
source§

impl FromStr for Cubic

§

type Err = SvgParserError

The associated error which can be returned from parsing.
source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Cubic

source§

fn eq(&self, other: &Cubic) -> 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 Copy for Cubic

source§

impl StructuralPartialEq for Cubic

Auto Trait Implementations§

§

impl Freeze for Cubic

§

impl RefUnwindSafe for Cubic

§

impl Send for Cubic

§

impl Sync for Cubic

§

impl Unpin for Cubic

§

impl UnwindSafe for Cubic

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.