Skip to main content

RoundedPolygon

Struct RoundedPolygon 

Source
pub struct RoundedPolygon { /* private fields */ }
Expand description

A closed polygonal outline with optional per-corner rounding.

Built from vertices (supplied, or generated on a circle/rectangle/star/pill outline) plus a CornerRounding per vertex, and carried around as both a Feature list and the flat Cubic list those features flatten to. Paint it with RoundedPolygon::to_path.

Nothing here is in screen units: a polygon built with the default radius of 1 lives in the (-1, -1)..(1, 1) box and wants transformed (or normalized plus a scale) before it is drawn.

Implementations§

Source§

impl RoundedPolygon

Source

pub fn from_features( features: Vec<Feature>, center: Option<Point>, ) -> RoundedPolygon

Builds a polygon from features that already describe a closed outline.

Specifying features directly is what gives a caller control over how cubics are grouped, which is what a Feature-matched morph maps on. With center None the centre is the average of every cubic’s starting anchor.

§Panics

If fewer than two features are given. Debug builds additionally assert that the resulting outline is contiguous (upstream asserts the same, also debug-only).

Source

pub fn from_vertices( vertices: &[Point], rounding: CornerRounding, per_vertex_rounding: Option<&[CornerRounding]>, center: Option<Point>, ) -> RoundedPolygon

Builds a polygon from an ordered vertex list, rounding each vertex as asked.

The outline runs from each vertex to the next in list order; an unordered list gives undefined results. per_vertex_rounding, when given, overrides rounding for every vertex and must have one entry per vertex. With center None the centre is the average of the vertices.

§Panics

If fewer than three vertices are given, or per_vertex_rounding has a different length than vertices.

Source

pub fn from_num_vertices( num_vertices: usize, radius: f64, center: Point, rounding: CornerRounding, per_vertex_rounding: Option<&[CornerRounding]>, ) -> RoundedPolygon

Builds a regular polygon: num_vertices vertices equally spaced on a circle of radius around center.

§Panics

If num_vertices is below 3, or per_vertex_rounding has a different length than the vertex count.

Source

pub fn circle(num_vertices: usize, radius: f64, center: Point) -> RoundedPolygon

Approximates a circle of radius around center with a rounded num_vertices-gon whose rounding consumes its every side.

§Panics

If num_vertices is below 3.

Source

pub fn rectangle( width: f64, height: f64, rounding: CornerRounding, per_vertex_rounding: Option<&[CornerRounding]>, center: Point, ) -> RoundedPolygon

Builds a width × height rectangle around center, optionally rounded.

Vertices run bottom-right, bottom-left, top-left, top-right, which is the order per_vertex_rounding’s four entries are read in.

§Panics

If per_vertex_rounding is given and does not hold exactly four entries.

Source

pub fn star(params: StarParams<'_>) -> RoundedPolygon

Builds a star: a polygon whose vertices alternate between an outer and an inner radius.

Equal radii would give a regular polygon with twice num_vertices_per_radius vertices — build that with RoundedPolygon::from_num_vertices instead.

§Panics

If either radius is not positive, if the inner radius is not smaller than the outer one, or if per_vertex_rounding does not hold 2 * num_vertices_per_radius entries.

Source

pub fn pill( width: f64, height: f64, smoothing: f64, center: Point, ) -> RoundedPolygon

Builds a pill: a rectangle capped by a semicircle at each end of its longer axis.

smoothing extends each end cap’s arc toward the straight edges the way CornerRounding::smoothing does.

§Panics

If width or height is not positive.

Source

pub fn pill_star(params: PillStarParams<'_>) -> RoundedPolygon

Builds a pill-star: a pill whose vertices alternate between an outer and an inner radius, the way a star’s do around a circle.

Vertices are spaced evenly along the underlying pill’s perimeter, which leaves a choice on the curved end caps: outer vertices sitting on the outline crowd the inner ones together, and vice versa. That is what PillStarParams::vertex_spacing picks between.

§Panics

If width or height is not positive, if inner_radius_ratio is outside (0, 1], if vertex_spacing or start_location is outside 0..=1, or if per_vertex_rounding does not hold 2 * num_vertices_per_radius entries.

Source

pub fn features(&self) -> &[Feature]

The features describing this outline, in path order.

Source

pub fn cubics(&self) -> &[Cubic]

The features flattened into one contiguous, closed run of curves — what gets painted.

Source

pub const fn center(&self) -> Point

The centre all of this polygon’s vertices were placed around.

Source

pub fn transformed_with( &self, f: impl Fn(Point) -> Point + Copy, ) -> RoundedPolygon

This polygon with every point mapped through f.

A low-level seam; reach for RoundedPolygon::transformed for the affine cases.

Source

pub fn transformed(&self, transform: Affine) -> RoundedPolygon

This polygon transformed by an affine map.

Source

pub fn normalized(&self) -> RoundedPolygon

This polygon moved and scaled to sit inside the (0, 0)..(1, 1) box, centred along whichever axis has room to spare.

Source

pub fn bounds(&self) -> Rect

The axis-aligned bounds of every anchor and control point — cheap, and never tighter than RoundedPolygon::exact_bounds.

Source

pub fn exact_bounds(&self) -> Rect

The true axis-aligned bounds of the outline, solving each curve for its extrema.

Source

pub fn max_bounds(&self) -> Rect

The smallest square centred on RoundedPolygon::center that holds this shape in any rotation — the size a UI element hosting a spinning shape needs to reserve.

Measured from the centre to each curve’s start and midpoint, so it is an approximation, matching upstream.

Source

pub fn to_path(&self) -> BezPath

This outline as a closed kurbo::BezPath.

The path is one MoveTo, one CurveTo per cubic, and a ClosePath. The final curve’s end point is bit-identical to the MoveTo point (see init_cubics) — a shape whose ends miss each other by a fraction of a pixel shows seam artifacts when filled.

Trait Implementations§

Source§

impl Clone for RoundedPolygon

Source§

fn clone(&self) -> Self

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 RoundedPolygon

Source§

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

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

impl PartialEq for RoundedPolygon

Source§

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

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<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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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