Skia
2D Graphics Library
SkRect Struct Reference

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 x-axis. More...
 
SkScalar height () const
 Returns span on the y-axis. 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: top-left, top-right, bottom-right, bottom-left. 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 SkScalarasScalars () 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 x-axis bounds More...
 
SkScalar fTop
 smaller y-axis bounds More...
 
SkScalar fRight
 larger x-axis bounds More...
 
SkScalar fBottom
 larger y-axis 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...
 

Detailed Description

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.

Member Function Documentation

◆ asScalars()

const SkScalar* SkRect::asScalars ( ) const
inline

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

Returns
pointer to fLeft

◆ bottom()

SkScalar SkRect::bottom ( ) const
inline

Returns bottom edge of SkRect, if sorted.

Call isEmpty() to see if SkRect may be invalid, and sort() to reverse fTop and fBottom if needed.

Returns
fBottom

◆ centerX()

SkScalar SkRect::centerX ( ) const
inline

Returns average of left edge and right edge.

Result does not change if SkRect is sorted. Result may overflow to infinity if SkRect is far from the origin.

Returns
midpoint on x-axis

◆ centerY()

SkScalar SkRect::centerY ( ) const
inline

Returns average of top edge and bottom edge.

Result does not change if SkRect is sorted.

Returns
midpoint on y-axis

◆ contains() [1/3]

bool SkRect::contains ( SkScalar  x,
SkScalar  y 
) const
inline

Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.

Returns false if SkRect is empty.

Parameters
xtest SkPoint x-coordinate
ytest SkPoint y-coordinate
Returns
true if (x, y) is inside SkRect

◆ contains() [2/3]

bool SkRect::contains ( const SkRect r) const
inline

Returns true if SkRect contains r.

Returns false if SkRect is empty or r is empty.

SkRect contains r when SkRect area completely includes r area.

Parameters
rSkRect contained
Returns
true if all sides of SkRect are outside r

◆ contains() [3/3]

bool SkRect::contains ( const SkIRect r) const
inline

Returns true if SkRect contains r.

Returns false if SkRect is empty or r is empty.

SkRect contains r when SkRect area completely includes r area.

Parameters
rSkIRect contained
Returns
true if all sides of SkRect are outside r

◆ dump() [1/2]

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.

Parameters
asHextrue if SkScalar values are written as hexadecimal

example: https://fiddle.skia.org/c/@Rect_dump

◆ dump() [2/2]

void SkRect::dump ( ) const
inline

Writes text representation of SkRect 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 SkRect from output.

◆ dumpHex()

void SkRect::dumpHex ( ) const
inline

Writes text representation of SkRect 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 SkRect.

Use instead of dump() when submitting

◆ height()

SkScalar SkRect::height ( ) const
inline

Returns span on the y-axis.

This does not check if SkRect is sorted, or if result fits in 32-bit float; result may be negative or infinity.

Returns
fBottom minus fTop

◆ inset()

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

Insets SkRect by (dx, dy).

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

Parameters
dxadded to fLeft and subtracted from fRight
dyadded to fTop and subtracted from fBottom

◆ intersect() [1/2]

bool SkRect::intersect ( const SkRect r)

Returns true if SkRect intersects r, and sets SkRect to intersection.

Returns false if SkRect does not intersect r, and leaves SkRect unchanged.

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

Parameters
rlimit of result
Returns
true if r and SkRect have area in common

example: https://fiddle.skia.org/c/@Rect_intersect

◆ intersect() [2/2]

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

Returns true if a intersects b, and sets SkRect to intersection.

Returns false if a does not intersect b, and leaves SkRect unchanged.

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

Parameters
aSkRect to intersect
bSkRect to intersect
Returns
true if a and b have area in common

◆ intersects()

bool SkRect::intersects ( const SkRect r) const
inline

Returns true if SkRect intersects r.

Returns false if either r or SkRect is empty, or do not intersect.

Parameters
rSkRect to intersect
Returns
true if r and SkRect have area in common

◆ Intersects()

static bool SkRect::Intersects ( const SkRect a,
const SkRect b 
)
inlinestatic

Returns true if a intersects b.

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

Parameters
aSkRect to intersect
bSkRect to intersect
Returns
true if a and b have area in common

◆ isEmpty()

bool SkRect::isEmpty ( ) const
inline

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().

Returns
true if width() or height() are zero or negative

◆ isFinite()

bool SkRect::isFinite ( ) const
inline

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

Returns
true if no member is infinite or NaN

◆ isSorted()

bool SkRect::isSorted ( ) const
inline

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().

Returns
true if width() or height() are zero or positive

◆ join()

void SkRect::join ( const SkRect r)

Sets SkRect to the union of itself and r.

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

Parameters
rexpansion SkRect

example: https://fiddle.skia.org/c/@Rect_join_2

◆ joinNonEmptyArg()

void SkRect::joinNonEmptyArg ( const SkRect r)
inline

Sets SkRect to the union of itself and r.

Asserts if r is empty and SK_DEBUG is defined. If SkRect is empty, sets SkRect to r.

May produce incorrect results if r is empty.

Parameters
rexpansion SkRect

◆ joinPossiblyEmptyRect()

void SkRect::joinPossiblyEmptyRect ( const SkRect r)
inline

Sets SkRect to the union of itself and the construction.

May produce incorrect results if SkRect or r is empty.

Parameters
rexpansion SkRect

◆ left()

SkScalar SkRect::left ( ) const
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.

Returns
fLeft

◆ Make() [1/2]

static SkRect SkRect::Make ( const SkISize size)
inlinestatic

Returns constructed SkIRect set to (0, 0, size.width(), size.height()).

Does not validate input; size.width() or size.height() may be negative.

Parameters
sizeinteger values for SkRect width and height
Returns
bounds (0, 0, size.width(), size.height())

◆ Make() [2/2]

static SkRect SK_WARN_UNUSED_RESULT SkRect::Make ( const SkIRect irect)
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.

Parameters
irectinteger unsorted bounds
Returns
irect members converted to SkScalar

◆ MakeEmpty()

static constexpr SkRect SK_WARN_UNUSED_RESULT SkRect::MakeEmpty ( )
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
bounds (0, 0, 0, 0)

◆ makeInset()

SkRect SkRect::makeInset ( SkScalar  dx,
SkScalar  dy 
) const
inline

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.

Parameters
dxadded to fLeft and subtracted from fRight
dyadded to fTop and subtracted from fBottom
Returns
SkRect inset symmetrically left and right, top and bottom

◆ MakeIWH()

static SkRect SK_WARN_UNUSED_RESULT SkRect::MakeIWH ( int  w,
int  h 
)
inlinestatic

Returns constructed SkRect 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
winteger width of constructed SkRect
hinteger height of constructed SkRect
Returns
bounds (0, 0, w, h)

◆ MakeLTRB()

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

Returns constructed SkRect set to (l, t, r, b).

Does not sort input; SkRect may result in fLeft greater than fRight, or fTop greater than fBottom.

Parameters
lSkScalar stored in fLeft
tSkScalar stored in fTop
rSkScalar stored in fRight
bSkScalar stored in fBottom
Returns
bounds (l, t, r, b)

◆ makeOffset() [1/2]

constexpr SkRect SkRect::makeOffset ( SkScalar  dx,
SkScalar  dy 
) const
inline

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.

Parameters
dxadded to fLeft and fRight
dyadded to fTop and fBottom
Returns
SkRect offset on axes, with original width and height

◆ makeOffset() [2/2]

constexpr SkRect SkRect::makeOffset ( SkVector  v) const
inline

Returns SkRect offset by v.

Parameters
vadded to rect
Returns
SkRect offset on axes, with original width and height

◆ makeOutset()

SkRect SkRect::makeOutset ( SkScalar  dx,
SkScalar  dy 
) const
inline

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.

Parameters
dxsubtracted to fLeft and added from fRight
dysubtracted to fTop and added from fBottom
Returns
SkRect outset symmetrically left and right, top and bottom

◆ MakeSize()

static constexpr SkRect SK_WARN_UNUSED_RESULT SkRect::MakeSize ( const SkSize size)
inlinestatic

Returns constructed SkRect set to (0, 0, size.width(), size.height()).

Does not validate input; size.width() or size.height() may be negative.

Parameters
sizeSkScalar values for SkRect width and height
Returns
bounds (0, 0, size.width(), size.height())

◆ makeSorted()

SkRect SkRect::makeSorted ( ) const
inline

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.

Result may be empty; and width() and height() will be zero or positive.

Returns
sorted SkRect

◆ MakeWH()

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

Returns constructed SkRect 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 SkRect cannot represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.

Parameters
wSkScalar width of constructed SkRect
hSkScalar height of constructed SkRect
Returns
bounds (0, 0, w, h)

◆ MakeXYWH()

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

Returns constructed SkRect set to (x, y, x + w, y + h).

Does not validate input; w or h may be negative.

Parameters
xstored in fLeft
ystored in fTop
wadded to x and stored in fRight
hadded to y and stored in fBottom
Returns
bounds at (x, y) with width w and height h

◆ offset() [1/2]

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

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.

Parameters
dxoffset added to fLeft and fRight
dyoffset added to fTop and fBottom

◆ offset() [2/2]

void SkRect::offset ( const SkPoint delta)
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.

Parameters
deltaadded to SkRect

◆ offsetTo()

void SkRect::offsetTo ( SkScalar  newX,
SkScalar  newY 
)
inline

Offsets SkRect so that fLeft equals newX, and fTop equals newY.

width and height are unchanged.

Parameters
newXstored in fLeft, preserving width()
newYstored in fTop, preserving height()

◆ outset()

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

Outsets SkRect by (dx, dy).

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

Parameters
dxsubtracted to fLeft and added from fRight
dysubtracted to fTop and added from fBottom

◆ right()

SkScalar SkRect::right ( ) const
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.

Returns
fRight

◆ round() [1/2]

void SkRect::round ( SkIRect dst) const
inline

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

Parameters
dststorage for SkIRect

◆ round() [2/2]

SkIRect SkRect::round ( ) const
inline

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

Returns
rounded SkIRect

◆ roundIn()

void SkRect::roundIn ( SkIRect dst) const
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)).

Parameters
dststorage for SkIRect

◆ roundOut() [1/3]

void SkRect::roundOut ( SkIRect dst) const
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)).

Parameters
dststorage for SkIRect

◆ roundOut() [2/3]

void SkRect::roundOut ( SkRect dst) const
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)).

Parameters
dststorage for SkRect

◆ roundOut() [3/3]

SkIRect SkRect::roundOut ( ) const
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)).

Returns
rounded SkIRect

◆ set() [1/2]

void SkRect::set ( const SkIRect src)
inline

Sets SkRect to src, promoting src members from integer to scalar.

Very large values in src may lose precision.

Parameters
srcinteger SkRect

◆ set() [2/2]

void SkRect::set ( const SkPoint p0,
const SkPoint p1 
)
inline

Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1.

The result is sorted and may be empty. Does not check to see if values are finite.

Parameters
p0corner to include
p1corner to include

◆ setBounds()

void SkRect::setBounds ( const SkPoint  pts[],
int  count 
)
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.

Parameters
ptsSkPoint array
countentries in array

◆ setBoundsCheck()

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.

Parameters
ptsSkPoint array
countentries in array
Returns
true if all SkPoint values are finite

example: https://fiddle.skia.org/c/@Rect_setBoundsCheck

◆ setBoundsNoCheck()

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

Sets to bounds of SkPoint pts array with count entries.

If any SkPoint in pts contains infinity or NaN, all SkRect dimensions are set to NaN.

Parameters
ptsSkPoint array
countentries in array

example: https://fiddle.skia.org/c/@Rect_setBoundsNoCheck

◆ setEmpty()

void SkRect::setEmpty ( )
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.

◆ setIWH()

void SkRect::setIWH ( int32_t  width,
int32_t  height 
)
inline

◆ setLTRB()

void SkRect::setLTRB ( SkScalar  left,
SkScalar  top,
SkScalar  right,
SkScalar  bottom 
)
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.

Parameters
leftstored in fLeft
topstored in fTop
rightstored in fRight
bottomstored in fBottom

◆ setWH()

void SkRect::setWH ( SkScalar  width,
SkScalar  height 
)
inline

Sets SkRect to (0, 0, width, height).

Does not validate input; width or height may be negative.

Parameters
widthstored in fRight
heightstored in fBottom

◆ setXYWH()

void SkRect::setXYWH ( SkScalar  x,
SkScalar  y,
SkScalar  width,
SkScalar  height 
)
inline

Sets SkRect to (x, y, x + width, y + height).

Does not validate input; width or height may be negative.

Parameters
xstored in fLeft
ystored in fTop
widthadded to x and stored in fRight
heightadded to y and stored in fBottom

◆ sort()

void SkRect::sort ( )
inline

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.

◆ top()

SkScalar SkRect::top ( ) const
inline

Returns top edge of SkRect, if sorted.

Call isEmpty() to see if SkRect may be invalid, and sort() to reverse fTop and fBottom if needed.

Returns
fTop

◆ toQuad()

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

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

TODO: Consider adding parameter to control whether quad is clockwise or counterclockwise.

Parameters
quadstorage for corners of SkRect

example: https://fiddle.skia.org/c/@Rect_toQuad

◆ width()

SkScalar SkRect::width ( ) const
inline

Returns span on the x-axis.

This does not check if SkRect is sorted, or if result fits in 32-bit float; result may be negative or infinity.

Returns
fRight minus fLeft

◆ x()

SkScalar SkRect::x ( ) const
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.

Returns
fLeft

◆ y()

SkScalar SkRect::y ( ) const
inline

Returns top edge of SkRect, if sorted.

Call isEmpty() to see if SkRect may be invalid, and sort() to reverse fTop and fBottom if needed.

Returns
fTop

Friends And Related Function Documentation

◆ operator!=

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

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.

Parameters
aSkRect to compare
bSkRect to compare
Returns
true if members are not equal

◆ operator==

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

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.

Parameters
aSkRect to compare
bSkRect to compare
Returns
true if members are equal

Member Data Documentation

◆ fBottom

SkScalar SkRect::fBottom

larger y-axis bounds

◆ fLeft

SkScalar SkRect::fLeft

smaller x-axis bounds

◆ fRight

SkScalar SkRect::fRight

larger x-axis bounds

◆ fTop

SkScalar SkRect::fTop

smaller y-axis bounds


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