Skia
2D Graphics Library
SkIRect Struct Reference

SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle. More...

#include <SkRect.h>

Public Member Functions

int32_t left () const
 Returns left edge of SkIRect, if sorted. More...
 
int32_t top () const
 Returns top edge of SkIRect, if sorted. More...
 
int32_t right () const
 Returns right edge of SkIRect, if sorted. More...
 
int32_t bottom () const
 Returns bottom edge of SkIRect, if sorted. More...
 
int32_t x () const
 Returns left edge of SkIRect, if sorted. More...
 
int32_t y () const
 Returns top edge of SkIRect, if sorted. More...
 
SkIPoint topLeft () const
 
int32_t width () const
 Returns span on the x-axis. More...
 
int32_t height () const
 Returns span on the y-axis. More...
 
SkISize size () const
 Returns spans on the x-axis and y-axis. More...
 
int64_t width64 () const
 Returns span on the x-axis. More...
 
int64_t height64 () const
 Returns span on the y-axis. More...
 
bool isEmpty64 () const
 Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom. More...
 
bool isEmpty () const
 Returns true if width() or height() are zero or negative. More...
 
void setEmpty ()
 Sets SkIRect to (0, 0, 0, 0). More...
 
void setLTRB (int32_t left, int32_t top, int32_t right, int32_t bottom)
 Sets SkIRect to (left, top, right, bottom). More...
 
void setXYWH (int32_t x, int32_t y, int32_t width, int32_t height)
 Sets SkIRect to: (x, y, x + width, y + height). More...
 
void setWH (int32_t width, int32_t height)
 
constexpr SkIRect makeOffset (int32_t dx, int32_t dy) const
 Returns SkIRect offset by (dx, dy). More...
 
constexpr SkIRect makeOffset (SkIVector offset) const
 Returns SkIRect offset by (offset.x(), offset.y()). More...
 
SkIRect makeInset (int32_t dx, int32_t dy) const
 Returns SkIRect, inset by (dx, dy). More...
 
SkIRect makeOutset (int32_t dx, int32_t dy) const
 Returns SkIRect, outset by (dx, dy). More...
 
void offset (int32_t dx, int32_t dy)
 Offsets SkIRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. More...
 
void offset (const SkIPoint &delta)
 Offsets SkIRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom. More...
 
void offsetTo (int32_t newX, int32_t newY)
 Offsets SkIRect so that fLeft equals newX, and fTop equals newY. More...
 
void inset (int32_t dx, int32_t dy)
 Insets SkIRect by (dx,dy). More...
 
void outset (int32_t dx, int32_t dy)
 Outsets SkIRect by (dx, dy). More...
 
void adjust (int32_t dL, int32_t dT, int32_t dR, int32_t dB)
 Adjusts SkIRect by adding dL to fLeft, dT to fTop, dR to fRight, and dB to fBottom. More...
 
bool contains (int32_t x, int32_t y) const
 Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. More...
 
bool contains (const SkIRect &r) const
 Returns true if SkIRect contains r. More...
 
bool contains (const SkRect &r) const
 Returns true if SkIRect contains r. More...
 
bool containsNoEmptyCheck (const SkIRect &r) const
 Returns true if SkIRect contains construction. More...
 
bool intersect (const SkIRect &r)
 Returns true if SkIRect intersects r, and sets SkIRect to intersection. More...
 
bool SK_WARN_UNUSED_RESULT intersect (const SkIRect &a, const SkIRect &b)
 Returns true if a intersects b, and sets SkIRect to intersection. More...
 
void join (const SkIRect &r)
 Sets SkIRect to the union of itself and r. 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...
 
SkIRect makeSorted () const
 Returns SkIRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom. More...
 

Static Public Member Functions

static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty ()
 Returns constructed SkIRect set to (0, 0, 0, 0). More...
 
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH (int32_t w, int32_t h)
 Returns constructed SkIRect set to (0, 0, w, h). More...
 
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize (const SkISize &size)
 Returns constructed SkIRect set to (0, 0, size.width(), size.height()). More...
 
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB (int32_t l, int32_t t, int32_t r, int32_t b)
 Returns constructed SkIRect set to (l, t, r, b). More...
 
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH (int32_t x, int32_t y, int32_t w, int32_t h)
 Returns constructed SkIRect set to: (x, y, x + w, y + h). More...
 
static bool Intersects (const SkIRect &a, const SkIRect &b)
 Returns true if a intersects b. More...
 

Public Attributes

int32_t fLeft
 smaller x-axis bounds More...
 
int32_t fTop
 smaller y-axis bounds More...
 
int32_t fRight
 larger x-axis bounds More...
 
int32_t fBottom
 larger y-axis bounds More...
 

Friends

bool operator== (const SkIRect &a, const SkIRect &b)
 Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are identical to corresponding members in b. More...
 
bool operator!= (const SkIRect &a, const SkIRect &b)
 Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not identical to the corresponding member in b. More...
 

Detailed Description

SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.

SkIRect may be created from outer bounds or from position, width, and height. SkIRect 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

◆ adjust()

void SkIRect::adjust ( int32_t  dL,
int32_t  dT,
int32_t  dR,
int32_t  dB 
)
inline

Adjusts SkIRect by adding dL to fLeft, dT to fTop, dR to fRight, and dB to fBottom.

If dL is positive, narrows SkIRect on the left. If negative, widens it on the left. If dT is positive, shrinks SkIRect on the top. If negative, lengthens it on the top. If dR is positive, narrows SkIRect on the right. If negative, widens it on the right. If dB is positive, shrinks SkIRect on the bottom. If negative, lengthens it on the bottom.

The resulting SkIRect is not checked for validity. Thus, if the resulting SkIRect left is greater than right, the SkIRect will be considered empty. Call sort() after this call if that is not the desired behavior.

Parameters
dLoffset added to fLeft
dToffset added to fTop
dRoffset added to fRight
dBoffset added to fBottom

◆ bottom()

int32_t SkIRect::bottom ( ) const
inline

Returns bottom edge of SkIRect, if sorted.

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

Returns
fBottom

◆ contains() [1/3]

bool SkIRect::contains ( int32_t  x,
int32_t  y 
) const
inline

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

Returns false if SkIRect is empty.

Considers input to describe constructed SkIRect: (x, y, x + 1, y + 1) and returns true if constructed area is completely enclosed by SkIRect area.

Parameters
xtest SkIPoint x-coordinate
ytest SkIPoint y-coordinate
Returns
true if (x, y) is inside SkIRect

◆ contains() [2/3]

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

Returns true if SkIRect contains r.

Returns false if SkIRect is empty or r is empty.

SkIRect contains r when SkIRect area completely includes r area.

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

◆ contains() [3/3]

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

Returns true if SkIRect contains r.

Returns false if SkIRect is empty or r is empty.

SkIRect contains r when SkIRect area completely includes r area.

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

◆ containsNoEmptyCheck()

bool SkIRect::containsNoEmptyCheck ( const SkIRect r) const
inline

Returns true if SkIRect contains construction.

Asserts if SkIRect is empty or construction is empty, and if SK_DEBUG is defined.

Return is undefined if SkIRect is empty or construction is empty.

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

◆ height()

int32_t SkIRect::height ( ) const
inline

Returns span on the y-axis.

This does not check if SkIRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Returns
fBottom minus fTop

◆ height64()

int64_t SkIRect::height64 ( ) const
inline

Returns span on the y-axis.

This does not check if SkIRect is sorted, so the result may be negative. This is safer than calling height() since height() might overflow in its calculation.

Returns
fBottom minus fTop cast to int64_t

◆ inset()

void SkIRect::inset ( int32_t  dx,
int32_t  dy 
)
inline

Insets SkIRect by (dx,dy).

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

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

◆ intersect() [1/2]

bool SkIRect::intersect ( const SkIRect r)
inline

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

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

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

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

◆ intersect() [2/2]

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

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

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

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

Parameters
aSkIRect to intersect
bSkIRect to intersect
Returns
true if a and b have area in common

◆ Intersects()

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

Returns true if a intersects b.

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

Parameters
aSkIRect to intersect
bSkIRect to intersect
Returns
true if a and b have area in common

◆ isEmpty()

bool SkIRect::isEmpty ( ) const
inline

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

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

◆ isEmpty64()

bool SkIRect::isEmpty64 ( ) 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 width64() or height64().

Returns
true if width64() or height64() are zero or negative

◆ join()

void SkIRect::join ( const SkIRect r)

Sets SkIRect to the union of itself and r.

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

Parameters
rexpansion SkIRect

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

◆ left()

int32_t SkIRect::left ( ) const
inline

Returns left edge of SkIRect, if sorted.

Call sort() to reverse fLeft and fRight if needed.

Returns
fLeft

◆ MakeEmpty()

static constexpr SkIRect SK_WARN_UNUSED_RESULT SkIRect::MakeEmpty ( )
inlinestatic

Returns constructed SkIRect 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()

SkIRect SkIRect::makeInset ( int32_t  dx,
int32_t  dy 
) const
inline

Returns SkIRect, inset by (dx, dy).

If dx is negative, SkIRect returned is wider. If dx is positive, SkIRect returned is narrower. If dy is negative, SkIRect returned is taller. If dy is positive, SkIRect returned is shorter.

Parameters
dxoffset added to fLeft and subtracted from fRight
dyoffset added to fTop and subtracted from fBottom
Returns
SkIRect inset symmetrically left and right, top and bottom

◆ MakeLTRB()

static constexpr SkIRect SK_WARN_UNUSED_RESULT SkIRect::MakeLTRB ( int32_t  l,
int32_t  t,
int32_t  r,
int32_t  b 
)
inlinestatic

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

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

Parameters
linteger stored in fLeft
tinteger stored in fTop
rinteger stored in fRight
binteger stored in fBottom
Returns
bounds (l, t, r, b)

◆ makeOffset() [1/2]

constexpr SkIRect SkIRect::makeOffset ( int32_t  dx,
int32_t  dy 
) const
inline

Returns SkIRect offset by (dx, dy).

If dx is negative, SkIRect returned is moved to the left. If dx is positive, SkIRect returned is moved to the right. If dy is negative, SkIRect returned is moved upward. If dy is positive, SkIRect returned is moved downward.

Parameters
dxoffset added to fLeft and fRight
dyoffset added to fTop and fBottom
Returns
SkIRect offset by dx and dy, with original width and height

◆ makeOffset() [2/2]

constexpr SkIRect SkIRect::makeOffset ( SkIVector  offset) const
inline

Returns SkIRect offset by (offset.x(), offset.y()).

If offset.x() is negative, SkIRect returned is moved to the left. If offset.x() is positive, SkIRect returned is moved to the right. If offset.y() is negative, SkIRect returned is moved upward. If offset.y() is positive, SkIRect returned is moved downward.

Parameters
offsettranslation vector
Returns
SkIRect translated by offset, with original width and height

◆ makeOutset()

SkIRect SkIRect::makeOutset ( int32_t  dx,
int32_t  dy 
) const
inline

Returns SkIRect, outset by (dx, dy).

If dx is negative, SkIRect returned is narrower. If dx is positive, SkIRect returned is wider. If dy is negative, SkIRect returned is shorter. If dy is positive, SkIRect returned is taller.

Parameters
dxoffset subtracted to fLeft and added from fRight
dyoffset subtracted to fTop and added from fBottom
Returns
SkIRect outset symmetrically left and right, top and bottom

◆ MakeSize()

static constexpr SkIRect SK_WARN_UNUSED_RESULT SkIRect::MakeSize ( 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
sizevalues for SkIRect width and height
Returns
bounds (0, 0, size.width(), size.height())

◆ makeSorted()

SkIRect SkIRect::makeSorted ( ) const
inline

Returns SkIRect 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 SkIRect

◆ MakeWH()

static constexpr SkIRect SK_WARN_UNUSED_RESULT SkIRect::MakeWH ( int32_t  w,
int32_t  h 
)
inlinestatic

Returns constructed SkIRect set to (0, 0, w, h).

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

Parameters
wwidth of constructed SkIRect
hheight of constructed SkIRect
Returns
bounds (0, 0, w, h)

◆ MakeXYWH()

static constexpr SkIRect SK_WARN_UNUSED_RESULT SkIRect::MakeXYWH ( int32_t  x,
int32_t  y,
int32_t  w,
int32_t  h 
)
inlinestatic

Returns constructed SkIRect 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 SkIRect::offset ( int32_t  dx,
int32_t  dy 
)
inline

Offsets SkIRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.

If dx is negative, moves SkIRect returned to the left. If dx is positive, moves SkIRect returned to the right. If dy is negative, moves SkIRect returned upward. If dy is positive, moves SkIRect returned downward.

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

◆ offset() [2/2]

void SkIRect::offset ( const SkIPoint delta)
inline

Offsets SkIRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.

If delta.fX is negative, moves SkIRect returned to the left. If delta.fX is positive, moves SkIRect returned to the right. If delta.fY is negative, moves SkIRect returned upward. If delta.fY is positive, moves SkIRect returned downward.

Parameters
deltaoffset added to SkIRect

◆ offsetTo()

void SkIRect::offsetTo ( int32_t  newX,
int32_t  newY 
)
inline

Offsets SkIRect 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 SkIRect::outset ( int32_t  dx,
int32_t  dy 
)
inline

Outsets SkIRect by (dx, dy).

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

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

◆ right()

int32_t SkIRect::right ( ) const
inline

Returns right edge of SkIRect, if sorted.

Call sort() to reverse fLeft and fRight if needed.

Returns
fRight

◆ setEmpty()

void SkIRect::setEmpty ( )
inline

Sets SkIRect 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.

◆ setLTRB()

void SkIRect::setLTRB ( int32_t  left,
int32_t  top,
int32_t  right,
int32_t  bottom 
)
inline

Sets SkIRect 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 SkIRect::setWH ( int32_t  width,
int32_t  height 
)
inline

◆ setXYWH()

void SkIRect::setXYWH ( int32_t  x,
int32_t  y,
int32_t  width,
int32_t  height 
)
inline

Sets SkIRect 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

◆ size()

SkISize SkIRect::size ( ) const
inline

Returns spans on the x-axis and y-axis.

This does not check if SkIRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Returns
SkISize (width, height)

◆ sort()

void SkIRect::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()

int32_t SkIRect::top ( ) const
inline

Returns top edge of SkIRect, if sorted.

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

Returns
fTop

◆ topLeft()

SkIPoint SkIRect::topLeft ( ) const
inline

◆ width()

int32_t SkIRect::width ( ) const
inline

Returns span on the x-axis.

This does not check if SkIRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Returns
fRight minus fLeft

◆ width64()

int64_t SkIRect::width64 ( ) const
inline

Returns span on the x-axis.

This does not check if SkIRect is sorted, so the result may be negative. This is safer than calling width() since width() might overflow in its calculation.

Returns
fRight minus fLeft cast to int64_t

◆ x()

int32_t SkIRect::x ( ) const
inline

Returns left edge of SkIRect, if sorted.

Call isEmpty() to see if SkIRect may be invalid, and sort() to reverse fLeft and fRight if needed.

Returns
fLeft

◆ y()

int32_t SkIRect::y ( ) const
inline

Returns top edge of SkIRect, if sorted.

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

Returns
fTop

Friends And Related Function Documentation

◆ operator!=

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

Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not identical to the corresponding member in b.

Parameters
aSkIRect to compare
bSkIRect to compare
Returns
true if members are not equal

◆ operator==

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

Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are identical to corresponding members in b.

Parameters
aSkIRect to compare
bSkIRect to compare
Returns
true if members are equal

Member Data Documentation

◆ fBottom

int32_t SkIRect::fBottom

larger y-axis bounds

◆ fLeft

int32_t SkIRect::fLeft

smaller x-axis bounds

◆ fRight

int32_t SkIRect::fRight

larger x-axis bounds

◆ fTop

int32_t SkIRect::fTop

smaller y-axis bounds


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