Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
SkRect Struct Reference

#include <SkRect.h>

Inheritance diagram for SkRect:
SkPathOpsBounds

Public Member Functions

bool contains (SkScalar x, SkScalar y) const
 
bool isEmpty () const
 
bool isSorted () const
 
bool isFinite () const
 
constexpr float x () const
 
constexpr float y () const
 
constexpr float left () const
 
constexpr float top () const
 
constexpr float right () const
 
constexpr float bottom () const
 
constexpr float width () const
 
constexpr float height () const
 
constexpr float centerX () const
 
constexpr float centerY () const
 
constexpr SkPoint center () const
 
void toQuad (SkPoint quad[4]) const
 
void setEmpty ()
 
void set (const SkIRect &src)
 
void setLTRB (float left, float top, float right, float bottom)
 
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 (float x, float y, float width, float height)
 
void setWH (float width, float height)
 
void setIWH (int32_t width, int32_t height)
 
constexpr SkRect makeOffset (float dx, float dy) const
 
constexpr SkRect makeOffset (SkVector v) const
 
SkRect makeInset (float dx, float dy) const
 
SkRect makeOutset (float dx, float dy) const
 
void offset (float dx, float dy)
 
void offset (const SkPoint &delta)
 
void offsetTo (float newX, float newY)
 
void inset (float dx, float dy)
 
void outset (float dx, float dy)
 
bool intersect (const SkRect &r)
 
bool intersect (const SkRect &a, const SkRect &b)
 
bool intersects (const SkRect &r) const
 
void join (const SkRect &r)
 
void joinNonEmptyArg (const SkRect &r)
 
void joinPossiblyEmptyRect (const SkRect &r)
 
bool contains (float x, float 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
 
SkIRect roundIn () const
 
void sort ()
 
SkRect makeSorted () const
 
const float * asScalars () const
 
void dump (bool asHex) const
 
void dump () const
 
void dumpHex () const
 

Static Public Member Functions

static constexpr SkRect MakeEmpty ()
 
static constexpr SkRect MakeWH (float w, float h)
 
static SkRect MakeIWH (int w, int h)
 
static constexpr SkRect MakeSize (const SkSize &size)
 
static constexpr SkRect MakeLTRB (float l, float t, float r, float b)
 
static constexpr SkRect MakeXYWH (float x, float y, float w, float h)
 
static SkRect Make (const SkISize &size)
 
static SkRect Make (const SkIRect &irect)
 
static bool Intersects (const SkRect &a, const SkRect &b)
 

Public Attributes

SkScalar fLeft
 smaller x-axis bounds
 
SkScalar fTop
 smaller y-axis bounds
 
SkScalar fRight
 larger x-axis bounds
 
SkScalar fBottom
 larger y-axis bounds
 
float fLeft = 0
 smaller x-axis bounds
 
float fTop = 0
 smaller y-axis bounds
 
float fRight = 0
 larger x-axis bounds
 
float fBottom = 0
 larger y-axis bounds
 

Friends

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

Detailed Description

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.

Definition at line 13 of file extension.cpp.

Member Function Documentation

◆ asScalars()

const float * SkRect::asScalars ( ) const
inline

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

Returns
pointer to fLeft

Definition at line 1340 of file SkRect.h.

1340{ return &fLeft; }
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14

◆ bottom()

constexpr float SkRect::bottom ( ) const
inlineconstexpr

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.

Returns
fBottom

Definition at line 755 of file SkRect.h.

755{ return fBottom; }
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17

◆ center()

constexpr SkPoint SkRect::center ( ) const
inlineconstexpr

Returns the point this->centerX(), this->centerY().

Returns
rectangle center

Definition at line 792 of file SkRect.h.

792{ return {this->centerX(), this->centerY()}; }
constexpr float centerX() const
Definition SkRect.h:776
constexpr float centerY() const
Definition SkRect.h:785

◆ centerX()

constexpr float SkRect::centerX ( ) const
inlineconstexpr

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.

Returns
midpoint on x-axis

Definition at line 776 of file SkRect.h.

776 {
778 }
static constexpr float sk_float_midpoint(float a, float b)
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16

◆ centerY()

constexpr float SkRect::centerY ( ) const
inlineconstexpr

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

Returns
midpoint on y-axis

Definition at line 785 of file SkRect.h.

785 {
787 }
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15

◆ contains() [1/4]

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

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
rSkIRect contained
Returns
true if all sides of SkRect are outside r

Definition at line 1215 of file SkRect.h.

1215 {
1216 // todo: can we eliminate the this->isEmpty check?
1217 return !r.isEmpty() && !this->isEmpty() &&
1218 fLeft <= r.fLeft && fTop <= r.fTop &&
1219 fRight >= r.fRight && fBottom >= r.fBottom;
1220 }
int32_t fBottom
larger y-axis bounds
Definition SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
bool isEmpty() const
Definition SkRect.h:202
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition SkRect.h:35
bool isEmpty() const
Definition SkRect.h:693

◆ contains() [2/4]

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

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
rSkRect contained
Returns
true if all sides of SkRect are outside r

Definition at line 1200 of file SkRect.h.

1200 {
1201 // todo: can we eliminate the this->isEmpty check?
1202 return !r.isEmpty() && !this->isEmpty() &&
1203 fLeft <= r.fLeft && fTop <= r.fTop &&
1204 fRight >= r.fRight && fBottom >= r.fBottom;
1205 }

◆ contains() [3/4]

bool SkRect::contains ( float  x,
float  y 
) const
inline

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

Parameters
xtest SkPoint x-coordinate
ytest SkPoint y-coordinate
Returns
true if (x, y) is inside SkRect

Definition at line 1188 of file SkRect.h.

1188 {
1189 return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
1190 }
constexpr float x() const
Definition SkRect.h:720
constexpr float y() const
Definition SkRect.h:727

◆ contains() [4/4]

bool SkRect::contains ( SkScalar  x,
SkScalar  y 
) const
inline

Definition at line 19 of file extension.cpp.

19 {
20 return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
21 }

◆ dump() [1/2]

void SkRect::dump ( ) const
inline

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.

Definition at line 1356 of file SkRect.h.

1356{ this->dump(false); }
void dump() const
Definition SkRect.h:1356

◆ dump() [2/2]

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.

Parameters
asHextrue if SkScalar values are written as hexadecimal

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

Definition at line 152 of file SkRect.cpp.

152 {
154
156 if (asHex) {
157 SkString tmp;
158 line.printf( "SkRect::MakeLTRB(%s, /* %f */\n", set_scalar(&tmp, fLeft, asType), fLeft);
159 line.appendf(" %s, /* %f */\n", set_scalar(&tmp, fTop, asType), fTop);
160 line.appendf(" %s, /* %f */\n", set_scalar(&tmp, fRight, asType), fRight);
161 line.appendf(" %s /* %f */);", set_scalar(&tmp, fBottom, asType), fBottom);
162 } else {
163 SkString strL, strT, strR, strB;
164 SkAppendScalarDec(&strL, fLeft);
165 SkAppendScalarDec(&strT, fTop);
168 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);",
169 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str());
170 }
171 SkDebugf("%s\n", line.c_str());
172}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static const char * set_scalar(SkString *storage, float value, SkScalarAsStringType asType)
Definition SkRect.cpp:146
SkScalarAsStringType
@ kHex_SkScalarAsStringType
@ kDec_SkScalarAsStringType
static void SkAppendScalarDec(SkString *str, SkScalar value)
const char * c_str() const
Definition SkString.h:133

◆ dumpHex()

void SkRect::dumpHex ( ) const
inline

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

Use instead of dump() when submitting

Definition at line 1365 of file SkRect.h.

1365{ this->dump(true); }

◆ height()

constexpr float SkRect::height ( ) const
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.

Returns
fBottom minus fTop

Definition at line 769 of file SkRect.h.

769{ return fBottom - fTop; }

◆ inset()

void SkRect::inset ( float  dx,
float  dy 
)
inline

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
dxadded to fLeft and subtracted from fRight
dyadded to fTop and subtracted from fBottom

Definition at line 1060 of file SkRect.h.

1060 {
1061 fLeft += dx;
1062 fTop += dy;
1063 fRight -= dx;
1064 fBottom -= dy;
1065 }
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition SkRecords.h:208

◆ intersect() [1/2]

bool SkRect::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
aSkRect to intersect
bSkRect to intersect
Returns
true if a and b have area in common

Definition at line 120 of file SkRect.cpp.

120 {
121 CHECK_INTERSECT(a.fLeft, a.fTop, a.fRight, a.fBottom, b.fLeft, b.fTop, b.fRight, b.fBottom);
122 this->setLTRB(L, T, R, B);
123 return true;
124}
#define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb)
Definition SkRect.cpp:106
static bool b
struct MyStruct a[10]
#define R(r)
#define T
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865

◆ intersect() [2/2]

bool SkRect::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
rlimit of result
Returns
true if r and SkRect have area in common

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

Definition at line 114 of file SkRect.cpp.

114 {
116 this->setLTRB(L, T, R, B);
117 return true;
118}

◆ Intersects()

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

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

Parameters
aSkRect to intersect
bSkRect to intersect
Returns
true if a and b have area in common

Definition at line 1133 of file SkRect.h.

1133 {
1134 return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
1135 b.fLeft, b.fTop, b.fRight, b.fBottom);
1136 }

◆ intersects()

bool SkRect::intersects ( const SkRect r) const
inline

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

Parameters
rSkRect to intersect
Returns
true if r and SkRect have area in common

Definition at line 1121 of file SkRect.h.

1121 {
1122 return Intersects(fLeft, fTop, fRight, fBottom,
1123 r.fLeft, r.fTop, r.fRight, r.fBottom);
1124 }

◆ isEmpty()

bool SkRect::isEmpty ( ) const
inline

Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBottom. Call sort() to reverse rectangles with negative width() or height().

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

Definition at line 693 of file SkRect.h.

693 {
694 // We write it as the NOT of a non-empty rect, so we will return true if any values
695 // are NaN.
696 return !(fLeft < fRight && fTop < fBottom);
697 }

◆ isFinite()

bool SkRect::isFinite ( ) const
inline

Returns true if all values in the rectangle are finite.

Returns
true if no member is infinite or NaN

Definition at line 711 of file SkRect.h.

711 {
713 }
static bool SkIsFinite(T x, Pack... values)

◆ isSorted()

bool SkRect::isSorted ( ) const
inline

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

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

Definition at line 705 of file SkRect.h.

705{ return fLeft <= fRight && fTop <= fBottom; }

◆ join()

void SkRect::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
rexpansion SkRect

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

Definition at line 126 of file SkRect.cpp.

126 {
127 if (r.isEmpty()) {
128 return;
129 }
130
131 if (this->isEmpty()) {
132 *this = r;
133 } else {
134 fLeft = std::min(fLeft, r.fLeft);
135 fTop = std::min(fTop, r.fTop);
136 fRight = std::max(fRight, r.fRight);
137 fBottom = std::max(fBottom, r.fBottom);
138 }
139}

◆ joinNonEmptyArg()

void SkRect::joinNonEmptyArg ( const SkRect r)
inline

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

Definition at line 1158 of file SkRect.h.

1158 {
1159 SkASSERT(!r.isEmpty());
1160 // if we are empty, just assign
1161 if (fLeft >= fRight || fTop >= fBottom) {
1162 *this = r;
1163 } else {
1164 this->joinPossiblyEmptyRect(r);
1165 }
1166 }
#define SkASSERT(cond)
Definition SkAssert.h:116
void joinPossiblyEmptyRect(const SkRect &r)
Definition SkRect.h:1174

◆ joinPossiblyEmptyRect()

void SkRect::joinPossiblyEmptyRect ( const SkRect r)
inline

Sets SkRect to the union of itself and the construction.

May produce incorrect results if SkRect or r is empty.

Parameters
rexpansion SkRect

Definition at line 1174 of file SkRect.h.

1174 {
1175 fLeft = std::min(fLeft, r.left());
1176 fTop = std::min(fTop, r.top());
1177 fRight = std::max(fRight, r.right());
1178 fBottom = std::max(fBottom, r.bottom());
1179 }
constexpr float left() const
Definition SkRect.h:734
constexpr float top() const
Definition SkRect.h:741
constexpr float right() const
Definition SkRect.h:748
constexpr float bottom() const
Definition SkRect.h:755

◆ left()

constexpr float SkRect::left ( ) const
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
fLeft

Definition at line 734 of file SkRect.h.

734{ return fLeft; }

◆ Make() [1/2]

static SkRect SkRect::Make ( const SkIRect irect)
inlinestatic

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.

Parameters
irectinteger unsorted bounds
Returns
irect members converted to float

Definition at line 680 of file SkRect.h.

680 {
681 return {
682 static_cast<float>(irect.fLeft), static_cast<float>(irect.fTop),
683 static_cast<float>(irect.fRight), static_cast<float>(irect.fBottom)
684 };
685 }

◆ Make() [2/2]

static SkRect SkRect::Make ( const SkISize size)
inlinestatic

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

Parameters
sizeinteger values for SkRect width and height
Returns
bounds (0, 0, size.width(), size.height())

Definition at line 669 of file SkRect.h.

669 {
670 return MakeIWH(size.width(), size.height());
671 }
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
static SkRect MakeIWH(int w, int h)
Definition SkRect.h:623

◆ MakeEmpty()

static constexpr SkRect SkRect::MakeEmpty ( )
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.

Returns
bounds (0, 0, 0, 0)

Definition at line 595 of file SkRect.h.

595 {
596 return SkRect{0, 0, 0, 0};
597 }

◆ makeInset()

SkRect SkRect::makeInset ( float  dx,
float  dy 
) const
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.

Parameters
dxadded to fLeft and subtracted from fRight
dyadded to fTop and subtracted from fBottom
Returns
SkRect inset symmetrically left and right, top and bottom

Definition at line 987 of file SkRect.h.

987 {
988 return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
989 }
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

◆ MakeIWH()

static SkRect SkRect::MakeIWH ( int  w,
int  h 
)
inlinestatic

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
winteger width of constructed SkRect
hinteger height of constructed SkRect
Returns
bounds (0, 0, w, h)

Definition at line 623 of file SkRect.h.

623 {
624 return {0, 0, static_cast<float>(w), static_cast<float>(h)};
625 }
SkScalar w
SkScalar h

◆ MakeLTRB()

static constexpr SkRect SkRect::MakeLTRB ( float  l,
float  t,
float  r,
float  b 
)
inlinestaticconstexpr

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
lfloat stored in fLeft
tfloat stored in fTop
rfloat stored in fRight
bfloat stored in fBottom
Returns
bounds (l, t, r, b)

Definition at line 646 of file SkRect.h.

646 {
647 return SkRect {l, t, r, b};
648 }

◆ makeOffset() [1/2]

constexpr SkRect SkRect::makeOffset ( float  dx,
float  dy 
) const
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.

Parameters
dxadded to fLeft and fRight
dyadded to fTop and fBottom
Returns
SkRect offset on axes, with original width and height

Definition at line 965 of file SkRect.h.

965 {
966 return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
967 }

◆ makeOffset() [2/2]

constexpr SkRect SkRect::makeOffset ( SkVector  v) const
inlineconstexpr

Returns SkRect offset by v.

Parameters
vadded to rect
Returns
SkRect offset on axes, with original width and height

Definition at line 974 of file SkRect.h.

974{ return this->makeOffset(v.x(), v.y()); }
constexpr float y() const
constexpr float x() const
constexpr SkRect makeOffset(float dx, float dy) const
Definition SkRect.h:965

◆ makeOutset()

SkRect SkRect::makeOutset ( float  dx,
float  dy 
) const
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.

Parameters
dxsubtracted to fLeft and added from fRight
dysubtracted to fTop and added from fBottom
Returns
SkRect outset symmetrically left and right, top and bottom

Definition at line 1002 of file SkRect.h.

1002 {
1003 return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
1004 }

◆ MakeSize()

static constexpr SkRect SkRect::MakeSize ( const SkSize size)
inlinestaticconstexpr

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

Parameters
sizefloat values for SkRect width and height
Returns
bounds (0, 0, size.width(), size.height())

Definition at line 633 of file SkRect.h.

633 {
634 return SkRect{0, 0, size.fWidth, size.fHeight};
635 }

◆ makeSorted()

SkRect SkRect::makeSorted ( ) const
inline

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.

Returns
sorted SkRect

Definition at line 1330 of file SkRect.h.

1330 {
1331 return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
1332 std::max(fLeft, fRight), std::max(fTop, fBottom));
1333 }

◆ MakeWH()

static constexpr SkRect SkRect::MakeWH ( float  w,
float  h 
)
inlinestaticconstexpr

Returns constructed SkRect set to float 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
wfloat width of constructed SkRect
hfloat height of constructed SkRect
Returns
bounds (0, 0, w, h)

Definition at line 609 of file SkRect.h.

609 {
610 return SkRect{0, 0, w, h};
611 }

◆ MakeXYWH()

static constexpr SkRect SkRect::MakeXYWH ( float  x,
float  y,
float  w,
float  h 
)
inlinestaticconstexpr

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

Parameters
xstored in fLeft
ystored in fTop
wadded to x and stored in fRight
hadded to y and stored in fBottom
Returns
bounds at (x, y) with width w and height h

Definition at line 659 of file SkRect.h.

659 {
660 return SkRect {x, y, x + w, y + h};
661 }

◆ offset() [1/2]

void SkRect::offset ( const SkPoint delta)
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.

Parameters
deltaadded to SkRect

Definition at line 1033 of file SkRect.h.

1033 {
1034 this->offset(delta.fX, delta.fY);
1035 }
Point offset
float fX
x-axis value

◆ offset() [2/2]

void SkRect::offset ( float  dx,
float  dy 
)
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.

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

Definition at line 1016 of file SkRect.h.

1016 {
1017 fLeft += dx;
1018 fTop += dy;
1019 fRight += dx;
1020 fBottom += dy;
1021 }

◆ offsetTo()

void SkRect::offsetTo ( float  newX,
float  newY 
)
inline

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

Parameters
newXstored in fLeft, preserving width()
newYstored in fTop, preserving height()

Definition at line 1043 of file SkRect.h.

1043 {
1044 fRight += newX - fLeft;
1045 fBottom += newY - fTop;
1046 fLeft = newX;
1047 fTop = newY;
1048 }

◆ outset()

void SkRect::outset ( float  dx,
float  dy 
)
inline

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
dxsubtracted to fLeft and added from fRight
dysubtracted to fTop and added from fBottom

Definition at line 1077 of file SkRect.h.

1077{ this->inset(-dx, -dy); }
void inset(float dx, float dy)
Definition SkRect.h:1060

◆ right()

constexpr float SkRect::right ( ) const
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.

Returns
fRight

Definition at line 748 of file SkRect.h.

748{ return fRight; }

◆ round() [1/2]

SkIRect SkRect::round ( ) const
inline

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

Returns
rounded SkIRect

Definition at line 1278 of file SkRect.h.

1278 {
1279 SkIRect ir;
1280 this->round(&ir);
1281 return ir;
1282 }
SkIRect round() const
Definition SkRect.h:1278

◆ round() [2/2]

void SkRect::round ( SkIRect dst) const
inline

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

Parameters
dststorage for SkIRect

Definition at line 1228 of file SkRect.h.

1228 {
1229 SkASSERT(dst);
1232 }
#define sk_float_round2int(x)
dst
Definition cp.py:12

◆ roundIn() [1/2]

SkIRect SkRect::roundIn ( ) const
inline

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

Returns
rounded SkIRect

Definition at line 1303 of file SkRect.h.

1303 {
1304 SkIRect ir;
1305 this->roundIn(&ir);
1306 return ir;
1307 }
SkIRect roundIn() const
Definition SkRect.h:1303

◆ roundIn() [2/2]

void SkRect::roundIn ( SkIRect dst) const
inline

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

Parameters
dststorage for SkIRect

Definition at line 1266 of file SkRect.h.

1266 {
1267 SkASSERT(dst);
1270 }
#define sk_float_ceil2int(x)
#define sk_float_floor2int(x)

◆ roundOut() [1/3]

SkIRect SkRect::roundOut ( ) const
inline

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

Returns
rounded SkIRect

Definition at line 1291 of file SkRect.h.

1291 {
1292 SkIRect ir;
1293 this->roundOut(&ir);
1294 return ir;
1295 }
SkIRect roundOut() const
Definition SkRect.h:1291

◆ roundOut() [2/3]

void SkRect::roundOut ( SkIRect dst) const
inline

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

Parameters
dststorage for SkIRect

Definition at line 1241 of file SkRect.h.

◆ roundOut() [3/3]

void SkRect::roundOut ( SkRect dst) const
inline

Sets SkRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBottom, using (std::floor(fLeft), std::floor(fTop), std::ceil(fRight), std::ceil(fBottom)).

Parameters
dststorage for SkRect

Definition at line 1254 of file SkRect.h.

1254 {
1255 dst->setLTRB(std::floor(fLeft), std::floor(fTop),
1256 std::ceil(fRight), std::ceil(fBottom));
1257 }

◆ set() [1/2]

void SkRect::set ( const SkIRect src)
inline

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

Parameters
srcinteger SkRect

Definition at line 849 of file SkRect.h.

849 {
850 fLeft = src.fLeft;
851 fTop = src.fTop;
852 fRight = src.fRight;
853 fBottom = src.fBottom;
854 }

◆ set() [2/2]

void SkRect::set ( const SkPoint p0,
const SkPoint p1 
)
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.

Parameters
p0corner to include
p1corner to include

Definition at line 916 of file SkRect.h.

916 {
917 fLeft = std::min(p0.fX, p1.fX);
918 fRight = std::max(p0.fX, p1.fX);
919 fTop = std::min(p0.fY, p1.fY);
920 fBottom = std::max(p0.fY, p1.fY);
921 }
float fY
y-axis value

◆ setBounds()

void SkRect::setBounds ( const SkPoint  pts[],
int  count 
)
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.

Parameters
ptsSkPoint array
countentries in array

Definition at line 881 of file SkRect.h.

881 {
882 (void)this->setBoundsCheck(pts, count);
883 }
int count
bool setBoundsCheck(const SkPoint pts[], int count)
Definition SkRect.cpp:61

◆ setBoundsCheck()

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.

Parameters
ptsSkPoint array
countentries in array
Returns
true if all SkPoint values are finite

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

Definition at line 61 of file SkRect.cpp.

61 {
62 SkASSERT((pts && count > 0) || count == 0);
63
64 if (count <= 0) {
65 this->setEmpty();
66 return true;
67 }
68
70 if (count & 1) {
71 min = max = skvx::float2::Load(pts).xyxy();
72 pts += 1;
73 count -= 1;
74 } else {
75 min = max = skvx::float4::Load(pts);
76 pts += 2;
77 count -= 2;
78 }
79
80 skvx::float4 accum = min * 0;
81 while (count) {
83 accum = accum * xy;
84 min = skvx::min(min, xy);
85 max = skvx::max(max, xy);
86 pts += 2;
87 count -= 2;
88 }
89
90 const bool all_finite = all(accum * 0 == 0);
91 if (all_finite) {
92 this->setLTRB(std::min(min[0], min[2]), std::min(min[1], min[3]),
93 std::max(max[0], max[2]), std::max(max[1], max[3]));
94 } else {
95 this->setEmpty();
96 }
97 return all_finite;
98}
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
SIT bool all(const Vec< 1, T > &x)
Definition SkVx.h:582
SIT T max(const Vec< 1, T > &x)
Definition SkVx.h:641
SIT T min(const Vec< 1, T > &x)
Definition SkVx.h:640
void setEmpty()
Definition SkRect.h:842
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition SkVx.h:109

◆ setBoundsNoCheck()

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.

Parameters
ptsSkPoint array
countentries in array

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

Definition at line 100 of file SkRect.cpp.

100 {
101 if (!this->setBoundsCheck(pts, count)) {
103 }
104}
constexpr float SK_FloatNaN

◆ setEmpty()

void SkRect::setEmpty ( )
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.

Definition at line 842 of file SkRect.h.

842{ *this = MakeEmpty(); }
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595

◆ setIWH()

void SkRect::setIWH ( int32_t  width,
int32_t  height 
)
inline

Definition at line 950 of file SkRect.h.

950 {
951 this->setWH(width, height);
952 }
int32_t height
int32_t width
void setWH(float width, float height)
Definition SkRect.h:944

◆ setLTRB()

void SkRect::setLTRB ( float  left,
float  top,
float  right,
float  bottom 
)
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.

Parameters
leftstored in fLeft
topstored in fTop
rightstored in fRight
bottomstored in fBottom

Definition at line 865 of file SkRect.h.

865 {
866 fLeft = left;
867 fTop = top;
868 fRight = right;
869 fBottom = bottom;
870 }

◆ setWH()

void SkRect::setWH ( float  width,
float  height 
)
inline

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

Parameters
widthstored in fRight
heightstored in fBottom

Definition at line 944 of file SkRect.h.

944 {
945 fLeft = 0;
946 fTop = 0;
947 fRight = width;
948 fBottom = height;
949 }

◆ setXYWH()

void SkRect::setXYWH ( float  x,
float  y,
float  width,
float  height 
)
inline

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

Parameters
xstored in fLeft
ystored in fTop
widthadded to x and stored in fRight
heightadded to y and stored in fBottom

Definition at line 931 of file SkRect.h.

931 {
932 fLeft = x;
933 fTop = y;
934 fRight = x + width;
935 fBottom = y + height;
936 }

◆ sort()

void SkRect::sort ( )
inline

Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater than fBottom. Result may be empty; and width() and height() will be zero or positive.

Definition at line 1313 of file SkRect.h.

1313 {
1314 using std::swap;
1315 if (fLeft > fRight) {
1316 swap(fLeft, fRight);
1317 }
1318
1319 if (fTop > fBottom) {
1320 swap(fTop, fBottom);
1321 }
1322 }
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition SkRefCnt.h:341

◆ top()

constexpr float SkRect::top ( ) const
inlineconstexpr

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.

Returns
fTop

Definition at line 741 of file SkRect.h.

741{ return fTop; }

◆ toQuad()

void SkRect::toQuad ( SkPoint  quad[4]) const

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

TODO: Consider adding parameter to control whether quad is clockwise or counterclockwise.

Parameters
quadstorage for corners of SkRect

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

Definition at line 50 of file SkRect.cpp.

50 {
51 SkASSERT(quad);
52
53 quad[0].set(fLeft, fTop);
54 quad[1].set(fRight, fTop);
55 quad[2].set(fRight, fBottom);
56 quad[3].set(fLeft, fBottom);
57}
void set(float x, float y)

◆ width()

constexpr float SkRect::width ( ) 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.

Returns
fRight minus fLeft

Definition at line 762 of file SkRect.h.

762{ return fRight - fLeft; }

◆ x()

constexpr float SkRect::x ( ) const
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
fLeft

Definition at line 720 of file SkRect.h.

720{ return fLeft; }

◆ y()

constexpr float SkRect::y ( ) const
inlineconstexpr

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.

Returns
fTop

Definition at line 727 of file SkRect.h.

727{ return fTop; }

Friends And Related Symbol Documentation

◆ operator!=

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

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
aSkRect to compare
bSkRect to compare
Returns
true if members are not equal

Definition at line 821 of file SkRect.h.

821 {
822 return !(a == b);
823 }

◆ operator==

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

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
aSkRect to compare
bSkRect to compare
Returns
true if members are equal

Definition at line 804 of file SkRect.h.

804 {
805 return a.fLeft == b.fLeft &&
806 a.fTop == b.fTop &&
807 a.fRight == b.fRight &&
808 a.fBottom == b.fBottom;
809 }

Member Data Documentation

◆ fBottom [1/2]

SkScalar SkRect::fBottom

larger y-axis bounds

Definition at line 17 of file extension.cpp.

◆ fBottom [2/2]

float SkRect::fBottom = 0

larger y-axis bounds

Definition at line 586 of file SkRect.h.

◆ fLeft [1/2]

SkScalar SkRect::fLeft

smaller x-axis bounds

Definition at line 14 of file extension.cpp.

◆ fLeft [2/2]

float SkRect::fLeft = 0

smaller x-axis bounds

Definition at line 583 of file SkRect.h.

◆ fRight [1/2]

SkScalar SkRect::fRight

larger x-axis bounds

Definition at line 16 of file extension.cpp.

◆ fRight [2/2]

float SkRect::fRight = 0

larger x-axis bounds

Definition at line 585 of file SkRect.h.

◆ fTop [1/2]

SkScalar SkRect::fTop

smaller y-axis bounds

Definition at line 15 of file extension.cpp.

◆ fTop [2/2]

float SkRect::fTop = 0

smaller y-axis bounds

Definition at line 584 of file SkRect.h.


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