RoundedPolygon.pill constructor
RoundedPolygon.pill({})
Creates a pill about center, width wide and height high: a
rectangle capped by a semicircle at either end of its longer dimension.
smoothing extends the curve from the circular arc of each cap towards
the edge between the two caps. The default of 0 leaves the caps as
circular arcs.
Throws ArgumentError if either width or height is not greater
than 0.
Implementation
factory pill({
double width = 2.0,
double height = 1.0,
double smoothing = 0.0,
Offset center = .zero,
}) {
if (width <= 0.0 || height <= 0.0) {
throw ArgumentError("Pill shapes must have positive width and height.");
}
final wHalf = width / 2.0;
final hHalf = height / 2.0;
return .fromVertices(
[
.new(wHalf + center.x, hHalf + center.y),
.new(-wHalf + center.x, hHalf + center.y),
.new(-wHalf + center.x, -hHalf + center.y),
.new(wHalf + center.x, -hHalf + center.y),
],
rounding: .new(radius: math.min(wHalf, hHalf), smoothing: smoothing),
center: center,
);
}