Skia
2D Graphics Library
|
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle. More...
#include <SkRect.h>
Public Member Functions | |
bool | isEmpty () const |
Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom. More... | |
bool | isSorted () const |
Returns true if fLeft is equal to or less than fRight, or if fTop is equal to or less than fBottom. More... | |
bool | isFinite () const |
Returns true if all values in the rectangle are finite. More... | |
constexpr float | x () const |
Returns left edge of SkRect, if sorted. More... | |
constexpr float | y () const |
Returns top edge of SkRect, if sorted. More... | |
constexpr float | left () const |
Returns left edge of SkRect, if sorted. More... | |
constexpr float | top () const |
Returns top edge of SkRect, if sorted. More... | |
constexpr float | right () const |
Returns right edge of SkRect, if sorted. More... | |
constexpr float | bottom () const |
Returns bottom edge of SkRect, if sorted. More... | |
constexpr float | width () const |
Returns span on the x-axis. More... | |
constexpr float | height () const |
Returns span on the y-axis. More... | |
constexpr float | centerX () const |
Returns average of left edge and right edge. More... | |
constexpr float | centerY () const |
Returns average of top edge and bottom edge. More... | |
constexpr SkPoint | center () const |
Returns the point this->centerX(), this->centerY(). More... | |
void | toQuad (SkPoint quad[4]) const |
Returns four points in quad that enclose SkRect ordered as: top-left, top-right, bottom-right, bottom-left. More... | |
void | setEmpty () |
Sets SkRect to (0, 0, 0, 0). More... | |
void | set (const SkIRect &src) |
Sets SkRect to src, promoting src members from integer to float. More... | |
void | setLTRB (float left, float top, float right, float bottom) |
Sets SkRect to (left, top, right, bottom). More... | |
void | setBounds (const SkPoint pts[], int count) |
Sets to bounds of SkPoint array with count entries. More... | |
bool | setBoundsCheck (const SkPoint pts[], int count) |
Sets to bounds of SkPoint array with count entries. More... | |
void | setBoundsNoCheck (const SkPoint pts[], int count) |
Sets to bounds of SkPoint pts array with count entries. More... | |
void | set (const SkPoint &p0, const SkPoint &p1) |
Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1. More... | |
void | setXYWH (float x, float y, float width, float height) |
Sets SkRect to (x, y, x + width, y + height). More... | |
void | setWH (float width, float height) |
Sets SkRect to (0, 0, width, height). More... | |
void | setIWH (int32_t width, int32_t height) |
constexpr SkRect | makeOffset (float dx, float dy) const |
Returns SkRect offset by (dx, dy). More... | |
constexpr SkRect | makeOffset (SkVector v) const |
Returns SkRect offset by v. More... | |
SkRect | makeInset (float dx, float dy) const |
Returns SkRect, inset by (dx, dy). More... | |
SkRect | makeOutset (float dx, float dy) const |
Returns SkRect, outset by (dx, dy). More... | |
void | offset (float dx, float dy) |
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. More... | |
void | offset (const SkPoint &delta) |
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom. More... | |
void | offsetTo (float newX, float newY) |
Offsets SkRect so that fLeft equals newX, and fTop equals newY. More... | |
void | inset (float dx, float dy) |
Insets SkRect by (dx, dy). More... | |
void | outset (float dx, float dy) |
Outsets SkRect by (dx, dy). More... | |
bool | intersect (const SkRect &r) |
Returns true if SkRect intersects r, and sets SkRect to intersection. More... | |
bool | intersect (const SkRect &a, const SkRect &b) |
Returns true if a intersects b, and sets SkRect to intersection. More... | |
bool | intersects (const SkRect &r) const |
Returns true if SkRect intersects r. More... | |
void | join (const SkRect &r) |
Sets SkRect to the union of itself and r. More... | |
void | joinNonEmptyArg (const SkRect &r) |
Sets SkRect to the union of itself and r. More... | |
void | joinPossiblyEmptyRect (const SkRect &r) |
Sets SkRect to the union of itself and the construction. More... | |
bool | contains (float x, float y) const |
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. More... | |
bool | contains (const SkRect &r) const |
Returns true if SkRect contains r. More... | |
bool | contains (const SkIRect &r) const |
Returns true if SkRect contains r. More... | |
void | round (SkIRect *dst) const |
Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (sk_float_round2int(fLeft), sk_float_round2int(fTop), sk_float_round2int(fRight), sk_float_round2int(fBottom)). More... | |
void | roundOut (SkIRect *dst) const |
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (sk_float_floor2int(fLeft), sk_float_floor2int(fTop), sk_float_ceil2int(fRight), sk_float_ceil2int(fBottom)). More... | |
void | roundOut (SkRect *dst) const |
Sets SkRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (sk_float_floor(fLeft), sk_float_floor(fTop), sk_float_ceil(fRight), sk_float_ceil(fBottom)). More... | |
void | roundIn (SkIRect *dst) const |
Sets SkRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (sk_float_ceil2int(fLeft), sk_float_ceil2int(fTop), sk_float_floor2int(fRight), sk_float_floor2int(fBottom)). More... | |
SkIRect | round () const |
Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect members, using (sk_float_round2int(fLeft), sk_float_round2int(fTop), sk_float_round2int(fRight), sk_float_round2int(fBottom)). More... | |
SkIRect | roundOut () const |
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (sk_float_floor2int(fLeft), sk_float_floor2int(fTop), sk_float_ceil2int(fRight), sk_float_ceil2int(fBottom)). More... | |
SkIRect | roundIn () const |
Sets SkIRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBottom, using (sk_float_ceil2int(fLeft), sk_float_ceil2int(fTop), sk_float_floor2int(fRight), sk_float_floor2int(fBottom)). More... | |
void | sort () |
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom. More... | |
SkRect | makeSorted () const |
Returns SkRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBottom swapped if fTop is greater than fBottom. More... | |
const float * | asScalars () const |
Returns pointer to first float in SkRect, to treat it as an array with four entries. More... | |
void | dump (bool asHex) const |
Writes text representation of SkRect to standard output. More... | |
void | dump () const |
Writes text representation of SkRect to standard output. More... | |
void | dumpHex () const |
Writes text representation of SkRect to standard output. More... | |
Static Public Member Functions | |
static constexpr SkRect | MakeEmpty () |
Returns constructed SkRect set to (0, 0, 0, 0). More... | |
static constexpr SkRect | MakeWH (float w, float h) |
Returns constructed SkRect set to float values (0, 0, w, h). More... | |
static SkRect | MakeIWH (int w, int h) |
Returns constructed SkRect set to integer values (0, 0, w, h). More... | |
static constexpr SkRect | MakeSize (const SkSize &size) |
Returns constructed SkRect set to (0, 0, size.width(), size.height()). More... | |
static constexpr SkRect | MakeLTRB (float l, float t, float r, float b) |
Returns constructed SkRect set to (l, t, r, b). More... | |
static constexpr SkRect | MakeXYWH (float x, float y, float w, float h) |
Returns constructed SkRect set to (x, y, x + w, y + h). More... | |
static SkRect | Make (const SkISize &size) |
Returns constructed SkIRect set to (0, 0, size.width(), size.height()). More... | |
static SkRect | Make (const SkIRect &irect) |
Returns constructed SkIRect set to irect, promoting integers to float. More... | |
static bool | Intersects (const SkRect &a, const SkRect &b) |
Returns true if a intersects b. More... | |
Public Attributes | |
float | fLeft = 0 |
smaller x-axis bounds More... | |
float | fTop = 0 |
smaller y-axis bounds More... | |
float | fRight = 0 |
larger x-axis bounds More... | |
float | fBottom = 0 |
larger y-axis bounds More... | |
Friends | |
bool | operator== (const SkRect &a, const SkRect &b) |
Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are equal to the corresponding members in b. More... | |
bool | operator!= (const SkRect &a, const SkRect &b) |
Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not equal the corresponding members in b. More... | |
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
SkRect may be created from outer bounds or from position, width, and height. SkRect describes an area; if its right is less than or equal to its left, or if its bottom is less than or equal to its top, it is considered empty.
|
inline |
Returns pointer to first float in SkRect, to treat it as an array with four entries.
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
Returns average of top edge and bottom edge.
Result does not change if SkRect is sorted.
|
inline |
|
inline |
|
inline |
|
inline |
void SkRect::dump | ( | bool | asHex | ) | const |
Writes text representation of SkRect to standard output.
Set asHex to true to generate exact binary representations of floating point numbers.
asHex | true if SkScalar values are written as hexadecimal |
example: https://fiddle.skia.org/c/@Rect_dump
|
inline |
|
inlineconstexpr |
Returns span on the y-axis.
This does not check if SkRect is sorted, or if result fits in 32-bit float; result may be negative or infinity.
|
inline |
bool SkRect::intersect | ( | const SkRect & | r | ) |
|
inline |
|
inline |
|
inline |
Returns true if all values in the rectangle are finite.
|
inline |
void SkRect::join | ( | const SkRect & | r | ) |
|
inline |
|
inline |
|
inlineconstexpr |
Returns left edge of SkRect, if sorted.
Call isSorted() to see if SkRect is valid. Call sort() to reverse fLeft and fRight if needed.
Returns constructed SkIRect set to irect, promoting integers to float.
Does not validate input; fLeft may be greater than fRight, fTop may be greater than fBottom.
irect | integer unsorted bounds |
|
inlinestaticconstexpr |
Returns constructed SkRect set to (0, 0, 0, 0).
Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle.
|
inline |
Returns SkRect, inset by (dx, dy).
If dx is negative, SkRect returned is wider. If dx is positive, SkRect returned is narrower. If dy is negative, SkRect returned is taller. If dy is positive, SkRect returned is shorter.
dx | added to fLeft and subtracted from fRight |
dy | added to fTop and subtracted from fBottom |
|
inlinestatic |
|
inlinestaticconstexpr |
|
inlineconstexpr |
Returns SkRect offset by (dx, dy).
If dx is negative, SkRect returned is moved to the left. If dx is positive, SkRect returned is moved to the right. If dy is negative, SkRect returned is moved upward. If dy is positive, SkRect returned is moved downward.
dx | added to fLeft and fRight |
dy | added to fTop and fBottom |
|
inlineconstexpr |
|
inline |
Returns SkRect, outset by (dx, dy).
If dx is negative, SkRect returned is narrower. If dx is positive, SkRect returned is wider. If dy is negative, SkRect returned is shorter. If dy is positive, SkRect returned is taller.
dx | subtracted to fLeft and added from fRight |
dy | subtracted to fTop and added from fBottom |
|
inline |
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
Returns constructed SkRect set to (x, y, x + w, y + h).
Does not validate input; w or h may be negative.
x | stored in fLeft |
y | stored in fTop |
w | added to x and stored in fRight |
h | added to y and stored in fBottom |
|
inline |
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop, fBottom.
If delta.fX is negative, moves SkRect to the left. If delta.fX is positive, moves SkRect to the right. If delta.fY is negative, moves SkRect upward. If delta.fY is positive, moves SkRect downward.
delta | added to SkRect |
|
inline |
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
If dx is negative, moves SkRect to the left. If dx is positive, moves SkRect to the right. If dy is negative, moves SkRect upward. If dy is positive, moves SkRect downward.
dx | offset added to fLeft and fRight |
dy | offset added to fTop and fBottom |
|
inline |
|
inline |
|
inlineconstexpr |
Returns right edge of SkRect, if sorted.
Call isSorted() to see if SkRect is valid. Call sort() to reverse fLeft and fRight if needed.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1.
The result is sorted and may be empty. Does not check to see if values are finite.
p0 | corner to include |
p1 | corner to include |
|
inline |
Sets to bounds of SkPoint array with count entries.
If count is zero or smaller, or if SkPoint array contains an infinity or NaN, sets to (0, 0, 0, 0).
Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom.
pts | SkPoint array |
count | entries in array |
bool SkRect::setBoundsCheck | ( | const SkPoint | pts[], |
int | count | ||
) |
Sets to bounds of SkPoint array with count entries.
Returns false if count is zero or smaller, or if SkPoint array contains an infinity or NaN; in these cases sets SkRect to (0, 0, 0, 0).
Result is either empty or sorted: fLeft is less than or equal to fRight, and fTop is less than or equal to fBottom.
pts | SkPoint array |
count | entries in array |
void SkRect::setBoundsNoCheck | ( | const SkPoint | pts[], |
int | count | ||
) |
Sets to bounds of SkPoint pts array with count entries.
If any SkPoint in pts contains infinity or NaN, all SkRect dimensions are set to NaN.
pts | SkPoint array |
count | entries in array |
|
inline |
Sets SkRect to (0, 0, 0, 0).
Many other rectangles are empty; if left is equal to or greater than right, or if top is equal to or greater than bottom. Setting all members to zero is a convenience, but does not designate a special empty rectangle.
|
inline |
|
inline |
Sets SkRect to (left, top, right, bottom).
left and right are not sorted; left is not necessarily less than right. top and bottom are not sorted; top is not necessarily less than bottom.
left | stored in fLeft |
top | stored in fTop |
right | stored in fRight |
bottom | stored in fBottom |
|
inline |
Sets SkRect to (0, 0, width, height).
Does not validate input; width or height may be negative.
width | stored in fRight |
height | stored in fBottom |
|
inline |
Sets SkRect to (x, y, x + width, y + height).
Does not validate input; width or height may be negative.
x | stored in fLeft |
y | stored in fTop |
width | added to x and stored in fRight |
height | added to y and stored in fBottom |
|
inline |
|
inlineconstexpr |
void SkRect::toQuad | ( | SkPoint | quad[4] | ) | const |
|
inlineconstexpr |
Returns span on the x-axis.
This does not check if SkRect is sorted, or if result fits in 32-bit float; result may be negative or infinity.
|
inlineconstexpr |
Returns left edge of SkRect, if sorted.
Call isSorted() to see if SkRect is valid. Call sort() to reverse fLeft and fRight if needed.
|
inlineconstexpr |
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.
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.
float SkRect::fBottom = 0 |
larger y-axis bounds
float SkRect::fLeft = 0 |
smaller x-axis bounds
float SkRect::fRight = 0 |
larger x-axis bounds
float SkRect::fTop = 0 |
smaller y-axis bounds