Skip to main content

CubicBezierShape

Struct CubicBezierShape 

Source
pub struct CubicBezierShape {
    pub points: [Pos2; 4],
    pub closed: bool,
    pub fill: Color32,
    pub stroke: PathStroke,
}
Available on crate feature egui only.
Expand description

Fields§

§points: [Pos2; 4]

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

§closed: bool§fill: Color32§stroke: PathStroke

Implementations§

Source§

impl CubicBezierShape

Source

pub fn from_points_stroke( points: [Pos2; 4], closed: bool, fill: Color32, stroke: impl Into<PathStroke>, ) -> CubicBezierShape

Creates a cubic Bézier curve based on 4 points and stroke.

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

Source

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

Transform the curve with the given transform.

Source

pub fn to_path_shapes( &self, tolerance: Option<f32>, epsilon: Option<f32>, ) -> Vec<PathShape>

Convert the cubic Bézier curve to one or two PathShape’s. When the curve is closed and it has to intersect with the base line, it will be converted into two shapes. Otherwise, it will be converted into one shape. The tolerance will be used to control the max distance between the curve and the base line. The epsilon is used when comparing two floats.

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 split_range(&self, t_range: Range<f32>) -> CubicBezierShape

split the original cubic curve into a new one within a range.

Source

pub fn num_quadratics(&self, tolerance: f32) -> u32

Source

pub fn find_cross_t(&self, epsilon: f32) -> Option<f32>

Find the t value (if any) in the open interval (epsilon, 1 - epsilon) where the curve crosses its base line, i.e. the line from P0 to P3.

If the curve only touches the base line at its end points (t = 0 and t = 1), the “fill” is simple since the curve is convex, and None is returned. If the curve crosses the base line once more in between, we return that t so the curve can be split into two curves (0.0..t and t..1.0).

The (scaled) signed distance from the base line is f(t) = cross(B(t) - P0, P3 - P0), which is a cubic polynomial in t:

B(t) - P0 = (P3 - 3*P2 + 3*P1 - P0)*t^3 + (3*P2 - 6*P1 + 3*P0)*t^2 + (3*P1 - 3*P0)*t
f(t) = a*t^3 + b*t^2 + c*t, where:
a = cross(P3 - 3*P2 + 3*P1 - P0, P3 - P0)
b = cross(3*P2 - 6*P1 + 3*P0, P3 - P0)
c = cross(3*P1 - 3*P0, P3 - P0)

Since f(0) = 0 and f(1) = cross(P3 - P0, P3 - P0) = 0, we have b = -(a + c), so f(t) = a*t*(t - 1)*(t - c/a), and the only interesting root is t = c/a.

Source

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

Calculate the point (x,y) at t based on the cubic 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 cubic 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 flatten_closed( &self, tolerance: Option<f32>, epsilon: Option<f32>, ) -> Vec<Vec<Pos2>>

find a set of points that approximate the cubic 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) this api will check whether the curve will cross the base line or not when closed = true. The result will be a vec of vec of Pos2. it will store two closed aren in different vec. The epsilon is used to compare a float value.

Source

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

Iterates through the curve invoking a callback at each point.

Trait Implementations§

Source§

impl Clone for CubicBezierShape

Source§

fn clone(&self) -> CubicBezierShape

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CubicBezierShape

Source§

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

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

impl From<CubicBezierShape> for Shape

Source§

fn from(shape: CubicBezierShape) -> Shape

Converts to this type from the input type.
Source§

impl PartialEq for CubicBezierShape

Source§

fn eq(&self, other: &CubicBezierShape) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CubicBezierShape

Auto Trait Implementations§

§

impl !RefUnwindSafe for CubicBezierShape

§

impl !UnwindSafe for CubicBezierShape

§

impl Forget for CubicBezierShape

§

impl Freeze for CubicBezierShape
where *const ArcInner<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send>>: Freeze,

§

impl Move for CubicBezierShape

§

impl Send for CubicBezierShape
where Arc<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send>: Send,

§

impl Sync for CubicBezierShape
where Arc<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send>: Sync,

§

impl Unpin for CubicBezierShape
where Arc<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send>: Unpin,

§

impl UnsafeUnpin for CubicBezierShape
where *const ArcInner<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(Rect, Pos2) -> Color32 + Sync + Send>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more