toPath function

Path toPath(
  1. Rect rect,
  2. BorderRadius borderRadius,
  3. double smoothingRadius
)

Creates a Path inside the given Rect.

Implementation

Path toPath(Rect rect, BorderRadius borderRadius, double smoothingRadius) {
    final width = rect.width;
    final height = rect.height;

    final result = Path();

    final topLeft = SmoothRadius(
      cornerRadius: borderRadius.topLeft.x,
      cornerSmoothing: smoothingRadius,
    );

    final bottomLeft = SmoothRadius(
      cornerRadius: borderRadius.bottomLeft.x,
      cornerSmoothing: smoothingRadius
    );

    final topRight = SmoothRadius(
      cornerRadius: borderRadius.topRight.x,
      cornerSmoothing: smoothingRadius
    );

    final bottomRight = SmoothRadius(
      cornerRadius: borderRadius.bottomRight.x,
      cornerSmoothing: smoothingRadius
    );

    /// Calculating only if values are different
    final processedTopLeft = ProccessedRadius(
      topLeft,
      width: width,
      height: height,
    );
    final processedBottomLeft = topLeft == bottomLeft
        ? processedTopLeft
        : ProccessedRadius(
            bottomLeft,
            width: width,
            height: height,
          );
    final processedBottomRight = bottomLeft == bottomRight
        ? processedBottomLeft
        : ProccessedRadius(
            bottomRight,
            width: width,
            height: height,
          );
    final processedTopRight = topRight == bottomRight
        ? processedBottomRight
        : ProccessedRadius(
            topRight,
            width: width,
            height: height,
          );

    result
      ..addSmoothTopRight(processedTopRight, rect)
      ..addSmoothBottomRight(processedBottomRight, rect)
      ..addSmoothBottomLeft(processedBottomLeft, rect)
      ..addSmoothTopLeft(processedTopLeft, rect);

    return result.transform(
      Matrix4.translationValues(rect.left, rect.top, 0).storage,
    );
  }