Skia 2DGraphicsLibrary
SkRect Struct Reference

## Public Member Functions

bool isEmpty () const
Return true if the rectangle's width or height are <= 0.

bool isSorted () const
Return true if the rectangle's width and height are >= 0.

bool isLargest () const

bool isFinite () const
Returns true iff all values in the rect are finite. More...

SkScalar x () const

SkScalar y () const

SkScalar left () const

SkScalar top () const

SkScalar right () const

SkScalar bottom () const

SkScalar width () const

SkScalar height () const

SkScalar centerX () const

SkScalar centerY () const

return the 4 points that enclose the rectangle (top-left, top-right, bottom-right, bottom-left). More...

void setEmpty ()
Set this rectangle to the empty rectangle (0,0,0,0)

void set (const SkIRect &src)

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

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

void iset (int left, int top, int right, int bottom)
Initialize the rect with the 4 specified integers. More...

void isetWH (int width, int height)
Set this rectangle to be left/top at 0,0, and have the specified width and height (automatically converted to SkScalar).

void set (const SkPoint pts[], int count)
Set this rectangle to be the bounds of the array of points. More...

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

bool setBoundsCheck (const SkPoint pts[], int count)
Compute the bounds of the array of points, and set this rect to that bounds and return true... More...

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

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

void setWH (SkScalar width, SkScalar height)

void setLargest ()
Make the largest representable rectangle.

void setLargestInverted ()
Make the largest representable rectangle, but inverted (e.g. More...

SkRect makeOffset (SkScalar dx, SkScalar dy) const
Return a new Rect, built as an offset of this rect.

SkRect makeInset (SkScalar dx, SkScalar dy) const
Return a new Rect, built as an inset of this rect.

SkRect makeOutset (SkScalar dx, SkScalar dy) const
Return a new Rect, built as an outset of this rect.

void offset (SkScalar dx, SkScalar dy)
Offset set the rectangle by adding dx to its left and right, and adding dy to its top and bottom.

void offset (const SkPoint &delta)

void offsetTo (SkScalar newX, SkScalar newY)
Offset this rect such its new x() and y() will equal newX and newY.

void inset (SkScalar dx, SkScalar dy)
Inset the rectangle by (dx,dy). More...

void outset (SkScalar dx, SkScalar dy)
Outset the rectangle by (dx,dy). More...

bool intersect (const SkRect &r)
If this rectangle intersects r, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. More...

bool intersect (SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
If this rectangle intersects the rectangle specified by left, top, right, bottom, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. More...

bool SK_WARN_UNUSED_RESULT intersect (const SkRect &a, const SkRect &b)
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. More...

bool intersects (SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
Return true if this rectangle is not empty, and the specified sides of a rectangle are not empty, and they intersect.

bool intersects (const SkRect &r) const

void join (SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
Update this rectangle to enclose itself and the specified rectangle. More...

void join (const SkRect &r)
Update this rectangle to enclose itself and the specified rectangle. More...

void joinNonEmptyArg (const SkRect &r)

void joinPossiblyEmptyRect (const SkRect &r)
Joins the rectangle with another without checking if either are empty (may produce unexpected results if either rect is inverted).

void growToInclude (SkScalar x, SkScalar y)
Grow the rect to include the specified (x,y). More...

void growToInclude (const SkPoint pts[], int count)
Bulk version of growToInclude.

void growToInclude (const SkPoint pts[], size_t stride, int count)
Bulk version of growToInclude with stride. More...

bool contains (const SkRect &r) const
Return true if this rectangle contains r, and if both rectangles are not empty.

bool contains (const SkIRect &r) const
Returns true if the specified rectangle r is inside or equal to this rectangle.

void round (SkIRect *dst) const
Set the dst rectangle by rounding this rectangle's coordinates to their nearest integer values using SkScalarRoundToInt.

void roundOut (SkIRect *dst) const
Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloor of top and left, and the SkScalarCeil of right and bottom.

void roundOut (SkRect *dst) const
Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloorToScalar of top and left, and the SkScalarCeilToScalar of right and bottom. More...

void roundIn (SkIRect *dst) const
Set the dst rectangle by rounding "in" this rectangle, choosing the ceil of top and left, and the floor of right and bottom. More...

SkIRect round () const
Returns the result of calling round(&dst)

SkIRect roundOut () const
Returns the result of calling roundOut(&dst)

void sort ()
Swap top/bottom or left/right if there are flipped (i.e. More...

SkRect makeSorted () const
Return a new Rect that is the sorted version of this rect (left <= right, top <= bottom).

const SkScalar * asScalars () const
cast-safe way to treat the rect as an array of (4) SkScalars.

void dump (bool asHex) const

void dump () const

void dumpHex () const

## Static Public Member Functions

static constexpr SkRect
SK_WARN_UNUSED_RESULT
MakeEmpty ()

static SkRect SK_WARN_UNUSED_RESULT MakeLargest ()

static SkRect SK_WARN_UNUSED_RESULT MakeWH (SkScalar w, SkScalar h)

static SkRect SK_WARN_UNUSED_RESULT MakeIWH (int w, int h)

static SkRect SK_WARN_UNUSED_RESULT MakeSize (const SkSize &size)

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

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

static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect (const SkIRect &irect)

static SkRect Make (const SkISize &size)

static SkRect SK_WARN_UNUSED_RESULT Make (const SkIRect &irect)

static bool Intersects (const SkRect &a, const SkRect &b)
Return true if rectangles a and b are not empty and intersect.

SkScalar fLeft

SkScalar fTop

SkScalar fRight

SkScalar fBottom

## Static Private Member Functions

static bool Intersects (SkScalar al, SkScalar at, SkScalar ar, SkScalar ab, SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb)

## Friends

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

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

## Member Function Documentation

 void SkRect::growToInclude ( SkScalar x, SkScalar y )
inline

Grow the rect to include the specified (x,y).

After this call, the following will be true: fLeft <= x <= fRight && fTop <= y <= fBottom.

This is close, but not quite the same contract as contains(), since contains() treats the left and top different from the right and bottom. contains(x,y) -> fLeft <= x < fRight && fTop <= y < fBottom. Also note that contains(x,y) always returns false if the rect is empty.

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

Bulk version of growToInclude with stride.

 void SkRect::inset ( SkScalar dx, SkScalar dy )
inline

Inset the rectangle by (dx,dy).

If dx is positive, then the sides are moved inwards, making the rectangle narrower. If dx is negative, then the sides are moved outwards, making the rectangle wider. The same holds true for dy and the top and bottom.

 bool SkRect::intersect ( const SkRect & r )

If this rectangle intersects r, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.

If either rectangle is empty, do nothing and return false.

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

If this rectangle intersects the rectangle specified by left, top, right, bottom, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.

If either rectangle is empty, do nothing and return false.

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

If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.

If either rectangle is empty, do nothing and return false.

 void SkRect::iset ( int left, int top, int right, int bottom )
inline

Initialize the rect with the 4 specified integers.

The routine handles converting them to scalars (by calling SkIntToScalar)

 bool SkRect::isFinite ( ) const
inline

Returns true iff all values in the rect are finite.

If any are infinite or NaN then this returns false.

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

Update this rectangle to enclose itself and the specified rectangle.

If this rectangle is empty, just set it to the specified rectangle. If the specified rectangle is empty, do nothing.

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

Update this rectangle to enclose itself and the specified rectangle.

If this rectangle is empty, just set it to the specified rectangle. If the specified rectangle is empty, do nothing.

 void SkRect::outset ( SkScalar dx, SkScalar dy )
inline

Outset the rectangle by (dx,dy).

If dx is positive, then the sides are moved outwards, making the rectangle wider. If dx is negative, then the sides are moved inwards, making the rectangle narrower. The same holds true for dy and the top and bottom.

 void SkRect::roundIn ( SkIRect * dst ) const
inline

Set the dst rectangle by rounding "in" this rectangle, choosing the ceil of top and left, and the floor of right and bottom.

This does not call sort(), so it is possible that the resulting rect is inverted... e.g. left >= right or top >= bottom. Call isEmpty() to detect that.

 void SkRect::roundOut ( SkRect * dst ) const
inline

Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloorToScalar of top and left, and the SkScalarCeilToScalar of right and bottom.

It is safe for this == dst

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

Set this rectangle to be the bounds of the array of points.

If the array is empty (count == 0), then set this rectangle to the empty rectangle (0,0,0,0)

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

Compute the bounds of the array of points, and set this rect to that bounds and return true...

unless a non-finite value is encountered, in which case this rect is set to empty and false is returned.

 void SkRect::setLargestInverted ( )
inline

Make the largest representable rectangle, but inverted (e.g.

fLeft will be max and right will be min).

 void SkRect::sort ( )
inline

Swap top/bottom or left/right if there are flipped (i.e.

if width() or height() would have returned a negative value.) This should be called if the edges are computed separately, and may have crossed over each other. When this returns, left <= right && top <= bottom

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

return the 4 points that enclose the rectangle (top-left, top-right, bottom-right, bottom-left).

TODO: Consider adding param to control whether quad is CW or CCW.

The documentation for this struct was generated from the following file: