RoundedPolygon.star constructor
- 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.
numVerticesPerRadius is the number of vertices along each of the two
radii.
radius is the outer radius for this star shape, must be greater than 0.
Default value is 1.
innerRadius is the inner radius for this star shape, must be greater
than 0 and less than or equal to radius. Note that equal radii would
be the same as creating a RoundedPolygon directly, but with
2 * numVerticesPerRadius vertices. Default value is 0.5.
rounding is the CornerRounding properties of every vertex. If some
vertices should have different rounding properties, then use
perVertexRounding instead. The default rounding value is
CornerRounding.unrounded, meaning that the polygon will use the
vertices themselves in the final shape and not curves rounded around the
vertices.
innerRounding is the optional rounding parameters for the vertices on
the innerRadius. If null (the default value), inner vertices will use
the rounding or perVertexRounding parameters instead.
perVertexRounding is the the CornerRounding properties of every
vertex. If this parameter is not null, then it must have the same size as
2 * numVerticesPerRadius. If this parameter is null, then the polygon
will use the rounding parameter for every vertex instead. The default
value is null.
centerX is the X coordinate of the center of the polygon, around which
all vertices will be placed. The default center is at (0,0).
centerY is the Y coordinate of the center of the polygon, around which
all vertices will be placed. The default center is at (0,0).
Throws ArgumentError if either radius or innerRadius are <= 0 or
innerRadius > radius.
Implementation
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,
}) {
if (radius <= 0 || innerRadius <= 0) {
throw ArgumentError('Star radii must both be greater than 0.');
}
if (innerRadius >= radius) {
throw ArgumentError('innerRadius must be less than radius.');
}
var pvRounding = perVertexRounding;
// If no per-vertex rounding supplied and caller asked for inner rounding,
// create per-vertex rounding list based on supplied outer/inner rounding
// parameters.
if (pvRounding == null && innerRounding != null) {
pvRounding = [
for (var i = 0; i < numVerticesPerRadius; i++) ...[
rounding,
innerRounding,
],
];
}
// Star polygon is just a polygon with all vertices supplied (where we
// generate those vertices to be on the inner/outer radii).
return RoundedPolygon.fromVertices(
_starVerticesFromNumVerts(
numVerticesPerRadius,
radius,
innerRadius,
centerX,
centerY,
),
rounding: rounding,
perVertexRounding: pvRounding,
centerX: centerX,
centerY: centerY,
);
}