pdfRenderPathBounds function

PdfRect? pdfRenderPathBounds(
  1. PdfPath path
)

Implementation

PdfRect? pdfRenderPathBounds(PdfPath path) {
  double? left, right, bottom, top;
  void include(double x, double y) {
    left = left == null ? x : math.min(left!, x);
    right = right == null ? x : math.max(right!, x);
    bottom = bottom == null ? y : math.min(bottom!, y);
    top = top == null ? y : math.max(top!, y);
  }

  final cursor = path.cursor();
  while (cursor.moveNext()) {
    switch (cursor.verb) {
      case PdfPathVerb.moveTo || PdfPathVerb.lineTo:
        include(cursor.x1, cursor.y1);
      case PdfPathVerb.cubicTo:
        // A cubic lies inside the convex hull of its endpoints/control points.
        include(cursor.x1, cursor.y1);
        include(cursor.x2, cursor.y2);
        include(cursor.x3, cursor.y3);
      case PdfPathVerb.close:
        break;
    }
  }
  if (left == null) return null;
  return PdfRect(left!, bottom!, right!, top!);
}