applyToRect method

Rect applyToRect(
  1. Rect rect
)

Applies the transform to rect and returns its axis-aligned world bounds.

Degenerate rectangles (zero width and/or height) are still transformed and may remain degenerate in world space.

Implementation

Rect applyToRect(Rect rect) {
  final p1 = applyToPoint(rect.topLeft);
  final p2 = applyToPoint(rect.topRight);
  final p3 = applyToPoint(rect.bottomRight);
  final p4 = applyToPoint(rect.bottomLeft);
  var minX = p1.dx;
  var maxX = p1.dx;
  var minY = p1.dy;
  var maxY = p1.dy;
  void include(Offset p) {
    if (p.dx < minX) minX = p.dx;
    if (p.dx > maxX) maxX = p.dx;
    if (p.dy < minY) minY = p.dy;
    if (p.dy > maxY) maxY = p.dy;
  }

  include(p2);
  include(p3);
  include(p4);
  return Rect.fromLTRB(minX, minY, maxX, maxY);
}