Skia
2D Graphics Library
SkRect Struct Reference

SkRect holds four float 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. More...
 
constexpr float x () const
 Returns left edge of SkRect, if sorted. More...
 
constexpr float y () const
 Returns top edge of SkRect, if sorted. More...
 
constexpr float left () const
 Returns left edge of SkRect, if sorted. More...
 
constexpr float top () const
 Returns top edge of SkRect, if sorted. More...
 
constexpr float right () const
 Returns right edge of SkRect, if sorted. More...
 
constexpr float bottom () const
 Returns bottom edge of SkRect, if sorted. More...
 
constexpr float width () const
 Returns span on the x-axis. More...
 
constexpr float height () const
 Returns span on the y-axis. More...
 
constexpr float centerX () const
 Returns average of left edge and right edge. More...
 
constexpr float centerY () const
 Returns average of top edge and bottom edge. More...
 
constexpr SkPoint center () const
 Returns the point this->centerX(), this->centerY(). 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 float. More...
 
void setLTRB (float left, float top, float right, float 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 (float x, float y, float width, float height)
 Sets SkRect to (x, y, x + width, y + height). More...
 
void setWH (float width, float height)
 Sets SkRect to (0, 0, width, height). More...
 
void setIWH (int32_t width, int32_t height)
 
constexpr SkRect makeOffset (float dx, float dy) const
 Returns SkRect offset by (dx, dy). More...
 
constexpr SkRect makeOffset (SkVector v) const
 Returns SkRect offset by v. More...
 
SkRect makeInset (float dx, float dy) const
 Returns SkRect, inset by (dx, dy). More...
 
SkRect makeOutset (float dx, float dy) const
 Returns SkRect, outset by (dx, dy). More...
 
void offset (float dx, float 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 (float newX, float newY)
 Offsets SkRect so that fLeft equals newX, and fTop equals newY. More...
 
void inset (float dx, float dy)
 Insets SkRect by (dx, dy). More...
 
void outset (float dx, float 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 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 (float x, float 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 (sk_float_round2int(fLeft), sk_float_round2int(fTop), sk_float_round2int(fRight), sk_float_round2int(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 (sk_float_floor2int(fLeft), sk_float_floor2int(fTop), sk_float_ceil2int(fRight), sk_float_ceil2int(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 (sk_float_floor(fLeft), sk_float_floor(fTop), sk_float_ceil(fRight), sk_float_ceil(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 (sk_float_ceil2int(fLeft), sk_float_ceil2int(fTop), sk_float_floor2int(fRight), sk_float_floor2int(fBottom)). More...
 
SkIRect round () const
 Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (sk_float_round2int(fLeft), sk_float_round2int(fTop), sk_float_round2int(fRight), sk_float_round2int(fBottom)). More...
 
SkIRect roundOut () const
 Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (sk_float_floor2int(fLeft), sk_float_floor2int(fTop), sk_float_ceil2int(fRight), sk_float_ceil2int(fBottom)). More...
 
SkIRect roundIn () const
 Sets SkIRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (sk_float_ceil2int(fLeft), sk_float_ceil2int(fTop), sk_float_floor2int(fRight), sk_float_floor2int(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 float * asScalars () const
 Returns pointer to first float 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 MakeEmpty ()
 Returns constructed SkRect set to (0, 0, 0, 0). More...
 
static constexpr SkRect MakeWH (float w, float h)
 Returns constructed SkRect set to float values (0, 0, w, h). More...
 
static SkRect MakeIWH (int w, int h)
 Returns constructed SkRect set to integer values (0, 0, w, h). More...
 
static constexpr SkRect MakeSize (const SkSize &size)
 Returns constructed SkRect set to (0, 0, size.width(), size.height()). More...
 
static constexpr SkRect MakeLTRB (float l, float t, float r, float b)
 Returns constructed SkRect set to (l, t, r, b). More...
 
static constexpr SkRect MakeXYWH (float x, float y, float w, float 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 Make (const SkIRect &irect)
 Returns constructed SkIRect set to irect, promoting integers to float. More...
 
static bool Intersects (const SkRect &a, const SkRect &b)
 Returns true if a intersects b. More...
 

Public Attributes

float fLeft = 0
 smaller x-axis bounds More...
 
float fTop = 0
 smaller y-axis bounds More...
 
float fRight = 0
 larger x-axis bounds More...
 
float fBottom = 0
 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 float 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 float* SkRect::asScalars ( ) const
inline

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

Returns
pointer to fLeft

◆ bottom()

constexpr float SkRect::bottom ( ) const
inlineconstexpr

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

◆ center()

constexpr SkPoint SkRect::center ( ) const
inlineconstexpr

Returns the point this->centerX(), this->centerY().

Returns
rectangle center

◆ centerX()

constexpr float SkRect::centerX ( ) const
inlineconstexpr

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

constexpr float SkRect::centerY ( ) const
inlineconstexpr

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

◆ 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 ( float  x,
float  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

◆ dump() [1/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.

◆ dump() [2/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

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

constexpr float SkRect::height ( ) const
inlineconstexpr

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 ( float  dx,
float  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 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

◆ intersect() [2/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

◆ 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

◆ 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

◆ 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.

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

constexpr float SkRect::left ( ) const
inlineconstexpr

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 SkIRect irect)
inlinestatic

Returns constructed SkIRect set to irect, promoting integers to float.

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 float

◆ Make() [2/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())

◆ MakeEmpty()

static constexpr SkRect SkRect::MakeEmpty ( )
inlinestaticconstexpr

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 ( float  dx,
float  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 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 SkRect::MakeLTRB ( float  l,
float  t,
float  r,
float  b 
)
inlinestaticconstexpr

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
lfloat stored in fLeft
tfloat stored in fTop
rfloat stored in fRight
bfloat stored in fBottom
Returns
bounds (l, t, r, b)

◆ makeOffset() [1/2]

constexpr SkRect SkRect::makeOffset ( float  dx,
float  dy 
) const
inlineconstexpr

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
inlineconstexpr

Returns SkRect offset by v.

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

◆ makeOutset()

SkRect SkRect::makeOutset ( float  dx,
float  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 SkRect::MakeSize ( const SkSize size)
inlinestaticconstexpr

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

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

Parameters
sizefloat 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 SkRect::MakeWH ( float  w,
float  h 
)
inlinestaticconstexpr

Returns constructed SkRect set to float 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
wfloat width of constructed SkRect
hfloat height of constructed SkRect
Returns
bounds (0, 0, w, h)

◆ MakeXYWH()

static constexpr SkRect SkRect::MakeXYWH ( float  x,
float  y,
float  w,
float  h 
)
inlinestaticconstexpr

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

◆ offset() [2/2]

void SkRect::offset ( float  dx,
float  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

◆ offsetTo()

void SkRect::offsetTo ( float  newX,
float  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 ( float  dx,
float  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()

constexpr float SkRect::right ( ) const
inlineconstexpr

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]

SkIRect SkRect::round ( ) const
inline

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

Returns
rounded SkIRect

◆ round() [2/2]

void SkRect::round ( SkIRect dst) const
inline

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

Parameters
dststorage for SkIRect

◆ roundIn() [1/2]

SkIRect SkRect::roundIn ( ) const
inline

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

Returns
rounded SkIRect

◆ roundIn() [2/2]

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 (sk_float_ceil2int(fLeft), sk_float_ceil2int(fTop), sk_float_floor2int(fRight), sk_float_floor2int(fBottom)).

Parameters
dststorage for SkIRect

◆ roundOut() [1/3]

SkIRect SkRect::roundOut ( ) const
inline

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

Returns
rounded SkIRect

◆ roundOut() [2/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 (sk_float_floor2int(fLeft), sk_float_floor2int(fTop), sk_float_ceil2int(fRight), sk_float_ceil2int(fBottom)).

Parameters
dststorage for SkIRect

◆ roundOut() [3/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 (sk_float_floor(fLeft), sk_float_floor(fTop), sk_float_ceil(fRight), sk_float_ceil(fBottom)).

Parameters
dststorage for SkRect

◆ set() [1/2]

void SkRect::set ( const SkIRect src)
inline

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

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 ( float  left,
float  top,
float  right,
float  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 ( float  width,
float  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 ( float  x,
float  y,
float  width,
float  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()

constexpr float SkRect::top ( ) const
inlineconstexpr

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

constexpr float SkRect::width ( ) const
inlineconstexpr

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

constexpr float SkRect::x ( ) const
inlineconstexpr

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

constexpr float SkRect::y ( ) const
inlineconstexpr

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

float SkRect::fBottom = 0

larger y-axis bounds

◆ fLeft

float SkRect::fLeft = 0

smaller x-axis bounds

◆ fRight

float SkRect::fRight = 0

larger x-axis bounds

◆ fTop

float SkRect::fTop = 0

smaller y-axis bounds


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