logo
pub struct QuadraticBezierSegment<S> {
    pub from: Point<S>,
    pub ctrl: Point<S>,
    pub to: Point<S>,
}
Expand description

A 2d curve segment defined by three points: the beginning of the segment, a control point and the end of the segment.

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

Fields

from: Point<S>ctrl: 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).

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).

Swap the beginning and the end of the segment.

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.

Return the y inflection point or None if this curve is y-monotonic.

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 advancement of the x-least position in the curve.

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

Return the x inflection point or None if this curve is x-monotonic.

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

This is equivalent 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.

Elevate this curve to a third order bézier.

Returns whether the curve can be approximated with a single point, given a tolerance threshold.

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.

Find the interval of the beginning of the curve that can be approximated with a line segment.

Approximates the curve with sequence of line segments.

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

This implements the algorithm described by Raph Levien at https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html

Compute a flattened approximation of the curve, invoking a callback at each step.

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.

This implements the algorithm described by Raph Levien at https://raphlinus.github.io/graphics/curves/2019/12/23/flatten-quadbez.html

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

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.

Returns a triangle containing this curve segment.

Returns a conservative rectangle that contains the curve.

Returns a conservative range of x that contains this curve.

Returns a conservative range of y that contains this curve.

Returns the smallest rectangle the curve is contained in

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 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 a line.

Computes the intersections (if any) between this segment 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.

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

Analytic solution to finding the closest point on the curve to pos.

Returns the shortest distance between this segment and a point.

Returns the shortest squared distance between this segment and a point.

May be useful to avoid the cost of a square root when comparing against a distance that can be squared instead.

Computes the length of this segment.

Implements Raph Levien’s analytical approach described in https://raphlinus.github.io/curves/2018/12/28/bezier-arclength.html

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.