# SkRect Reference

# Rect

# Struct SkRect

SkRect holds four SkScalar coordinates describing the upper and lower bounds of a rectangle. SkRect may be created from outer bounds or from position, width, and height. SkRect describes an area; if its right is less than or equal to its left, or if its bottom is less than or equal to its top, it is considered empty.

SkRect can be constructed from int values to avoid compiler warnings that integer input cannot convert to SkScalar without loss of precision.

# Overview

## Subtopics

topics | description |
---|

## Operators

description | function |
---|---|

bool operator!=(const SkRect& a, const SkRect& b) | Returns true if member bits are unequal. |

bool operator==(const SkRect& a, const SkRect& b) | Returns true if member bits are equal. |

## Member Functions

description | function |
---|---|

Intersects | Returns true if areas overlap. |

Make | Constructs from ISize returning (0, 0, width, height). |

MakeEmpty | Constructs from bounds of (0, 0, 0, 0). |

MakeFromIRect | Deprecated. |

MakeIWH | Constructs from int input returning (0, 0, width, height). |

MakeLTRB | Constructs from SkScalar left, top, right, bottom. |

MakeLargest | Constructs (SK ScalarMin, SK ScalarMin, SK ScalarMax, SK ScalarMax). |

MakeLargestS32 | Constructs largest signed integers that fit in 32-bit float. |

MakeSize | Constructs from Size returning (0, 0, width, height). |

MakeWH | Constructs from SkScalar input returning (0, 0, width, height). |

MakeXYWH | Constructs from SkScalar input returning (x, y, width, height). |

asScalars | Returns pointer to members as array. |

bottom | Returns larger bounds in y, if sorted. |

centerX | Returns midpoint in x. |

centerY | Returns midpoint in y. |

contains | Returns true if points are equal or inside. |

dump | Sends text representation using floats to standard output. |

dumpHex | Sends text representation using hexadecimal to standard output. |

growToInclude | Sets to union of bounds and one or more Points. |

height | Returns span in y. |

inset | Moves the sides symmetrically about the center. |

intersect | Sets to shared area; returns true if not empty. |

intersects | Returns true if areas overlap. |

isEmpty | Returns true if width or height are zero or negative. |

isFinite | Returns true if no member is infinite or NaN. |

isLargest | Returns equal to (SK ScalarMin, SK ScalarMin, SK ScalarMax, SK ScalarMax). |

isSorted | Returns true if width or height are zero or positive. |

iset | Sets to int input (left, top, right, bottom). |

isetWH | Sets to int input (0, 0, width, height). |

join | Sets to union of bounds. |

joinNonEmptyArg | Sets to union of bounds, asserting that argument is not empty. |

joinPossiblyEmptyRect | Sets to union of bounds. Skips empty check for both. |

left | Returns smaller bounds in x, if sorted. |

makeInset | Constructs from sides moved symmetrically about the center. |

makeOffset | Constructs from translated sides. |

makeOutset | Constructs from sides moved symmetrically about the center. |

makeSorted | Constructs, ordering sides from smaller to larger. |

offset | Translates sides without changing width and height. |

offsetTo | Translates to (x, y) without changing width and height. |

outset | Moves the sides symmetrically about the center. |

right | Returns larger bounds in x, if sorted. |

round | Sets members to nearest integer value. |

roundIn | Sets members to nearest integer value towards opposite. |

roundOut | Sets members to nearest integer value away from opposite. |

set | Sets to SkScalar input (left, top, right, bottom) and others. |

setBounds | Sets to upper and lower limits of Point array. |

setBoundsCheck | Sets to upper and lower limits of Point array. |

setEmpty | Sets to (0, 0, 0, 0). |

setLTRB | Sets to SkScalar input (left, top, right, bottom). |

setLargest | Sets to (SK ScalarMin, SK ScalarMin, SK ScalarMax, SK ScalarMax). |

setLargestInverted | Sets to (SK ScalarMax, SK ScalarMax, SK ScalarMin, SK ScalarMin). |

setWH | Sets to SkScalar input (0, 0, width, height). |

setXYWH | Sets to SkScalar input (x, y, width, height). |

sort | Orders sides from smaller to larger. |

toQuad | Returns four corners as Point. |

top | Returns smaller bounds in y, if sorted. |

width | Returns span in x. |

x | Returns bounds left. |

y | Returns bounds top. |

May contain any value, including infinities and NaN. The smaller of the horizontal values when sorted. When equal to or greater than fRight, Rect is empty.

May contain any value, including infinities and NaN. The smaller of the vertical values when sorted. When equal to or greater than fBottom, Rect is empty.

May contain any value, including infinities and NaN. The larger of the horizontal values when sorted. When equal to or less than fLeft, Rect is empty.

May contain any value, including infinities and NaN. The larger of the vertical values when sorted. When equal to or less than fTop, Rect is empty.

## MakeEmpty

static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()

Returns constructed Rect set to (0, 0, 0, 0). Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle.

### Return Value

bounds (0, 0, 0, 0)

### Example

### See Also

isEmpty setEmpty setLargestInverted SkIRect::MakeEmpty

## MakeLargest

static SkRect SK_WARN_UNUSED_RESULT MakeLargest()

Returns constructed Rect setting left and top to most negative finite value, and setting right and bottom to most positive finite value.

### Return Value

bounds (SK ScalarMin, SK ScalarMin, SK ScalarMax, SK ScalarMax)

### Example

### See Also

MakeLargestS32 isLargest setLargest SkIRect::MakeLargest

## MakeLargestS32

static SkRect SK_WARN_UNUSED_RESULT MakeLargestS32()

Returns constructed Rect that can be represented exactly with IRect. The left and top are set to the most negative integer value that fits in a 32-bit float, and the right and bottom are set to the most positive finite value that fits in a 32-bit float.

These are the largest values for which round is well defined.

### Return Value

bounds (SK MinS32FitsInFloat, SK MinS32FitsInFloat, SK MaxS32FitsInFloat, SK MaxS32FitsInFloat)

### Example

### See Also

MakeLargest isLargest setLargest SkIRect::MakeLargest

## MakeWH

static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)

Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not validate input; w or h may be negative.

Passing integer values may generate a compiler warning since Rect cannot represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.

### Parameters

| SkScalar width of constructed Rect |

| SkScalar height of constructed Rect |

### Return Value

### Example

### See Also

MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH

## MakeIWH

static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)

Returns constructed Rect set to integer values (0, 0, w, h). Does not validate input; w or h may be negative.

Use to avoid a compiler warning that input may lose precision when stored. Use SkIRect for an exact integer rectangle.

### Parameters

| integer width of constructed Rect |

| integer height of constructed Rect |

### Return Value

### Example

### See Also

MakeXYWH MakeWH isetWH SkIRect::MakeWH

## MakeSize

static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)

Returns constructed Rect set to (0, 0, size.width, size.height). Does not validate input; size.width or size.height may be negative.

### Parameters

| SkScalar values for Rect width and height |

### Return Value

bounds (0, 0, size.width, size.height)

### Example

### See Also

MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH

## MakeLTRB

static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r, SkScalar b)

Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may result in fLeft greater than fRight, or fTop greater than fBottom.

### Parameters

| SkScalar stored in fLeft |

| SkScalar stored in fTop |

| SkScalar stored in fRight |

| SkScalar stored in fBottom |

### Return Value

### Example

### See Also

## MakeXYWH

static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)

Returns constructed Rect set to(x, y, x + w, y + h). Does not validate input; w or h may be negative.

### Parameters

| stored in fLeft |

| stored in fTop |

| added to x and stored in fRight |

| added to y and stored in fBottom |

### Return Value

bounds at (x, y) with width w and height h

### Example

### See Also

## MakeFromIRect

static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)

Deprecated.

### Parameters

| integer rect |

### Return Value

### See Also

## Make

static SkRect Make(const SkISize& size)

Returns constructed IRect set to (0, 0, size.width, size.height). Does not validate input; size.width or size.height may be negative.

### Parameters

| integer values for Rect width and height |

### Return Value

bounds (0, 0, size.width, size.height)

### Example

### See Also

MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize

static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)

Returns constructed IRect set to irect, promoting integers to Scalar. Does not validate input; fLeft may be greater than fRight, fTop may be greater than fBottom.

### Parameters

| integer unsorted bounds |

### Return Value

irect members converted to SkScalar

### Example

### See Also

## isEmpty

bool isEmpty() const

Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom. Call sort to reverse rectangles with negative width or height.

### Return Value

true if width or height are zero or negative

### Example

### See Also

MakeEmpty sort SkIRect::isEmpty

## isSorted

bool isSorted() const

Returns true if fLeft is equal to or less than fRight, or if fTop is equal to or less than fBottom. Call sort to reverse rectangles with negative width or height.

### Return Value

true if width or height are zero or positive

### Example

### See Also

## isLargest

bool isLargest() const

Returns true if Rect encloses largest possible area.

### Return Value

true if equal to (SK ScalarMin, SK ScalarMin, SK ScalarMax, SK ScalarMax)

### Example

#### Example Output

```
large is largest: true
large width inf
large is empty: false
large is sorted: true
large is finite: true
```

### See Also

MakeLargest SkIRect::isLargest

## isFinite

bool isFinite() const

Returns true if all values in the rectangle are finite: SK ScalarMin or larger, and SK ScalarMax or smaller.

### Return Value

true if no member is infinite or NaN

### Example

### See Also

SkScalarIsFinite SkScalarIsNaN

## x

SkScalar x() const

Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. Call sort to reverse fLeft and fRight if needed.

### Return Value

### Example

### See Also

## y

SkScalar y() const

Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, and sort to reverse fTop and fBottom if needed.

### Return Value

### Example

### See Also

## left

SkScalar left() const

Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. Call sort to reverse fLeft and fRight if needed.

### Return Value

### Example

### See Also

## top

SkScalar top() const

Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, and sort to reverse fTop and fBottom if needed.

### Return Value

### Example

### See Also

## right

SkScalar right() const

Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid. Call sort to reverse fLeft and fRight if needed.

### Return Value

### Example

### See Also

## bottom

SkScalar bottom() const

Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, and sort to reverse fTop and fBottom if needed.

### Return Value

### Example

### See Also

## width

SkScalar width() const

Returns span on the x-axis. This does not check if Rect is sorted, or if result fits in 32-bit float; result may be negative or infinity.

### Return Value

### Example

#### Example Output

```
unsorted width: -5
large width: 4294967296
```

### See Also

## height

SkScalar height() const

Returns span on the y-axis. This does not check if IRect is sorted, or if result fits in 32-bit float; result may be negative or infinity.

### Return Value

### Example

#### Example Output

```
unsorted height: -5
large height: 4294967296
```

### See Also

## centerX

SkScalar centerX() const

Returns average of left edge and right edge. Result does not change if Rect is sorted. Result may overflow to infinity if Rect is far from the origin.

### Return Value

midpoint in x

### Example

### See Also

## centerY

SkScalar centerY() const

Returns average of top edge and bottom edge. Result does not change if Rect is sorted. Result may overflow to infinity if Rect is far from the origin.

### Return Value

midpoint in y

### Example

### See Also

## operator==

bool operator==(const SkRect& a, const SkRect& b)

Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are

equal to the corresponding members in b.

a and b are not equal if either contain NaN. a and b are equal if members contain zeroes width different signs.

### Parameters

| Rect to compare |

| Rect to compare |

### Return Value

true if members are equal

### Example

### See Also

operator!=(const SkRect& a, const SkRect& b)

## operator!=

bool operator!=(const SkRect& a, const SkRect& b)

Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not

equal the corresponding members in b.

a and b are not equal if either contain NaN. a and b are equal if members contain zeroes width different signs.

### Parameters

| Rect to compare |

| Rect to compare |

### Return Value

true if members are not equal

### Example

### See Also

operator==(const SkRect& a, const SkRect& b)

## toQuad

void toQuad(SkPoint quad[4]) const

Returns four points in quad that enclose Rect ordered as: top-left, top-right, bottom-right, bottom-left.

### Parameters

| storage for corners of Rect |

### Example

### See Also

## setEmpty

void setEmpty()

Sets Rect to (0, 0, 0, 0).

Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle.

### Example

### See Also

## set

void set(const SkIRect& src)

Sets Rect to src, promoting src members from integer to Scalar. Very large values in src may lose precision.

### Parameters

| integer Rect |

### Example

### See Also

void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)

Sets Rect to (left, top, right, bottom). left and right are not sorted; left is not necessarily less than right. top and bottom are not sorted; top is not necessarily less than bottom.

### Parameters

| stored in fLeft |

| stored in fTop |

| stored in fRight |

| stored in fBottom |

### Example

### See Also

## setLTRB

void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)

Sets Rect to (left, top, right, bottom). left and right are not sorted; left is not necessarily less than right. top and bottom are not sorted; top is not necessarily less than bottom.

### Parameters

| stored in fLeft |

| stored in fTop |

| stored in fRight |

| stored in fBottom |

### Example

### See Also

## iset

void iset(int left, int top, int right, int bottom)

Sets Rect to (left, top, right, bottom). All parameters are promoted from integer to Scalar. left and right are not sorted; left is not necessarily less than right. top and bottom are not sorted; top is not necessarily less than bottom.

### Parameters

| promoted to SkScalar and stored in fLeft |

| promoted to SkScalar and stored in fTop |

| promoted to SkScalar and stored in fRight |

| promoted to SkScalar and stored in fBottom |

### Example

### See Also

set setLTRB SkIRect::set SkIntToScalar

## isetWH

void isetWH(int width, int height)

Sets Rect to (0, 0, width, height). width and height may be zero or negative. width and height are promoted from integer to SkScalar, large values may lose precision.

### Parameters

| promoted to SkScalar and stored in fRight |

| promoted to SkScalar and stored in fBottom |

### Example

### See Also

MakeWH MakeXYWH iset SkIRect:MakeWH

void set(const SkPoint pts[], int count)

Sets to bounds of Point array with count entries. If count is zero or smaller, or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).

Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom.

### Parameters

| Point array |

| entries in array |

### Example

### See Also

setBounds setBoundsCheck SkPath::addPoly

## setBounds

void setBounds(const SkPoint pts[], int count)

Sets to bounds of Point array with count entries. If count is zero or smaller, or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).

Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom.

### Parameters

| Point array |

| entries in array |

### Example

### See Also

set setBoundsCheck SkPath::addPoly

## setBoundsCheck

bool setBoundsCheck(const SkPoint pts[], int count)

Sets to bounds of Point array with count entries. Returns false if count is zero or smaller, or if Point array contains an infinity or NaN; in these cases sets Rect to (0, 0, 0, 0).

Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom.

### Parameters

| Point array |

| entries in array |

### Return Value

true if all Point values are finite

### Example

### See Also

void set(const SkPoint& p0, const SkPoint& p1)

Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is sorted and may be empty. Does not check to see if values are finite.

### Parameters

| corner to include |

| corner to include |

### Example

### See Also

## setXYWH

void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)

Sets Rect to(x, y, x + width, y + height). Does not validate input; width or height may be negative.

### Parameters

| stored in fLeft |

| stored in fTop |

| added to x and stored in fRight |

| added to y and stored in fBottom |

### Example

### See Also

MakeXYWH setLTRB set SkIRect::setXYWH

## setWH

void setWH(SkScalar width, SkScalar height)

Sets Rect to (0, 0, width, height). Does not validate input; width or height may be negative.

### Parameters

| stored in fRight |

| stored in fBottom |

### Example

### See Also

## setLargest

void setLargest()

Sets rectangle left and top to most negative finite value, and sets right and bottom to most positive finite value.

### Example

### See Also

MakeLargest isLargest setLargestInverted SK ScalarMin SK ScalarMax

## setLargestInverted

void setLargestInverted()

Sets rectangle left and top to most positive finite value, and sets right and bottom to most negative finite value.

Use to initial Rect before one or more calls to growToInclude.

### Example

### See Also

growToInclude setEmpty setLargest

## makeOffset

SkRect makeOffset(SkScalar dx, SkScalar dy) const

Returns Rect offset by (dx, dy).

If dx is negative, Rect returned is moved to the left. If dx is positive, Rect returned is moved to the right. If dy is negative, Rect returned is moved upward. If dy is positive, Rect returned is moved downward.

### Parameters

| added to fLeft and fRight |

| added to fTop and fBottom |

### Return Value

Rect offset in x or y, with original width and height

### Example

### See Also

offset makeInset makeOutset SkIRect::makeOffset

## makeInset

SkRect makeInset(SkScalar dx, SkScalar dy) const

Returns Rect, inset by (dx, dy).

If dx is negative, Rect returned is wider. If dx is positive, Rect returned is narrower. If dy is negative, Rect returned is taller. If dy is positive, Rect returned is shorter.

### Parameters

| added to fLeft and subtracted from fRight |

| added to fTop and subtracted from fBottom |

### Return Value

Rect inset symmetrically left and right, top and bottom

### Example

### See Also

inset makeOffset makeOutset SkIRect::makeInset

## makeOutset

SkRect makeOutset(SkScalar dx, SkScalar dy) const

Returns Rect, outset by (dx, dy).

If dx is negative, Rect returned is narrower. If dx is positive, Rect returned is wider. If dy is negative, Rect returned is shorter. If dy is positive, Rect returned is taller.

### Parameters

| subtracted to fLeft and added from fRight |

| subtracted to fTop and added from fBottom |

### Return Value

Rect outset symmetrically left and right, top and bottom

### Example

### See Also

outset makeOffset makeInset SkIRect::makeOutset

## offset

void offset(SkScalar dx, SkScalar dy)

Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.

If dx is negative, moves Rect to the left. If dx is positive, moves Rect to the right. If dy is negative, moves Rect upward. If dy is positive, moves Rect downward.

### Parameters

| offset added to fLeft and fRight |

| offset added to fTop and fBottom |

### Example

### See Also

offsetTo makeOffset SkIRect::offset

void offset(const SkPoint& delta)

Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.

If delta.fX is negative, moves Rect to the left. If delta.fX is positive, moves Rect to the right. If delta.fY is negative, moves Rect upward. If delta.fY is positive, moves Rect downward.

### Parameters

| added to Rect |

### Example

### See Also

offsetTo makeOffset SkIRect::offset

## offsetTo

void offsetTo(SkScalar newX, SkScalar newY)

Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height are unchanged.

### Parameters

| stored in fLeft, preserving width |

| stored in fTop, preserving height |

### Example

### See Also

offset makeOffset setXYWH SkIRect::offsetTo

## inset

void inset(SkScalar dx, SkScalar dy)

If dx is positive, makes Rect narrower. If dx is negative, makes Rect wider. If dy is positive, makes Rect shorter. If dy is negative, makes Rect taller.

### Parameters

| added to fLeft and subtracted from fRight |

| added to fTop and subtracted from fBottom |

### Example

### See Also

outset makeInset SkIRect::inset

## outset

void outset(SkScalar dx, SkScalar dy)

If dx is positive, makes Rect wider. If dx is negative, makes Rect narrower. If dy is positive, makes Rect taller. If dy is negative, makes Rect shorter.

### Parameters

| subtracted to fLeft and added from fRight |

| subtracted to fTop and added from fBottom |

### Example

### See Also

inset makeOutset SkIRect::outset

# Intersection

Rects intersect when they enclose a common area. To intersect, each of the pair must describe area; fLeft is less than fRight, and fTop is less than fBottom; empty() returns false. The intersection of Rect a and Rect b can be described by: (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))The intersection is only meaningful if the resulting Rect is not empty and describes an area: fLeft is less than fRight, and fTop is less than fBottom.

## intersect

bool intersect(const SkRect& r)

Returns true if Rect intersects r, and sets Rect to intersection. Returns false if Rect does not intersect r, and leaves Rect unchanged.

Returns false if either r or Rect is empty, leaving Rect unchanged.

### Parameters

| limit of result |

### Return Value

true if r and Rect have area in common

### Example

#### Example Output

```
intersection: 30, 60, 50, 80
```

### See Also

intersects Intersects join SkIRect::intersect

bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)

Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction.

Returns true if Rect intersects construction, and sets Rect to intersection. Returns false if Rect does not intersect construction, and leaves Rect unchanged.

Returns false if either construction or Rect is empty, leaving Rect unchanged.

### Parameters

| x minimum of constructed Rect |

| y minimum of constructed Rect |

| x maximum of constructed Rect |

| y maximum of constructed Rect |

### Return Value

true if construction and Rect have area in common

### Example

#### Example Output

```
intersection: 30, 60, 50, 80
```

### See Also

intersects Intersects join SkIRect::intersect

bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)

Returns true if a intersects b, and sets Rect to intersection. Returns false if a does not intersect b, and leaves Rect unchanged.

Returns false if either a or b is empty, leaving Rect unchanged.

### Parameters

| Rect to intersect |

| Rect to intersect |

### Return Value

true if a and b have area in common

### Example

### See Also

intersects Intersects join SkIRect::intersect

## intersects

bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const

Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction.

Returns true if Rect intersects construction. Returns false if either construction or Rect is empty, or do not intersect.

### Parameters

| x minimum of constructed Rect |

| y minimum of constructed Rect |

| x maximum of constructed Rect |

| y maximum of constructed Rect |

### Return Value

true if construction and Rect have area in common

### Example

### See Also

intersect Intersects SkIRect::Intersects

bool intersects(const SkRect& r) const

Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not intersect.

### Parameters

| Rect to intersect |

### Return Value

true if r and Rect have area in common

### Example

### See Also

intersect Intersects SkIRect::Intersects

## Intersects

static bool Intersects(const SkRect& a, const SkRect& b)

Returns true if a intersects b. Returns false if either a or b is empty, or do not intersect.

### Parameters

| Rect to intersect |

| Rect to intersect |

### Return Value

true if a and b have area in common

### Example

### See Also

intersect intersects SkIRect::Intersects

## join

void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)

Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction.

Sets Rect to the union of itself and the construction.

Has no effect if construction is empty. Otherwise, if Rect is empty, sets Rect to construction.

### Parameters

| x minimum of constructed Rect |

| y minimum of constructed Rect |

| x maximum of constructed Rect |

| y maximum of constructed Rect |

### Example

### See Also

joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join

void join(const SkRect& r)

Sets Rect to the union of itself and r.

Has no effect if r is empty. Otherwise, if Rect is empty, sets Rect to r.

### Parameters

| expansion Rect |

### Example

### See Also

joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join

## joinNonEmptyArg

void joinNonEmptyArg(const SkRect& r)

Sets Rect to the union of itself and r.

Asserts if r is empty and SK DEBUG is defined. If Rect is empty, sets Rect to r.

May produce incorrect results if r is empty.

### Parameters

| expansion Rect |

### Example

#### Example Output

```
rect: 50, 60, 55, 65
sorted: 10, 0, 55, 100
```

### See Also

join joinPossiblyEmptyRect SkIRect::join

## joinPossiblyEmptyRect

void joinPossiblyEmptyRect(const SkRect& r)

Sets Rect to the union of itself and the construction.

May produce incorrect results if Rect or r is empty.

### Parameters

| expansion Rect |

### Example

#### Example Output

```
rect: 10, 60, 55, 65
sorted: 10, 0, 55, 100
```

### See Also

joinNonEmptyArg join SkIRect::join

## growToInclude

void growToInclude(SkPoint pt)

Grows Rect to include (pt.fX, pt.fY), modifying it so that: fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom.

If Rect is initialized with setLargestInverted, then Rect will contain bounds of Points after one or more calls. In this case, Rect is empty after first call.

### Parameters

| Point to include |

### Example

### See Also

void growToInclude(const SkPoint pts[], int count)

For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying it so that: fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom.

If Rect is initialized with setLargestInverted, then Rect will contain bounds of Points after one or more calls. In this case, Rect is empty after first call.

### Parameters

| Point array |

| number of points in array |

### Example

### See Also

void growToInclude(const SkPoint pts[], size_t stride, int count)

For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying it so that: fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom. Point may be followed with other data in each array element. stride is number of bytes in element; the interval to skip to advance from one Point to the next.

If Rect is initialized with setLargestInverted, then Rect will contain bounds of Points after one or more calls. In this case, Rect is empty after first call.

### Parameters

| array of elements beginning with Point |

| size of pts elements in 32-bit words; zero or greater |

| number of elements in array |

### Example

### See Also

## contains

bool contains(const SkRect& r) const

Returns true if Rect contains r. Returns false if Rect is empty or r is empty.

Rect contains r when Rect area completely includes r area.

### Parameters

| Rect contained |

### Return Value

true if all sides of Rect are outside r

### Example

### See Also

bool contains(const SkIRect& r) const

Returns true if Rect contains r. Returns false if Rect is empty or r is empty.

Rect contains r when Rect area completely includes r area.

### Parameters

| IRect contained |

### Return Value

true if all sides of Rect are outside r

### Example

### See Also

# Round

## round

void round(SkIRect* dst) const

Sets IRect by adding 0.5 and discarding the fractional portion of Rect members, using(.

### Parameters

| storage for IRect |

### Example

### See Also

roundIn roundOut SkScalarRoundToInt

## roundOut

void roundOut(SkIRect* dst) const

Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and FBottom, using(.

### Parameters

| storage for IRect |

### Example

### See Also

roundIn round SkScalarRoundToInt

void roundOut(SkRect* dst) const

Sets Rect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and FBottom, using(.

### Parameters

| storage for Rect |

### Example

### See Also

roundIn round SkScalarRoundToInt

## roundIn

void roundIn(SkIRect* dst) const

Sets Rect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and FBottom, using(.

### Parameters

| storage for IRect |

### Example

### See Also

roundOut round SkScalarRoundToInt

SkIRect round() const

Returns IRect by adding 0.5 and discarding the fractional portion of Rect members, using(.

### Return Value

rounded IRect

### Example

### See Also

roundOut roundIn SkScalarRoundToInt

SkIRect roundOut() const

Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and FBottom, using(.

### Return Value

rounded IRect

### Example

### See Also

round roundIn SkScalarRoundToInt

## sort

void sort()

Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom. Result may be empty; and width and height will be zero or positive.

### Example

### See Also

## makeSorted

SkRect makeSorted() const

Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty; and width and height will be zero or positive.

### Return Value

sorted Rect

### Example

### See Also

## asScalars

const SkScalar* asScalars() const

Returns pointer to first Scalar in Rect, to treat it as an array with four entries.

### Return Value

pointer to fLeft

### Example

### See Also

## dump

void dump(bool asHex) const

Writes text representation of Rect to standard output. Set asHex to true to generate exact binary representations of floating point numbers.

### Parameters

| true if SkScalar values are written as hexadecimal |

### Example

### See Also

void dump() const

Writes text representation of Rect to standard output. The representation may be directly compiled as C++ code. Floating point values are written with limited precision; it may not be possible to reconstruct original Rect from output.

### Example

### See Also

## dumpHex

void dumpHex() const

Writes text representation of Rect to standard output. The representation may be directly compiled as C++ code. Floating point values are written in hexadecimal to preserve their exact bit pattern. The output reconstructs the original Rect.

Use instead of dump when submittingbug reports against Skia.