buildCornerPath function

Path buildCornerPath(
  1. Rect rect,
  2. CornerRadius radius,
  3. int smoothing
)

The outline of rect with radius corners, smoothed by smoothing percent (0–100).

Implementation

Path buildCornerPath(Rect rect, CornerRadius radius, int smoothing) {
  final double s = (smoothing / 100).clamp(0.0, 1.0);
  if (s == 0 || radius.isZero) {
    return Path()..addRRect(radius.toRRect(rect));
  }

  final double w = rect.width;
  final double h = rect.height;
  final _Corner tl = _Corner(radius.topLeft, radius.topRight, radius.bottomLeft, w, h, s);
  final _Corner tr = _Corner(radius.topRight, radius.topLeft, radius.bottomRight, w, h, s);
  final _Corner br = _Corner(radius.bottomRight, radius.bottomLeft, radius.topRight, w, h, s);
  final _Corner bl = _Corner(radius.bottomLeft, radius.bottomRight, radius.topLeft, w, h, s);

  final Path path = Path()..moveTo(rect.left, rect.top + tl.p);
  _corner(path, rect.topLeft, const Offset(0, 1), const Offset(1, 0), tl);
  path.lineTo(rect.right - tr.p, rect.top);
  _corner(path, rect.topRight, const Offset(-1, 0), const Offset(0, 1), tr);
  path.lineTo(rect.right, rect.bottom - br.p);
  _corner(path, rect.bottomRight, const Offset(0, -1), const Offset(-1, 0), br);
  path.lineTo(rect.left + bl.p, rect.bottom);
  _corner(path, rect.bottomLeft, const Offset(1, 0), const Offset(0, -1), bl);
  return path..close();
}