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
impl RoundedPolygon
Sourcepub fn from_features(
features: Vec<Feature>,
center: Option<Point>,
) -> RoundedPolygon
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).
Sourcepub fn from_vertices(
vertices: &[Point],
rounding: CornerRounding,
per_vertex_rounding: Option<&[CornerRounding]>,
center: Option<Point>,
) -> RoundedPolygon
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.
Sourcepub fn from_num_vertices(
num_vertices: usize,
radius: f64,
center: Point,
rounding: CornerRounding,
per_vertex_rounding: Option<&[CornerRounding]>,
) -> RoundedPolygon
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.
Sourcepub fn circle(num_vertices: usize, radius: f64, center: Point) -> RoundedPolygon
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.
Sourcepub fn rectangle(
width: f64,
height: f64,
rounding: CornerRounding,
per_vertex_rounding: Option<&[CornerRounding]>,
center: Point,
) -> RoundedPolygon
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.
Sourcepub fn star(params: StarParams<'_>) -> RoundedPolygon
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.
Sourcepub fn pill(
width: f64,
height: f64,
smoothing: f64,
center: Point,
) -> RoundedPolygon
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.
Sourcepub fn pill_star(params: PillStarParams<'_>) -> RoundedPolygon
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.
Sourcepub fn cubics(&self) -> &[Cubic]
pub fn cubics(&self) -> &[Cubic]
The features flattened into one contiguous, closed run of curves — what gets painted.
Sourcepub const fn center(&self) -> Point
pub const fn center(&self) -> Point
The centre all of this polygon’s vertices were placed around.
Sourcepub fn transformed_with(
&self,
f: impl Fn(Point) -> Point + Copy,
) -> RoundedPolygon
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.
Sourcepub fn transformed(&self, transform: Affine) -> RoundedPolygon
pub fn transformed(&self, transform: Affine) -> RoundedPolygon
This polygon transformed by an affine map.
Sourcepub fn normalized(&self) -> RoundedPolygon
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.
Sourcepub fn bounds(&self) -> Rect
pub fn bounds(&self) -> Rect
The axis-aligned bounds of every anchor and control point — cheap, and
never tighter than RoundedPolygon::exact_bounds.
Sourcepub fn exact_bounds(&self) -> Rect
pub fn exact_bounds(&self) -> Rect
The true axis-aligned bounds of the outline, solving each curve for its extrema.
Sourcepub fn max_bounds(&self) -> Rect
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.
Sourcepub fn to_path(&self) -> BezPath
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
impl Clone for RoundedPolygon
Source§impl Debug for RoundedPolygon
impl Debug for RoundedPolygon
Source§impl PartialEq for RoundedPolygon
impl PartialEq for RoundedPolygon
impl StructuralPartialEq for RoundedPolygon
Auto Trait Implementations§
impl Freeze for RoundedPolygon
impl RefUnwindSafe for RoundedPolygon
impl Send for RoundedPolygon
impl Sync for RoundedPolygon
impl Unpin for RoundedPolygon
impl UnsafeUnpin for RoundedPolygon
impl UnwindSafe for RoundedPolygon
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.