RoundedPolygon.circle constructor
Creates a circle of the given radius about center, approximated by
rounding a polygon of numVertices vertices.
Throws ArgumentError if numVertices is less than 3.
Implementation
factory RoundedPolygon.circle({
int numVertices = 8,
double radius = 1,
Offset center = Offset.zero,
}) {
if (numVertices < 3) {
throw ArgumentError('Circle must have at least three vertices.');
}
// Half of the angle between two adjacent vertices on the polygon.
final double theta = math.pi / numVertices;
// Radius of the underlying RoundedPolygon object given the desired radius
// of the circle.
final double polygonRadius = radius / math.cos(theta);
return RoundedPolygon(
numVertices,
radius: polygonRadius,
center: center,
rounding: CornerRounding(radius: radius),
);
}