RoundedPolygon.circle constructor

RoundedPolygon.circle({
  1. int numVertices = 8,
  2. double radius = 1,
  3. double centerX = 0,
  4. double centerY = 0,
})

Creates a circular shape, approximating the rounding of the shape around the underlying polygon vertices.

numVertices is the number of vertices in the underlying polygon with which to approximate the circle, default value is 8.

radius is the optional radius for the circle, default value is 1.0.

centerX is the X coordinate of optional center for the circle, default value is 0.

centerY is the Y coordinate of optional center for the circle, default value is 0.

Throws ArgumentError when numVertices is less than 3.

Implementation

factory RoundedPolygon.circle({
  int numVertices = 8,
  double radius = 1,
  double centerX = 0,
  double centerY = 0,
}) {
  if (numVertices < 3) {
    throw ArgumentError('Circle must have at least three vertices.');
  }

  // Half of the angle between two adjacent vertices on the polygon.
  final theta = math.pi / numVertices;
  // Radius of the underlying RoundedPolygon object given the desired radius
  // of the circle.
  final polygonRadius = radius / math.cos(theta);
  return RoundedPolygon.fromVerticesNum(
    numVertices,
    radius: polygonRadius,
    centerX: centerX,
    centerY: centerY,
    rounding: CornerRounding(radius: radius),
  );
}