SkIRect Reference
struct SkIRect { int32_t fLeft; int32_t fTop; int32_t fRight; int32_t fBottom; static constexpr SkIRect MakeEmpty(); static constexpr SkIRect MakeWH(int32_t w, int32_t h); static constexpr SkIRect MakeSize(const SkISize& size); static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b); static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h); int32_t left() const; int32_t top() const; int32_t right() const; int32_t bottom() const; int32_t x() const; int32_t y() const; int32_t width() const; int32_t height() const; SkISize size() const; int64_t width64() const; int64_t height64() const; bool isEmpty64() const; bool isEmpty() const; friend bool operator==(const SkIRect& a, const SkIRect& b); friend bool operator!=(const SkIRect& a, const SkIRect& b); void setEmpty(); void set(int32_t left, int32_t top, int32_t right, int32_t bottom); void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom); void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height); SkIRect makeOffset(int32_t dx, int32_t dy) const; SkIRect makeInset(int32_t dx, int32_t dy) const; SkIRect makeOutset(int32_t dx, int32_t dy) const; void offset(int32_t dx, int32_t dy); void offset(const SkIPoint& delta); void offsetTo(int32_t newX, int32_t newY); void inset(int32_t dx, int32_t dy); void outset(int32_t dx, int32_t dy); void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB); 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; bool contains(const SkRect& r) const; bool containsNoEmptyCheck(int32_t left, int32_t top, int32_t right, int32_t bottom) const; bool containsNoEmptyCheck(const SkIRect& r) const; bool intersect(const SkIRect& r); bool intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b); bool intersect(const SkIRect& a, const SkIRect& b); bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom); static bool Intersects(const SkIRect& a, const SkIRect& b); static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b); void join(int32_t left, int32_t top, int32_t right, int32_t bottom); void join(const SkIRect& r); void sort(); SkIRect makeSorted() const; static const SkIRect& EmptyIRect(); };
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.
Type | Member | Description |
---|---|---|
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. |
static constexpr SkIRect MakeEmpty()
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.
Return Value
bounds (0, 0, 0, 0)
Example
See Also
EmptyIRect isEmpty setEmpty SkRect::MakeEmpty
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Returns constructed SkIRect set to (0, 0, w, h). Does not validate input; w or h may be negative.
Parameters
w |
width of constructed SkIRect |
h |
height of constructed SkIRect |
Return Value
Example
See Also
MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH
static constexpr SkIRect MakeSize(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 |
values for SkIRect width and height |
Return Value
bounds (0, 0, size.width(), size.height())
Example
See Also
MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
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
l |
integer stored in fLeft |
t |
integer stored in fTop |
r |
integer stored in fRight |
b |
integer stored in fBottom |
Return Value
Example
See Also
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Returns constructed SkIRect 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
See Also
int32_t left()const
Returns left edge of SkIRect, if sorted. Call sort() to reverse fLeft and fRight if needed.
Return Value
Example
See Also
int32_t top()const
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.
Return Value
Example
See Also
int32_t right()const
Returns right edge of SkIRect, if sorted. Call sort() to reverse fLeft and fRight if needed.
Return Value
Example
See Also
int32_t bottom()const
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.
Return Value
Example
See Also
int32_t x()const
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.
Return Value
Example
See Also
int32_t y()const
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.
Return Value
Example
See Also
int32_t width()const
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.
Return Value
Example
See Also
height() width64() height64() SkRect::width()
int64_t width64()const
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.
Return Value
fRight minus fLeft cast to int64_t
Example
See Also
width() height() height64() SkRect::width()
int32_t height()const
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.
Return Value
Example
See Also
int64_t height64()const
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.
Return Value
fBottom minus fTop cast to int64_t
Example
See Also
width() height() width64() SkRect::height()
SkISize size()const
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.
Return Value
SkISize (width, height)
Example
See Also
bool isEmpty()const
Returns true if width() or height() are zero or negative.
Return Value
true if width() or height() are zero or negative
Example
See Also
EmptyIRect MakeEmpty sort SkRect::isEmpty
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
Example
See Also
EmptyIRect MakeEmpty sort SkRect::isEmpty
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 |
SkIRect to compare |
b |
SkIRect to compare |
Return Value
true if members are equal
Example
See Also
operator!=(const SkIRect& a, const SkIRect& b)
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 |
SkIRect to compare |
b |
SkIRect to compare |
Return Value
true if members are not equal
Example
See Also
operator==(const SkIRect& a, const SkIRect& b)
void setEmpty()
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.
Example
See Also
void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
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
left |
assigned to fLeft |
top |
assigned to fTop |
right |
assigned to fRight |
bottom |
assigned to fBottom |
Example
See Also
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
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
left |
stored in fLeft |
top |
stored in fTop |
right |
stored in fRight |
bottom |
stored in fBottom |
Example
See Also
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
See Also
MakeXYWH setLTRB set SkRect::setXYWH
SkIRect makeOffset(int32_t dx, int32_t dy)const
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
dx |
offset added to fLeft and fRight |
dy |
offset added to fTop and fBottom |
Return Value
SkIRect offset by dx and dy, with original width and height
Example
See Also
offset() makeInset makeOutset SkRect::makeOffset
SkIRect makeInset(int32_t dx, int32_t dy)const
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
dx |
offset added to fLeft and subtracted from fRight |
dy |
offset added to fTop and subtracted from fBottom |
Return Value
SkIRect inset symmetrically left and right, top and bottom
Example
See Also
inset() makeOffset makeOutset SkRect::makeInset
SkIRect makeOutset(int32_t dx, int32_t dy)const
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
dx |
offset subtracted to fLeft and added from fRight |
dy |
offset subtracted to fTop and added from fBottom |
Return Value
SkIRect outset symmetrically left and right, top and bottom
Example
See Also
outset() makeOffset makeInset SkRect::makeOutset
void offset(int32_t dx, int32_t dy)
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
dx |
offset added to fLeft and fRight |
dy |
offset added to fTop and fBottom |
Example
See Also
offsetTo makeOffset SkRect::offset
void offset(const SkIPoint& delta)
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
delta |
offset added to SkIRect |
Example
See Also
offsetTo makeOffset SkRect::offset
void offsetTo(int32_t newX, int32_t newY)
Offsets SkIRect 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
See Also
offset makeOffset setXYWH SkRect::offsetTo
void inset(int32_t dx, int32_t 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
dx |
offset added to fLeft and subtracted from fRight |
dy |
offset added to fTop and subtracted from fBottom |
Example
See Also
outset makeInset SkRect::inset
void outset(int32_t dx, int32_t 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
dx |
subtracted to fLeft and added from fRight |
dy |
subtracted to fTop and added from fBottom |
Example
See Also
inset makeOutset SkRect::outset
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;
SkIRect::isEmpty() 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.
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.
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
dL |
offset added to fLeft |
dT |
offset added to fTop |
dR |
offset added to fRight |
dB |
offset added to fBottom |
Example
See Also
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 IPoint x-coordinate |
y |
test IPoint y-coordinate |
Return Value
true if (x, y) is inside IRect
Example
See Also
containsNoEmptyCheck SkRect::contains
bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom)const
Constructs SkIRect to intersect from (left, top, right, bottom). Does not sort construction.
Returns true if SkIRect contains construction. Returns false if SkIRect is empty or construction is empty.
Parameters
left |
x-axis minimum of constructed SkIRect |
top |
y-axis minimum of constructed SkIRect |
right |
x-axis maximum of constructed SkIRect |
bottom |
y-axis maximum of constructed SkIRect |
Return Value
true if all sides of SkIRect are outside construction
Example
See Also
containsNoEmptyCheck SkRect::contains
bool contains(const SkIRect& r)const
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
r |
SkIRect contained |
Return Value
true if all sides of SkIRect are outside r
Example
See Also
containsNoEmptyCheck SkRect::contains
bool contains(const SkRect& r)const
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
r |
SkRect contained |
Return Value
true if all sides of SkIRect are outside r
Example
See Also
containsNoEmptyCheck SkRect::contains
bool containsNoEmptyCheck(int32_t left, int32_t top, int32_t right, int32_t bottom)const
Constructs SkIRect from (left, top, right, bottom). Does not sort construction.
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
left |
x-axis minimum of constructed SkIRect |
top |
y-axis minimum of constructed SkIRect |
right |
x-axis maximum of constructed SkIRect |
bottom |
y-axis maximum of constructed SkIRect |
Return Value
true if all sides of SkIRect are outside construction
Example
See Also
bool containsNoEmptyCheck(const SkIRect& r)const
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
r |
SkIRect contained |
Return Value
true if all sides of SkIRect are outside r
Example
See Also
bool intersect(const SkIRect& r)
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
r |
limit of result |
Return Value
true if r and SkIRect have area in common
Example
Example Output
intersection: 30, 60, 50, 80
See Also
Intersects intersectNoEmptyCheck join SkRect::intersect
bool 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
a |
SkIRect to intersect |
b |
SkIRect to intersect |
Return Value
true if a and b have area in common
Example
See Also
Intersects intersectNoEmptyCheck join SkRect::intersect
bool intersectNoEmptyCheck(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.
Asserts if either a or b is empty, and if SK_DEBUG is defined.
Parameters
a |
SkIRect to intersect |
b |
SkIRect to intersect |
Return Value
true if a and b have area in common
Example
See Also
Intersects intersect join SkRect::intersect
bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
Constructs SkIRect to intersect from (left, top, right, bottom). Does not sort construction.
Returns true if SkIRect intersects construction, and sets SkIRect to intersection. Returns false if SkIRect does not intersect construction, and leaves SkIRect unchanged.
Returns false if either construction or SkIRect is empty, leaving SkIRect unchanged.
Parameters
left |
x-axis minimum of constructed SkIRect |
top |
y-axis minimum of constructed SkIRect |
right |
x-axis maximum of constructed SkIRect |
bottom |
y-axis maximum of constructed SkIRect |
Return Value
true if construction and SkIRect have area in common
Example
Example Output
intersection: 30, 60, 50, 80
See Also
intersectNoEmptyCheck Intersects join SkRect::intersect
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 |
SkIRect to intersect |
b |
SkIRect to intersect |
Return Value
true if a and b have area in common
Example
See Also
IntersectsNoEmptyCheck intersect SkRect::intersect
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 |
SkIRect to intersect |
b |
SkIRect to intersect |
Return Value
true if a and b have area in common
Example
See Also
Intersects intersect SkRect::intersect
void join(int32_t left, int32_t top, int32_t right, int32_t bottom)
Constructs SkIRect to intersect from (left, top, right, bottom). Does not sort construction.
Sets SkIRect to the union of itself and the construction.
Has no effect if construction is empty. Otherwise, if SkIRect is empty, sets SkIRect to construction.
Parameters
left |
x-axis minimum of constructed SkIRect |
top |
y-axis minimum of constructed SkIRect |
right |
x-axis maximum of constructed SkIRect |
bottom |
y-axis maximum of constructed SkIRect |
Example
See Also
void 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
r |
expansion SkIRect |
Example
See Also
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
See Also
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. Result may be empty; and width() and height() will be zero or positive.
Return Value
sorted SkIRect
Example
See Also
static const SkIRect& EmptyIRect()
Returns a reference to immutable empty SkIRect, set to (0, 0, 0, 0).
Return Value
global SkIRect set to all zeroes