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.
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.
bounds (0, 0, 0, 0)
MakeEmpty isEmpty: true offset rect isEmpty: true inset rect isEmpty: true outset rect isEmpty: false
isEmpty setEmpty SkIRect::MakeEmpty
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.
bounds (0, 0, w, h)
all equal
MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
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.
bounds (0, 0, w, h)
i_rect width: 25 f_rect width:25 i_rect width: 125000111 f_rect width:125000112
MakeXYWH MakeWH isetWH SkIRect::MakeWH
Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not validate input; size.width() or size.height() may be negative.
bounds (0, 0, size.width(), size.height())
rect width: 25.5 height: 35.5 floor width: 25 height: 35
MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
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.
bounds (l, t, r, b)
rect: 5, 35, 15, 25 isEmpty: true rect: 5, 25, 15, 35 isEmpty: false
MakeXYWH SkIRect::MakeLTRB
Returns constructed Rect set to (x, y, x + w, y + h). Does not validate input; w or h may be negative.
bounds at (x, y) with width w and height h
rect: 5, 35, -10, 60 isEmpty: true rect: -10, 35, 5, 60 isEmpty: false
MakeLTRB SkIRect::MakeXYWH
Returns constructed SkIRect set to (0, 0, size.width(), size.height()). Does not validate input; size.width() or size.height() may be negative.
bounds (0, 0, size.width(), size.height())
rect1 == rect2
MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
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.
irect members converted to SkScalar
MakeLTRB
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().
true if width() or height() are not positive and valid
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
MakeEmpty sort SkIRect::isEmpty
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().
true if width() or height() are zero or positive
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
sort makeSorted isEmpty
Returns true if all values in the rectangle are finite: SK ScalarMin or larger, and SK ScalarMax or smaller.
true if no member is infinite or NaN
largest is finite: true large width inf widest is finite: false
SkScalarIsFinite SkScalarIsNaN
Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. Call sort() to reverse fLeft and fRight if needed.
fLeft
unsorted.fLeft: 15 unsorted.x(): 15 sorted.fLeft: 10 sorted.x(): 10
fLeft left() y() SkIRect::x()
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.
fTop
unsorted.fTop: 25 unsorted.y(): 25 sorted.fTop: 5 sorted.y(): 5
fTop top() x() SkIRect::y()
Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. Call sort() to reverse fLeft and fRight if needed.
fLeft
unsorted.fLeft: 15 unsorted.left(): 15 sorted.fLeft: 10 sorted.left(): 10
fLeft x() SkIRect::left()
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.
fTop
unsorted.fTop: 25 unsorted.top(): 25 sorted.fTop: 5 sorted.top(): 5
fTop y() SkIRect::top()
Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid. Call sort() to reverse fLeft and fRight if needed.
fRight
unsorted.fRight: 10 unsorted.right(): 10 sorted.fRight: 15 sorted.right(): 15
fRight SkIRect::right()
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.
fBottom
unsorted.fBottom: 5 unsorted.bottom(): 5 sorted.fBottom: 25 sorted.bottom(): 25
fBottom SkIRect::bottom()
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.
fRight minus fLeft
unsorted width: -5 large width: 4294967296
height() SkIRect::width()
Returns span on the y-axis. This does not check if Rect is sorted, or if result fits in 32-bit float; result may be negative or infinity.
fBottom minus fTop
unsorted height: -5 large height: 4294967296
width() SkIRect::height()
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.
midpoint in x
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
centerY
Returns average of top edge and bottom edge. Result does not change if Rect is sorted.
midpoint in y
left: 2e+38 right: 3e+38 centerX: 2.5e+38 safe mid x: 2.5e+38
centerX
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.
true if members are equal
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
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.
true if members are not equal
test with NaN is not equal to itself
operator==(const SkRect& a, const SkRect& b)
Returns four points in quad that enclose Rect ordered as: top-left, top-right, bottom-right, bottom-left.
Private: Consider adding param to control whether quad is clockwise or counterclockwise.
rect: {1, 2, 3, 4} corners: {1, 2} {3, 2} {3, 4} {1, 4}
SkPath::addRect[2][3]
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.
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
set[2][3][4] setBoundsCheck SkPath::addPoly[2]
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.
true if all Point values are finite
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
set[2][3][4] setBounds SkPath::addPoly[2]
Sets to bounds of Point pts array with count entries. If any Point in pts contains infinity or NaN, all Rect dimensions are set to NaN.
setBoundsCheck
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.
rect: {3, 4, 1, 2} is empty rect: {0, 0, 0, 0} is empty
MakeEmpty SkIRect::setEmpty
Sets Rect to src, promoting src members from integer to Scalar. Very large values in src may lose precision.
i_rect: {3, 4, 1, 2} f_rect: {3, 4, 1, 2}
setLTRB SkIntToScalar
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.
rect1: {3, 4, 1, 2} rect2: {3, 4, 1, 2}
setLTRB setXYWH SkIRect::set
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.
rect1: {3, 4, 1, 2} rect2: {3, 4, 1, 2}
set[2][3][4] setXYWH SkIRect::set
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.
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
setBounds setBoundsCheck SkPath::addPoly[2]
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.
setBounds setBoundsCheck
Sets Rect to (x, y, x + width, y + height). Does not validate input; width or height may be negative.
rect: 5, 35, -10, 60 isEmpty: true rect: -10, 35, 5, 60 isEmpty: false
MakeXYWH setLTRB set[2][3][4] SkIRect::setXYWH
Sets Rect to (0, 0, width, height). Does not validate input; width or height may be negative.
rect: 0, 0, -15, 25 isEmpty: true rect: -15, 0, 0, 25 isEmpty: false
MakeWH setXYWH isetWH
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.
rect1: {3, 4, 1, 2} rect2: {3, 4, 1, 2}
set[2][3][4] setLTRB SkIRect::set SkIntToScalar
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.
rect1: {0, 0, 1, 2} rect2: {0, 0, 1, 2}
MakeWH MakeXYWH iset() SkIRect:MakeWH
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.
Rect offset on axes, with original width and height
rect: 10, 50, 20, 60 isEmpty: false rect: 25, 82, 35, 92 isEmpty: false
offset[2]() makeInset makeOutset SkIRect::makeOffset
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.
Rect inset symmetrically left and right, top and bottom
rect: 10, 50, 20, 60 isEmpty: false rect: 25, 82, 5, 28 isEmpty: true
inset() makeOffset makeOutset SkIRect::makeInset
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.
Rect outset symmetrically left and right, top and bottom
rect: 10, 50, 20, 60 isEmpty: false rect: -5, 18, 35, 92 isEmpty: false
outset() makeOffset makeInset SkIRect::makeOutset
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.
rect: 15, 27, 55, 86
offsetTo makeOffset SkIRect::offset[2]
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.
rect: 15, 27, 55, 86
offsetTo makeOffset SkIRect::offset[2]
Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height are unchanged.
rect: 15, 27, 55, 86
offset[2] makeOffset setXYWH SkIRect::offsetTo
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.
rect: 15, 27, 45, 60
outset makeInset SkIRect::inset
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.
rect: 5, 1, 55, 86
inset makeOutset SkIRect::outset
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.
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. Returns false if SkRect is empty.
true if (x, y) is inside Rect
rect: (30, 50, 40, 60) contains (30, 50) rect: (30, 50, 40, 60) does not contain (39, 49) rect: (30, 50, 40, 60) does not contain (29, 59)
SkIRect::contains[2][3][4] SkRRect::contains
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.
true if all sides of Rect are outside r
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)
SkIRect::contains[2][3][4]
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.
true if all sides of Rect are outside r
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)
SkIRect::contains[2][3][4]
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.
true if r and Rect have area in common
intersection: 30, 60, 50, 80
intersects[2] Intersects join[2] SkIRect::intersect[2][3]
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.
true if construction and Rect have area in common
intersection: 30, 60, 50, 80
intersects[2] Intersects join[2] SkIRect::intersect[2][3]
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.
true if a and b have area in common
intersection: 30, 60, 50, 80
intersects[2] Intersects join[2] SkIRect::intersect[2][3]
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.
true if construction and Rect have area in common
intersection
intersect[2][3] Intersects SkIRect::Intersects
Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not intersect.
true if r and Rect have area in common
intersection
intersect[2][3] Intersects SkIRect::Intersects
Returns true if a intersects b. Returns false if either a or b is empty, or do not intersect.
true if a and b have area in common
intersection
intersect[2][3] intersects[2] SkIRect::Intersects
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.
join: 10, 20, 55, 65
joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join[2]
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.
join: 10, 20, 55, 65
joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join[2]
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.
rect: 50, 60, 55, 65 sorted: 10, 0, 55, 100
join[2] joinPossiblyEmptyRect SkIRect::join[2]
Sets Rect to the union of itself and the construction.
May produce incorrect results if Rect or r is empty.
rect: 10, 60, 55, 65 sorted: 10, 0, 55, 100
joinNonEmptyArg join[2] SkIRect::join[2]
Sets IRect by adding 0.5 and discarding the fractional portion of Rect members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)).
round: 31, 51, 41, 61
roundIn roundOut[2][3] SkScalarRoundToInt
Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
round: 30, 50, 41, 61
roundIn round[2] SkScalarRoundToInt
Sets Rect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
round: 30, 50, 41, 61
roundIn round[2] SkScalarRoundToInt
Sets Rect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)).
round: 31, 51, 40, 60
roundOut[2][3] round[2] SkScalarRoundToInt
Returns IRect by adding 0.5 and discarding the fractional portion of Rect members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)).
rounded IRect
round: 31, 51, 41, 61
roundOut[2][3] roundIn SkScalarRoundToInt
Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
rounded IRect
round: 30, 50, 41, 61
round[2] roundIn SkScalarRoundToInt
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.
rect: 30.5, 50.5, 20.5, 10.5 sorted: 20.5, 10.5, 30.5, 50.5
makeSorted SkIRect::sort isSorted
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.
sorted Rect
rect: 30.5, 50.5, 20.5, 10.5 sorted: 20.5, 10.5, 30.5, 50.5
sort SkIRect::makeSorted isSorted
Returns pointer to first Scalar in Rect, to treat it as an array with four entries.
pointer to fLeft
rect.asScalars() == &rect.fLeft
toQuad
Writes text representation of Rect to standard output. Set asHex to true to generate exact binary representations of floating point numbers.
SkRect::MakeLTRB(20, 30, 40, 50); SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */ SkBits2Float(0x41f00000), /* 30.000000 */ SkBits2Float(0x42200000), /* 40.000000 */ SkBits2Float(0x42480000) /* 50.000000 */);
dumpHex
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.
SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7); rect is not equal to copy
dumpHex
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 .
SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ SkBits2Float(0x3f2aaaab), /* 0.666667 */ SkBits2Float(0x40266666), /* 2.600000 */ SkBits2Float(0x40e00000) /* 7.000000 */); rect is equal to copy
dump[2]