# Rect

``public struct Rect: Equatable, CustomStringConvertible``

A structure that contains the location and dimensions of a rectangle.

• ` origin `

The origin (top-left) of the rect.

#### Declaration

Swift

``public var origin: Point``
• ` size `

The size (width / height) of the rect.

#### Declaration

Swift

``public var size: Size``
• ` width `

The width of the rect.

#### Declaration

Swift

``public var width: Double``
• ` height `

The height of the rect.

#### Declaration

Swift

``public var height: Double``
• ` init() `

Initializes a new Rect with the origin {0,0} and the size {0,0} ` let r = Rect() `

#### Declaration

Swift

``public init()``
• ` init(_:_:_:_:) `

Initializes a new Rect with the origin {x,y} and the size {w,h} ` let r = Rect(0.0,0.0,10.0,10.0) `

#### Declaration

Swift

``public init(_ x: Double, _ y: Double, _ w: Double, _ h: Double)``
• ` init(_:_:_:_:) `

Initializes a new Rect with the origin {x,y} and the size {w,h}, converting values from Int to Double ` let r = Rect(0,0,10,10) `

#### Declaration

Swift

``public init(_ x: Int, _ y: Int, _ w: Int, _ h: Int)``
• ` init(_:_:) `

Initializes a new Rect with the origin {o.x,o.y} and the size {s.w,s.h} ` let p = Point() let s = Size() let r = Rect(p,s) `

#### Declaration

Swift

``public init(_ o: Point, _ s: Size)``
• ` init(_:) `

Initializes a Rect from a CGRect

#### Declaration

Swift

``public init(_ rect: CGRect)``
• ` init(_:) `

Initializes a rectangle that contains all of the specified coordinates in an array. ` let pts = [Point(), Point(0,5), Point(10,10), Point(9,8)] let r = Rect(pts) //-> {{0.0, 0.0}, {10.0, 10.0}} ` - parameter points: An array of Point coordinates

#### Declaration

Swift

``public init(_ points: [Point])``

#### Parameters

 ` points ` An array of Point coordinates
• ` init(_:) `

Initializes a rectangle that contains the specified coordinates in a tuple. ` let pts = (Point(), Point(0,5)) let r = Rect(pts) ` - parameter points: An tuple of Point coordinates

#### Declaration

Swift

``public init(_ points: (Point, Point))``

#### Parameters

 ` points ` An tuple of Point coordinates
• ` intersects(_:) `

Returns whether two rectangles intersect. ` let r1 = Rect(0,0,10,10) let r2 = Rect(5,5,10,10) let r3 = Rect(10,10,10,10) r1.intersects(r2) //-> true r1.intersects(r3) //-> false ` - parameter rect: The rectangle to examine. - returns: true if the two specified rectangles intersect; otherwise, false.

#### Declaration

Swift

``public func intersects(rect: Rect) -> Bool``

#### Parameters

 ` rect ` The rectangle to examine.

#### Return Value

true if the two specified rectangles intersect; otherwise, false.

• ` center `

The center point of the receiver. ` let r = Rect(0,0,10,10) r.center //-> {5,5} `

#### Declaration

Swift

``public var center: Point``
• ` max `

The bottom-right point of the receiver. ` let r = Rect(5,5,10,10) r.max //-> {15,15} `

#### Declaration

Swift

``public var max: Point``
• ` isZero() `

Checks to see if the receiver has zero size and position ` let r = Point() r.isZero() //-> true ` - returns: true if origin = {0,0} and size = {0,0}

#### Declaration

Swift

``public func isZero() -> Bool``

#### Return Value

true if origin = {0,0} and size = {0,0}

• ` contains(_:) `

Returns whether a rectangle contains a specified point. ` let r1 = Rect(0,0,10,10) let r2 = Rect(5,5,10,10) let p = Rect(2,2,2,2) r1.contains(p) //-> true r2.contains(p) //-> false ` - parameter point: The point to examine. - returns: true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false.

#### Declaration

Swift

``public func contains(point: Point) -> Bool``

#### Parameters

 ` point ` The point to examine.

#### Return Value

true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false.

• ` contains(_:) `

Returns whether the first rectangle contains the second rectangle. ` let r1 = Rect(0,0,10,10) let r2 = Rect(5,5,10,10) let r3 = Rect(2,2,2,2) r1.contains(r2) //-> false r1.contains(r3) //-> true ` - parameter rect: The rectangle to examine for containment. - returns: `true` if the rectangle is contained in this rectangle; otherwise, `false`.

#### Declaration

Swift

``public func contains(rect: Rect) -> Bool``

#### Parameters

 ` rect ` The rectangle to examine for containment.

#### Return Value

`true` if the rectangle is contained in this rectangle; otherwise, `false`.

• ` description `

A string representation of the rect. - returns: A string formatted to look like {{x,y},{w,h}}

#### Declaration

Swift

``public var description: String``

#### Return Value

A string formatted to look like {{x,y},{w,h}}