---
title: "NSUnionRect(_:_:)"
framework: foundation
role: symbol
role_heading: Function
path: "foundation/nsunionrect(_:_:)"
---

# NSUnionRect(_:_:)

Calculates the union of two rectangles.

## Declaration

```swift
func NSUnionRect(_ aRect: NSRect, _ bRect: NSRect) -> NSRect
```

## Discussion

Discussion Returns the smallest rectangle that completely encloses both aRect and bRect. If one of the rectangles has 0 (or negative) width or height, a copy of the other rectangle is returned; but if both have 0 (or negative) width or height, the returned rectangle has its origin at (0.0, 0.0) and has 0 width and height.

## See Also

### Managing Rectangles

- [NSContainsRect(_:_:)](foundation/nscontainsrect(_:_:).md)
- [NSDivideRect(_:_:_:_:_:)](foundation/nsdividerect(_:_:_:_:_:).md)
- [NSEqualRects(_:_:)](foundation/nsequalrects(_:_:).md)
- [NSIsEmptyRect(_:)](foundation/nsisemptyrect(_:).md)
- [NSHeight(_:)](foundation/nsheight(_:).md)
- [NSInsetRect(_:_:_:)](foundation/nsinsetrect(_:_:_:).md)
- [NSIntegralRect(_:)](foundation/nsintegralrect(_:).md)
- [NSIntegralRectWithOptions(_:_:)](foundation/nsintegralrectwithoptions(_:_:).md)
- [NSIntersectionRect(_:_:)](foundation/nsintersectionrect(_:_:).md)
- [NSIntersectsRect(_:_:)](foundation/nsintersectsrect(_:_:).md)
- [NSMakeRect(_:_:_:_:)](foundation/nsmakerect(_:_:_:_:).md)
- [NSMaxX(_:)](foundation/nsmaxx(_:).md)
- [NSMaxY(_:)](foundation/nsmaxy(_:).md)
- [NSMidX(_:)](foundation/nsmidx(_:).md)
- [NSMidY(_:)](foundation/nsmidy(_:).md)
