21 int32_t fLeft, fTop, fRight, fBottom;
23 static SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() {
29 static SkIRect SK_WARN_UNUSED_RESULT MakeLargest() {
35 static SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
41 static SkIRect SK_WARN_UNUSED_RESULT MakeSize(
const SkISize& size) {
43 r.set(0, 0, size.width(), size.height());
47 static SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) {
53 static SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) {
55 r.set(x, y, x + w, y + h);
59 int left()
const {
return fLeft; }
60 int top()
const {
return fTop; }
61 int right()
const {
return fRight; }
62 int bottom()
const {
return fBottom; }
65 int x()
const {
return fLeft; }
67 int y()
const {
return fTop; }
72 int width()
const {
return fRight - fLeft; }
78 int height()
const {
return fBottom - fTop; }
80 SkISize size()
const {
return SkISize::Make(this->width(), this->height()); }
89 int centerX()
const {
return (fRight + fLeft) >> 1; }
98 int centerY()
const {
return (fBottom + fTop) >> 1; }
103 bool isEmpty()
const {
return fLeft >= fRight || fTop >= fBottom; }
105 bool isLargest()
const {
return SK_MinS32 == fLeft &&
107 SK_MaxS32 == fRight &&
108 SK_MaxS32 == fBottom; }
111 return !memcmp(&a, &b,
sizeof(a));
118 bool is16Bit()
const {
125 void setEmpty() { memset(
this, 0,
sizeof(*
this)); }
127 void set(int32_t left, int32_t top, int32_t right, int32_t bottom) {
134 void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) {
135 this->set(left, top, right, bottom);
138 void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) {
142 fBottom = y + height;
149 fLeft = fTop = SK_MinS32;
150 fRight = fBottom = SK_MaxS32;
158 fLeft = fTop = SK_MaxS32;
159 fRight = fBottom = SK_MinS32;
166 return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
173 return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
180 return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
193 void offset(
const SkIPoint& delta) {
194 this->offset(delta.fX, delta.fY);
201 fRight += newX - fLeft;
202 fBottom += newY - fTop;
211 void inset(int32_t dx, int32_t dy) {
223 void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
225 bool quickReject(
int l,
int t,
int r,
int b)
const {
226 return l >= fRight || fLeft >= r || t >= fBottom || fTop >= b;
235 return (
unsigned)(x - fLeft) < (
unsigned)(fRight - fLeft) &&
236 (
unsigned)(y - fTop) < (
unsigned)(fBottom - fTop);
242 bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom)
const {
243 return left < right && top < bottom && !this->isEmpty() &&
244 fLeft <= left && fTop <= top &&
245 fRight >= right && fBottom >= bottom;
251 return !r.
isEmpty() && !this->isEmpty() &&
252 fLeft <= r.fLeft && fTop <= r.fTop &&
253 fRight >= r.fRight && fBottom >= r.fBottom;
258 bool contains(
const SkRect& r)
const;
267 int32_t right, int32_t bottom)
const {
268 SkASSERT(fLeft < fRight && fTop < fBottom);
269 SkASSERT(left < right && top < bottom);
271 return fLeft <= left && fTop <= top &&
272 fRight >= right && fBottom >= bottom;
275 bool containsNoEmptyCheck(
const SkIRect& r)
const {
276 return containsNoEmptyCheck(r.fLeft, r.fTop, r.fRight, r.fBottom);
284 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
294 a.fLeft < b.fRight && b.fLeft < a.fRight &&
295 a.fTop < b.fBottom && b.fTop < a.fBottom) {
296 fLeft = SkMax32(a.fLeft, b.fLeft);
297 fTop = SkMax32(a.fTop, b.fTop);
298 fRight = SkMin32(a.fRight, b.fRight);
299 fBottom = SkMin32(a.fBottom, b.fBottom);
314 if (a.fLeft < b.fRight && b.fLeft < a.fRight &&
315 a.fTop < b.fBottom && b.fTop < a.fBottom) {
316 fLeft = SkMax32(a.fLeft, b.fLeft);
317 fTop = SkMax32(a.fTop, b.fTop);
318 fRight = SkMin32(a.fRight, b.fRight);
319 fBottom = SkMin32(a.fBottom, b.fBottom);
330 bool SK_WARN_UNUSED_RESULT
intersect(int32_t left, int32_t top,
331 int32_t right, int32_t bottom) {
332 if (left < right && top < bottom && !this->isEmpty() &&
333 fLeft < right && left < fRight && fTop < bottom && top < fBottom) {
334 if (fLeft < left) fLeft = left;
335 if (fTop < top) fTop = top;
336 if (fRight > right) fRight = right;
337 if (fBottom > bottom) fBottom = bottom;
347 a.fLeft < b.fRight && b.fLeft < a.fRight &&
348 a.fTop < b.fBottom && b.fTop < a.fBottom;
357 return a.fLeft < b.fRight && b.fLeft < a.fRight &&
358 a.fTop < b.fBottom && b.fTop < a.fBottom;
365 void join(int32_t left, int32_t top, int32_t right, int32_t bottom);
372 this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
382 static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect() {
383 static const SkIRect gEmpty = { 0, 0, 0, 0 };
391 SkScalar fLeft, fTop, fRight, fBottom;
393 static constexpr
SkRect SK_WARN_UNUSED_RESULT MakeEmpty() {
394 return SkRect{0, 0, 0, 0};
397 static SkRect SK_WARN_UNUSED_RESULT MakeLargest() {
403 static SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) {
409 static SkRect SK_WARN_UNUSED_RESULT MakeIWH(
int w,
int h) {
411 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
415 static SkRect SK_WARN_UNUSED_RESULT MakeSize(
const SkSize& size) {
417 r.set(0, 0, size.width(), size.height());
421 static constexpr
SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
423 return SkRect {l, t, r, b};
426 static SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) {
428 r.set(x, y, x + w, y + h);
432 SK_ATTR_DEPRECATED(
"use Make()")
433 static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(
const SkIRect& irect) {
435 r.set(SkIntToScalar(irect.fLeft),
436 SkIntToScalar(irect.fTop),
437 SkIntToScalar(irect.fRight),
438 SkIntToScalar(irect.fBottom));
442 static SkRect SK_WARN_UNUSED_RESULT Make(
const SkIRect& irect) {
444 r.set(SkIntToScalar(irect.fLeft),
445 SkIntToScalar(irect.fTop),
446 SkIntToScalar(irect.fRight),
447 SkIntToScalar(irect.fBottom));
454 bool isEmpty()
const {
return fLeft >= fRight || fTop >= fBottom; }
456 bool isLargest()
const {
return SK_ScalarMin == fLeft &&
457 SK_ScalarMin == fTop &&
458 SK_ScalarMax == fRight &&
459 SK_ScalarMax == fBottom; }
473 SkASSERT(0 == accum || SkScalarIsNaN(accum));
477 return !SkScalarIsNaN(accum);
480 SkScalar x()
const {
return fLeft; }
481 SkScalar y()
const {
return fTop; }
482 SkScalar left()
const {
return fLeft; }
483 SkScalar top()
const {
return fTop; }
484 SkScalar right()
const {
return fRight; }
485 SkScalar bottom()
const {
return fBottom; }
486 SkScalar width()
const {
return fRight - fLeft; }
487 SkScalar height()
const {
return fBottom - fTop; }
488 SkScalar centerX()
const {
return SkScalarHalf(fLeft + fRight); }
489 SkScalar centerY()
const {
return SkScalarHalf(fTop + fBottom); }
491 friend bool operator==(
const SkRect& a,
const SkRect& b) {
492 return SkScalarsEqual((SkScalar*)&a, (SkScalar*)&b, 4);
495 friend bool operator!=(
const SkRect& a,
const SkRect& b) {
496 return !SkScalarsEqual((SkScalar*)&a, (SkScalar*)&b, 4);
502 void toQuad(
SkPoint quad[4])
const;
509 fLeft = SkIntToScalar(src.fLeft);
510 fTop = SkIntToScalar(src.fTop);
511 fRight = SkIntToScalar(src.fRight);
512 fBottom = SkIntToScalar(src.fBottom);
515 void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
522 void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
523 this->set(left, top, right, bottom);
529 void iset(
int left,
int top,
int right,
int bottom) {
530 fLeft = SkIntToScalar(left);
531 fTop = SkIntToScalar(top);
532 fRight = SkIntToScalar(right);
533 fBottom = SkIntToScalar(bottom);
542 fRight = SkIntToScalar(width);
543 fBottom = SkIntToScalar(height);
554 (void)this->setBoundsCheck(pts, count);
558 void setBounds(
const SkPoint pts[],
int count) {
559 (void)this->setBoundsCheck(pts, count);
567 bool setBoundsCheck(
const SkPoint pts[],
int count);
570 fLeft = SkMinScalar(p0.fX, p1.fX);
571 fRight = SkMaxScalar(p0.fX, p1.fX);
572 fTop = SkMinScalar(p0.fY, p1.fY);
573 fBottom = SkMaxScalar(p0.fY, p1.fY);
576 void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) {
580 fBottom = y + height;
583 void setWH(SkScalar width, SkScalar height) {
594 fLeft = fTop = SK_ScalarMin;
595 fRight = fBottom = SK_ScalarMax;
603 fLeft = fTop = SK_ScalarMax;
604 fRight = fBottom = SK_ScalarMin;
611 return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
618 return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
625 return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
638 void offset(
const SkPoint& delta) {
639 this->offset(delta.fX, delta.fY);
646 fRight += newX - fLeft;
647 fBottom += newY - fTop;
657 void inset(SkScalar dx, SkScalar dy) {
669 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); }
675 bool SK_WARN_UNUSED_RESULT intersect(
const SkRect& r);
682 bool SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top,
683 SkScalar right, SkScalar bottom);
690 bool SK_WARN_UNUSED_RESULT intersect(
const SkRect& a,
const SkRect& b);
694 static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab,
695 SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) {
696 SkScalar L = SkMaxScalar(al, bl);
697 SkScalar R = SkMinScalar(ar, br);
698 SkScalar T = SkMaxScalar(at, bt);
699 SkScalar B = SkMinScalar(ab, bb);
700 return L < R && T < B;
708 bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
const {
709 return Intersects(fLeft, fTop, fRight, fBottom, left, top, right, bottom);
712 bool intersects(
const SkRect& r)
const {
713 return Intersects(fLeft, fTop, fRight, fBottom,
714 r.fLeft, r.fTop, r.fRight, r.fBottom);
721 return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
722 b.fLeft, b.fTop, b.fRight, b.fBottom);
730 void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
737 this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
740 void joinNonEmptyArg(
const SkRect& r) {
743 if (fLeft >= fRight || fTop >= fBottom) {
746 this->joinPossiblyEmptyRect(r);
755 fLeft = SkMinScalar(fLeft, r.left());
756 fTop = SkMinScalar(fTop, r.top());
757 fRight = SkMaxScalar(fRight, r.right());
758 fBottom = SkMaxScalar(fBottom, r.bottom());
771 fLeft = SkMinScalar(x, fLeft);
772 fRight = SkMaxScalar(x, fRight);
773 fTop = SkMinScalar(y, fTop);
774 fBottom = SkMaxScalar(y, fBottom);
779 this->growToInclude(pts,
sizeof(
SkPoint), count);
784 SkASSERT(count >= 0);
785 SkASSERT(stride >=
sizeof(
SkPoint));
786 const SkPoint* end = (
const SkPoint*)((intptr_t)pts + count * stride);
787 for (; pts < end; pts = (
const SkPoint*)((intptr_t)pts + stride)) {
788 this->growToInclude(pts->fX, pts->fY);
798 return !r.
isEmpty() && !this->isEmpty() &&
799 fLeft <= r.fLeft && fTop <= r.fTop &&
800 fRight >= r.fRight && fBottom >= r.fBottom;
808 return !r.
isEmpty() && !this->isEmpty() &&
809 fLeft <= SkIntToScalar(r.fLeft) && fTop <= SkIntToScalar(r.fTop) &&
810 fRight >= SkIntToScalar(r.fRight) && fBottom >= SkIntToScalar(r.fBottom);
819 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
820 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
829 dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
830 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
840 dst->set(SkScalarFloorToScalar(fLeft),
841 SkScalarFloorToScalar(fTop),
842 SkScalarCeilToScalar(fRight),
843 SkScalarCeilToScalar(fBottom));
854 dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
855 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
879 if (fLeft > fRight) {
880 SkTSwap<SkScalar>(fLeft, fRight);
883 if (fTop > fBottom) {
884 SkTSwap<SkScalar>(fTop, fBottom);
893 void dump(
bool asHex)
const;
894 void dump()
const { this->dump(
false); }
895 void dumpHex()
const { this->dump(
true); }
900 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop &&
901 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom;
static bool Intersects(const SkIRect &a, const SkIRect &b)
Returns true if a and b are not empty, and they intersect.
Definition: SkRect.h:345
void growToInclude(const SkPoint pts[], int count)
Bulk version of growToInclude.
Definition: SkRect.h:778
void inset(int32_t dx, int32_t dy)
Inset the rectangle by (dx,dy).
Definition: SkRect.h:211
SkIRect makeOffset(int32_t dx, int32_t dy) const
Return a new IRect, built as an offset of this rect.
Definition: SkRect.h:165
void outset(SkScalar dx, SkScalar dy)
Outset the rectangle by (dx,dy).
Definition: SkRect.h:669
void setLargest()
Make the largest representable rectangle.
Definition: SkRect.h:593
void isetWH(int width, int height)
Set this rectangle to be left/top at 0,0, and have the specified width and height (automatically conv...
Definition: SkRect.h:540
bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect &a, const SkIRect &b)
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:311
void set(const SkPoint pts[], int count)
Set this rectangle to be the bounds of the array of points.
Definition: SkRect.h:550
void sort()
Swap top/bottom or left/right if there are flipped (i.e.
Definition: SkRect.h:878
void roundOut(SkRect *dst) const
Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloorToScalar of top and...
Definition: SkRect.h:839
bool contains(const SkRect &r) const
Return true if this rectangle contains r, and if both rectangles are not empty.
Definition: SkRect.h:796
bool containsNoEmptyCheck(int32_t left, int32_t top, int32_t right, int32_t bottom) const
Return true if this rectangle contains the specified rectangle.
Definition: SkRect.h:266
void iset(int left, int top, int right, int bottom)
Initialize the rect with the 4 specified integers.
Definition: SkRect.h:529
void offsetTo(SkScalar newX, SkScalar newY)
Offset this rect such its new x() and y() will equal newX and newY.
Definition: SkRect.h:645
Definition: SkPoint.h:156
void growToInclude(const SkPoint pts[], size_t stride, int count)
Bulk version of growToInclude with stride.
Definition: SkRect.h:783
const SkScalar * asScalars() const
cast-safe way to treat the rect as an array of (4) SkScalars.
Definition: SkRect.h:891
bool contains(const SkIRect &r) const
Returns true if the specified rectangle r is inside or equal to this rectangle.
Definition: SkRect.h:806
void setEmpty()
Set the rectangle to (0,0,0,0)
Definition: SkRect.h:125
SkRect makeInset(SkScalar dx, SkScalar dy) const
Return a new Rect, built as an inset of this rect.
Definition: SkRect.h:617
void setLargestInverted()
Make the largest representable rectangle, but inverted (e.g.
Definition: SkRect.h:602
void outset(int32_t dx, int32_t dy)
Outset the rectangle by (dx,dy).
Definition: SkRect.h:223
void inset(SkScalar dx, SkScalar dy)
Inset the rectangle by (dx,dy).
Definition: SkRect.h:657
int centerY() const
Since the center of an integer rect may fall on a factional value, this method is defined to return (...
Definition: SkRect.h:98
bool isFinite() const
Returns true iff all values in the rect are finite.
Definition: SkRect.h:465
int x() const
return the left edge of the rect
Definition: SkRect.h:65
bool contains(int32_t x, int32_t y) const
Returns true if (x,y) is inside the rectangle and the rectangle is not empty.
Definition: SkRect.h:234
void offset(SkScalar dx, SkScalar dy)
Offset set the rectangle by adding dx to its left and right, and adding dy to its top and bottom...
Definition: SkRect.h:631
int height() const
Returns the rectangle's height.
Definition: SkRect.h:78
bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
Returns true if the 4 specified sides of a rectangle are inside or equal to this rectangle.
Definition: SkRect.h:242
static bool Intersects(const SkRect &a, const SkRect &b)
Return true if rectangles a and b are not empty and intersect.
Definition: SkRect.h:720
void growToInclude(SkScalar x, SkScalar y)
Grow the rect to include the specified (x,y).
Definition: SkRect.h:770
bool isEmpty() const
Return true if the rectangle's width or height are <= 0.
Definition: SkRect.h:103
bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set th...
Definition: SkRect.h:330
static bool SkIsS16(long x)
Returns true if the value can be represented with signed 16bits.
Definition: SkTypes.h:301
static bool IntersectsNoEmptyCheck(const SkIRect &a, const SkIRect &b)
Returns true if a and b intersect.
Definition: SkRect.h:354
int centerX() const
Since the center of an integer rect may fall on a factional value, this method is defined to return (...
Definition: SkRect.h:89
SkRect makeOutset(SkScalar dx, SkScalar dy) const
Return a new Rect, built as an outset of this rect.
Definition: SkRect.h:624
SkIRect roundOut() const
Returns the result of calling roundOut(&dst)
Definition: SkRect.h:866
SkIRect round() const
Returns the result of calling round(&dst)
Definition: SkRect.h:859
void setLargest()
Make the largest representable rectangle.
Definition: SkRect.h:148
SkIRect makeOutset(int32_t dx, int32_t dy) const
Return a new Rect, built as an outset of this rect.
Definition: SkRect.h:179
void setEmpty()
Set this rectangle to the empty rectangle (0,0,0,0)
Definition: SkRect.h:506
void offset(int32_t dx, int32_t dy)
Offset set the rectangle by adding dx to its left and right, and adding dy to its top and bottom...
Definition: SkRect.h:186
void roundIn(SkIRect *dst) const
Set the dst rectangle by rounding "in" this rectangle, choosing the ceil of top and left...
Definition: SkRect.h:852
int width() const
Returns the rectangle's width.
Definition: SkRect.h:72
void roundOut(SkIRect *dst) const
Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloor of top and left...
Definition: SkRect.h:827
void offsetTo(int32_t newX, int32_t newY)
Offset this rect such its new x() and y() will equal newX and newY.
Definition: SkRect.h:200
bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
Return true if this rectangle is not empty, and the specified sides of a rectangle are not empty...
Definition: SkRect.h:708
void join(const SkIRect &r)
Update this rectangle to enclose itself and the specified rectangle.
Definition: SkRect.h:371
bool contains(const SkIRect &r) const
Returns true if the specified rectangle r is inside or equal to this rectangle.
Definition: SkRect.h:250
void round(SkIRect *dst) const
Set the dst rectangle by rounding this rectangle's coordinates to their nearest integer values using ...
Definition: SkRect.h:817
void join(const SkRect &r)
Update this rectangle to enclose itself and the specified rectangle.
Definition: SkRect.h:736
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &r)
If r intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:283
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
bool isEmpty() const
Return true if the rectangle's width or height are <= 0.
Definition: SkRect.h:454
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
int y() const
return the top edge of the rect
Definition: SkRect.h:67
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &a, const SkIRect &b)
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:291
SkRect makeOffset(SkScalar dx, SkScalar dy) const
Return a new Rect, built as an offset of this rect.
Definition: SkRect.h:610
SkIRect makeInset(int32_t dx, int32_t dy) const
Return a new IRect, built as an inset of this rect.
Definition: SkRect.h:172
void setLargestInverted()
Make the largest representable rectangle, but inverted (e.g.
Definition: SkRect.h:157
void joinPossiblyEmptyRect(const SkRect &r)
Joins the rectangle with another without checking if either are empty (may produce unexpected results...
Definition: SkRect.h:754