Skia
2D Graphics Library

SkRect holds four SkScalar coordinates describing the upper and lower bounds of a rectangle. More...
#include <SkRect.h>
Public Member Functions  
bool  isEmpty () const 
Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom. More...  
bool  isSorted () const 
Returns true if fLeft is equal to or less than fRight, or if fTop is equal to or less than fBottom. More...  
bool  isFinite () const 
Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, and SK_ScalarMax or smaller. More...  
SkScalar  x () const 
Returns left edge of SkRect, if sorted. More...  
SkScalar  y () const 
Returns top edge of SkRect, if sorted. More...  
SkScalar  left () const 
Returns left edge of SkRect, if sorted. More...  
SkScalar  top () const 
Returns top edge of SkRect, if sorted. More...  
SkScalar  right () const 
Returns right edge of SkRect, if sorted. More...  
SkScalar  bottom () const 
Returns bottom edge of SkRect, if sorted. More...  
SkScalar  width () const 
Returns span on the xaxis. More...  
SkScalar  height () const 
Returns span on the yaxis. More...  
SkScalar  centerX () const 
Returns average of left edge and right edge. More...  
SkScalar  centerY () const 
Returns average of top edge and bottom edge. More...  
void  toQuad (SkPoint quad[4]) const 
Returns four points in quad that enclose SkRect ordered as: topleft, topright, bottomright, bottomleft. More...  
void  setEmpty () 
Sets SkRect to (0, 0, 0, 0). More...  
void  set (const SkIRect &src) 
Sets SkRect to src, promoting src members from integer to scalar. More...  
void  setLTRB (SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) 
Sets SkRect to (left, top, right, bottom). More...  
void  setBounds (const SkPoint pts[], int count) 
Sets to bounds of SkPoint array with count entries. More...  
bool  setBoundsCheck (const SkPoint pts[], int count) 
Sets to bounds of SkPoint array with count entries. More...  
void  setBoundsNoCheck (const SkPoint pts[], int count) 
Sets to bounds of SkPoint pts array with count entries. More...  
void  set (const SkPoint &p0, const SkPoint &p1) 
Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1. More...  
void  setXYWH (SkScalar x, SkScalar y, SkScalar width, SkScalar height) 
Sets SkRect to (x, y, x + width, y + height). More...  
void  setWH (SkScalar width, SkScalar height) 
Sets SkRect to (0, 0, width, height). More...  
void  setIWH (int32_t width, int32_t height) 
constexpr SkRect  makeOffset (SkScalar dx, SkScalar dy) const 
Returns SkRect offset by (dx, dy). More...  
constexpr SkRect  makeOffset (SkVector v) const 
Returns SkRect offset by v. More...  
SkRect  makeInset (SkScalar dx, SkScalar dy) const 
Returns SkRect, inset by (dx, dy). More...  
SkRect  makeOutset (SkScalar dx, SkScalar dy) const 
Returns SkRect, outset by (dx, dy). More...  
void  offset (SkScalar dx, SkScalar dy) 
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. More...  
void  offset (const SkPoint &delta) 
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom. More...  
void  offsetTo (SkScalar newX, SkScalar newY) 
Offsets SkRect so that fLeft equals newX, and fTop equals newY. More...  
void  inset (SkScalar dx, SkScalar dy) 
Insets SkRect by (dx, dy). More...  
void  outset (SkScalar dx, SkScalar dy) 
Outsets SkRect by (dx, dy). More...  
bool  intersect (const SkRect &r) 
Returns true if SkRect intersects r, and sets SkRect to intersection. More...  
bool SK_WARN_UNUSED_RESULT  intersect (const SkRect &a, const SkRect &b) 
Returns true if a intersects b, and sets SkRect to intersection. More...  
bool  intersects (const SkRect &r) const 
Returns true if SkRect intersects r. More...  
void  join (const SkRect &r) 
Sets SkRect to the union of itself and r. More...  
void  joinNonEmptyArg (const SkRect &r) 
Sets SkRect to the union of itself and r. More...  
void  joinPossiblyEmptyRect (const SkRect &r) 
Sets SkRect to the union of itself and the construction. More...  
bool  contains (SkScalar x, SkScalar y) const 
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. More...  
bool  contains (const SkRect &r) const 
Returns true if SkRect contains r. More...  
bool  contains (const SkIRect &r) const 
Returns true if SkRect contains r. More...  
void  round (SkIRect *dst) const 
Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)). More...  
void  roundOut (SkIRect *dst) const 
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)). More...  
void  roundOut (SkRect *dst) const 
Sets SkRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)). More...  
void  roundIn (SkIRect *dst) const 
Sets SkRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)). More...  
SkIRect  round () const 
Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)). More...  
SkIRect  roundOut () const 
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)). More...  
void  sort () 
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom. More...  
SkRect  makeSorted () const 
Returns SkRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom. More...  
const SkScalar *  asScalars () const 
Returns pointer to first scalar in SkRect, to treat it as an array with four entries. More...  
void  dump (bool asHex) const 
Writes text representation of SkRect to standard output. More...  
void  dump () const 
Writes text representation of SkRect to standard output. More...  
void  dumpHex () const 
Writes text representation of SkRect to standard output. More...  
Static Public Member Functions  
static constexpr SkRect SK_WARN_UNUSED_RESULT  MakeEmpty () 
Returns constructed SkRect set to (0, 0, 0, 0). More...  
static constexpr SkRect SK_WARN_UNUSED_RESULT  MakeWH (SkScalar w, SkScalar h) 
Returns constructed SkRect set to SkScalar values (0, 0, w, h). More...  
static SkRect SK_WARN_UNUSED_RESULT  MakeIWH (int w, int h) 
Returns constructed SkRect set to integer values (0, 0, w, h). More...  
static constexpr SkRect SK_WARN_UNUSED_RESULT  MakeSize (const SkSize &size) 
Returns constructed SkRect set to (0, 0, size.width(), size.height()). More...  
static constexpr SkRect SK_WARN_UNUSED_RESULT  MakeLTRB (SkScalar l, SkScalar t, SkScalar r, SkScalar b) 
Returns constructed SkRect set to (l, t, r, b). More...  
static constexpr SkRect SK_WARN_UNUSED_RESULT  MakeXYWH (SkScalar x, SkScalar y, SkScalar w, SkScalar h) 
Returns constructed SkRect set to (x, y, x + w, y + h). More...  
static SkRect  Make (const SkISize &size) 
Returns constructed SkIRect set to (0, 0, size.width(), size.height()). More...  
static SkRect SK_WARN_UNUSED_RESULT  Make (const SkIRect &irect) 
Returns constructed SkIRect set to irect, promoting integers to scalar. More...  
static bool  Intersects (const SkRect &a, const SkRect &b) 
Returns true if a intersects b. More...  
Public Attributes  
SkScalar  fLeft 
smaller xaxis bounds More...  
SkScalar  fTop 
smaller yaxis bounds More...  
SkScalar  fRight 
larger xaxis bounds More...  
SkScalar  fBottom 
larger yaxis bounds More...  
Friends  
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. More...  
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. More...  
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.

inline 
Returns pointer to first scalar in SkRect, to treat it as an array with four entries.

inline 

inline 

inline 
Returns average of top edge and bottom edge.
Result does not change if SkRect is sorted.

inline 

inline 
void SkRect::dump  (  bool  asHex  )  const 
Writes text representation of SkRect to standard output.
Set asHex to true to generate exact binary representations of floating point numbers.
asHex  true if SkScalar values are written as hexadecimal 
example: https://fiddle.skia.org/c/@Rect_dump

inline 

inline 

inline 
Returns span on the yaxis.
This does not check if SkRect is sorted, or if result fits in 32bit float; result may be negative or infinity.
bool SkRect::intersect  (  const SkRect &  r  ) 
bool SK_WARN_UNUSED_RESULT SkRect::intersect  (  const SkRect &  a, 
const SkRect &  b  
) 

inline 

inline 

inline 
Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, and SK_ScalarMax or smaller.

inline 
void SkRect::join  (  const SkRect &  r  ) 

inline 

inline 

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

inlinestatic 
Returns constructed SkIRect set to irect, promoting integers to scalar.
Does not validate input; fLeft may be greater than fRight, fTop may be greater than fBottom.
irect  integer unsorted bounds 

inlinestatic 
Returns constructed SkRect 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.
Returns SkRect, inset by (dx, dy).
If dx is negative, SkRect returned is wider. If dx is positive, SkRect returned is narrower. If dy is negative, SkRect returned is taller. If dy is positive, SkRect returned is shorter.
dx  added to fLeft and subtracted from fRight 
dy  added to fTop and subtracted from fBottom 

inlinestatic 
Returns SkRect offset by (dx, dy).
If dx is negative, SkRect returned is moved to the left. If dx is positive, SkRect returned is moved to the right. If dy is negative, SkRect returned is moved upward. If dy is positive, SkRect returned is moved downward.
dx  added to fLeft and fRight 
dy  added to fTop and fBottom 
Returns SkRect, outset by (dx, dy).
If dx is negative, SkRect returned is narrower. If dx is positive, SkRect returned is wider. If dy is negative, SkRect returned is shorter. If dy is positive, SkRect returned is taller.
dx  subtracted to fLeft and added from fRight 
dy  subtracted to fTop and added from fBottom 

inlinestatic 

inline 

inlinestatic 

inlinestatic 
Returns constructed SkRect set to (x, y, x + w, y + h).
Does not validate input; w or h may be negative.
x  stored in fLeft 
y  stored in fTop 
w  added to x and stored in fRight 
h  added to y and stored in fBottom 
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
If dx is negative, moves SkRect to the left. If dx is positive, moves SkRect to the right. If dy is negative, moves SkRect upward. If dy is positive, moves SkRect downward.
dx  offset added to fLeft and fRight 
dy  offset added to fTop and fBottom 

inline 
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.
If delta.fX is negative, moves SkRect to the left. If delta.fX is positive, moves SkRect to the right. If delta.fY is negative, moves SkRect upward. If delta.fY is positive, moves SkRect downward.
delta  added to SkRect 

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

inline 
Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)).
dst  storage for SkIRect 

inline 
Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)).

inline 
Sets SkRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)).
dst  storage for SkIRect 

inline 
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
dst  storage for SkIRect 

inline 
Sets SkRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
dst  storage for SkRect 

inline 
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).

inline 

inline 
Sets to bounds of SkPoint array with count entries.
If count is zero or smaller, or if SkPoint 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.
pts  SkPoint array 
count  entries in array 
bool SkRect::setBoundsCheck  (  const SkPoint  pts[], 
int  count  
) 
Sets to bounds of SkPoint array with count entries.
Returns false if count is zero or smaller, or if SkPoint array contains an infinity or NaN; in these cases sets SkRect 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.
pts  SkPoint array 
count  entries in array 
void SkRect::setBoundsNoCheck  (  const SkPoint  pts[], 
int  count  
) 

inline 
Sets SkRect 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.

inline 
Sets SkRect 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.
left  stored in fLeft 
top  stored in fTop 
right  stored in fRight 
bottom  stored in fBottom 
Sets SkRect to (0, 0, width, height).
Does not validate input; width or height may be negative.
width  stored in fRight 
height  stored in fBottom 
Sets SkRect to (x, y, x + width, y + height).
Does not validate input; width or height may be negative.
x  stored in fLeft 
y  stored in fTop 
width  added to x and stored in fRight 
height  added to y and stored in fBottom 

inline 

inline 
void SkRect::toQuad  (  SkPoint  quad[4]  )  const 

inline 
Returns span on the xaxis.
This does not check if SkRect is sorted, or if result fits in 32bit float; result may be negative or infinity.

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

inline 
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 with different signs.
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 with different signs.
SkScalar SkRect::fBottom 
larger yaxis bounds
SkScalar SkRect::fLeft 
smaller xaxis bounds
SkScalar SkRect::fRight 
larger xaxis bounds
SkScalar SkRect::fTop 
smaller yaxis bounds