RoundedPolygon.star constructor

RoundedPolygon.star({
  1. required int numVerticesPerRadius,
  2. double radius = 1.0,
  3. double innerRadius = 0.5,
  4. CornerRounding rounding = .unrounded,
  5. CornerRounding? innerRounding,
  6. List<CornerRounding>? perVertexRounding,
  7. Offset center = .zero,
})

Creates a star about center, with numVerticesPerRadius vertices on the outer radius alternating with as many on the innerRadius.

Both radii must be greater than 0, and innerRadius must be less than radius.

rounding rounds every vertex the same way. innerRounding overrides it for the vertices on innerRadius. perVertexRounding overrides both, and must have 2 * numVerticesPerRadius elements when it is not null, alternating outer and inner starting with an outer vertex. The default leaves the corners sharp and the edges straight.

Throws ArgumentError if numVerticesPerRadius is less than 3, if either radius is not greater than 0, if innerRadius is not less than radius, or if perVertexRounding has the wrong number of elements.

Implementation

factory star({
  required int numVerticesPerRadius,
  double radius = 1.0,
  double innerRadius = 0.5,
  CornerRounding rounding = .unrounded,
  CornerRounding? innerRounding,
  List<CornerRounding>? perVertexRounding,
  Offset center = .zero,
}) {
  if (numVerticesPerRadius < 3) {
    throw ArgumentError("numVerticesPerRadius must be at least 3.");
  }
  if (radius <= 0.0 || innerRadius <= 0.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 .fromVertices(
    _starVerticesFromNumVerts(
      numVerticesPerRadius,
      radius,
      innerRadius,
      center,
    ),
    rounding: rounding,
    perVertexRounding: pvRounding,
    center: center,
  );
}