getBounds function

Rect getBounds(
  1. Iterable<Offset> points
)

Calculates the bounding box of a collection of Offsets.

Implementation

@pragma('vm:prefer-inline')
Rect getBounds(Iterable<Offset> points) {
  if (points.isEmpty) return Rect.zero;
  double minX = double.infinity, maxX = double.negativeInfinity;
  double minY = double.infinity, maxY = double.negativeInfinity;
  for (final p in points) {
    minX = math.min(minX, p.dx);
    maxX = math.max(maxX, p.dx);
    minY = math.min(minY, p.dy);
    maxY = math.max(maxY, p.dy);
  }
  return Rect.fromLTRB(minX, minY, maxX, maxY);
}