skia2/site/user/api/SkRect_Reference.md
Cary Clark abaffd85ab bookmaker does deprecated
Bookmaker does not require documentation for public symbols
described as "deprecated", "private", or "experimental".
Adding one of these words (case-insensitive) to the symbol
description in the include file tells bookmaker that the bmh file
should not include documentation, and the generated markdown
should omit it in its indices and descriptions.

Symbols marked as "to be deprecated" or "may be deprecated"
are still regarded as public and documented.

Private notes in the includes that start with TODO: are
omitted as well.

This CL updated generated includes to describe its symbols
accordingly. The includes will be fully regenerated in a future
CL. The corresponding documentation has been deleted from the
bmh files, and the web markup has been regenerated.

TBR=reed@google.com
Docs-Preview: https://skia.org/?cl=169830
Bug: skia:
Change-Id: Ie6ec3ccdadb7be9ac15db4811823a30948c4af25
Reviewed-on: https://skia-review.googlesource.com/c/169830
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Cary Clark <caryclark@skia.org>
2018-11-15 14:08:45 +00:00

108 KiB

SkRect Reference


struct SkRect {
    SkScalar fLeft;
    SkScalar fTop;
    SkScalar fRight;
    SkScalar fBottom;

    static constexpr SkRect MakeEmpty();
    static constexpr SkRect MakeWH(SkScalar w, SkScalar h);
    static SkRect MakeIWH(int w, int h);
    static constexpr SkRect MakeSize(const SkSize& size);
    static constexpr SkRect MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
                                     SkScalar b);
    static constexpr SkRect MakeXYWH(SkScalar x, SkScalar y, SkScalar w,
                                     SkScalar h);
    static SkRect Make(const SkISize& size);
    static SkRect Make(const SkIRect& irect);
    bool isEmpty() const;
    bool isSorted() const;
    bool isFinite() const;
    SkScalar x() const;
    SkScalar y() const;
    SkScalar left() const;
    SkScalar top() const;
    SkScalar right() const;
    SkScalar bottom() const;
    SkScalar width() const;
    SkScalar height() const;
    SkScalar centerX() const;
    SkScalar centerY() const;
    friend bool operator==(const SkRect& a, const SkRect& b);
    friend bool operator!=(const SkRect& a, const SkRect& b);
    void toQuad(SkPoint quad[4]) const;
    void setEmpty();
    void set(const SkIRect& src);
    void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
    void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
    void iset(int left, int top, int right, int bottom);
    void isetWH(int width, int height);
    void set(const SkPoint pts[], int count);
    void setBounds(const SkPoint pts[], int count);
    bool setBoundsCheck(const SkPoint pts[], int count);
    void setBoundsNoCheck(const SkPoint pts[], int count);
    void set(const SkPoint& p0, const SkPoint& p1);
    void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height);
    void setWH(SkScalar width, SkScalar height);
    SkRect makeOffset(SkScalar dx, SkScalar dy) const;
    SkRect makeInset(SkScalar dx, SkScalar dy) const;
    SkRect makeOutset(SkScalar dx, SkScalar dy) const;
    void offset(SkScalar dx, SkScalar dy);
    void offset(const SkPoint& delta);
    void offsetTo(SkScalar newX, SkScalar newY);
    void inset(SkScalar dx, SkScalar dy);
    void outset(SkScalar dx, SkScalar dy);
    bool intersect(const SkRect& r);
    bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
    bool intersect(const SkRect& a, const SkRect& b);
    bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const;
    bool intersects(const SkRect& r) const;
    static bool Intersects(const SkRect& a, const SkRect& b);
    void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
    void join(const SkRect& r);
    void joinNonEmptyArg(const SkRect& r);
    void joinPossiblyEmptyRect(const SkRect& r);
    bool contains(SkScalar x, SkScalar y) const;
    bool contains(const SkRect& r) const;
    bool contains(const SkIRect& r) const;
    void round(SkIRect* dst) const;
    void roundOut(SkIRect* dst) const;
    void roundOut(SkRect* dst) const;
    void roundIn(SkIRect* dst) const;
    SkIRect round() const;
    SkIRect roundOut() const;
    void sort();
    SkRect makeSorted() const;
    const SkScalar* asScalars() const;
    void dump(bool asHex) const;
    void dump() const;
    void dumpHex() const;
};

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.

SkRect can be constructed from int values to avoid compiler warnings that integer input cannot convert to SkScalar without loss of precision.

Type Member Description
SkScalar fLeft May contain any value, including infinities and NaN. The smaller of the horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
SkScalar fTop May contain any value, including infinities and NaN. The smaller of the vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
SkScalar fRight May contain any value, including infinities and NaN. The larger of the horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
SkScalar fBottom May contain any value, including infinities and NaN. The larger of the vertical values when sorted. When equal to or less than fTop, Rect is empty.


static constexpr SkRect MakeEmpty()

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.

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

isEmpty setEmpty SkIRect::MakeEmpty


static constexpr SkRect MakeWH(SkScalar w, SkScalar h)

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

w SkScalar width of constructed SkRect
h SkScalar height of constructed SkRect

Return Value

bounds (0, 0, w, h)

Example

Example Output

all equal

See Also

MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH


static SkRect MakeIWH(int w, int h)

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

w integer width of constructed SkRect
h integer height of constructed SkRect

Return Value

bounds (0, 0, w, h)

Example

Example Output

i_rect width: 25 f_rect width:25
i_rect width: 125000111 f_rect width:125000112

See Also

MakeXYWH MakeWH isetWH SkIRect::MakeWH


static constexpr SkRect MakeSize(const SkSize& size)

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

Parameters

size SkScalar values for SkRect width and height

Return Value

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

Example

Example Output

rect width: 25.5  height: 35.5
floor width: 25  height: 35

See Also

MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH


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

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

l SkScalar stored in fLeft
t SkScalar stored in fTop
r SkScalar stored in fRight
b SkScalar 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 SkIRect::MakeLTRB


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

Returns constructed Rect 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 SkIRect::MakeXYWH


static SkRect Make(const SkISize& size)

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

Parameters

size integer values for SkRect width and height

Return Value

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

Example

Example Output

rect1 == rect2

See Also

MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize


static SkRect Make(const SkIRect& irect)

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

irect integer unsorted bounds

Return Value

irect members converted to SkScalar

Example

See Also

MakeLTRB


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

MakeEmpty sort SkIRect::isEmpty


bool isSorted() const

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

Return Value

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

Example

Example Output

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

See Also

sort makeSorted isEmpty


bool isFinite() const

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

Return Value

true if no member is infinite or NaN

Example

Example Output

largest is finite: true
large width inf
widest is finite: false

See Also

SkScalarIsFinite SkScalarIsNaN


SkScalar    x() const

Returns left edge of SkRect, if sorted. Call isSorted() to see if SkRect is valid. Call 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() SkIRect::x()


SkScalar    y() const

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.

Return Value

fTop

Example

Example Output

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

See Also

fTop top() x() SkIRect::y()


SkScalar    left() const

Returns left edge of SkRect, if sorted. Call isSorted() to see if SkRect is valid. 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() SkIRect::left()


SkScalar    top() const

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.

Return Value

fTop

Example

Example Output

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

See Also

fTop y() SkIRect::top()


SkScalar    right() const

Returns right edge of SkRect, if sorted. Call isSorted() to see if SkRect is valid. 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 SkIRect::right()


SkScalar    bottom() const

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.

Return Value

fBottom

Example

Example Output

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

See Also

fBottom SkIRect::bottom()


SkScalar    width() const

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.

Return Value

fRight minus fLeft

Example

Compare with SkIRect::width() example.

Example Output

unsorted width: -5
large width: 4294967296

See Also

height() SkIRect::width()


SkScalar    height() const

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.

Return Value

fBottom minus fTop

Example

Compare with SkIRect::height() example.

Example Output

unsorted height: -5
large height: 4294967296

See Also

width() SkIRect::height()


SkScalar    centerX() const

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.

Return Value

midpoint on x-axis

Example

Example Output

left:  20 right:  41 centerX: 30.5
left:  20 right:  41 centerX: 30.5
left: -20 right: -41 centerX: -30.5
left: -41 right: -20 centerX: -30.5

See Also

centerY


SkScalar    centerY() const

Returns average of top edge and bottom edge. Result does not change if SkRect is sorted.

Return Value

midpoint on y-axis

Example

Example Output

left: 2e+38 right: 3e+38 centerX: 2.5e+38 safe mid x: 2.5e+38

See Also

centerX


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.

a and b are not equal if either contain NaN. a and b are equal if members contain zeroes with different signs.

Parameters

a SkRect to compare
b SkRect to compare

Return Value

true if members are equal

Example

Example Output

tests are equal
{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal

See Also

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


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.

a and b are not equal if either contain NaN. a and b are equal if members contain zeroes with different signs.

Parameters

a SkRect to compare
b SkRect to compare

Return Value

true if members are not equal

Example

Example Output

test with NaN is not equal to itself

See Also

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


void toQuad(SkPoint quad[4]) const

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

Parameters

quad storage for corners of SkRect

Example

Example Output

rect: {1, 2, 3, 4}
corners: {1, 2} {3, 2} {3, 4} {1, 4}

See Also

SkPath::addRect


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

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

pts SkPoint array
count entries in array

Example

Example Output

count: 0 rect: 0, 0, 0, 0
added:   3, 4 count: 1 rect: 3, 4, 3, 4
added:   1, 2 count: 2 rect: 1, 2, 3, 4
added:   5, 6 count: 3 rect: 1, 2, 5, 6
added: nan, 8 count: 4 rect: 0, 0, 0, 0

See Also

set setBoundsCheck SkPath::addPoly


bool 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

pts SkPoint array
count entries in array

Return Value

true if all SkPoint values are finite

Example

Example Output

count: 0 rect: 0, 0, 0, 0 success: true
added:   3, 4 count: 1 rect: 3, 4, 3, 4 success: true
added:   1, 2 count: 2 rect: 1, 2, 3, 4 success: true
added:   5, 6 count: 3 rect: 1, 2, 5, 6 success: true
added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false

See Also

set setBounds SkPath::addPoly


void 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

pts SkPoint array
count entries in array

Example

See Also

setBoundsCheck


void setEmpty()

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.

Example

Example Output

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

See Also

MakeEmpty SkIRect::setEmpty


void set(const SkIRect& src)

Sets SkRect to src, promoting src members from integer to scalar. Very large values in src may lose precision.

Parameters

src integer SkRect

Example

Example Output

i_rect: {3, 4, 1, 2}
f_rect: {3, 4, 1, 2}

See Also

setLTRB SkIntToScalar


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

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

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

setLTRB setXYWH SkIRect::set


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

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

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 SkIRect::set


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

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

pts SkPoint array
count entries in array

Example

Example Output

count: 0 rect: 0, 0, 0, 0
added:   3, 4 count: 1 rect: 3, 4, 3, 4
added:   1, 2 count: 2 rect: 1, 2, 3, 4
added:   5, 6 count: 3 rect: 1, 2, 5, 6
added: nan, 8 count: 4 rect: 0, 0, 0, 0

See Also

setBounds setBoundsCheck SkPath::addPoly


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

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

p0 corner to include
p1 corner to include

Example

p0 and p1 may be swapped and have the same effect unless one contains NaN.

See Also

setBounds setBoundsCheck


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

Sets Rect 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 SkIRect::setXYWH


void setWH(SkScalar width, SkScalar height)

Sets SkRect to (0, 0, width, height). Does not validate input; width or height may be negative.

Parameters

width stored in fRight
height stored in fBottom

Example

Example Output

rect: 0, 0, -15, 25  isEmpty: true
rect: -15, 0, 0, 25  isEmpty: false

See Also

MakeWH setXYWH isetWH


void iset(int left, int top, int right, int bottom)

Sets SkRect to (left, top, right, bottom). All parameters are promoted from integer to scalar. 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 promoted to SkScalar and stored in fLeft
top promoted to SkScalar and stored in fTop
right promoted to SkScalar and stored in fRight
bottom promoted to SkScalar and stored in fBottom

Example

Example Output

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

See Also

set setLTRB SkIRect::set SkIntToScalar


void isetWH(int width, int height)

Sets SkRect to (0, 0, width, height). width and height may be zero or negative. width and height are promoted from integer to SkScalar, large values may lose precision.

Parameters

width promoted to SkScalar and stored in fRight
height promoted to SkScalar and stored in fBottom

Example

Example Output

rect1: {0, 0, 1, 2}
rect2: {0, 0, 1, 2}

See Also

MakeWH MakeXYWH iset() SkIRect:MakeWH


SkRect makeOffset(SkScalar dx, SkScalar dy) const

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

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

Return Value

SkRect offset on axes, 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() makeInset makeOutset SkIRect::makeOffset


SkRect makeInset(SkScalar dx, SkScalar dy) const

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

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

Return Value

SkRect 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 SkIRect::makeInset


SkRect makeOutset(SkScalar dx, SkScalar dy) const

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

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

Return Value

SkRect 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 SkIRect::makeOutset


void offset(SkScalar dx, SkScalar dy)

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

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 SkIRect::offset


void offset(const SkPoint& delta)

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

delta added to SkRect

Example

Example Output

rect: 15, 27, 55, 86

See Also

offsetTo makeOffset SkIRect::offset


void offsetTo(SkScalar newX, SkScalar newY)

Offsets SkRect 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 makeOffset setXYWH SkIRect::offsetTo


void inset(SkScalar dx, SkScalar dy)

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

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

Example

Example Output

rect: 15, 27, 45, 60

See Also

outset makeInset SkIRect::inset


void outset(SkScalar dx, SkScalar dy)

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

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 SkIRect::outset

Rects 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; isEmpty() returns false. The intersection of Rect 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 Rect is not empty and describes an area: fLeft is less than fRight, and fTop is less than fBottom.


bool contains(SkScalar x, SkScalar y) const

Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. Returns false if SkRect is empty.

Parameters

x test SkPoint x-coordinate
y test SkPoint y-coordinate

Return Value

true if (x, y) is inside SkRect

Example

Example Output

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

See Also

SkIRect::contains SkRRect::contains


bool contains(const SkRect& r) const

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

r SkRect contained

Return Value

true if all sides of SkRect 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

SkIRect::contains


bool contains(const SkIRect& r) const

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

r SkIRect contained

Return Value

true if all sides of SkRect 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

SkIRect::contains


bool 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

r limit of result

Return Value

true if r and SkRect 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 Intersects join SkIRect::intersect


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

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

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

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

Parameters

left x-axis minimum of constructed SkRect
top y-axis minimum of constructed SkRect
right x-axis maximum of constructed SkRect
bottom y-axis maximum of constructed SkRect

Return Value

true if construction and SkRect 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 Intersects join SkIRect::intersect


bool 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

a SkRect to intersect
b SkRect to intersect

Return Value

true if a and b have area in common

Example

Example Output

intersection: 30, 60, 50, 80

See Also

intersects Intersects join SkIRect::intersect


bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const

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

Returns true if SkRect intersects construction. Returns false if either construction or SkRect is empty, or do not intersect.

Parameters

left x-axis minimum of constructed SkRect
top y-axis minimum of constructed SkRect
right x-axis maximum of constructed SkRect
bottom y-axis maximum of constructed SkRect

Return Value

true if construction and SkRect have area in common

Example

Example Output

intersection

See Also

intersect Intersects SkIRect::Intersects


bool intersects(const SkRect& r) const

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

Parameters

r SkRect to intersect

Return Value

true if r and SkRect have area in common

Example

Example Output

intersection

See Also

intersect Intersects SkIRect::Intersects


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

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

Parameters

a SkRect to intersect
b SkRect to intersect

Return Value

true if a and b have area in common

Example

Example Output

intersection

See Also

intersect intersects SkIRect::Intersects


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

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

Sets SkRect to the union of itself and the construction.

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

Parameters

left x-axis minimum of constructed SkRect
top y-axis minimum of constructed SkRect
right x-axis maximum of constructed SkRect
bottom y-axis maximum of constructed SkRect

Example

Example Output

join: 10, 20, 55, 65

See Also

joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join


void 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

r expansion SkRect

Example

Example Output

join: 10, 20, 55, 65

See Also

joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join


void joinNonEmptyArg(const SkRect& r)

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

r expansion SkRect

Example

Since Rect is not sorted, first result is copy of toJoin.

Example Output

rect: 50, 60, 55, 65
sorted: 10, 0, 55, 100

See Also

join joinPossiblyEmptyRect SkIRect::join


void joinPossiblyEmptyRect(const SkRect& r)

Sets SkRect to the union of itself and the construction.

May produce incorrect results if SkRect or r is empty.

Parameters

r expansion SkRect

Example

Since Rect is not sorted, first result is not useful.

Example Output

rect: 10, 60, 55, 65
sorted: 10, 0, 55, 100

See Also

joinNonEmptyArg join SkIRect::join


void round(SkIRect* dst) const

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

Parameters

dst storage for IRect

Example

Example Output

round: 31, 51, 41, 61

See Also

roundIn roundOut SkScalarRoundToInt


void roundOut(SkIRect* dst) const

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

dst storage for IRect

Example

Example Output

round: 30, 50, 41, 61

See Also

roundIn round SkScalarRoundToInt


void roundOut(SkRect* dst) const

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

dst storage for Rect

Example

Example Output

round: 30, 50, 41, 61

See Also

roundIn round SkScalarRoundToInt


void roundIn(SkIRect* dst) const

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

dst storage for IRect

Example

Example Output

round: 31, 51, 40, 60

See Also

roundOut round SkScalarRoundToInt


SkIRect round() const

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

Return Value

rounded IRect

Example

Example Output

round: 31, 51, 41, 61

See Also

roundOut roundIn SkScalarRoundToInt


SkIRect roundOut() const

Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).

Return Value

rounded IRect

Example

Example Output

round: 30, 50, 41, 61

See Also

round roundIn SkScalarRoundToInt


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.5, 50.5, 20.5, 10.5
sorted: 20.5, 10.5, 30.5, 50.5

See Also

makeSorted SkIRect::sort isSorted


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. Result may be empty; and width() and height() will be zero or positive.

Return Value

sorted SkRect

Example

Example Output

rect: 30.5, 50.5, 20.5, 10.5
sorted: 20.5, 10.5, 30.5, 50.5

See Also

sort SkIRect::makeSorted isSorted


const SkScalar* asScalars() const

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

Return Value

pointer to fLeft

Example

Example Output

rect.asScalars() == &rect.fLeft

See Also

toQuad


void 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

asHex true if SkScalar values are written as hexadecimal

Example

Example Output

SkRect::MakeLTRB(20, 30, 40, 50);
SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
SkBits2Float(0x41f00000), /* 30.000000 */
SkBits2Float(0x42200000), /* 40.000000 */
SkBits2Float(0x42480000)  /* 50.000000 */);

See Also

dumpHex


void dump() const

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.

Example

Example Output

SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
rect is not equal to copy

See Also

dumpHex


void dumpHex() const

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

Use instead of dump() when submitting bug reports against Skia .

Example

Example Output

SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
SkBits2Float(0x3f2aaaab), /* 0.666667 */
SkBits2Float(0x40266666), /* 2.600000 */
SkBits2Float(0x40e00000)  /* 7.000000 */);
rect is equal to copy

See Also

dump