pub struct CubicBezierShape {
pub points: [Pos2; 4],
pub closed: bool,
pub fill: Color32,
pub stroke: PathStroke,
}egui only.Expand description
A cubic Bézier Curve.
See also QuadraticBezierShape.
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: PathStrokeImplementations§
Source§impl CubicBezierShape
impl CubicBezierShape
Sourcepub fn from_points_stroke(
points: [Pos2; 4],
closed: bool,
fill: Color32,
stroke: impl Into<PathStroke>,
) -> CubicBezierShape
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.
Sourcepub fn transform(&self, transform: &RectTransform) -> CubicBezierShape
pub fn transform(&self, transform: &RectTransform) -> CubicBezierShape
Transform the curve with the given transform.
Sourcepub fn to_path_shapes(
&self,
tolerance: Option<f32>,
epsilon: Option<f32>,
) -> Vec<PathShape>
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.
Sourcepub fn visual_bounding_rect(&self) -> Rect
pub fn visual_bounding_rect(&self) -> Rect
The visual bounding rectangle (includes stroke width)
Sourcepub fn logical_bounding_rect(&self) -> Rect
pub fn logical_bounding_rect(&self) -> Rect
Logical bounding rectangle (ignoring stroke width)
Sourcepub fn split_range(&self, t_range: Range<f32>) -> CubicBezierShape
pub fn split_range(&self, t_range: Range<f32>) -> CubicBezierShape
split the original cubic curve into a new one within a range.
pub fn num_quadratics(&self, tolerance: f32) -> u32
Sourcepub fn find_cross_t(&self, epsilon: f32) -> Option<f32>
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.
Sourcepub fn sample(&self, t: f32) -> Pos2
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
Sourcepub fn flatten(&self, tolerance: Option<f32>) -> Vec<Pos2>
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)
Sourcepub fn flatten_closed(
&self,
tolerance: Option<f32>,
epsilon: Option<f32>,
) -> Vec<Vec<Pos2>>
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.
Trait Implementations§
Source§impl Clone for CubicBezierShape
impl Clone for CubicBezierShape
Source§fn clone(&self) -> CubicBezierShape
fn clone(&self) -> CubicBezierShape
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CubicBezierShape
impl Debug for CubicBezierShape
Source§impl From<CubicBezierShape> for Shape
impl From<CubicBezierShape> for Shape
Source§fn from(shape: CubicBezierShape) -> Shape
fn from(shape: CubicBezierShape) -> Shape
Source§impl PartialEq for CubicBezierShape
impl PartialEq for CubicBezierShape
impl StructuralPartialEq for CubicBezierShape
Auto Trait Implementations§
impl !RefUnwindSafe for CubicBezierShape
impl !UnwindSafe for CubicBezierShape
impl Forget for CubicBezierShape
impl Freeze for CubicBezierShape
impl Move for CubicBezierShape
impl Send for CubicBezierShape
impl Sync for CubicBezierShape
impl Unpin for CubicBezierShape
impl UnsafeUnpin for CubicBezierShape
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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