skia2/site/user/api/SkIRect_Reference.md
Cary Clark 08895c4814 auto table generation
Replace manually entered summary tables with ones that are populated
and sorted by bookmaker. This introduces a slight regression for
anonymous enums but fixes a lot of bugs and omissions.

The format is

#Topic somethingTopical
#Populate
##

where somethingTopical is one of Subtopics, Constructors, Constants,
Classes_and_Structs, Members, Member_Functions, and Related_Functions.

Fix the bad formatting in SkCanvas reference. The #Error tag was
was corrupting the markdown table. Remove the tag and replace it
with #NoExample.

Next up: revise self-check to know about populated topics.

TBR=caryclark@google.com
Docs-Preview: https://skia.org/?cl=102080
Bug: skia:6898
Change-Id: Idef5d1c14c740c18a81d6a5106182788dd2a09e1
Reviewed-on: https://skia-review.googlesource.com/102080
Commit-Queue: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-02-01 15:09:17 +00:00

76 KiB

SkIRect Reference

IRect

Overview

Subtopics

name description
Constructors functions that construct SkIRect
Member Functions static functions and member methods
Members member values
Operators operator overloading methods
Related Functions similar methods grouped together

Struct SkIRect

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.

name description
Inset Outset Offset moves sides
Intersection set to shared bounds
Join set to union of bounds
Properties side values, center, validity
Rounding adjust to integer bounds
Set replaces all values
Sorting orders sides

Member Functions

name description
EmptyIRect returns immutable bounds of (0, 0, 0, 0)
Intersects returns true if areas overlap
IntersectsNoEmptyCheck returns true if areas overlap skips empty check
MakeEmpty returns bounds of (0, 0, 0, 0)
MakeLTRB constructs from int left, top, right, bottom
MakeLargest deprecated
MakeSize constructs from ISize returning (0, 0, width, height)
MakeWH constructs from int input returning (0, 0, width, height)
MakeXYWH constructs from int input returning (x, y, width, height)
bottom returns larger bounds in y, if sorted
centerX returns midpoint in x
centerY returns midpoint in y
contains returns true if points are equal or inside
containsNoEmptyCheck returns true if points are equal or inside skips empty check
height returns span in y
height64 returns span in y as int64_t
inset moves the sides symmetrically about the center
intersect sets to shared area; returns true if not empty
intersectNoEmptyCheck sets to shared area; returns true if not empty skips empty check
is16Bit returns true if members fit in 16-bit word
isEmpty returns true if width or height are zero or negative or they exceed int32_t
isEmpty64 returns true if width or height are zero or negative
join sets to union of bounds
left returns smaller bounds in x, if sorted
makeInset constructs from sides moved symmetrically about the center
makeOffset constructs from translated sides
makeOutset constructs from sides moved symmetrically about the center
makeSorted constructs, ordering sides from smaller to larger
offset translates sides without changing width and height
offsetTo translates to (x, y) without changing width and height
outset moves the sides symmetrically about the center
quickReject returns true if rectangles do not intersect
right returns larger bounds in x, if sorted
set sets to (left, top, right, bottom)
setEmpty sets to (0, 0, 0, 0)
setLTRB sets to SkScalar input (left, top, right, bottom)
setXYWH sets to (x, y, width, height)
size returns ISize (width, height)
sort orders sides from smaller to larger
top returns smaller bounds in y, if sorted
width returns span in x
width64 returns span in y as int64_t
x returns bounds left
y returns bounds top

Members

name description
fBottom larger y-axis bounds
fLeft smaller x-axis bounds
fRight larger x-axis bounds
fTop smaller y-axis bounds

int32_t fLeft

May contain any value. The smaller of the horizontal values when sorted. When equal to or greater than fRight, IRect is empty.

int32_t fTop

May contain any value. The smaller of the horizontal values when sorted. When equal to or greater than fBottom, IRect is empty.

int32_t fRight

May contain any value. The larger of the vertical values when sorted. When equal to or less than fLeft, IRect is empty.

int32_t fBottom

May contain any value. The larger of the vertical values when sorted. When equal to or less than fTop, IRect is empty.

Constructors

name description
MakeEmpty returns bounds of (0, 0, 0, 0)
MakeLTRB constructs from int left, top, right, bottom
MakeLargest deprecated
MakeSize constructs from ISize returning (0, 0, width, height)
MakeWH constructs from int input returning (0, 0, width, height)
MakeXYWH constructs from int input returning (x, y, width, height)
makeInset constructs from sides moved symmetrically about the center
makeOffset constructs from translated sides
makeOutset constructs from sides moved symmetrically about the center
makeSorted constructs, ordering sides from smaller to larger

MakeEmpty

static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty()

Returns constructed IRect 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.

Return Value

bounds (0, 0, 0, 0)

Example

Example Output

MakeEmpty isEmpty: true
offset rect isEmpty: true
inset rect isEmpty: true
outset rect isEmpty: false

See Also

EmptyIRect isEmpty setEmpty SkRect::MakeEmpty


MakeWH

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

Returns constructed IRect set to (0, 0, w, h). Does not validate input; w or h may be negative.

Parameters

w width of constructed IRect
h height of constructed IRect

Return Value

bounds (0, 0, w, h)

Example

Example Output

all equal

See Also

MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH


MakeSize

static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size)

Returns constructed IRect set to (0, 0, size.width, size.height). Does not validate input; size.width or size.height may be negative.

Parameters

size values for IRect width and height

Return Value

bounds (0, 0, size.width, size.height)

Example

Example Output

round width: 26  height: 36
floor width: 25  height: 35

See Also

MakeWH MakeXYWH SkRect::Make[2] SkRect::MakeIWH


MakeLTRB

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

Returns constructed IRect set to (l, t, r, b). Does not sort input; IRect may result in fLeft greater than fRight, or fTop greater than fBottom.

Parameters

l integer stored in fLeft
t integer stored in fTop
r integer stored in fRight
b integer stored in fBottom

Return Value

bounds (l, t, r, b)

Example

Example Output

rect: 5, 35, 15, 25  isEmpty: true
rect: 5, 25, 15, 35  isEmpty: false

See Also

MakeXYWH SkRect::MakeLTRB


MakeXYWH

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

Returns constructed IRect set to: (x, y, x + w, y + h). Does not validate input; w or h may be negative.

Parameters

x stored in fLeft
y stored in fTop
w added to x and stored in fRight
h added to y and stored in fBottom

Return Value

bounds at (x, y) with width w and height h

Example

Example Output

rect: 5, 35, -10, 60  isEmpty: true
rect: -10, 35, 5, 60  isEmpty: false

See Also

MakeLTRB SkRect::MakeXYWH


left

int32_t left() const

Returns left edge of IRect, if sorted. Call sort to reverse fLeft and fRight if needed.

Return Value

fLeft

Example

Example Output

unsorted.fLeft: 15 unsorted.left(): 15
sorted.fLeft: 10 sorted.left(): 10

See Also

fLeft x SkRect::left()


top

int32_t top() const

Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, and sort to reverse fTop and fBottom if needed.

Return Value

fTop

Example

Example Output

unsorted.fTop: 25 unsorted.top(): 25
sorted.fTop: 5 sorted.top(): 5

See Also

fTop y SkRect::top()


right

int32_t right() const

Returns right edge of IRect, if sorted. Call sort to reverse fLeft and fRight if needed.

Return Value

fRight

Example

Example Output

unsorted.fRight: 10 unsorted.right(): 10
sorted.fRight: 15 sorted.right(): 15

See Also

fRight SkRect::right()


bottom

int32_t bottom() const

Returns bottom edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, and sort to reverse fTop and fBottom if needed.

Return Value

fBottom

Example

Example Output

unsorted.fBottom: 5 unsorted.bottom(): 5
sorted.fBottom: 25 sorted.bottom(): 25

See Also

fBottom SkRect::bottom()


x

int32_t x() const

Returns left edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, and sort to reverse fLeft and fRight if needed.

Return Value

fLeft

Example

Example Output

unsorted.fLeft: 15 unsorted.x(): 15
sorted.fLeft: 10 sorted.x(): 10

See Also

fLeft left y SkRect::x()


y

int32_t y() const

Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, and sort to reverse fTop and fBottom if needed.

Return Value

fTop

Example

Example Output

unsorted.fTop: 25 unsorted.y(): 25
sorted.fTop: 5 sorted.y(): 5

See Also

fTop top x SkRect::y()


width

int32_t width() const

Returns span on the x-axis. This does not check if IRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Return Value

fRight minus fLeft

Example

Example Output

unsorted width: -5
large width: -5

See Also

height width64 height64 SkRect::width()


width64

int64_t width64() const

Returns span on the x-axis. This does not check if IRect is sorted, so the result may be negative. This is safer than calling width since width might overflow in its calculation.

Return Value

fRight minus fLeft cast to int64_t

SkIRect large = { -2147483647, 1, 2147483644, 2 };

Example Output

width: -5 width64: 4294967291

See Also

width height height64 SkRect::width()


height

int32_t height() const

Returns span on the y-axis. This does not check if IRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Return Value

fBottom minus fTop

Example

Example Output

unsorted height: -5
large height: -5

See Also

width SkRect::height()


height64

int64_t height64() const

Returns span on the y-axis. This does not check if IRect is sorted, so the result may be negative. This is safer than calling height since height might overflow in its calculation.

Return Value

fBottom minus fTop cast to int64_t

SkIRect large = { 1, -2147483647, 2, 2147483644 };

Example Output

height: -5 height64: 4294967291

See Also

width height width64 SkRect::height()


size

SkISize size() const

Returns spans on the x-axis and y-axis. This does not check if IRect is sorted, or if result fits in 32-bit signed integer; result may be negative.

Return Value

ISize (width, height)

Example

Example Output

original rect: 20, 30, 40, 50  size: 20, 20
offset rect: 40, 50, 60, 70  size: 20, 20
outset rect: 20, 30, 80, 90  size: 60, 60

See Also

height width MakeSize


centerX

int32_t centerX() const

Returns average of left edge and right edge. Result does not change if IRect is sorted. Result may be incorrect if IRect is far from the origin.

Result is rounded down.

Return Value

midpoint in x

Example

Dividing by two rounds towards zero. centerX uses a bit shift and rounds down.

Example Output

left:  20 right:  41 centerX:  30 div2:  30
left: -20 right: -41 centerX: -31 div2: -30
left: -10 right:  11 centerX:   0 div2:   0

See Also

centerY SkRect::centerX


centerY

int32_t centerY() const

Returns average of top edge and bottom edge. Result does not change if IRect is sorted. Result may be incorrect if IRect is far from the origin.

Result is rounded down.

Return Value

midpoint in y

Example

Example Output

left: 1073741824 right: 1073741826 centerX: -1073741823 safe mid x: 1073741825

See Also

centerX SkRect::centerY


isEmpty

bool isEmpty() const

Returns true if width or height .

Return Value

true if width or height are zero or negative

Example

Example Output

rect: {20, 40, 10, 50} is empty
sorted: {10, 40, 20, 50} is not empty
rect: {20, 40, 20, 50} is empty
sorted: {20, 40, 20, 50} is empty

See Also

EmptyIRect MakeEmpty sort SkRect::isEmpty


isEmpty64

bool isEmpty64() const

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.

Return Value

true if width64 or height64 are zero or negative

SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; for (auto rect : tests) {

Example Output

rect: {20, 40, 10, 50} is empty
sorted: {10, 40, 20, 50} is not empty
rect: {20, 40, 20, 50} is empty
sorted: {20, 40, 20, 50} is empty

See Also

EmptyIRect MakeEmpty sort SkRect::isEmpty


Operators

name description
operator!=(const SkIRect& a, const SkIRect& b) returns true if members are unequal
operator==(const SkIRect& a, const SkIRect& b) returns true if members are equal

operator==

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.

Parameters

a IRect to compare
b IRect to compare

Return Value

true if members are equal

Example

Example Output

test == sorted

See Also

operator!=(const SkIRect& a, const SkIRect& b)


operator!=

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.

Parameters

a IRect to compare
b IRect to compare

Return Value

true if members are not equal

Example

Example Output

test != sorted

See Also

operator==(const SkIRect& a, const SkIRect& b)


is16Bit

bool is16Bit() const

Returns true if all members: fLeft, fTop, fRight, and fBottom; values are equal to or larger than -32768 and equal to or smaller than 32767.

Return Value

true if members fit in 16-bit word

Example

Example Output

{-32768, -32768, 32767, 32767} fits in 16 bits
{-32768, -32768, 32768, 32768} does not fit in 16 bits

See Also

SkTFitsIn


setEmpty

void setEmpty()

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

Example

Example Output

rect: {3, 4, 1, 2} is empty
rect: {0, 0, 0, 0} is empty

See Also

MakeEmpty SkRect::setEmpty


set

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

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

left assigned to fLeft
top assigned to fTop
right assigned to fRight
bottom assigned to fBottom

Example

Example Output

rect1: {3, 4, 1, 2}
rect2: {3, 4, 1, 2}

See Also

setLTRB setXYWH SkRect::set[2][3][4]


setLTRB

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

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

left stored in fLeft
top stored in fTop
right stored in fRight
bottom stored in fBottom

Example

Example Output

rect1: {3, 4, 1, 2}
rect2: {3, 4, 1, 2}

See Also

set setXYWH SkRect::setLTRB


setXYWH

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

Sets IRect to: (x, y, x + width, y + height). Does not validate input; width or height may be negative.

Parameters

x stored in fLeft
y stored in fTop
width added to x and stored in fRight
height added to y and stored in fBottom

Example

Example Output

rect: 5, 35, -10, 60  isEmpty: true
rect: -10, 35, 5, 60  isEmpty: false

See Also

MakeXYWH setLTRB set SkRect::setXYWH


Inset Outset Offset

name description
inset moves the sides symmetrically about the center
makeInset constructs from sides moved symmetrically about the center
makeOffset constructs from translated sides
makeOutset constructs from sides moved symmetrically about the center
offset translates sides without changing width and height
void offset(int32 t dx, int32 t dy)
void offset(const SkIPoint& delta)
offsetTo translates to (x, y) without changing width and height
outset moves the sides symmetrically about the center

makeOffset

SkIRect makeOffset(int32_t dx, int32_t dy) const

Returns IRect offset by (dx, dy).

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

Parameters

dx offset added to fLeft and fRight
dy offset added to fTop and fBottom

Return Value

IRect offset in x or y, with original width and height

Example

Example Output

rect: 10, 50, 20, 60  isEmpty: false
rect: 25, 82, 35, 92  isEmpty: false

See Also

offset[2] makeInset makeOutset SkRect::makeOffset


makeInset

SkIRect makeInset(int32_t dx, int32_t dy) const

Returns IRect, inset by (dx, dy).

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

Parameters

dx offset added to fLeft and subtracted from fRight
dy offset added to fTop and subtracted from fBottom

Return Value

IRect inset symmetrically left and right, top and bottom

Example

Example Output

rect: 10, 50, 20, 60  isEmpty: false
rect: 25, 82, 5, 28  isEmpty: true

See Also

inset makeOffset makeOutset SkRect::makeInset


makeOutset

SkIRect makeOutset(int32_t dx, int32_t dy) const

Returns IRect, outset by (dx, dy).

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

Parameters

dx offset subtracted to fLeft and added from fRight
dy offset subtracted to fTop and added from fBottom

Return Value

IRect outset symmetrically left and right, top and bottom

Example

Example Output

rect: 10, 50, 20, 60  isEmpty: false
rect: -5, 18, 35, 92  isEmpty: false

See Also

outset makeOffset makeInset SkRect::makeOutset


offset

void offset(int32_t dx, int32_t dy)

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

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

Parameters

dx offset added to fLeft and fRight
dy offset added to fTop and fBottom

Example

Example Output

rect: 15, 27, 55, 86

See Also

offsetTo makeOffset SkRect::offset[2]


void offset(const SkIPoint& delta)

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

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

Parameters

delta offset added to IRect

Example

Example Output

rect: 15, 27, 55, 86

See Also

offsetTo makeOffset SkRect::offset[2]


offsetTo

void offsetTo(int32_t newX, int32_t newY)

Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height are unchanged.

Parameters

newX stored in fLeft, preserving width
newY stored in fTop, preserving height

Example

Example Output

rect: 15, 27, 55, 86

See Also

offset[2] makeOffset setXYWH SkRect::offsetTo


inset

void inset(int32_t dx, int32_t dy)

Insets IRect by (dx,dy).

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

Parameters

dx offset added to fLeft and subtracted from fRight
dy offset added to fTop and subtracted from fBottom

Example

Example Output

rect: 15, 27, 45, 60

See Also

outset makeInset SkRect::inset


outset

void outset(int32_t dx, int32_t dy)

Outsets IRect by (dx, dy).

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

Parameters

dx subtracted to fLeft and added from fRight
dy subtracted to fTop and added from fBottom

Example

Example Output

rect: 5, 1, 55, 86

See Also

inset makeOutset SkRect::outset


Intersection

IRects intersect when they enclose a common area. To intersect, each of the pair must describe area; fLeft is less than fRight, and fTop is less than fBottom; empty() returns false. The intersection of IRect pair can be described by:

(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)).

The intersection is only meaningful if the resulting IRect is not empty and describes an area: fLeft is less than fRight, and fTop is less than fBottom.

name description
Intersects returns true if areas overlap
IntersectsNoEmptyCheck returns true if areas overlap skips empty check
contains returns true if points are equal or inside
bool contains(int32 t x, int32 t y) const
bool contains(int32 t left, int32 t top, int32 t right, int32 t bottom) const
bool contains(const SkIRect& r) const
intersect sets to shared area; returns true if not empty
bool intersect(const SkIRect& r)
bool intersect(const SkIRect& a, const SkIRect& b)
bool intersect(int32 t left, int32 t top, int32 t right, int32 t bottom)
intersectNoEmptyCheck sets to shared area; returns true if not empty skips empty check
quickReject returns true if rectangles do not intersect

quickReject

bool quickReject(int l, int t, int r, int b) const

Constructs IRect (l, t, r, b) and returns true if constructed IRect does not intersect IRect. Does not check to see if construction or IRect is empty.

Is implemented with short circuit logic so that true can be returned after a single compare.

Parameters

l x minimum of constructed IRect
t y minimum of constructed IRect
r x maximum of constructed IRect
b y maximum of constructed IRect

Return Value

true if construction and IRect have no area in common

Example

quickReject is the complement of Intersects.

Example Output

rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false
rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false
rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true

See Also

Intersects


contains

bool contains(int32_t x, int32_t y) const

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

Returns false if IRect is empty.

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

Parameters

x test Point x-coordinate
y test Point y-coordinate

Return Value

true if (x, y) is inside IRect

Example

Example Output

rect: (30, 50, 40, 60) contains (30, 50)
rect: (30, 50, 40, 60) does not contain (40, 50)
rect: (30, 50, 40, 60) does not contain (30, 60)

See Also

containsNoEmptyCheck[2] SkRect::contains[2]


bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const

Constructs IRect to intersect from (left, top, right, bottom). Does not sort construction.

Returns true if IRect contains construction. Returns false if IRect is empty or construction is empty.

Parameters

left x minimum of constructed IRect
top y minimum of constructed IRect
right x maximum of constructed IRect
bottom y maximum of constructed IRect

Return Value

true if all sides of IRect are outside construction

Example

Example Output

rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)

See Also

containsNoEmptyCheck[2] SkRect::contains[2]


bool contains(const SkIRect& r) const

Returns true if IRect contains r. Returns false if IRect is empty or r is empty.

IRect contains r when IRect area completely includes r area.

Parameters

r IRect contained

Return Value

true if all sides of IRect are outside r

Example

Example Output

rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)

See Also

containsNoEmptyCheck[2] SkRect::contains[2]


bool contains(const SkRect& r) const

Returns true if IRect contains r. Returns false if IRect is empty or r is empty.

IRect contains r when IRect area completely includes r area.

Parameters

r Rect contained

Return Value

true if all sides of IRect are outside r

Example

Example Output

rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)

See Also

containsNoEmptyCheck[2] SkRect::contains[2]


containsNoEmptyCheck

bool containsNoEmptyCheck(int32_t left, int32_t top, int32_t right, int32_t bottom) const

Constructs IRect from (left, top, right, bottom). Does not sort construction.

Returns true if IRect contains construction. Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.

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

Parameters

left x minimum of constructed IRect
top y minimum of constructed IRect
right x maximum of constructed IRect
bottom y maximum of constructed IRect

Return Value

true if all sides of IRect are outside construction

Example

Example Output

rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)

See Also

contains[2][3][4] SkRect::contains[2]


bool containsNoEmptyCheck(const SkIRect& r) const

Returns true if IRect contains construction. Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.

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

Parameters

r IRect contained

Return Value

true if all sides of IRect are outside r

Example

Example Output

rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)

See Also

contains[2][3][4] SkRect::contains[2]


intersect

bool intersect(const SkIRect& r)

Returns true if IRect intersects r, and sets IRect to intersection. Returns false if IRect does not intersect r, and leaves IRect unchanged.

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

Parameters

r limit of result

Return Value

true if r and IRect have area in common

Example

Two SkDebugf calls are required. If the calls are combined, their arguments may not be evaluated in left to right order: the printed intersection may be before or after the call to intersect.

Example Output

intersection: 30, 60, 50, 80

See Also

Intersects intersectNoEmptyCheck join[2] SkRect::intersect[2][3]


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

Returns true if a intersects b, and sets IRect to intersection. Returns false if a does not intersect b, and leaves IRect unchanged.

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

Parameters

a IRect to intersect
b IRect to intersect

Return Value

true if a and b have area in common

Example

Example Output

intersection: 30, 60, 50, 80

See Also

Intersects intersectNoEmptyCheck join[2] SkRect::intersect[2][3]


intersectNoEmptyCheck

bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)

Returns true if a intersects b, and sets IRect to intersection. Returns false if a does not intersect b, and leaves IRect unchanged.

Asserts if either a or b is empty, and if SK_DEBUG is defined.

Parameters

a IRect to intersect
b IRect to intersect

Return Value

true if a and b have area in common

Example

Example Output

intersection: 30, 60, 50, 80

See Also

Intersects intersect[2][3] join[2] SkRect::intersect[2][3]


bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)

Constructs IRect to intersect from (left, top, right, bottom). Does not sort construction.

Returns true if IRect intersects construction, and sets IRect to intersection. Returns false if IRect does not intersect construction, and leaves IRect unchanged.

Returns false if either construction or IRect is empty, leaving IRect unchanged.

Parameters

left x minimum of constructed IRect
top y minimum of constructed IRect
right x maximum of constructed IRect
bottom y maximum of constructed IRect

Return Value

true if construction and IRect have area in common

Example

Two SkDebugf calls are required. If the calls are combined, their arguments may not be evaluated in left to right order: the printed intersection may be before or after the call to intersect.

Example Output

intersection: 30, 60, 50, 80

See Also

intersectNoEmptyCheck Intersects join[2] SkRect::intersect[2][3]


Intersects

static bool Intersects(const SkIRect& a, const SkIRect& b)

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

Parameters

a IRect to intersect
b IRect to intersect

Return Value

true if a and b have area in common

Example

Example Output

intersection

See Also

IntersectsNoEmptyCheck intersect[2][3] SkRect::intersect[2][3]


IntersectsNoEmptyCheck

static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b)

Returns true if a intersects b. Asserts if either a or b is empty, and if SK_DEBUG is defined.

Parameters

a IRect to intersect
b IRect to intersect

Return Value

true if a and b have area in common

Example

Example Output

intersection

See Also

Intersects intersect[2][3] SkRect::intersect[2][3]


join

void join(int32_t left, int32_t top, int32_t right, int32_t bottom)

Constructs IRect to intersect from (left, top, right, bottom). Does not sort construction.

Sets IRect to the union of itself and the construction.

Has no effect if construction is empty. Otherwise, if IRect is empty, sets IRect to construction.

Parameters

left x minimum of constructed IRect
top y minimum of constructed IRect
right x maximum of constructed IRect
bottom y maximum of constructed IRect

Example

Example Output

join: 10, 20, 55, 65

See Also

set SkRect::join[2]


void join(const SkIRect& r)

Sets IRect to the union of itself and r.

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

Parameters

r expansion IRect

Example

Example Output

join: 10, 20, 55, 65

See Also

set SkRect::join[2]


sort

void sort()

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.

Example

Example Output

rect: 30, 50, 20, 10
sorted: 20, 10, 30, 50

See Also

makeSorted SkRect::sort


makeSorted

SkIRect makeSorted() const

Returns IRect 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.

Return Value

sorted IRect

Example

Example Output

rect: 30, 50, 20, 10
sorted: 20, 10, 30, 50

See Also

sort SkRect::makeSorted


EmptyIRect

static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect()

Returns a reference to immutable empty IRect, set to (0, 0, 0, 0).

Return Value

global IRect set to all zeroes

Example

Example Output

rect: 0, 0, 0, 0

See Also

MakeEmpty


MakeLargest

static SkIRect SK_WARN_UNUSED_RESULT MakeLargest()

Returns constructed SkIRect setting left and top to most negative value, and setting right and bottom to most positive value.

Return Value

bounds (SK MinS32, SK MinS32, SK MaxS32, SK MaxS32)