RoundedPolygon.pill constructor

RoundedPolygon.pill({
  1. double width = 2.0,
  2. double height = 1.0,
  3. double smoothing = 0.0,
  4. double centerX = 0.0,
  5. double centerY = 0.0,
})

Implementation

factory RoundedPolygon.pill({
  double width = 2.0,
  double height = 1.0,
  double smoothing = 0.0,
  double centerX = 0.0,
  double centerY = 0.0,
}) {
  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(
    vertices: [
      wHalf + centerX,
      hHalf + centerY,
      -wHalf + centerX,
      hHalf + centerY,
      -wHalf + centerX,
      -hHalf + centerY,
      wHalf + centerX,
      -hHalf + centerY,
    ],
    rounding: .from(radius: math.min(wHalf, hHalf), smoothing: smoothing),
    centerX: centerX,
    centerY: centerY,
  );
}