logo
pub struct CubicBezierSegment<S> {
    pub from: Point<S>,
    pub ctrl1: Point<S>,
    pub ctrl2: Point<S>,
    pub to: Point<S>,
}
Expand description

A 2d curve segment defined by four points: the beginning of the segment, two control points and the end of the segment.

The curve is defined by equation:² ∀ t ∈ [0..1], P(t) = (1 - t)³ * from + 3 * (1 - t)² * t * ctrl1 + 3 * t² * (1 - t) * ctrl2 + t³ * to

Fields

from: Point<S>ctrl1: Point<S>ctrl2: Point<S>to: Point<S>

Implementations

Sample the curve at t (expecting t between 0 and 1).

Sample the x coordinate of the curve at t (expecting t between 0 and 1).

Sample the y coordinate of the curve at t (expecting t between 0 and 1).

Return the parameter values corresponding to a given x coordinate.

Return the parameter values corresponding to a given y coordinate.

Sample the curve’s derivative at t (expecting t between 0 and 1).

Sample the x coordinate of the curve’s derivative at t (expecting t between 0 and 1).

Sample the y coordinate of the curve’s derivative at t (expecting t between 0 and 1).

Return the sub-curve inside a given range of t.

This is equivalent to splitting at the range’s end points.

Split this curve into two sub-curves.

Return the curve before the split point.

Return the curve after the split point.

Returns true if the curve can be approximated with a single line segment, given a tolerance threshold.

Computes a “fat line” of this segment.

A fat line is two conservative lines between which the segment is fully contained.

Applies the transform to this curve and returns the results.

Swap the beginning and the end of the segment.

Approximate the curve with a single quadratic bézier segment.

This is terrible as a general approximation but works if the cubic curve does not have inflection points and is “flat” enough. Typically usable after subdividing the curve a few times.

Evaluates an upper bound on the maximum distance between the curve and its quadratic approximation obtained using to_quadratic.

Returns true if the curve can be safely approximated with a single quadratic bézier segment given the provided tolerance threshold.

Equivalent to comparing to_quadratic_error with the tolerance threshold, avoiding the cost of two square roots.

Computes the number of quadratic bézier segments required to approximate this cubic curve given a tolerance threshold.

Derived by Raph Levien from section 10.6 of Sedeberg’s CAGD notes https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=1000&context=facpub#section.10.6 and the error metric from the caffein owl blog post http://caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html

Returns the flattened representation of the curve as an iterator, starting after the current point.

Invokes a callback for each monotonic part of the segment.

Invokes a callback for each monotonic part of the segment.

Invokes a callback for each y-monotonic part of the segment.

Invokes a callback for each y-monotonic part of the segment.

Invokes a callback for each x-monotonic part of the segment.

Invokes a callback for each x-monotonic part of the segment.

Approximates the cubic bézier curve with sequence of quadratic ones, invoking a callback at each step.

Approximates the cubic bézier curve with sequence of quadratic ones, invoking a callback at each step.

Approximates the curve with sequence of line segments.

The tolerance parameter defines the maximum distance between the curve and its approximation.

Approximates the curve with sequence of line segments.

The tolerance parameter defines the maximum distance between the curve and its approximation.

The end of the t parameter range at the final segment is guaranteed to be equal to 1.0.

Compute the length of the segment using a flattened approximation.

Invokes a callback at each inflection point if any.

Return local x extrema or None if this curve is monotonic.

This returns the advancements along the curve, not the actual x position.

Return local y extrema or None if this curve is monotonic.

This returns the advancements along the curve, not the actual y position.

Find the advancement of the y-most position in the curve.

This returns the advancement along the curve, not the actual y position.

Find the advancement of the y-least position in the curve.

This returns the advancement along the curve, not the actual y position.

Find the advancement of the x-most position in the curve.

This returns the advancement along the curve, not the actual x position.

Find the x-least position in the curve.

Returns a conservative rectangle the curve is contained in.

This method is faster than bounding_box but more conservative.

Returns a conservative range of x that contains this curve.

Returns a conservative range of y that contains this curve.

Returns a conservative rectangle that contains the curve.

Returns the smallest range of x that contains this curve.

Returns the smallest range of y that contains this curve.

Returns whether this segment is monotonic on the x axis.

Returns whether this segment is monotonic on the y axis.

Returns whether this segment is fully monotonic.

Computes the intersections (if any) between this segment and another one.

The result is provided in the form of the t parameters of each point along the curves. To get the intersection points, sample the curves at the corresponding values.

Returns endpoint intersections where an endpoint intersects the interior of the other curve, but not endpoint/endpoint intersections.

Returns no intersections if either curve is a point.

Computes the intersection points (if any) between this segment and another one.

Computes the intersections (if any) between this segment a quadratic bézier segment.

The result is provided in the form of the t parameters of each point along the curves. To get the intersection points, sample the curves at the corresponding values.

Returns endpoint intersections where an endpoint intersects the interior of the other curve, but not endpoint/endpoint intersections.

Returns no intersections if either curve is a point.

Computes the intersection points (if any) between this segment and a quadratic bézier segment.

Computes the intersections (if any) between this segment and a line.

The result is provided in the form of the t parameters of each point along curve. To get the intersection points, sample the curve at the corresponding values.

Computes the intersection points (if any) between this segment and a line.

Computes the intersections (if any) between this segment and a line segment.

The result is provided in the form of the t parameters of each point along curve and segment. To get the intersection points, sample the segments at the corresponding values.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Start of the curve.

End of the curve.

Sample the curve at t (expecting t between 0 and 1).

Sample x at t (expecting t between 0 and 1).

Sample y at t (expecting t between 0 and 1).

Sample the derivative at t (expecting t between 0 and 1).

Sample x derivative at t (expecting t between 0 and 1).

Sample y derivative at t (expecting t between 0 and 1).

Split this curve into two sub-curves.

Return the curve before the split point.

Return the curve after the split point.

Return the curve inside a given range of t. Read more

Swap the direction of the segment.

Compute the length of the segment using a flattened approximation.

Approximates the curve with sequence of line segments. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.