Skia
2D Graphics Library
SkRect.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkRect_DEFINED
9 #define SkRect_DEFINED
10 
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkScalar.h"
13 #include "include/core/SkSize.h"
14 #include "include/core/SkTypes.h"
15 #include "include/private/base/SkSafe32.h"
16 #include "include/private/base/SkTFitsIn.h"
17 
18 #include <string>
19 #include <algorithm>
20 #include <cstdint>
21 
22 struct SkRect;
23 
31 struct SK_API SkIRect {
32  int32_t fLeft;
33  int32_t fTop;
34  int32_t fRight;
35  int32_t fBottom;
36 
44  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() {
45  return SkIRect{0, 0, 0, 0};
46  }
47 
55  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
56  return SkIRect{0, 0, w, h};
57  }
58 
65  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) {
66  return SkIRect{0, 0, size.fWidth, size.fHeight};
67  }
68 
77  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakePtSize(SkIPoint pt, SkISize size) {
78  return MakeXYWH(pt.x(), pt.y(), size.width(), size.height());
79  }
80 
90  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t,
91  int32_t r, int32_t b) {
92  return SkIRect{l, t, r, b};
93  }
94 
104  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y,
105  int32_t w, int32_t h) {
106  return { x, y, Sk32_sat_add(x, w), Sk32_sat_add(y, h) };
107  }
108 
114  constexpr int32_t left() const { return fLeft; }
115 
121  constexpr int32_t top() const { return fTop; }
122 
128  constexpr int32_t right() const { return fRight; }
129 
135  constexpr int32_t bottom() const { return fBottom; }
136 
142  constexpr int32_t x() const { return fLeft; }
143 
149  constexpr int32_t y() const { return fTop; }
150 
151  // Experimental
152  constexpr SkIPoint topLeft() const { return {fLeft, fTop}; }
153 
159  constexpr int32_t width() const { return Sk32_can_overflow_sub(fRight, fLeft); }
160 
166  constexpr int32_t height() const { return Sk32_can_overflow_sub(fBottom, fTop); }
167 
173  constexpr SkISize size() const { return SkISize::Make(this->width(), this->height()); }
174 
181  constexpr int64_t width64() const { return (int64_t)fRight - (int64_t)fLeft; }
182 
189  constexpr int64_t height64() const { return (int64_t)fBottom - (int64_t)fTop; }
190 
197  bool isEmpty64() const { return fRight <= fLeft || fBottom <= fTop; }
198 
203  bool isEmpty() const {
204  int64_t w = this->width64();
205  int64_t h = this->height64();
206  if (w <= 0 || h <= 0) {
207  return true;
208  }
209  // Return true if either exceeds int32_t
210  return !SkTFitsIn<int32_t>(w | h);
211  }
212 
220  friend bool operator==(const SkIRect& a, const SkIRect& b) {
221  return a.fLeft == b.fLeft && a.fTop == b.fTop &&
222  a.fRight == b.fRight && a.fBottom == b.fBottom;
223  }
224 
232  friend bool operator!=(const SkIRect& a, const SkIRect& b) {
233  return a.fLeft != b.fLeft || a.fTop != b.fTop ||
234  a.fRight != b.fRight || a.fBottom != b.fBottom;
235  }
236 
243  void setEmpty() { memset(this, 0, sizeof(*this)); }
244 
254  void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) {
255  fLeft = left;
256  fTop = top;
257  fRight = right;
258  fBottom = bottom;
259  }
260 
269  void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) {
270  fLeft = x;
271  fTop = y;
272  fRight = Sk32_sat_add(x, width);
273  fBottom = Sk32_sat_add(y, height);
274  }
275 
276  void setWH(int32_t width, int32_t height) {
277  fLeft = 0;
278  fTop = 0;
279  fRight = width;
280  fBottom = height;
281  }
282 
283  void setSize(SkISize size) {
284  fLeft = 0;
285  fTop = 0;
286  fRight = size.width();
287  fBottom = size.height();
288  }
289 
301  constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const {
302  return {
303  Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
304  Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
305  };
306  }
307 
318  constexpr SkIRect makeOffset(SkIVector offset) const {
319  return this->makeOffset(offset.x(), offset.y());
320  }
321 
333  SkIRect makeInset(int32_t dx, int32_t dy) const {
334  return {
335  Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
336  Sk32_sat_sub(fRight, dx), Sk32_sat_sub(fBottom, dy),
337  };
338  }
339 
351  SkIRect makeOutset(int32_t dx, int32_t dy) const {
352  return {
353  Sk32_sat_sub(fLeft, dx), Sk32_sat_sub(fTop, dy),
354  Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
355  };
356  }
357 
368  void offset(int32_t dx, int32_t dy) {
369  fLeft = Sk32_sat_add(fLeft, dx);
370  fTop = Sk32_sat_add(fTop, dy);
371  fRight = Sk32_sat_add(fRight, dx);
372  fBottom = Sk32_sat_add(fBottom, dy);
373  }
374 
385  void offset(const SkIPoint& delta) {
386  this->offset(delta.fX, delta.fY);
387  }
388 
395  void offsetTo(int32_t newX, int32_t newY) {
396  fRight = Sk64_pin_to_s32((int64_t)fRight + newX - fLeft);
397  fBottom = Sk64_pin_to_s32((int64_t)fBottom + newY - fTop);
398  fLeft = newX;
399  fTop = newY;
400  }
401 
412  void inset(int32_t dx, int32_t dy) {
413  fLeft = Sk32_sat_add(fLeft, dx);
414  fTop = Sk32_sat_add(fTop, dy);
415  fRight = Sk32_sat_sub(fRight, dx);
416  fBottom = Sk32_sat_sub(fBottom, dy);
417  }
418 
429  void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
430 
447  void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) {
448  fLeft = Sk32_sat_add(fLeft, dL);
449  fTop = Sk32_sat_add(fTop, dT);
450  fRight = Sk32_sat_add(fRight, dR);
451  fBottom = Sk32_sat_add(fBottom, dB);
452  }
453 
464  bool contains(int32_t x, int32_t y) const {
465  return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
466  }
467 
476  bool contains(const SkIRect& r) const {
477  return !r.isEmpty() && !this->isEmpty() && // check for empties
478  fLeft <= r.fLeft && fTop <= r.fTop &&
479  fRight >= r.fRight && fBottom >= r.fBottom;
480  }
481 
490  inline bool contains(const SkRect& r) const;
491 
500  bool containsNoEmptyCheck(const SkIRect& r) const {
501  SkASSERT(fLeft < fRight && fTop < fBottom);
502  SkASSERT(r.fLeft < r.fRight && r.fTop < r.fBottom);
503  return fLeft <= r.fLeft && fTop <= r.fTop && fRight >= r.fRight && fBottom >= r.fBottom;
504  }
505 
514  bool intersect(const SkIRect& r) {
515  return this->intersect(*this, r);
516  }
517 
527  bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b);
528 
536  static bool Intersects(const SkIRect& a, const SkIRect& b) {
537  return SkIRect{}.intersect(a, b);
538  }
539 
548  void join(const SkIRect& r);
549 
554  void sort() {
555  using std::swap;
556  if (fLeft > fRight) {
557  swap(fLeft, fRight);
558  }
559  if (fTop > fBottom) {
560  swap(fTop, fBottom);
561  }
562  }
563 
570  SkIRect makeSorted() const {
571  return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
572  std::max(fLeft, fRight), std::max(fTop, fBottom));
573  }
574 };
575 
583 struct SK_API SkRect {
588 
596  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty() {
597  return SkRect{0, 0, 0, 0};
598  }
599 
610  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) {
611  return SkRect{0, 0, w, h};
612  }
613 
624  static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) {
625  return {0, 0, SkIntToScalar(w), SkIntToScalar(h)};
626  }
627 
634  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) {
635  return SkRect{0, 0, size.fWidth, size.fHeight};
636  }
637 
647  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
648  SkScalar b) {
649  return SkRect {l, t, r, b};
650  }
651 
661  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w,
662  SkScalar h) {
663  return SkRect {x, y, x + w, y + h};
664  }
665 
672  static SkRect Make(const SkISize& size) {
673  return MakeIWH(size.width(), size.height());
674  }
675 
683  static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) {
684  return {
685  SkIntToScalar(irect.fLeft), SkIntToScalar(irect.fTop),
687  };
688  }
689 
696  bool isEmpty() const {
697  // We write it as the NOT of a non-empty rect, so we will return true if any values
698  // are NaN.
699  return !(fLeft < fRight && fTop < fBottom);
700  }
701 
708  bool isSorted() const { return fLeft <= fRight && fTop <= fBottom; }
709 
715  bool isFinite() const {
716  float accum = 0;
717  accum *= fLeft;
718  accum *= fTop;
719  accum *= fRight;
720  accum *= fBottom;
721 
722  // accum is either NaN or it is finite (zero).
723  SkASSERT(0 == accum || SkScalarIsNaN(accum));
724 
725  // value==value will be true iff value is not NaN
726  // TODO: is it faster to say !accum or accum==accum?
727  return !SkScalarIsNaN(accum);
728  }
729 
735  constexpr SkScalar x() const { return fLeft; }
736 
742  constexpr SkScalar y() const { return fTop; }
743 
749  constexpr SkScalar left() const { return fLeft; }
750 
756  constexpr SkScalar top() const { return fTop; }
757 
763  constexpr SkScalar right() const { return fRight; }
764 
770  constexpr SkScalar bottom() const { return fBottom; }
771 
777  constexpr SkScalar width() const { return fRight - fLeft; }
778 
784  constexpr SkScalar height() const { return fBottom - fTop; }
785 
791  constexpr SkScalar centerX() const {
792  // don't use SkScalarHalf(fLeft + fBottom) as that might overflow before the 0.5
793  return SkScalarHalf(fLeft) + SkScalarHalf(fRight);
794  }
795 
801  constexpr SkScalar centerY() const {
802  // don't use SkScalarHalf(fTop + fBottom) as that might overflow before the 0.5
803  return SkScalarHalf(fTop) + SkScalarHalf(fBottom);
804  }
805 
809  constexpr SkPoint center() const { return {this->centerX(), this->centerY()}; }
810 
821  friend bool operator==(const SkRect& a, const SkRect& b) {
822  return SkScalarsEqual((const SkScalar*)&a, (const SkScalar*)&b, 4);
823  }
824 
835  friend bool operator!=(const SkRect& a, const SkRect& b) {
836  return !SkScalarsEqual((const SkScalar*)&a, (const SkScalar*)&b, 4);
837  }
838 
848  void toQuad(SkPoint quad[4]) const;
849 
856  void setEmpty() { *this = MakeEmpty(); }
857 
863  void set(const SkIRect& src) {
864  fLeft = SkIntToScalar(src.fLeft);
865  fTop = SkIntToScalar(src.fTop);
866  fRight = SkIntToScalar(src.fRight);
867  fBottom = SkIntToScalar(src.fBottom);
868  }
869 
879  void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
880  fLeft = left;
881  fTop = top;
882  fRight = right;
883  fBottom = bottom;
884  }
885 
895  void setBounds(const SkPoint pts[], int count) {
896  (void)this->setBoundsCheck(pts, count);
897  }
898 
912  bool setBoundsCheck(const SkPoint pts[], int count);
913 
922  void setBoundsNoCheck(const SkPoint pts[], int count);
923 
930  void set(const SkPoint& p0, const SkPoint& p1) {
931  fLeft = std::min(p0.fX, p1.fX);
932  fRight = std::max(p0.fX, p1.fX);
933  fTop = std::min(p0.fY, p1.fY);
934  fBottom = std::max(p0.fY, p1.fY);
935  }
936 
945  void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) {
946  fLeft = x;
947  fTop = y;
948  fRight = x + width;
949  fBottom = y + height;
950  }
951 
958  void setWH(SkScalar width, SkScalar height) {
959  fLeft = 0;
960  fTop = 0;
961  fRight = width;
962  fBottom = height;
963  }
964  void setIWH(int32_t width, int32_t height) {
965  this->setWH(SkIntToScalar(width), SkIntToScalar(height));
966  }
967 
979  constexpr SkRect makeOffset(SkScalar dx, SkScalar dy) const {
980  return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
981  }
982 
988  constexpr SkRect makeOffset(SkVector v) const { return this->makeOffset(v.x(), v.y()); }
989 
1002  return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
1003  }
1004 
1017  return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
1018  }
1019 
1030  void offset(SkScalar dx, SkScalar dy) {
1031  fLeft += dx;
1032  fTop += dy;
1033  fRight += dx;
1034  fBottom += dy;
1035  }
1036 
1047  void offset(const SkPoint& delta) {
1048  this->offset(delta.fX, delta.fY);
1049  }
1050 
1057  void offsetTo(SkScalar newX, SkScalar newY) {
1058  fRight += newX - fLeft;
1059  fBottom += newY - fTop;
1060  fLeft = newX;
1061  fTop = newY;
1062  }
1063 
1074  void inset(SkScalar dx, SkScalar dy) {
1075  fLeft += dx;
1076  fTop += dy;
1077  fRight -= dx;
1078  fBottom -= dy;
1079  }
1080 
1091  void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); }
1092 
1103  bool intersect(const SkRect& r);
1104 
1114  bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b);
1115 
1116 
1117 private:
1118  static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab,
1119  SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) {
1120  SkScalar L = std::max(al, bl);
1121  SkScalar R = std::min(ar, br);
1122  SkScalar T = std::max(at, bt);
1123  SkScalar B = std::min(ab, bb);
1124  return L < R && T < B;
1125  }
1126 
1127 public:
1128 
1135  bool intersects(const SkRect& r) const {
1136  return Intersects(fLeft, fTop, fRight, fBottom,
1137  r.fLeft, r.fTop, r.fRight, r.fBottom);
1138  }
1139 
1147  static bool Intersects(const SkRect& a, const SkRect& b) {
1148  return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
1149  b.fLeft, b.fTop, b.fRight, b.fBottom);
1150  }
1151 
1161  void join(const SkRect& r);
1162 
1172  void joinNonEmptyArg(const SkRect& r) {
1173  SkASSERT(!r.isEmpty());
1174  // if we are empty, just assign
1175  if (fLeft >= fRight || fTop >= fBottom) {
1176  *this = r;
1177  } else {
1178  this->joinPossiblyEmptyRect(r);
1179  }
1180  }
1181 
1189  fLeft = std::min(fLeft, r.left());
1190  fTop = std::min(fTop, r.top());
1191  fRight = std::max(fRight, r.right());
1192  fBottom = std::max(fBottom, r.bottom());
1193  }
1194 
1202  bool contains(SkScalar x, SkScalar y) const {
1203  return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
1204  }
1205 
1214  bool contains(const SkRect& r) const {
1215  // todo: can we eliminate the this->isEmpty check?
1216  return !r.isEmpty() && !this->isEmpty() &&
1217  fLeft <= r.fLeft && fTop <= r.fTop &&
1218  fRight >= r.fRight && fBottom >= r.fBottom;
1219  }
1220 
1229  bool contains(const SkIRect& r) const {
1230  // todo: can we eliminate the this->isEmpty check?
1231  return !r.isEmpty() && !this->isEmpty() &&
1232  fLeft <= SkIntToScalar(r.fLeft) && fTop <= SkIntToScalar(r.fTop) &&
1233  fRight >= SkIntToScalar(r.fRight) && fBottom >= SkIntToScalar(r.fBottom);
1234  }
1235 
1242  void round(SkIRect* dst) const {
1243  SkASSERT(dst);
1244  dst->setLTRB(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1245  SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
1246  }
1247 
1255  void roundOut(SkIRect* dst) const {
1256  SkASSERT(dst);
1257  dst->setLTRB(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1258  SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
1259  }
1260 
1268  void roundOut(SkRect* dst) const {
1270  SkScalarCeilToScalar(fRight), SkScalarCeilToScalar(fBottom));
1271  }
1272 
1280  void roundIn(SkIRect* dst) const {
1281  SkASSERT(dst);
1282  dst->setLTRB(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1283  SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
1284  }
1285 
1292  SkIRect round() const {
1293  SkIRect ir;
1294  this->round(&ir);
1295  return ir;
1296  }
1297 
1305  SkIRect roundOut() const {
1306  SkIRect ir;
1307  this->roundOut(&ir);
1308  return ir;
1309  }
1317  SkIRect roundIn() const {
1318  SkIRect ir;
1319  this->roundIn(&ir);
1320  return ir;
1321  }
1322 
1327  void sort() {
1328  using std::swap;
1329  if (fLeft > fRight) {
1330  swap(fLeft, fRight);
1331  }
1332 
1333  if (fTop > fBottom) {
1334  swap(fTop, fBottom);
1335  }
1336  }
1337 
1344  SkRect makeSorted() const {
1345  return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
1346  std::max(fLeft, fRight), std::max(fTop, fBottom));
1347  }
1348 
1354  const SkScalar* asScalars() const { return &fLeft; }
1355 
1363  void dump(bool asHex) const;
1364 
1370  void dump() const { this->dump(false); }
1371 
1379  void dumpHex() const { this->dump(true); }
1380 };
1381 
1382 inline bool SkIRect::contains(const SkRect& r) const {
1383  return !r.isEmpty() && !this->isEmpty() && // check for empties
1384  (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop &&
1385  (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom;
1386 }
1387 
1388 #endif
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:340
#define SkScalarFloorToScalar(x)
Definition: SkScalar.h:31
#define SkScalarHalf(a)
Definition: SkScalar.h:90
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:38
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:37
#define SkIntToScalar(x)
Definition: SkScalar.h:58
static bool SkScalarIsNaN(SkScalar x)
Definition: SkScalar.h:67
#define SkScalarFloorToInt(x)
Definition: SkScalar.h:36
float SkScalar
Definition: SkScalar.h:17
#define SkScalarCeilToScalar(x)
Definition: SkScalar.h:32
static bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
Definition: SkScalar.h:166
SkIPoint holds two 32-bit integer coordinates.
Definition: SkPoint.h:27
constexpr int32_t y() const
Returns y-axis value of SkIPoint.
Definition: SkPoint.h:51
int32_t fX
x-axis value
Definition: SkPoint.h:28
int32_t fY
y-axis value
Definition: SkPoint.h:29
constexpr int32_t x() const
Returns x-axis value of SkIPoint.
Definition: SkPoint.h:45
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:31
constexpr int64_t height64() const
Returns span on the y-axis.
Definition: SkRect.h:189
void sort()
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater...
Definition: SkRect.h:554
constexpr int32_t x() const
Returns left edge of SkIRect, if sorted.
Definition: SkRect.h:142
friend 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 correspond...
Definition: SkRect.h:232
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.
Definition: SkRect.h:447
SkIRect makeOutset(int32_t dx, int32_t dy) const
Returns SkIRect, outset by (dx, dy).
Definition: SkRect.h:351
void inset(int32_t dx, int32_t dy)
Insets SkIRect by (dx,dy).
Definition: SkRect.h:412
bool isEmpty64() const
Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBot...
Definition: SkRect.h:197
bool contains(const SkIRect &r) const
Returns true if SkIRect contains r.
Definition: SkRect.h:476
constexpr int32_t y() const
Returns top edge of SkIRect, if sorted.
Definition: SkRect.h:149
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Returns constructed SkIRect set to (l, t, r, b).
Definition: SkRect.h:90
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakePtSize(SkIPoint pt, SkISize size)
Returns constructed SkIRect set to (pt.x(), pt.y(), pt.x() + size.width(), pt.y() + size....
Definition: SkRect.h:77
void offset(const SkIPoint &delta)
Offsets SkIRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop,...
Definition: SkRect.h:385
bool intersect(const SkIRect &r)
Returns true if SkIRect intersects r, and sets SkIRect to intersection.
Definition: SkRect.h:514
static bool Intersects(const SkIRect &a, const SkIRect &b)
Returns true if a intersects b.
Definition: SkRect.h:536
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:35
constexpr int32_t top() const
Returns top edge of SkIRect, if sorted.
Definition: SkRect.h:121
void offsetTo(int32_t newX, int32_t newY)
Offsets SkIRect so that fLeft equals newX, and fTop equals newY.
Definition: SkRect.h:395
bool containsNoEmptyCheck(const SkIRect &r) const
Returns true if SkIRect contains construction.
Definition: SkRect.h:500
constexpr SkISize size() const
Returns spans on the x-axis and y-axis.
Definition: SkRect.h:173
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Returns constructed SkIRect set to: (x, y, x + w, y + h).
Definition: SkRect.h:104
constexpr int32_t bottom() const
Returns bottom edge of SkIRect, if sorted.
Definition: SkRect.h:135
constexpr int32_t height() const
Returns span on the y-axis.
Definition: SkRect.h:166
constexpr int32_t right() const
Returns right edge of SkIRect, if sorted.
Definition: SkRect.h:128
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:33
void join(const SkIRect &r)
Sets SkIRect to the union of itself and r.
constexpr SkIRect makeOffset(SkIVector offset) const
Returns SkIRect offset by (offset.x(), offset.y()).
Definition: SkRect.h:318
constexpr int32_t width() const
Returns span on the x-axis.
Definition: SkRect.h:159
friend bool operator==(const SkIRect &a, const SkIRect &b)
Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are identical to corresponding me...
Definition: SkRect.h:220
constexpr int64_t width64() const
Returns span on the x-axis.
Definition: SkRect.h:181
void offset(int32_t dx, int32_t dy)
Offsets SkIRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Definition: SkRect.h:368
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize &size)
Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:65
void setEmpty()
Sets SkIRect to (0, 0, 0, 0).
Definition: SkRect.h:243
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const
Returns SkIRect offset by (dx, dy).
Definition: SkRect.h:301
bool isEmpty() const
Returns true if width() or height() are zero or negative.
Definition: SkRect.h:203
void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
Sets SkIRect to: (x, y, x + width, y + height).
Definition: SkRect.h:269
constexpr SkIPoint topLeft() const
Definition: SkRect.h:152
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h)
Returns constructed SkIRect set to (0, 0, w, h).
Definition: SkRect.h:55
void setWH(int32_t width, int32_t height)
Definition: SkRect.h:276
SkIRect makeInset(int32_t dx, int32_t dy) const
Returns SkIRect, inset by (dx, dy).
Definition: SkRect.h:333
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty()
Returns constructed SkIRect set to (0, 0, 0, 0).
Definition: SkRect.h:44
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:32
SkIRect makeSorted() const
Returns SkIRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBot...
Definition: SkRect.h:570
void outset(int32_t dx, int32_t dy)
Outsets SkIRect by (dx, dy).
Definition: SkRect.h:429
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &a, const SkIRect &b)
Returns true if a intersects b, and sets SkIRect to intersection.
constexpr int32_t left() const
Returns left edge of SkIRect, if sorted.
Definition: SkRect.h:114
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
Sets SkIRect to (left, top, right, bottom).
Definition: SkRect.h:254
bool contains(int32_t x, int32_t y) const
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
Definition: SkRect.h:464
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:34
void setSize(SkISize size)
Definition: SkRect.h:283
Definition: SkSize.h:15
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:19
int32_t fHeight
Definition: SkSize.h:17
int32_t fWidth
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:35
constexpr int32_t height() const
Definition: SkSize.h:36
SkPoint holds two 32-bit floating point coordinates.
Definition: SkPoint.h:162
SkScalar fX
x-axis value
Definition: SkPoint.h:163
constexpr SkScalar y() const
Returns y-axis value of SkPoint or vector.
Definition: SkPoint.h:186
SkScalar fY
y-axis value
Definition: SkPoint.h:164
constexpr SkScalar x() const
Returns x-axis value of SkPoint or vector.
Definition: SkPoint.h:180
SkRect holds four SkScalar coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:583
constexpr SkRect makeOffset(SkVector v) const
Returns SkRect offset by v.
Definition: SkRect.h:988
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
Returns constructed SkRect set to (0, 0, 0, 0).
Definition: SkRect.h:596
SkRect makeSorted() const
Returns SkRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBott...
Definition: SkRect.h:1344
constexpr SkScalar centerY() const
Returns average of top edge and bottom edge.
Definition: SkRect.h:801
static SkRect Make(const SkISize &size)
Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:672
bool SK_WARN_UNUSED_RESULT intersect(const SkRect &a, const SkRect &b)
Returns true if a intersects b, and sets SkRect to intersection.
void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
Sets SkRect to (left, top, right, bottom).
Definition: SkRect.h:879
static bool Intersects(const SkRect &a, const SkRect &b)
Returns true if a intersects b.
Definition: SkRect.h:1147
SkScalar fBottom
larger y-axis bounds
Definition: SkRect.h:587
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize &size)
Returns constructed SkRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:634
void toQuad(SkPoint quad[4]) const
Returns four points in quad that enclose SkRect ordered as: top-left, top-right, bottom-right,...
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Returns constructed SkRect set to SkScalar values (0, 0, w, h).
Definition: SkRect.h:610
void joinNonEmptyArg(const SkRect &r)
Sets SkRect to the union of itself and r.
Definition: SkRect.h:1172
void outset(SkScalar dx, SkScalar dy)
Outsets SkRect by (dx, dy).
Definition: SkRect.h:1091
void offset(const SkPoint &delta)
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop,...
Definition: SkRect.h:1047
static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
Returns constructed SkRect set to integer values (0, 0, w, h).
Definition: SkRect.h:624
void setWH(SkScalar width, SkScalar height)
Sets SkRect to (0, 0, width, height).
Definition: SkRect.h:958
constexpr SkScalar x() const
Returns left edge of SkRect, if sorted.
Definition: SkRect.h:735
friend 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 me...
Definition: SkRect.h:821
bool isFinite() const
Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, and SK_ScalarMax or s...
Definition: SkRect.h:715
void joinPossiblyEmptyRect(const SkRect &r)
Sets SkRect to the union of itself and the construction.
Definition: SkRect.h:1188
void roundIn(SkIRect *dst) const
Sets SkRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBotto...
Definition: SkRect.h:1280
constexpr SkScalar bottom() const
Returns bottom edge of SkRect, if sorted.
Definition: SkRect.h:770
bool intersect(const SkRect &r)
Returns true if SkRect intersects r, and sets SkRect to intersection.
SkScalar fLeft
smaller x-axis bounds
Definition: SkRect.h:584
constexpr SkScalar centerX() const
Returns average of left edge and right edge.
Definition: SkRect.h:791
void roundOut(SkRect *dst) const
Sets SkRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBotto...
Definition: SkRect.h:1268
void offset(SkScalar dx, SkScalar dy)
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Definition: SkRect.h:1030
bool contains(const SkRect &r) const
Returns true if SkRect contains r.
Definition: SkRect.h:1214
bool intersects(const SkRect &r) const
Returns true if SkRect intersects r.
Definition: SkRect.h:1135
void set(const SkPoint &p0, const SkPoint &p1)
Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1.
Definition: SkRect.h:930
bool contains(const SkIRect &r) const
Returns true if SkRect contains r.
Definition: SkRect.h:1229
SkScalar fRight
larger x-axis bounds
Definition: SkRect.h:586
constexpr SkRect makeOffset(SkScalar dx, SkScalar dy) const
Returns SkRect offset by (dx, dy).
Definition: SkRect.h:979
SkIRect roundOut() const
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBott...
Definition: SkRect.h:1305
bool contains(SkScalar x, SkScalar y) const
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
Definition: SkRect.h:1202
void roundOut(SkIRect *dst) const
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBott...
Definition: SkRect.h:1255
void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
Sets SkRect to (x, y, x + width, y + height).
Definition: SkRect.h:945
SkIRect roundIn() const
Sets SkIRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBott...
Definition: SkRect.h:1317
void round(SkIRect *dst) const
Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect members,...
Definition: SkRect.h:1242
const SkScalar * asScalars() const
Returns pointer to first scalar in SkRect, to treat it as an array with four entries.
Definition: SkRect.h:1354
constexpr SkScalar top() const
Returns top edge of SkRect, if sorted.
Definition: SkRect.h:756
constexpr SkScalar right() const
Returns right edge of SkRect, if sorted.
Definition: SkRect.h:763
SkRect makeOutset(SkScalar dx, SkScalar dy) const
Returns SkRect, outset by (dx, dy).
Definition: SkRect.h:1016
constexpr SkScalar left() const
Returns left edge of SkRect, if sorted.
Definition: SkRect.h:749
bool setBoundsCheck(const SkPoint pts[], int count)
Sets to bounds of SkPoint array with count entries.
SkIRect round() const
Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect members,...
Definition: SkRect.h:1292
void setIWH(int32_t width, int32_t height)
Definition: SkRect.h:964
constexpr SkScalar width() const
Returns span on the x-axis.
Definition: SkRect.h:777
void setBounds(const SkPoint pts[], int count)
Sets to bounds of SkPoint array with count entries.
Definition: SkRect.h:895
SkRect makeInset(SkScalar dx, SkScalar dy) const
Returns SkRect, inset by (dx, dy).
Definition: SkRect.h:1001
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r, SkScalar b)
Returns constructed SkRect set to (l, t, r, b).
Definition: SkRect.h:647
bool isEmpty() const
Returns true if fLeft is equal to or greater than fRight, or if fTop is equal to or greater than fBot...
Definition: SkRect.h:696
void join(const SkRect &r)
Sets SkRect to the union of itself and r.
constexpr SkScalar height() const
Returns span on the y-axis.
Definition: SkRect.h:784
void sort()
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater...
Definition: SkRect.h:1327
constexpr SkPoint center() const
Returns the point this->centerX(), this->centerY().
Definition: SkRect.h:809
void dump() const
Writes text representation of SkRect to standard output.
Definition: SkRect.h:1370
void dumpHex() const
Writes text representation of SkRect to standard output.
Definition: SkRect.h:1379
void setBoundsNoCheck(const SkPoint pts[], int count)
Sets to bounds of SkPoint pts array with count entries.
constexpr SkScalar y() const
Returns top edge of SkRect, if sorted.
Definition: SkRect.h:742
void inset(SkScalar dx, SkScalar dy)
Insets SkRect by (dx, dy).
Definition: SkRect.h:1074
friend 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 ...
Definition: SkRect.h:835
static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect &irect)
Returns constructed SkIRect set to irect, promoting integers to scalar.
Definition: SkRect.h:683
void offsetTo(SkScalar newX, SkScalar newY)
Offsets SkRect so that fLeft equals newX, and fTop equals newY.
Definition: SkRect.h:1057
bool isSorted() const
Returns true if fLeft is equal to or less than fRight, or if fTop is equal to or less than fBottom.
Definition: SkRect.h:708
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Returns constructed SkRect set to (x, y, x + w, y + h).
Definition: SkRect.h:661
void set(const SkIRect &src)
Sets SkRect to src, promoting src members from integer to scalar.
Definition: SkRect.h:863
void dump(bool asHex) const
Writes text representation of SkRect to standard output.
SkScalar fTop
smaller y-axis bounds
Definition: SkRect.h:585
void setEmpty()
Sets SkRect to (0, 0, 0, 0).
Definition: SkRect.h:856
Definition: SkSize.h:51
SkScalar fHeight
Definition: SkSize.h:53
SkScalar fWidth
Definition: SkSize.h:52