SkRect Reference === # Rect # Overview ## Subtopics | name | description | | --- | --- | | Constructors | functions that construct SkRect | | Member Functions | static functions and member methods | | Members | member values | | Operators | operator overloading methods | | Related Functions | similar methods grouped together | # 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. ## Related Functions | name | description | | --- | --- | | As Points | conversion to and from Points | | From Integers | set Scalar values from integer input | | Inset Outset Offset | moves sides | | Intersection | set to shared bounds | | Join | set to union of bounds | | Properties | side values, center, validity | | Rounding | adjust to integer bounds | | Set | replaces all values | | Sorting | orders sides | ## 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 | deprecated | | 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 to standard output using floats | | dumpHex | sends text representation to standard output using hexadecimal | | 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 | | 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) | | 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 | ## Members SkScalar fLeft 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. SkScalar fTop 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. SkScalar fRight 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. SkScalar fBottom 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. ## Constructors | name | description | | --- | --- | | 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 | deprecated | | 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) | | 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 | ## 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
#### Example Output ~~~~ MakeEmpty isEmpty: true offset rect isEmpty: true inset rect isEmpty: true outset rect isEmpty: false ~~~~
### See Also isEmpty setEmpty SkIRect::MakeEmpty --- ## 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
w SkScalar width of constructed Rect
h SkScalar height of constructed Rect
### Return Value bounds (0, 0, w, h) ### Example
#### Example Output ~~~~ all equal ~~~~
### 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
w integer width of constructed Rect
h integer height of constructed Rect
### Return Value bounds (0, 0, w, h) ### Example
#### Example Output ~~~~ i_rect width: 25 f_rect width:25 i_rect width: 125000111 f_rect width:125000112 ~~~~
### 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
size SkScalar values for Rect width and height
### Return Value bounds (0, 0, size.width, size.height) ### Example
#### Example Output ~~~~ rect width: 25.5 height: 35.5 floor width: 25 height: 35 ~~~~
### 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
l SkScalar stored in fLeft
t SkScalar stored in fTop
r SkScalar stored in fRight
b SkScalar stored in fBottom
### Return Value bounds (l, t, r, b) ### Example
#### Example Output ~~~~ rect: 5, 35, 15, 25 isEmpty: true rect: 5, 25, 15, 35 isEmpty: false ~~~~
### See Also MakeXYWH SkIRect::MakeLTRB --- ## 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
x stored in fLeft
y stored in fTop
w added to x and stored in fRight
h added to y and stored in fBottom
### Return Value bounds at (x, y) with width w and height h ### Example
#### Example Output ~~~~ rect: 5, 35, -10, 60 isEmpty: true rect: -10, 35, 5, 60 isEmpty: false ~~~~
### See Also MakeLTRB SkIRect::MakeXYWH --- ## MakeFromIRect
static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
Deprecated. ### Parameters
irect integer rect
### Return Value irect as SkRect ### See Also Make[2] --- ## 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
size integer values for Rect width and height
### Return Value bounds (0, 0, size.width, size.height) ### Example
#### Example Output ~~~~ rect1 == rect2 ~~~~
### 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
irect integer unsorted bounds
### Return Value irect members converted to SkScalar ### Example
### See Also MakeLTRB --- ## Properties | name | description | | --- | --- | | bottom | returns larger bounds in y, if sorted | | centerX | returns midpoint in x | | centerY | returns midpoint in y | | height | returns span in y | | isEmpty | returns true if width or height are zero or negative | | isFinite | returns true if no member is infinite or NaN | | isSorted | returns true if width or height are zero or positive | | left | returns smaller bounds in x, if sorted | | right | returns larger bounds in x, if sorted | | top | returns smaller bounds in y, if sorted | | width | returns span in x | | x | returns bounds left | | y | returns bounds top | ## 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
#### Example Output ~~~~ rect: {20, 40, 10, 50} is empty sorted: {10, 40, 20, 50} is not empty rect: {20, 40, 20, 50} is empty sorted: {20, 40, 20, 50} is empty ~~~~
### 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
#### Example Output ~~~~ rect: {20, 40, 10, 50} is not sorted sorted: {10, 40, 20, 50} is sorted rect: {20, 40, 20, 50} is sorted sorted: {20, 40, 20, 50} is sorted ~~~~
### See Also sort makeSorted isEmpty --- ## 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
#### Example Output ~~~~ largest is finite: true large width inf widest is finite: false ~~~~
### 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 fLeft ### Example
#### Example Output ~~~~ unsorted.fLeft: 15 unsorted.x(): 15 sorted.fLeft: 10 sorted.x(): 10 ~~~~
### See Also fLeft left y SkIRect::x() --- ## 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 fTop ### Example
#### Example Output ~~~~ unsorted.fTop: 25 unsorted.y(): 25 sorted.fTop: 5 sorted.y(): 5 ~~~~
### See Also fTop top x SkIRect::y() --- ## 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 fLeft ### Example
#### Example Output ~~~~ unsorted.fLeft: 15 unsorted.left(): 15 sorted.fLeft: 10 sorted.left(): 10 ~~~~
### See Also fLeft x SkIRect::left() --- ## 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 fTop ### Example
#### Example Output ~~~~ unsorted.fTop: 25 unsorted.top(): 25 sorted.fTop: 5 sorted.top(): 5 ~~~~
### See Also fTop y SkIRect::top() --- ## 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 fRight ### Example
#### Example Output ~~~~ unsorted.fRight: 10 unsorted.right(): 10 sorted.fRight: 15 sorted.right(): 15 ~~~~
### See Also fRight SkIRect::right() --- ## 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 fBottom ### Example
#### Example Output ~~~~ unsorted.fBottom: 5 unsorted.bottom(): 5 sorted.fBottom: 25 sorted.bottom(): 25 ~~~~
### See Also fBottom SkIRect::bottom() --- ## 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 fRight minus fLeft ### Example
Compare with SkIRect::width() example.
#### Example Output ~~~~ unsorted width: -5 large width: 4294967296 ~~~~
### See Also height SkIRect::width() --- ## 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 fBottom minus fTop ### Example
Compare with SkIRect::height() example.
#### Example Output ~~~~ unsorted height: -5 large height: 4294967296 ~~~~
### See Also width SkIRect::height() --- ## 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
#### Example Output ~~~~ left: 20 right: 41 centerX: 30.5 left: 20 right: 41 centerX: 30.5 left: -20 right: -41 centerX: -30.5 left: -41 right: -20 centerX: -30.5 ~~~~
### See Also centerY SkIRect::centerX --- ## 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
#### Example Output ~~~~ left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38 ~~~~
### See Also centerX SkIRect::centerY --- ## Operators | name | description | | --- | --- | | bool operator!=(const SkRect& a, const SkRect& b) | returns true if members are unequal | | bool operator==(const SkRect& a, const SkRect& b) | returns true if members are equal | ## 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
a Rect to compare
b Rect to compare
### Return Value true if members are equal ### Example
#### Example Output ~~~~ tests are equal {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal ~~~~
### 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
a Rect to compare
b Rect to compare
### Return Value true if members are not equal ### Example
#### Example Output ~~~~ test with NaN is not equal to itself ~~~~
### See Also operator==(const SkRect& a, const SkRect& b) --- ## As Points | name | description | | --- | --- | | setBounds | sets to upper and lower limits of Point array | | setBoundsCheck | sets to upper and lower limits of Point array | | toQuad | returns four corners as Point | ## 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
quad storage for corners of Rect
### Example
#### Example Output ~~~~ rect: {1, 2, 3, 4} corners: {1, 2} {3, 2} {3, 4} {1, 4} ~~~~
### See Also SkPath::addRect[2][3] --- ## 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
pts Point array
count entries in array
### Example
#### Example Output ~~~~ count: 0 rect: 0, 0, 0, 0 added: 3, 4 count: 1 rect: 3, 4, 3, 4 added: 1, 2 count: 2 rect: 1, 2, 3, 4 added: 5, 6 count: 3 rect: 1, 2, 5, 6 added: nan, 8 count: 4 rect: 0, 0, 0, 0 ~~~~
### See Also set[2][3][4] 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
pts Point array
count entries in array
### Return Value true if all Point values are finite ### Example
#### Example Output ~~~~ count: 0 rect: 0, 0, 0, 0 success: true added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false ~~~~
### See Also set[2][3][4] setBounds SkPath::addPoly --- ## Set | name | description | | --- | --- | | iset | sets to int input (left, top, right, bottom) | | isetWH | sets to int input (0, 0, width, height) | | set | sets to SkScalar input (left, top, right, bottom) and others | | | void set(const SkIRect& src) | | | void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) | | | void set(const SkPoint pts[], int count) | | | void set(const SkPoint& p0, const SkPoint& p1) | | setEmpty | sets to (0, 0, 0, 0) | | setLTRB | sets to SkScalar input (left, top, right, bottom) | | setWH | sets to SkScalar input (0, 0, width, height) | | setXYWH | sets to SkScalar input (x, y, width, height) | ## 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
#### Example Output ~~~~ rect: {3, 4, 1, 2} is empty rect: {0, 0, 0, 0} is empty ~~~~
### See Also MakeEmpty SkIRect::setEmpty --- ## 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
src integer Rect
### Example
#### Example Output ~~~~ i_rect: {3, 4, 1, 2} f_rect: {3, 4, 1, 2} ~~~~
### See Also setLTRB SkIntToScalar ---
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
left stored in fLeft
top stored in fTop
right stored in fRight
bottom stored in fBottom
### Example
#### Example Output ~~~~ rect1: {3, 4, 1, 2} rect2: {3, 4, 1, 2} ~~~~
### See Also setLTRB setXYWH SkIRect::set --- ## 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
left stored in fLeft
top stored in fTop
right stored in fRight
bottom stored in fBottom
### Example
#### Example Output ~~~~ rect1: {3, 4, 1, 2} rect2: {3, 4, 1, 2} ~~~~
### See Also set[2][3][4] setXYWH SkIRect::set ---
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
pts Point array
count entries in array
### Example
#### Example Output ~~~~ count: 0 rect: 0, 0, 0, 0 added: 3, 4 count: 1 rect: 3, 4, 3, 4 added: 1, 2 count: 2 rect: 1, 2, 3, 4 added: 5, 6 count: 3 rect: 1, 2, 5, 6 added: nan, 8 count: 4 rect: 0, 0, 0, 0 ~~~~
### See Also setBounds setBoundsCheck SkPath::addPoly ---
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
p0 corner to include
p1 corner to include
### Example
p0 and p1 may be swapped and have the same effect unless one contains NaN.
### See Also setBounds setBoundsCheck --- ## 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
x stored in fLeft
y stored in fTop
width added to x and stored in fRight
height added to y and stored in fBottom
### Example
#### Example Output ~~~~ rect: 5, 35, -10, 60 isEmpty: true rect: -10, 35, 5, 60 isEmpty: false ~~~~
### See Also MakeXYWH setLTRB set[2][3][4] 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
width stored in fRight
height stored in fBottom
### Example
#### Example Output ~~~~ rect: 0, 0, -15, 25 isEmpty: true rect: -15, 0, 0, 25 isEmpty: false ~~~~
### See Also MakeWH setXYWH isetWH --- ## From Integers | name | description | | --- | --- | | iset | sets to int input (left, top, right, bottom) | | isetWH | sets to int input (0, 0, width, height) | ## 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
left promoted to SkScalar and stored in fLeft
top promoted to SkScalar and stored in fTop
right promoted to SkScalar and stored in fRight
bottom promoted to SkScalar and stored in fBottom
### Example
#### Example Output ~~~~ rect1: {3, 4, 1, 2} rect2: {3, 4, 1, 2} ~~~~
### See Also set[2][3][4] 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
width promoted to SkScalar and stored in fRight
height promoted to SkScalar and stored in fBottom
### Example
#### Example Output ~~~~ rect1: {0, 0, 1, 2} rect2: {0, 0, 1, 2} ~~~~
### See Also MakeWH MakeXYWH iset SkIRect:MakeWH --- ## Inset Outset Offset | name | description | | --- | --- | | inset | moves the sides symmetrically about the center | | makeInset | constructs from sides moved symmetrically about the center | | makeOffset | constructs from translated sides | | makeOutset | constructs from sides moved symmetrically about the center | | offset | translates sides without changing width and height | | | void offset(SkScalar dx, SkScalar dy) | | | void offset(const SkPoint& delta) | | offsetTo | translates to (x, y) without changing width and height | | outset | moves the sides symmetrically about the center | ## 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
dx added to fLeft and fRight
dy added to fTop and fBottom
### Return Value Rect offset in x or y, with original width and height ### Example
#### Example Output ~~~~ rect: 10, 50, 20, 60 isEmpty: false rect: 25, 82, 35, 92 isEmpty: false ~~~~
### See Also offset[2] 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
dx added to fLeft and subtracted from fRight
dy added to fTop and subtracted from fBottom
### Return Value Rect inset symmetrically left and right, top and bottom ### Example
#### Example Output ~~~~ rect: 10, 50, 20, 60 isEmpty: false rect: 25, 82, 5, 28 isEmpty: true ~~~~
### 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
dx subtracted to fLeft and added from fRight
dy subtracted to fTop and added from fBottom
### Return Value Rect outset symmetrically left and right, top and bottom ### Example
#### Example Output ~~~~ rect: 10, 50, 20, 60 isEmpty: false rect: -5, 18, 35, 92 isEmpty: false ~~~~
### 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
dx offset added to fLeft and fRight
dy offset added to fTop and fBottom
### Example
#### Example Output ~~~~ rect: 15, 27, 55, 86 ~~~~
### See Also offsetTo makeOffset SkIRect::offset[2] ---
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
delta added to Rect
### Example
#### Example Output ~~~~ rect: 15, 27, 55, 86 ~~~~
### See Also offsetTo makeOffset SkIRect::offset[2] --- ## offsetTo
void offsetTo(SkScalar newX, SkScalar newY)
Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height are unchanged. ### Parameters
newX stored in fLeft, preserving width
newY stored in fTop, preserving height
### Example
#### Example Output ~~~~ rect: 15, 27, 55, 86 ~~~~
### See Also offset[2] makeOffset setXYWH SkIRect::offsetTo --- ## inset
void inset(SkScalar dx, SkScalar dy)
Insets Rect by (dx, 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
dx added to fLeft and subtracted from fRight
dy added to fTop and subtracted from fBottom
### Example
#### Example Output ~~~~ rect: 15, 27, 45, 60 ~~~~
### See Also outset makeInset SkIRect::inset --- ## outset
void outset(SkScalar dx, SkScalar dy)
Outsets Rect by (dx, 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
dx subtracted to fLeft and added from fRight
dy subtracted to fTop and added from fBottom
### Example
#### Example Output ~~~~ rect: 5, 1, 55, 86 ~~~~
### 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 pair 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. | name | description | | --- | --- | | Intersects | returns true if areas overlap | | contains | returns true if points are equal or inside | | | bool contains(const SkRect& r) const | | | bool contains(const SkIRect& r) const | | intersect | sets to shared area; returns true if not empty | | | bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) | | | bool intersect(const SkRect& r) | | | bool intersect(const SkRect& a, const SkRect& b) | | intersects | returns true if areas overlap | | | bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const | | | bool intersects(const SkRect& r) const | ## 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
r Rect contained
### Return Value true if all sides of Rect are outside r ### Example
#### Example Output ~~~~ rect: (30, 50, 40, 60) contains (30, 50, 31, 51) rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) ~~~~
### See Also SkIRect::contains[2][3][4] ---
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
r IRect contained
### Return Value true if all sides of Rect are outside r ### Example
#### Example Output ~~~~ rect: (30, 50, 40, 60) contains (30, 50, 31, 51) rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) ~~~~
### See Also SkIRect::contains[2][3][4] --- ## 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
r limit of result
### Return Value true if r and Rect have area in common ### Example
Two SkDebugf calls are required. If the calls are combined, their arguments may not be evaluated in left to right order: the printed intersection may be before or after the call to intersect.
#### Example Output ~~~~ intersection: 30, 60, 50, 80 ~~~~
### See Also intersects[2] Intersects join[2] SkIRect::intersect[2][3] ---
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
left x minimum of constructed Rect
top y minimum of constructed Rect
right x maximum of constructed Rect
bottom y maximum of constructed Rect
### Return Value true if construction and Rect have area in common ### Example
Two SkDebugf calls are required. If the calls are combined, their arguments may not be evaluated in left to right order: the printed intersection may be before or after the call to intersect.
#### Example Output ~~~~ intersection: 30, 60, 50, 80 ~~~~
### See Also intersects[2] Intersects join[2] SkIRect::intersect[2][3] ---
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
a Rect to intersect
b Rect to intersect
### Return Value true if a and b have area in common ### Example
#### Example Output ~~~~ intersection: 30, 60, 50, 80 ~~~~
### See Also intersects[2] Intersects join[2] SkIRect::intersect[2][3] --- ## 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
left x minimum of constructed Rect
top y minimum of constructed Rect
right x maximum of constructed Rect
bottom y maximum of constructed Rect
### Return Value true if construction and Rect have area in common ### Example
#### Example Output ~~~~ intersection ~~~~
### See Also intersect[2][3] 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
r Rect to intersect
### Return Value true if r and Rect have area in common ### Example
#### Example Output ~~~~ intersection ~~~~
### See Also intersect[2][3] 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
a Rect to intersect
b Rect to intersect
### Return Value true if a and b have area in common ### Example
#### Example Output ~~~~ intersection ~~~~
### See Also intersect[2][3] intersects[2] SkIRect::Intersects --- ## Join | name | description | | --- | --- | | join | sets to union of bounds | | | void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) | | | void join(const SkRect& r) | | joinNonEmptyArg | sets to union of bounds, asserting that argument is not empty | | joinPossiblyEmptyRect | sets to union of bounds. Skips empty check for both | ## 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
left x minimum of constructed Rect
top y minimum of constructed Rect
right x maximum of constructed Rect
bottom y maximum of constructed Rect
### Example
#### Example Output ~~~~ join: 10, 20, 55, 65 ~~~~
### See Also joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join[2] ---
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
r expansion Rect
### Example
#### Example Output ~~~~ join: 10, 20, 55, 65 ~~~~
### See Also joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join[2] --- ## 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
r expansion Rect
### Example
Since Rect is not sorted, first result is copy of toJoin.
#### Example Output ~~~~ rect: 50, 60, 55, 65 sorted: 10, 0, 55, 100 ~~~~
### See Also join[2] joinPossiblyEmptyRect SkIRect::join[2] --- ## 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
r expansion Rect
### Example
Since Rect is not sorted, first result is not useful.
#### Example Output ~~~~ rect: 10, 60, 55, 65 sorted: 10, 0, 55, 100 ~~~~
### See Also joinNonEmptyArg join[2] SkIRect::join[2] --- ## Rounding | name | description | | --- | --- | | round | sets members to nearest integer value | | | void round(SkIRect* dst) const | | | SkIRect round const | | roundIn | sets members to nearest integer value towards opposite | | roundOut | sets members to nearest integer value away from opposite | | | void roundOut(SkIRect* dst) const | | | void roundOut(SkRect* dst) const | | | SkIRect roundOut const | ## round
void round(SkIRect* dst) const
Sets IRect by adding 0.5 and discarding the fractional portion of Rect members, using(. ### Parameters
dst storage for IRect
### Example
#### Example Output ~~~~ round: 31, 51, 41, 61 ~~~~
### See Also roundIn roundOut[2][3] 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
dst storage for IRect
### Example
#### Example Output ~~~~ round: 30, 50, 41, 61 ~~~~
### See Also roundIn round[2] 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
dst storage for Rect
### Example
#### Example Output ~~~~ round: 30, 50, 41, 61 ~~~~
### See Also roundIn round[2] 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
dst storage for IRect
### Example
#### Example Output ~~~~ round: 31, 51, 40, 60 ~~~~
### See Also roundOut[2][3] round[2] SkScalarRoundToInt ---
SkIRect round() const
Returns IRect by adding 0.5 and discarding the fractional portion of Rect members, using(. ### Return Value rounded IRect ### Example
#### Example Output ~~~~ round: 31, 51, 41, 61 ~~~~
### See Also roundOut[2][3] 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
#### Example Output ~~~~ round: 30, 50, 41, 61 ~~~~
### See Also round[2] roundIn SkScalarRoundToInt --- ## Sorting | name | description | | --- | --- | | makeSorted | constructs, ordering sides from smaller to larger | | sort | orders sides from smaller to larger | ## 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
#### Example Output ~~~~ rect: 30.5, 50.5, 20.5, 10.5 sorted: 20.5, 10.5, 30.5, 50.5 ~~~~
### See Also makeSorted SkIRect::sort isSorted --- ## 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
#### Example Output ~~~~ rect: 30.5, 50.5, 20.5, 10.5 sorted: 20.5, 10.5, 30.5, 50.5 ~~~~
### See Also sort SkIRect::makeSorted isSorted --- ## 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
#### Example Output ~~~~ rect.asScalars() == &rect.fLeft ~~~~
### See Also toQuad --- ## 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
asHex true if SkScalar values are written as hexadecimal
### Example
#### Example Output ~~~~ SkRect::MakeLTRB(20, 30, 40, 50); SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */ SkBits2Float(0x41f00000), /* 30.000000 */ SkBits2Float(0x42200000), /* 40.000000 */ SkBits2Float(0x42480000) /* 50.000000 */); ~~~~
### See Also dumpHex ---
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
#### Example Output ~~~~ SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7); rect is not equal to copy ~~~~
### See Also dumpHex --- ## 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 submitting bug reports against Skia . ### Example
#### Example Output ~~~~ SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ SkBits2Float(0x3f2aaaab), /* 0.666667 */ SkBits2Float(0x40266666), /* 2.600000 */ SkBits2Float(0x40e00000) /* 7.000000 */); rect is equal to copy ~~~~
### See Also dump[2] --- ## MakeLargest
static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
Returns constructed SkRect 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) ---