RoundedPolygon.circle constructor

RoundedPolygon.circle({
  1. int numVertices = 8,
  2. double radius = 1,
  3. Offset center = Offset.zero,
})

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),
  );
}