---
title: "CGRectUnion(_:_:)"
framework: coregraphics
role: symbol
role_heading: Function
path: "coregraphics/cgrectunion(_:_:)"
---

# CGRectUnion(_:_:)

Returns the smallest rectangle that contains the two source rectangles.

## Declaration

```swift
func CGRectUnion(_ r1: CGRect, _ r2: CGRect) -> CGRect
```

## Parameters

- `r1`: The first source rectangle.
- `r2`: The second source rectangle.

## Return Value

Return Value The smallest rectangle that completely contains both of the source rectangles.

## Discussion

Discussion Both rectangles are standardized prior to calculating the union. If either of the rectangles is a null rectangle, a copy of the other rectangle is returned (resulting in a null rectangle if both rectangles are null). Otherwise a rectangle that completely contains the source rectangles is returned.

## See Also

### Modifying Rectangles

- [CGRectInset(_:_:_:)](coregraphics/cgrectinset(_:_:_:).md)
- [CGRectIntegral(_:)](coregraphics/cgrectintegral(_:).md)
- [CGRectIntersection(_:_:)](coregraphics/cgrectintersection(_:_:).md)
- [CGRectOffset(_:_:_:)](coregraphics/cgrectoffset(_:_:_:).md)
- [CGRectStandardize(_:)](coregraphics/cgrectstandardize(_:).md)
