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/SkSize.h"
13 #include "include/private/SkSafe32.h"
14 #include "include/private/SkTFitsIn.h"
15 
16 #include <algorithm>
17 #include <utility>
18 
19 struct SkRect;
20 
28 struct SK_API SkIRect {
29  int32_t fLeft;
30  int32_t fTop;
31  int32_t fRight;
32  int32_t fBottom;
33 
42  return SkIRect{0, 0, 0, 0};
43  }
44 
52  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
53  return SkIRect{0, 0, w, h};
54  }
55 
62  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) {
63  return SkIRect{0, 0, size.fWidth, size.fHeight};
64  }
65 
75  return MakeXYWH(pt.x(), pt.y(), size.width(), size.height());
76  }
77 
87  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t,
88  int32_t r, int32_t b) {
89  return SkIRect{l, t, r, b};
90  }
91 
101  static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y,
102  int32_t w, int32_t h) {
103  return { x, y, Sk32_sat_add(x, w), Sk32_sat_add(y, h) };
104  }
105 
111  int32_t left() const { return fLeft; }
112 
118  int32_t top() const { return fTop; }
119 
125  int32_t right() const { return fRight; }
126 
132  int32_t bottom() const { return fBottom; }
133 
139  int32_t x() const { return fLeft; }
140 
146  int32_t y() const { return fTop; }
147 
148  // Experimental
149  SkIPoint topLeft() const { return {fLeft, fTop}; }
150 
156  int32_t width() const { return Sk32_can_overflow_sub(fRight, fLeft); }
157 
163  int32_t height() const { return Sk32_can_overflow_sub(fBottom, fTop); }
164 
170  SkISize size() const { return SkISize::Make(this->width(), this->height()); }
171 
178  int64_t width64() const { return (int64_t)fRight - (int64_t)fLeft; }
179 
186  int64_t height64() const { return (int64_t)fBottom - (int64_t)fTop; }
187 
194  bool isEmpty64() const { return fRight <= fLeft || fBottom <= fTop; }
195 
200  bool isEmpty() const {
201  int64_t w = this->width64();
202  int64_t h = this->height64();
203  if (w <= 0 || h <= 0) {
204  return true;
205  }
206  // Return true if either exceeds int32_t
207  return !SkTFitsIn<int32_t>(w | h);
208  }
209 
217  friend bool operator==(const SkIRect& a, const SkIRect& b) {
218  return !memcmp(&a, &b, sizeof(a));
219  }
220 
228  friend bool operator!=(const SkIRect& a, const SkIRect& b) {
229  return !(a == b);
230  }
231 
238  void setEmpty() { memset(this, 0, sizeof(*this)); }
239 
249  void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) {
250  fLeft = left;
251  fTop = top;
252  fRight = right;
253  fBottom = bottom;
254  }
255 
264  void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) {
265  fLeft = x;
266  fTop = y;
267  fRight = Sk32_sat_add(x, width);
268  fBottom = Sk32_sat_add(y, height);
269  }
270 
271  void setWH(int32_t width, int32_t height) {
272  fLeft = 0;
273  fTop = 0;
274  fRight = width;
275  fBottom = height;
276  }
277 
289  constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const {
290  return {
291  Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
292  Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
293  };
294  }
295 
306  constexpr SkIRect makeOffset(SkIVector offset) const {
307  return this->makeOffset(offset.x(), offset.y());
308  }
309 
321  SkIRect makeInset(int32_t dx, int32_t dy) const {
322  return {
323  Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
324  Sk32_sat_sub(fRight, dx), Sk32_sat_sub(fBottom, dy),
325  };
326  }
327 
339  SkIRect makeOutset(int32_t dx, int32_t dy) const {
340  return {
341  Sk32_sat_sub(fLeft, dx), Sk32_sat_sub(fTop, dy),
342  Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
343  };
344  }
345 
356  void offset(int32_t dx, int32_t dy) {
357  fLeft = Sk32_sat_add(fLeft, dx);
358  fTop = Sk32_sat_add(fTop, dy);
359  fRight = Sk32_sat_add(fRight, dx);
360  fBottom = Sk32_sat_add(fBottom, dy);
361  }
362 
373  void offset(const SkIPoint& delta) {
374  this->offset(delta.fX, delta.fY);
375  }
376 
383  void offsetTo(int32_t newX, int32_t newY) {
384  fRight = Sk64_pin_to_s32((int64_t)fRight + newX - fLeft);
385  fBottom = Sk64_pin_to_s32((int64_t)fBottom + newY - fTop);
386  fLeft = newX;
387  fTop = newY;
388  }
389 
400  void inset(int32_t dx, int32_t dy) {
401  fLeft = Sk32_sat_add(fLeft, dx);
402  fTop = Sk32_sat_add(fTop, dy);
403  fRight = Sk32_sat_sub(fRight, dx);
404  fBottom = Sk32_sat_sub(fBottom, dy);
405  }
406 
417  void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
418 
435  void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) {
436  fLeft = Sk32_sat_add(fLeft, dL);
437  fTop = Sk32_sat_add(fTop, dT);
438  fRight = Sk32_sat_add(fRight, dR);
439  fBottom = Sk32_sat_add(fBottom, dB);
440  }
441 
452  bool contains(int32_t x, int32_t y) const {
453  return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
454  }
455 
464  bool contains(const SkIRect& r) const {
465  return !r.isEmpty() && !this->isEmpty() && // check for empties
466  fLeft <= r.fLeft && fTop <= r.fTop &&
467  fRight >= r.fRight && fBottom >= r.fBottom;
468  }
469 
478  inline bool contains(const SkRect& r) const;
479 
488  bool containsNoEmptyCheck(const SkIRect& r) const {
489  SkASSERT(fLeft < fRight && fTop < fBottom);
490  SkASSERT(r.fLeft < r.fRight && r.fTop < r.fBottom);
491  return fLeft <= r.fLeft && fTop <= r.fTop && fRight >= r.fRight && fBottom >= r.fBottom;
492  }
493 
502  bool intersect(const SkIRect& r) {
503  return this->intersect(*this, r);
504  }
505 
515  bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b);
516 
524  static bool Intersects(const SkIRect& a, const SkIRect& b) {
525  SkIRect dummy;
526  return dummy.intersect(a, b);
527  }
528 
537  void join(const SkIRect& r);
538 
543  void sort() {
544  using std::swap;
545  if (fLeft > fRight) {
546  swap(fLeft, fRight);
547  }
548  if (fTop > fBottom) {
549  swap(fTop, fBottom);
550  }
551  }
552 
559  SkIRect makeSorted() const {
560  return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
561  std::max(fLeft, fRight), std::max(fTop, fBottom));
562  }
563 };
564 
572 struct SK_API SkRect {
577 
586  return SkRect{0, 0, 0, 0};
587  }
588 
600  return SkRect{0, 0, w, h};
601  }
602 
613  static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) {
614  return {0, 0, SkIntToScalar(w), SkIntToScalar(h)};
615  }
616 
623  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) {
624  return SkRect{0, 0, size.fWidth, size.fHeight};
625  }
626 
637  SkScalar b) {
638  return SkRect {l, t, r, b};
639  }
640 
651  SkScalar h) {
652  return SkRect {x, y, x + w, y + h};
653  }
654 
661  static SkRect Make(const SkISize& size) {
662  return MakeIWH(size.width(), size.height());
663  }
664 
672  static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) {
673  return {
674  SkIntToScalar(irect.fLeft), SkIntToScalar(irect.fTop),
676  };
677  }
678 
685  bool isEmpty() const {
686  // We write it as the NOT of a non-empty rect, so we will return true if any values
687  // are NaN.
688  return !(fLeft < fRight && fTop < fBottom);
689  }
690 
697  bool isSorted() const { return fLeft <= fRight && fTop <= fBottom; }
698 
704  bool isFinite() const {
705  float accum = 0;
706  accum *= fLeft;
707  accum *= fTop;
708  accum *= fRight;
709  accum *= fBottom;
710 
711  // accum is either NaN or it is finite (zero).
712  SkASSERT(0 == accum || SkScalarIsNaN(accum));
713 
714  // value==value will be true iff value is not NaN
715  // TODO: is it faster to say !accum or accum==accum?
716  return !SkScalarIsNaN(accum);
717  }
718 
724  SkScalar x() const { return fLeft; }
725 
731  SkScalar y() const { return fTop; }
732 
738  SkScalar left() const { return fLeft; }
739 
745  SkScalar top() const { return fTop; }
746 
752  SkScalar right() const { return fRight; }
753 
759  SkScalar bottom() const { return fBottom; }
760 
766  SkScalar width() const { return fRight - fLeft; }
767 
773  SkScalar height() const { return fBottom - fTop; }
774 
780  SkScalar centerX() const {
781  // don't use SkScalarHalf(fLeft + fBottom) as that might overflow before the 0.5
782  return SkScalarHalf(fLeft) + SkScalarHalf(fRight);
783  }
784 
790  SkScalar centerY() const {
791  // don't use SkScalarHalf(fTop + fBottom) as that might overflow before the 0.5
792  return SkScalarHalf(fTop) + SkScalarHalf(fBottom);
793  }
794 
805  friend bool operator==(const SkRect& a, const SkRect& b) {
806  return SkScalarsEqual((const SkScalar*)&a, (const SkScalar*)&b, 4);
807  }
808 
819  friend bool operator!=(const SkRect& a, const SkRect& b) {
820  return !SkScalarsEqual((const SkScalar*)&a, (const SkScalar*)&b, 4);
821  }
822 
832  void toQuad(SkPoint quad[4]) const;
833 
840  void setEmpty() { *this = MakeEmpty(); }
841 
847  void set(const SkIRect& src) {
848  fLeft = SkIntToScalar(src.fLeft);
849  fTop = SkIntToScalar(src.fTop);
850  fRight = SkIntToScalar(src.fRight);
851  fBottom = SkIntToScalar(src.fBottom);
852  }
853 
863  void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
864  fLeft = left;
865  fTop = top;
866  fRight = right;
867  fBottom = bottom;
868  }
869 
879  void setBounds(const SkPoint pts[], int count) {
880  (void)this->setBoundsCheck(pts, count);
881  }
882 
896  bool setBoundsCheck(const SkPoint pts[], int count);
897 
906  void setBoundsNoCheck(const SkPoint pts[], int count);
907 
914  void set(const SkPoint& p0, const SkPoint& p1) {
915  fLeft = std::min(p0.fX, p1.fX);
916  fRight = std::max(p0.fX, p1.fX);
917  fTop = std::min(p0.fY, p1.fY);
918  fBottom = std::max(p0.fY, p1.fY);
919  }
920 
929  void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) {
930  fLeft = x;
931  fTop = y;
932  fRight = x + width;
933  fBottom = y + height;
934  }
935 
942  void setWH(SkScalar width, SkScalar height) {
943  fLeft = 0;
944  fTop = 0;
945  fRight = width;
946  fBottom = height;
947  }
948  void setIWH(int32_t width, int32_t height) {
949  this->setWH(SkIntToScalar(width), SkIntToScalar(height));
950  }
951 
963  constexpr SkRect makeOffset(SkScalar dx, SkScalar dy) const {
964  return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
965  }
966 
972  constexpr SkRect makeOffset(SkVector v) const { return this->makeOffset(v.x(), v.y()); }
973 
986  return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
987  }
988 
1001  return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
1002  }
1003 
1014  void offset(SkScalar dx, SkScalar dy) {
1015  fLeft += dx;
1016  fTop += dy;
1017  fRight += dx;
1018  fBottom += dy;
1019  }
1020 
1031  void offset(const SkPoint& delta) {
1032  this->offset(delta.fX, delta.fY);
1033  }
1034 
1041  void offsetTo(SkScalar newX, SkScalar newY) {
1042  fRight += newX - fLeft;
1043  fBottom += newY - fTop;
1044  fLeft = newX;
1045  fTop = newY;
1046  }
1047 
1058  void inset(SkScalar dx, SkScalar dy) {
1059  fLeft += dx;
1060  fTop += dy;
1061  fRight -= dx;
1062  fBottom -= dy;
1063  }
1064 
1075  void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); }
1076 
1087  bool intersect(const SkRect& r);
1088 
1098  bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b);
1099 
1100 
1101 private:
1102  static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab,
1103  SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) {
1104  SkScalar L = std::max(al, bl);
1105  SkScalar R = std::min(ar, br);
1106  SkScalar T = std::max(at, bt);
1107  SkScalar B = std::min(ab, bb);
1108  return L < R && T < B;
1109  }
1110 
1111 public:
1112 
1119  bool intersects(const SkRect& r) const {
1120  return Intersects(fLeft, fTop, fRight, fBottom,
1121  r.fLeft, r.fTop, r.fRight, r.fBottom);
1122  }
1123 
1131  static bool Intersects(const SkRect& a, const SkRect& b) {
1132  return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
1133  b.fLeft, b.fTop, b.fRight, b.fBottom);
1134  }
1135 
1145  void join(const SkRect& r);
1146 
1156  void joinNonEmptyArg(const SkRect& r) {
1157  SkASSERT(!r.isEmpty());
1158  // if we are empty, just assign
1159  if (fLeft >= fRight || fTop >= fBottom) {
1160  *this = r;
1161  } else {
1162  this->joinPossiblyEmptyRect(r);
1163  }
1164  }
1165 
1173  fLeft = std::min(fLeft, r.left());
1174  fTop = std::min(fTop, r.top());
1175  fRight = std::max(fRight, r.right());
1176  fBottom = std::max(fBottom, r.bottom());
1177  }
1178 
1186  bool contains(SkScalar x, SkScalar y) const {
1187  return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
1188  }
1189 
1198  bool contains(const SkRect& r) const {
1199  // todo: can we eliminate the this->isEmpty check?
1200  return !r.isEmpty() && !this->isEmpty() &&
1201  fLeft <= r.fLeft && fTop <= r.fTop &&
1202  fRight >= r.fRight && fBottom >= r.fBottom;
1203  }
1204 
1213  bool contains(const SkIRect& r) const {
1214  // todo: can we eliminate the this->isEmpty check?
1215  return !r.isEmpty() && !this->isEmpty() &&
1216  fLeft <= SkIntToScalar(r.fLeft) && fTop <= SkIntToScalar(r.fTop) &&
1217  fRight >= SkIntToScalar(r.fRight) && fBottom >= SkIntToScalar(r.fBottom);
1218  }
1219 
1226  void round(SkIRect* dst) const {
1227  SkASSERT(dst);
1228  dst->setLTRB(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1229  SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
1230  }
1231 
1239  void roundOut(SkIRect* dst) const {
1240  SkASSERT(dst);
1241  dst->setLTRB(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1242  SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
1243  }
1244 
1252  void roundOut(SkRect* dst) const {
1254  SkScalarCeilToScalar(fRight), SkScalarCeilToScalar(fBottom));
1255  }
1256 
1264  void roundIn(SkIRect* dst) const {
1265  SkASSERT(dst);
1266  dst->setLTRB(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1267  SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
1268  }
1269 
1276  SkIRect round() const {
1277  SkIRect ir;
1278  this->round(&ir);
1279  return ir;
1280  }
1281 
1289  SkIRect roundOut() const {
1290  SkIRect ir;
1291  this->roundOut(&ir);
1292  return ir;
1293  }
1294 
1299  void sort() {
1300  using std::swap;
1301  if (fLeft > fRight) {
1302  swap(fLeft, fRight);
1303  }
1304 
1305  if (fTop > fBottom) {
1306  swap(fTop, fBottom);
1307  }
1308  }
1309 
1316  SkRect makeSorted() const {
1317  return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
1318  std::max(fLeft, fRight), std::max(fTop, fBottom));
1319  }
1320 
1326  const SkScalar* asScalars() const { return &fLeft; }
1327 
1335  void dump(bool asHex) const;
1336 
1342  void dump() const { this->dump(false); }
1343 
1351  void dumpHex() const { this->dump(true); }
1352 };
1353 
1354 inline bool SkIRect::contains(const SkRect& r) const {
1355  return !r.isEmpty() && !this->isEmpty() && // check for empties
1356  (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop &&
1357  (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom;
1358 }
1359 
1360 #endif
SkRect::left
SkScalar left() const
Returns left edge of SkRect, if sorted.
Definition: SkRect.h:738
SkRect::fBottom
SkScalar fBottom
larger y-axis bounds
Definition: SkRect.h:576
SkRect::setBoundsCheck
bool setBoundsCheck(const SkPoint pts[], int count)
Sets to bounds of SkPoint array with count entries.
SkRect::setWH
void setWH(SkScalar width, SkScalar height)
Sets SkRect to (0, 0, width, height).
Definition: SkRect.h:942
SkRect::round
void round(SkIRect *dst) const
Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect members,...
Definition: SkRect.h:1226
SkIPoint::fX
int32_t fX
x-axis value
Definition: SkPoint.h:26
SkRect::setLTRB
void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
Sets SkRect to (left, top, right, bottom).
Definition: SkRect.h:863
SkSize.h
SkRect::fRight
SkScalar fRight
larger x-axis bounds
Definition: SkRect.h:575
SkScalarIsNaN
static bool SkScalarIsNaN(SkScalar x)
Definition: SkScalar.h:67
SkIPoint::fY
int32_t fY
y-axis value
Definition: SkPoint.h:27
SkRect::operator!=
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:819
SkScalarRoundToInt
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:36
SkScalarFloorToScalar
#define SkScalarFloorToScalar(x)
Definition: SkScalar.h:29
SkRect::MakeEmpty
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
Returns constructed SkRect set to (0, 0, 0, 0).
Definition: SkRect.h:585
SkRect::isSorted
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:697
SkIRect::join
void join(const SkIRect &r)
Sets SkIRect to the union of itself and r.
SkIRect::containsNoEmptyCheck
bool containsNoEmptyCheck(const SkIRect &r) const
Returns true if SkIRect contains construction.
Definition: SkRect.h:488
SkRect::offsetTo
void offsetTo(SkScalar newX, SkScalar newY)
Offsets SkRect so that fLeft equals newX, and fTop equals newY.
Definition: SkRect.h:1041
SkRect::offset
void offset(const SkPoint &delta)
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop,...
Definition: SkRect.h:1031
SkISize::fHeight
int32_t fHeight
Definition: SkSize.h:15
SkIRect::bottom
int32_t bottom() const
Returns bottom edge of SkIRect, if sorted.
Definition: SkRect.h:132
SkRect::bottom
SkScalar bottom() const
Returns bottom edge of SkRect, if sorted.
Definition: SkRect.h:759
SkRect::isFinite
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:704
SkRect::makeSorted
SkRect makeSorted() const
Returns SkRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBott...
Definition: SkRect.h:1316
SkIRect::MakeLTRB
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:87
SkIRect::makeInset
SkIRect makeInset(int32_t dx, int32_t dy) const
Returns SkIRect, inset by (dx, dy).
Definition: SkRect.h:321
SkRect::set
void set(const SkPoint &p0, const SkPoint &p1)
Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1.
Definition: SkRect.h:914
SkRect::dump
void dump(bool asHex) const
Writes text representation of SkRect to standard output.
SkRect::makeInset
SkRect makeInset(SkScalar dx, SkScalar dy) const
Returns SkRect, inset by (dx, dy).
Definition: SkRect.h:985
SkIRect::offset
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:356
SkISize::width
constexpr int32_t width() const
Definition: SkSize.h:33
SkRect::x
SkScalar x() const
Returns left edge of SkRect, if sorted.
Definition: SkRect.h:724
SkIRect::setEmpty
void setEmpty()
Sets SkIRect to (0, 0, 0, 0).
Definition: SkRect.h:238
SkRect::sort
void sort()
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater...
Definition: SkRect.h:1299
SkRect::right
SkScalar right() const
Returns right edge of SkRect, if sorted.
Definition: SkRect.h:752
SkRect::round
SkIRect round() const
Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect members,...
Definition: SkRect.h:1276
SkRect::MakeWH
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:599
SkIRect::height64
int64_t height64() const
Returns span on the y-axis.
Definition: SkRect.h:186
SkIPoint::y
constexpr int32_t y() const
Returns y-axis value of SkIPoint.
Definition: SkPoint.h:49
SkIPoint::x
constexpr int32_t x() const
Returns x-axis value of SkIPoint.
Definition: SkPoint.h:43
SkRect::makeOffset
constexpr SkRect makeOffset(SkVector v) const
Returns SkRect offset by v.
Definition: SkRect.h:972
SkIRect::operator!=
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:228
SkIRect::makeSorted
SkIRect makeSorted() const
Returns SkIRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBot...
Definition: SkRect.h:559
SkIRect::width64
int64_t width64() const
Returns span on the x-axis.
Definition: SkRect.h:178
SkRect::contains
bool contains(const SkIRect &r) const
Returns true if SkRect contains r.
Definition: SkRect.h:1213
SkRect::set
void set(const SkIRect &src)
Sets SkRect to src, promoting src members from integer to scalar.
Definition: SkRect.h:847
SkIRect::fLeft
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:29
SkRect::roundOut
SkIRect roundOut() const
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBott...
Definition: SkRect.h:1289
SkIRect::setLTRB
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
Sets SkIRect to (left, top, right, bottom).
Definition: SkRect.h:249
SkRect::offset
void offset(SkScalar dx, SkScalar dy)
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Definition: SkRect.h:1014
SkRect::dumpHex
void dumpHex() const
Writes text representation of SkRect to standard output.
Definition: SkRect.h:1351
SkRect::intersects
bool intersects(const SkRect &r) const
Returns true if SkRect intersects r.
Definition: SkRect.h:1119
SkRect::dump
void dump() const
Writes text representation of SkRect to standard output.
Definition: SkRect.h:1342
SkIRect::adjust
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:435
SkIRect::MakePtSize
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:74
SkRect::Intersects
static bool Intersects(const SkRect &a, const SkRect &b)
Returns true if a intersects b.
Definition: SkRect.h:1131
SkIRect::contains
bool contains(const SkIRect &r) const
Returns true if SkIRect contains r.
Definition: SkRect.h:464
SkRect::MakeXYWH
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:650
SkRect::y
SkScalar y() const
Returns top edge of SkRect, if sorted.
Definition: SkRect.h:731
SkIRect::fBottom
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:32
SkRect::joinNonEmptyArg
void joinNonEmptyArg(const SkRect &r)
Sets SkRect to the union of itself and r.
Definition: SkRect.h:1156
SkPoint
Definition: SkPoint.h:160
SkIRect::contains
bool contains(int32_t x, int32_t y) const
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
Definition: SkRect.h:452
SkRect::height
SkScalar height() const
Returns span on the y-axis.
Definition: SkRect.h:773
SkIRect::Intersects
static bool Intersects(const SkIRect &a, const SkIRect &b)
Returns true if a intersects b.
Definition: SkRect.h:524
SkRect::toQuad
void toQuad(SkPoint quad[4]) const
Returns four points in quad that enclose SkRect ordered as: top-left, top-right, bottom-right,...
SkRect::Make
static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect &irect)
Returns constructed SkIRect set to irect, promoting integers to scalar.
Definition: SkRect.h:672
SK_API
#define SK_API
Definition: SkTypes.h:181
SkASSERT
#define SkASSERT(cond)
Definition: SkTypes.h:460
SkIRect::top
int32_t top() const
Returns top edge of SkIRect, if sorted.
Definition: SkRect.h:118
SkRect::isEmpty
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:685
SkIRect::x
int32_t x() const
Returns left edge of SkIRect, if sorted.
Definition: SkRect.h:139
SkRect::inset
void inset(SkScalar dx, SkScalar dy)
Insets SkRect by (dx, dy).
Definition: SkRect.h:1058
SkPoint::fY
SkScalar fY
y-axis value
Definition: SkPoint.h:162
SkRect::MakeSize
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:623
SkRect::MakeIWH
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:613
SkIRect::topLeft
SkIPoint topLeft() const
Definition: SkRect.h:149
SkISize
Definition: SkSize.h:13
SkRect::makeOffset
constexpr SkRect makeOffset(SkScalar dx, SkScalar dy) const
Returns SkRect offset by (dx, dy).
Definition: SkRect.h:963
SkRect::top
SkScalar top() const
Returns top edge of SkRect, if sorted.
Definition: SkRect.h:745
SkSize
Definition: SkSize.h:49
SkIRect::width
int32_t width() const
Returns span on the x-axis.
Definition: SkRect.h:156
SkRect::setBoundsNoCheck
void setBoundsNoCheck(const SkPoint pts[], int count)
Sets to bounds of SkPoint pts array with count entries.
SkRect::operator==
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:805
SkScalarHalf
#define SkScalarHalf(a)
Definition: SkScalar.h:110
SkRect::roundIn
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:1264
SkPoint.h
SkRect::asScalars
const SkScalar * asScalars() const
Returns pointer to first scalar in SkRect, to treat it as an array with four entries.
Definition: SkRect.h:1326
SkRect::setBounds
void setBounds(const SkPoint pts[], int count)
Sets to bounds of SkPoint array with count entries.
Definition: SkRect.h:879
SkScalarsEqual
static bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
Definition: SkScalar.h:184
SkRect::intersect
bool intersect(const SkRect &r)
Returns true if SkRect intersects r, and sets SkRect to intersection.
SkIRect::offsetTo
void offsetTo(int32_t newX, int32_t newY)
Offsets SkIRect so that fLeft equals newX, and fTop equals newY.
Definition: SkRect.h:383
SkSize::fHeight
SkScalar fHeight
Definition: SkSize.h:51
SkISize::Make
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:17
SkRect::makeOutset
SkRect makeOutset(SkScalar dx, SkScalar dy) const
Returns SkRect, outset by (dx, dy).
Definition: SkRect.h:1000
SkIRect::MakeWH
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:52
SkIRect::offset
void offset(const SkIPoint &delta)
Offsets SkIRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop,...
Definition: SkRect.h:373
SkRect::setEmpty
void setEmpty()
Sets SkRect to (0, 0, 0, 0).
Definition: SkRect.h:840
SkIRect::intersect
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &a, const SkIRect &b)
Returns true if a intersects b, and sets SkIRect to intersection.
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkIRect::size
SkISize size() const
Returns spans on the x-axis and y-axis.
Definition: SkRect.h:170
SkIRect::MakeEmpty
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty()
Returns constructed SkIRect set to (0, 0, 0, 0).
Definition: SkRect.h:41
SkIRect::isEmpty64
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:194
SkRect::intersect
bool SK_WARN_UNUSED_RESULT intersect(const SkRect &a, const SkRect &b)
Returns true if a intersects b, and sets SkRect to intersection.
SkIRect::right
int32_t right() const
Returns right edge of SkIRect, if sorted.
Definition: SkRect.h:125
swap
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:334
SkIRect::MakeXYWH
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:101
SkRect::centerY
SkScalar centerY() const
Returns average of top edge and bottom edge.
Definition: SkRect.h:790
SkPoint::fX
SkScalar fX
x-axis value
Definition: SkPoint.h:161
SkRect::setXYWH
void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
Sets SkRect to (x, y, x + width, y + height).
Definition: SkRect.h:929
SkIRect::makeOffset
constexpr SkIRect makeOffset(SkIVector offset) const
Returns SkIRect offset by (offset.x(), offset.y()).
Definition: SkRect.h:306
SkIRect::MakeSize
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:62
SkIRect
Definition: SkRect.h:28
SkIRect::height
int32_t height() const
Returns span on the y-axis.
Definition: SkRect.h:163
SkIRect::operator==
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:217
SK_WARN_UNUSED_RESULT
#define SK_WARN_UNUSED_RESULT
Definition: SkTypes.h:60
SkISize::height
constexpr int32_t height() const
Definition: SkSize.h:34
SkRect::roundOut
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:1252
SkScalarCeilToInt
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:35
SkRect::roundOut
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:1239
SkPoint::y
constexpr SkScalar y() const
Returns y-axis value of SkPoint or vector.
Definition: SkPoint.h:184
SkRect::join
void join(const SkRect &r)
Sets SkRect to the union of itself and r.
SkIRect::inset
void inset(int32_t dx, int32_t dy)
Insets SkIRect by (dx,dy).
Definition: SkRect.h:400
SkIRect::intersect
bool intersect(const SkIRect &r)
Returns true if SkIRect intersects r, and sets SkIRect to intersection.
Definition: SkRect.h:502
SkIRect::outset
void outset(int32_t dx, int32_t dy)
Outsets SkIRect by (dx, dy).
Definition: SkRect.h:417
SkRect::fTop
SkScalar fTop
smaller y-axis bounds
Definition: SkRect.h:574
SkIRect::y
int32_t y() const
Returns top edge of SkIRect, if sorted.
Definition: SkRect.h:146
SkIRect::setXYWH
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:264
SkIRect::left
int32_t left() const
Returns left edge of SkIRect, if sorted.
Definition: SkRect.h:111
SkIntToScalar
#define SkIntToScalar(x)
Definition: SkScalar.h:56
SkIRect::setWH
void setWH(int32_t width, int32_t height)
Definition: SkRect.h:271
SkIRect::makeOffset
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const
Returns SkIRect offset by (dx, dy).
Definition: SkRect.h:289
SkRect::width
SkScalar width() const
Returns span on the x-axis.
Definition: SkRect.h:766
SkRect
Definition: SkRect.h:572
SkRect::fLeft
SkScalar fLeft
smaller x-axis bounds
Definition: SkRect.h:573
SkScalarFloorToInt
#define SkScalarFloorToInt(x)
Definition: SkScalar.h:34
SkRect::joinPossiblyEmptyRect
void joinPossiblyEmptyRect(const SkRect &r)
Sets SkRect to the union of itself and the construction.
Definition: SkRect.h:1172
SkRect::MakeLTRB
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:636
SkRect::Make
static SkRect Make(const SkISize &size)
Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:661
SkIRect::fRight
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:31
SkIPoint
Definition: SkPoint.h:25
SkRect::centerX
SkScalar centerX() const
Returns average of left edge and right edge.
Definition: SkRect.h:780
SkRect::outset
void outset(SkScalar dx, SkScalar dy)
Outsets SkRect by (dx, dy).
Definition: SkRect.h:1075
SkIRect::sort
void sort()
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater...
Definition: SkRect.h:543
SkRect::contains
bool contains(const SkRect &r) const
Returns true if SkRect contains r.
Definition: SkRect.h:1198
SkSize::fWidth
SkScalar fWidth
Definition: SkSize.h:50
SkIRect::makeOutset
SkIRect makeOutset(int32_t dx, int32_t dy) const
Returns SkIRect, outset by (dx, dy).
Definition: SkRect.h:339
SkRect::setIWH
void setIWH(int32_t width, int32_t height)
Definition: SkRect.h:948
SkISize::fWidth
int32_t fWidth
Definition: SkSize.h:14
SkRect::contains
bool contains(SkScalar x, SkScalar y) const
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
Definition: SkRect.h:1186
SkScalarCeilToScalar
#define SkScalarCeilToScalar(x)
Definition: SkScalar.h:30
SkIRect::isEmpty
bool isEmpty() const
Returns true if width() or height() are zero or negative.
Definition: SkRect.h:200
SkIRect::fTop
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:30
SkPoint::x
constexpr SkScalar x() const
Returns x-axis value of SkPoint or vector.
Definition: SkPoint.h:178