RoundedPolygon class

The RoundedPolygon class allows simple construction of polygonal shapes with optional rounding at the vertices. Polygons can be constructed with either the number of vertices desired or an ordered list of vertices.

Available extensions
Annotations

Constructors

RoundedPolygon.circle({int numVertices = 8, double radius = 1, double centerX = 0, double centerY = 0})
Creates a circular shape, approximating the rounding of the shape around the underlying polygon vertices.
factory
RoundedPolygon.from(RoundedPolygon roundedPolygon)
Creates a copy of the given RoundedPolygon.
RoundedPolygon.fromFeatures(List<Feature> features, {double centerX = double.nan, double centerY = double.nan})
Takes a list of Feature objects that define the polygon's shape and curves. By specifying the features directly, the summarization of Cubic objects to curves can be precisely controlled. This affects Morph's default mapping, as curves with the same type (convex or concave) are mapped with each other. For example, if you have a convex curve in your start polygon, Morph will map it to another convex curve in the end polygon.
factory
RoundedPolygon.fromVertices(List<double> vertices, {CornerRounding rounding = CornerRounding.unrounded, List<CornerRounding>? perVertexRounding, double centerX = double.minPositive, double centerY = double.minPositive})
This function takes the vertices (either supplied or calculated, depending on the constructor called), plus CornerRounding parameters, and creates the actual RoundedPolygon shape, rounding around the vertices (or not) as specified. The result is a list of Cubic curves which represent the geometry of the final shape.
factory
RoundedPolygon.fromVerticesNum(int numVertices, {double radius = 1, double centerX = 0, double centerY = 0, CornerRounding rounding = CornerRounding.unrounded, List<CornerRounding>? perVertexRounding})
This constructor takes the number of vertices in the resulting polygon. These vertices are positioned on a virtual circle around a given center with each vertex positioned radius distance from that center, equally spaced (with equal angles between them). If no radius is supplied, the shape will be created with a default radius of 1, resulting in a shape whose vertices lie on a unit circle, with width/height of 2. That default polygon will probably need to be rescaled using transformed into the appropriate size for the UI in which it will be drawn.
factory
RoundedPolygon.pill({double width = 2, double height = 1, double smoothing = 0, double centerX = 0, double centerY = 0})
A pill shape consists of a rectangle shape bounded by two semicircles at either of the long ends of the rectangle.
factory
RoundedPolygon.pillStar({double width = 2, double height = 1, int numVerticesPerRadius = 8, double innerRadiusRatio = 0.5, CornerRounding rounding = CornerRounding.unrounded, CornerRounding? innerRounding, List<CornerRounding>? perVertexRounding, double vertexSpacing = 0.5, double startLocation = 0, double centerX = 0, double centerY = 0})
A pillStar shape is like a RoundedPolygon.pill except it has inner and outer radii along its pill-shaped outline, just like a RoundedPolygon.star has inner and outer radii along its circular outline. The parameters for a RoundedPolygon.pillStar are similar to those of a RoundedPolygon.star except, like RoundedPolygon.pill, it has a width and height to determine the general shape of the underlying pill. Also, there is a subtle complication with the way that inner and outer vertices proceed along the circular ends of the shape, depending on the magnitudes of the rounding, innerRounding, and innerRadiusRatio parameters. For example, a shape with outer vertices that lie along the curved end outline will necessarily have inner vertices that are closer to each other, because of the curvature of that part of the shape. Conversely, if the inner vertices are lined up along the pill outline at the ends, then the outer vertices will be much further apart from each other.
factory
RoundedPolygon.rectangle({double width = 2, double height = 2, CornerRounding rounding = CornerRounding.unrounded, List<CornerRounding>? perVertexRounding, double centerX = 0, double centerY = 0})
Creates a rectangular shape with the given width/height around the given center. Optional rounding parameters can be used to create a rounded rectangle instead.
factory
RoundedPolygon.star({required int numVerticesPerRadius, double radius = 1, double innerRadius = 0.5, CornerRounding rounding = CornerRounding.unrounded, CornerRounding? innerRounding, List<CornerRounding>? perVertexRounding, double centerX = 0, double centerY = 0})
Creates a star polygon, which is like a regular polygon except every other vertex is on either an inner or outer radius. The two radii specified in the constructor must both both nonzero. If the radii are equal, the result will be a regular (not star) polygon with twice the number of vertices specified in numVerticesPerRadius.
factory

Properties

center → Point
final
centerX double
no setter
centerY double
no setter
cubics List<Cubic>
A flattened version of the Features, as a List<Cubic>.
final
features List<Feature>
final
hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

calculateBounds({List<double>? bounds, bool approximate = true}) List<double>
Calculates the axis-aligned bounds of the object.
calculateMaxBounds([List<double>? bounds]) List<double>
Like calculateBounds, this function calculates the axis-aligned bounds of the object and returns that rectangle. But this function determines the max dimension of the shape (by calculating the distance from its center to the start and midpoint of each curve) and returns a square which can be used to hold the object in any rotation. This function can be used, for example, to calculate the max size of a UI element meant to hold this shape in any rotation.
normalized() RoundedPolygon
Creates a new RoundedPolygon, moving and resizing this one, so it's completely inside the (0, 0) -> (1, 1) square, centered if there extra space in one direction.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toPath({int startAngle = 0, bool repeatPath = false, bool closePath = true, Path? path}) Path

Available on RoundedPolygon, provided by the RoundedPolygonToPathExtension extension

Returns a Path representation for a RoundedPolygon shape. Note that there is some rounding happening (to the nearest thousandth), to work around rendering artifacts introduced by some points being just slightly off from each other (far less than a pixel). This also allows for a more optimal path, as redundant curves (usually a single point) can be detected and not added to the resulting path.
toString() String
A string representation of this object.
override
transformed(PointTransformer f) RoundedPolygon
Transforms (scales/translates/etc.) this RoundedPolygon with the given PointTransformer and returns a new RoundedPolygon. This is a low level API and there should be more platform idiomatic ways to transform a RoundedPolygon provided by the platform specific wrapper.

Operators

operator ==(Object other) bool
The equality operator.
override