toPath method

Path toPath(
  1. Rect rect
)

Creates a Path inside the given Rect.

Implementation

Path toPath(Rect rect) {
  final width = rect.width;
  final height = rect.height;

  final result = Path();

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

  result
    ..addSharpTopRight(processedTopRight, rect)
    ..addSharpBottomRight(processedBottomRight, rect)
    ..addSharpBottomLeft(processedBottomLeft, rect)
    ..addSharpTopLeft(processedTopLeft, rect);

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