pub struct QuadraticBezierShape {
    pub points: [Pos2; 3],
    pub closed: bool,
    pub fill: Color32,
    pub stroke: Stroke,
}
Expand description

A quadratic Bézier Curve.

See also CubicBezierShape.

Fields§

§points: [Pos2; 3]

The first point is the starting point and the last one is the ending point of the curve. The middle point is the control points.

§closed: bool§fill: Color32§stroke: Stroke

Implementations§

source§

impl QuadraticBezierShape

source

pub fn from_points_stroke( points: [Pos2; 3], closed: bool, fill: Color32, stroke: impl Into<Stroke> ) -> Self

Create a new quadratic Bézier shape based on the 3 points and stroke.

The first point is the starting point and the last one is the ending point of the curve. The middle point is the control points. The points should be in the order [start, control, end]

source

pub fn transform(&self, transform: &RectTransform) -> Self

Transform the curve with the given transform.

source

pub fn to_path_shape(&self, tolerance: Option<f32>) -> PathShape

Convert the quadratic Bézier curve to one PathShape. The tolerance will be used to control the max distance between the curve and the base line.

source

pub fn visual_bounding_rect(&self) -> Rect

The visual bounding rectangle (includes stroke width)

source

pub fn logical_bounding_rect(&self) -> Rect

Logical bounding rectangle (ignoring stroke width)

source

pub fn sample(&self, t: f32) -> Pos2

Calculate the point (x,y) at t based on the quadratic Bézier curve equation. t is in [0.0,1.0] Bézier Curve

source

pub fn flatten(&self, tolerance: Option<f32>) -> Vec<Pos2>

find a set of points that approximate the quadratic Bézier curve. the number of points is determined by the tolerance. the points may not be evenly distributed in the range [0.0,1.0] (t value)

source

pub fn for_each_flattened_with_t<F>(&self, tolerance: f32, callback: &mut F)
where F: FnMut(Pos2, f32),

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

The callback takes the point and corresponding curve parameter at each step.

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

Trait Implementations§

source§

impl Clone for QuadraticBezierShape

source§

fn clone(&self) -> QuadraticBezierShape

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 Debug for QuadraticBezierShape

source§

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

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

impl From<QuadraticBezierShape> for Shape

source§

fn from(shape: QuadraticBezierShape) -> Self

Converts to this type from the input type.
source§

impl PartialEq for QuadraticBezierShape

source§

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

source§

impl StructuralPartialEq for QuadraticBezierShape

Auto Trait Implementations§

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