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/core/SkTypes.h"
14 #include "include/private/base/SkFloatingPoint.h"
15 #include "include/private/base/SkSafe32.h"
16 #include "include/private/base/SkTFitsIn.h"
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <cstdint>
21 #include <cstring>
22 
23 struct SkRect;
24 
32 struct SK_API SkIRect {
33  int32_t fLeft = 0;
34  int32_t fTop = 0;
35  int32_t fRight = 0;
36  int32_t fBottom = 0;
37 
45  [[nodiscard]] static constexpr SkIRect MakeEmpty() {
46  return SkIRect{0, 0, 0, 0};
47  }
48 
56  [[nodiscard]] static constexpr SkIRect MakeWH(int32_t w, int32_t h) {
57  return SkIRect{0, 0, w, h};
58  }
59 
66  [[nodiscard]] static constexpr SkIRect MakeSize(const SkISize& size) {
67  return SkIRect{0, 0, size.fWidth, size.fHeight};
68  }
69 
78  [[nodiscard]] static constexpr SkIRect MakePtSize(SkIPoint pt, SkISize size) {
79  return MakeXYWH(pt.x(), pt.y(), size.width(), size.height());
80  }
81 
91  [[nodiscard]] static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) {
92  return SkIRect{l, t, r, b};
93  }
94 
104  [[nodiscard]] static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) {
105  return { x, y, Sk32_sat_add(x, w), Sk32_sat_add(y, h) };
106  }
107 
113  constexpr int32_t left() const { return fLeft; }
114 
120  constexpr int32_t top() const { return fTop; }
121 
127  constexpr int32_t right() const { return fRight; }
128 
134  constexpr int32_t bottom() const { return fBottom; }
135 
141  constexpr int32_t x() const { return fLeft; }
142 
148  constexpr int32_t y() const { return fTop; }
149 
150  // Experimental
151  constexpr SkIPoint topLeft() const { return {fLeft, fTop}; }
152 
158  constexpr int32_t width() const { return Sk32_can_overflow_sub(fRight, fLeft); }
159 
165  constexpr int32_t height() const { return Sk32_can_overflow_sub(fBottom, fTop); }
166 
172  constexpr SkISize size() const { return SkISize::Make(this->width(), this->height()); }
173 
180  constexpr int64_t width64() const { return (int64_t)fRight - (int64_t)fLeft; }
181 
188  constexpr int64_t height64() const { return (int64_t)fBottom - (int64_t)fTop; }
189 
196  bool isEmpty64() const { return fRight <= fLeft || fBottom <= fTop; }
197 
202  bool isEmpty() const {
203  int64_t w = this->width64();
204  int64_t h = this->height64();
205  if (w <= 0 || h <= 0) {
206  return true;
207  }
208  // Return true if either exceeds int32_t
209  return !SkTFitsIn<int32_t>(w | h);
210  }
211 
219  friend bool operator==(const SkIRect& a, const SkIRect& b) {
220  return a.fLeft == b.fLeft && a.fTop == b.fTop &&
221  a.fRight == b.fRight && a.fBottom == b.fBottom;
222  }
223 
231  friend bool operator!=(const SkIRect& a, const SkIRect& b) {
232  return a.fLeft != b.fLeft || a.fTop != b.fTop ||
233  a.fRight != b.fRight || a.fBottom != b.fBottom;
234  }
235 
242  void setEmpty() { memset(this, 0, sizeof(*this)); }
243 
253  void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) {
254  fLeft = left;
255  fTop = top;
256  fRight = right;
257  fBottom = bottom;
258  }
259 
268  void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) {
269  fLeft = x;
270  fTop = y;
271  fRight = Sk32_sat_add(x, width);
272  fBottom = Sk32_sat_add(y, height);
273  }
274 
275  void setWH(int32_t width, int32_t height) {
276  fLeft = 0;
277  fTop = 0;
278  fRight = width;
279  fBottom = height;
280  }
281 
282  void setSize(SkISize size) {
283  fLeft = 0;
284  fTop = 0;
285  fRight = size.width();
286  fBottom = size.height();
287  }
288 
300  constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const {
301  return {
302  Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
303  Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
304  };
305  }
306 
317  constexpr SkIRect makeOffset(SkIVector offset) const {
318  return this->makeOffset(offset.x(), offset.y());
319  }
320 
332  SkIRect makeInset(int32_t dx, int32_t dy) const {
333  return {
334  Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
335  Sk32_sat_sub(fRight, dx), Sk32_sat_sub(fBottom, dy),
336  };
337  }
338 
350  SkIRect makeOutset(int32_t dx, int32_t dy) const {
351  return {
352  Sk32_sat_sub(fLeft, dx), Sk32_sat_sub(fTop, dy),
353  Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
354  };
355  }
356 
367  void offset(int32_t dx, int32_t dy) {
368  fLeft = Sk32_sat_add(fLeft, dx);
369  fTop = Sk32_sat_add(fTop, dy);
370  fRight = Sk32_sat_add(fRight, dx);
371  fBottom = Sk32_sat_add(fBottom, dy);
372  }
373 
384  void offset(const SkIPoint& delta) {
385  this->offset(delta.fX, delta.fY);
386  }
387 
394  void offsetTo(int32_t newX, int32_t newY) {
395  fRight = Sk64_pin_to_s32((int64_t)fRight + newX - fLeft);
396  fBottom = Sk64_pin_to_s32((int64_t)fBottom + newY - fTop);
397  fLeft = newX;
398  fTop = newY;
399  }
400 
411  void inset(int32_t dx, int32_t dy) {
412  fLeft = Sk32_sat_add(fLeft, dx);
413  fTop = Sk32_sat_add(fTop, dy);
414  fRight = Sk32_sat_sub(fRight, dx);
415  fBottom = Sk32_sat_sub(fBottom, dy);
416  }
417 
428  void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
429 
446  void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) {
447  fLeft = Sk32_sat_add(fLeft, dL);
448  fTop = Sk32_sat_add(fTop, dT);
449  fRight = Sk32_sat_add(fRight, dR);
450  fBottom = Sk32_sat_add(fBottom, dB);
451  }
452 
463  bool contains(int32_t x, int32_t y) const {
464  return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
465  }
466 
475  bool contains(const SkIRect& r) const {
476  return !r.isEmpty() && !this->isEmpty() && // check for empties
477  fLeft <= r.fLeft && fTop <= r.fTop &&
478  fRight >= r.fRight && fBottom >= r.fBottom;
479  }
480 
489  inline bool contains(const SkRect& r) const;
490 
499  bool containsNoEmptyCheck(const SkIRect& r) const {
500  SkASSERT(fLeft < fRight && fTop < fBottom);
501  SkASSERT(r.fLeft < r.fRight && r.fTop < r.fBottom);
502  return fLeft <= r.fLeft && fTop <= r.fTop && fRight >= r.fRight && fBottom >= r.fBottom;
503  }
504 
513  bool intersect(const SkIRect& r) {
514  return this->intersect(*this, r);
515  }
516 
526  [[nodiscard]] bool intersect(const SkIRect& a, const SkIRect& b);
527 
535  static bool Intersects(const SkIRect& a, const SkIRect& b) {
536  return SkIRect{}.intersect(a, b);
537  }
538 
547  void join(const SkIRect& r);
548 
553  void sort() {
554  using std::swap;
555  if (fLeft > fRight) {
556  swap(fLeft, fRight);
557  }
558  if (fTop > fBottom) {
559  swap(fTop, fBottom);
560  }
561  }
562 
569  SkIRect makeSorted() const {
570  return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
571  std::max(fLeft, fRight), std::max(fTop, fBottom));
572  }
573 };
574 
582 struct SK_API SkRect {
583  float fLeft = 0;
584  float fTop = 0;
585  float fRight = 0;
586  float fBottom = 0;
587 
595  [[nodiscard]] static constexpr SkRect MakeEmpty() {
596  return SkRect{0, 0, 0, 0};
597  }
598 
609  [[nodiscard]] static constexpr SkRect MakeWH(float w, float h) {
610  return SkRect{0, 0, w, h};
611  }
612 
623  [[nodiscard]] static SkRect MakeIWH(int w, int h) {
624  return {0, 0, static_cast<float>(w), static_cast<float>(h)};
625  }
626 
633  [[nodiscard]] static constexpr SkRect MakeSize(const SkSize& size) {
634  return SkRect{0, 0, size.fWidth, size.fHeight};
635  }
636 
646  [[nodiscard]] static constexpr SkRect MakeLTRB(float l, float t, float r, float b) {
647  return SkRect {l, t, r, b};
648  }
649 
659  [[nodiscard]] static constexpr SkRect MakeXYWH(float x, float y, float w, float h) {
660  return SkRect {x, y, x + w, y + h};
661  }
662 
669  static SkRect Make(const SkISize& size) {
670  return MakeIWH(size.width(), size.height());
671  }
672 
680  [[nodiscard]] static SkRect Make(const SkIRect& irect) {
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  }
686 
693  bool isEmpty() const {
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  }
698 
705  bool isSorted() const { return fLeft <= fRight && fTop <= fBottom; }
706 
711  bool isFinite() const {
712  float accum = 0;
713  accum *= fLeft;
714  accum *= fTop;
715  accum *= fRight;
716  accum *= fBottom;
717 
718  // accum is either NaN or it is finite (zero).
719  SkASSERT(0 == accum || std::isnan(accum));
720 
721  // value==value will be true iff value is not NaN
722  // TODO: is it faster to say !accum or accum==accum?
723  return !std::isnan(accum);
724  }
725 
731  constexpr float x() const { return fLeft; }
732 
738  constexpr float y() const { return fTop; }
739 
745  constexpr float left() const { return fLeft; }
746 
752  constexpr float top() const { return fTop; }
753 
759  constexpr float right() const { return fRight; }
760 
766  constexpr float bottom() const { return fBottom; }
767 
773  constexpr float width() const { return fRight - fLeft; }
774 
780  constexpr float height() const { return fBottom - fTop; }
781 
787  constexpr float centerX() const {
788  return sk_float_midpoint(fLeft, fRight);
789  }
790 
796  constexpr float centerY() const {
797  return sk_float_midpoint(fTop, fBottom);
798  }
799 
803  constexpr SkPoint center() const { return {this->centerX(), this->centerY()}; }
804 
815  friend bool operator==(const SkRect& a, const SkRect& b) {
816  return a.fLeft == b.fLeft &&
817  a.fTop == b.fTop &&
818  a.fRight == b.fRight &&
819  a.fBottom == b.fBottom;
820  }
821 
832  friend bool operator!=(const SkRect& a, const SkRect& b) {
833  return !(a == b);
834  }
835 
845  void toQuad(SkPoint quad[4]) const;
846 
853  void setEmpty() { *this = MakeEmpty(); }
854 
860  void set(const SkIRect& src) {
861  fLeft = src.fLeft;
862  fTop = src.fTop;
863  fRight = src.fRight;
864  fBottom = src.fBottom;
865  }
866 
876  void setLTRB(float left, float top, float right, float bottom) {
877  fLeft = left;
878  fTop = top;
879  fRight = right;
880  fBottom = bottom;
881  }
882 
892  void setBounds(const SkPoint pts[], int count) {
893  (void)this->setBoundsCheck(pts, count);
894  }
895 
909  bool setBoundsCheck(const SkPoint pts[], int count);
910 
919  void setBoundsNoCheck(const SkPoint pts[], int count);
920 
927  void set(const SkPoint& p0, const SkPoint& p1) {
928  fLeft = std::min(p0.fX, p1.fX);
929  fRight = std::max(p0.fX, p1.fX);
930  fTop = std::min(p0.fY, p1.fY);
931  fBottom = std::max(p0.fY, p1.fY);
932  }
933 
942  void setXYWH(float x, float y, float width, float height) {
943  fLeft = x;
944  fTop = y;
945  fRight = x + width;
946  fBottom = y + height;
947  }
948 
955  void setWH(float width, float height) {
956  fLeft = 0;
957  fTop = 0;
958  fRight = width;
959  fBottom = height;
960  }
961  void setIWH(int32_t width, int32_t height) {
962  this->setWH(width, height);
963  }
964 
976  constexpr SkRect makeOffset(float dx, float dy) const {
977  return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
978  }
979 
985  constexpr SkRect makeOffset(SkVector v) const { return this->makeOffset(v.x(), v.y()); }
986 
998  SkRect makeInset(float dx, float dy) const {
999  return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
1000  }
1001 
1013  SkRect makeOutset(float dx, float dy) const {
1014  return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
1015  }
1016 
1027  void offset(float dx, float dy) {
1028  fLeft += dx;
1029  fTop += dy;
1030  fRight += dx;
1031  fBottom += dy;
1032  }
1033 
1044  void offset(const SkPoint& delta) {
1045  this->offset(delta.fX, delta.fY);
1046  }
1047 
1054  void offsetTo(float newX, float newY) {
1055  fRight += newX - fLeft;
1056  fBottom += newY - fTop;
1057  fLeft = newX;
1058  fTop = newY;
1059  }
1060 
1071  void inset(float dx, float dy) {
1072  fLeft += dx;
1073  fTop += dy;
1074  fRight -= dx;
1075  fBottom -= dy;
1076  }
1077 
1088  void outset(float dx, float dy) { this->inset(-dx, -dy); }
1089 
1100  bool intersect(const SkRect& r);
1101 
1111  [[nodiscard]] bool intersect(const SkRect& a, const SkRect& b);
1112 
1113 
1114 private:
1115  static bool Intersects(float al, float at, float ar, float ab,
1116  float bl, float bt, float br, float bb) {
1117  float L = std::max(al, bl);
1118  float R = std::min(ar, br);
1119  float T = std::max(at, bt);
1120  float B = std::min(ab, bb);
1121  return L < R && T < B;
1122  }
1123 
1124 public:
1125 
1132  bool intersects(const SkRect& r) const {
1133  return Intersects(fLeft, fTop, fRight, fBottom,
1134  r.fLeft, r.fTop, r.fRight, r.fBottom);
1135  }
1136 
1144  static bool Intersects(const SkRect& a, const SkRect& b) {
1145  return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
1146  b.fLeft, b.fTop, b.fRight, b.fBottom);
1147  }
1148 
1158  void join(const SkRect& r);
1159 
1169  void joinNonEmptyArg(const SkRect& r) {
1170  SkASSERT(!r.isEmpty());
1171  // if we are empty, just assign
1172  if (fLeft >= fRight || fTop >= fBottom) {
1173  *this = r;
1174  } else {
1175  this->joinPossiblyEmptyRect(r);
1176  }
1177  }
1178 
1186  fLeft = std::min(fLeft, r.left());
1187  fTop = std::min(fTop, r.top());
1188  fRight = std::max(fRight, r.right());
1189  fBottom = std::max(fBottom, r.bottom());
1190  }
1191 
1199  bool contains(float x, float y) const {
1200  return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
1201  }
1202 
1211  bool contains(const SkRect& r) const {
1212  // todo: can we eliminate the this->isEmpty check?
1213  return !r.isEmpty() && !this->isEmpty() &&
1214  fLeft <= r.fLeft && fTop <= r.fTop &&
1215  fRight >= r.fRight && fBottom >= r.fBottom;
1216  }
1217 
1226  bool contains(const SkIRect& r) const {
1227  // todo: can we eliminate the this->isEmpty check?
1228  return !r.isEmpty() && !this->isEmpty() &&
1229  fLeft <= r.fLeft && fTop <= r.fTop &&
1230  fRight >= r.fRight && fBottom >= r.fBottom;
1231  }
1232 
1239  void round(SkIRect* dst) const {
1240  SkASSERT(dst);
1241  dst->setLTRB(sk_float_round2int(fLeft), sk_float_round2int(fTop),
1242  sk_float_round2int(fRight), sk_float_round2int(fBottom));
1243  }
1244 
1252  void roundOut(SkIRect* dst) const {
1253  SkASSERT(dst);
1254  dst->setLTRB(sk_float_floor2int(fLeft), sk_float_floor2int(fTop),
1255  sk_float_ceil2int(fRight), sk_float_ceil2int(fBottom));
1256  }
1257 
1265  void roundOut(SkRect* dst) const {
1266  dst->setLTRB(sk_float_floor(fLeft), sk_float_floor(fTop),
1267  sk_float_ceil(fRight), sk_float_ceil(fBottom));
1268  }
1269 
1277  void roundIn(SkIRect* dst) const {
1278  SkASSERT(dst);
1279  dst->setLTRB(sk_float_ceil2int(fLeft), sk_float_ceil2int(fTop),
1280  sk_float_floor2int(fRight), sk_float_floor2int(fBottom));
1281  }
1282 
1289  SkIRect round() const {
1290  SkIRect ir;
1291  this->round(&ir);
1292  return ir;
1293  }
1294 
1302  SkIRect roundOut() const {
1303  SkIRect ir;
1304  this->roundOut(&ir);
1305  return ir;
1306  }
1314  SkIRect roundIn() const {
1315  SkIRect ir;
1316  this->roundIn(&ir);
1317  return ir;
1318  }
1319 
1324  void sort() {
1325  using std::swap;
1326  if (fLeft > fRight) {
1327  swap(fLeft, fRight);
1328  }
1329 
1330  if (fTop > fBottom) {
1331  swap(fTop, fBottom);
1332  }
1333  }
1334 
1341  SkRect makeSorted() const {
1342  return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom),
1343  std::max(fLeft, fRight), std::max(fTop, fBottom));
1344  }
1345 
1351  const float* asScalars() const { return &fLeft; }
1352 
1360  void dump(bool asHex) const;
1361 
1367  void dump() const { this->dump(false); }
1368 
1376  void dumpHex() const { this->dump(true); }
1377 };
1378 
1379 inline bool SkIRect::contains(const SkRect& r) const {
1380  return !r.isEmpty() && !this->isEmpty() && // check for empties
1381  fLeft <= r.fLeft && fTop <= r.fTop &&
1382  fRight >= r.fRight && fBottom >= r.fBottom;
1383 }
1384 
1385 #endif
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:32
constexpr int64_t height64() const
Returns span on the y-axis.
Definition: SkRect.h:188
void sort()
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater...
Definition: SkRect.h:553
constexpr int32_t x() const
Returns left edge of SkIRect, if sorted.
Definition: SkRect.h:141
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:231
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:446
SkIRect makeOutset(int32_t dx, int32_t dy) const
Returns SkIRect, outset by (dx, dy).
Definition: SkRect.h:350
void inset(int32_t dx, int32_t dy)
Insets SkIRect by (dx,dy).
Definition: SkRect.h:411
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:196
bool contains(const SkIRect &r) const
Returns true if SkIRect contains r.
Definition: SkRect.h:475
constexpr int32_t y() const
Returns top edge of SkIRect, if sorted.
Definition: SkRect.h:148
void offset(const SkIPoint &delta)
Offsets SkIRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop,...
Definition: SkRect.h:384
bool intersect(const SkIRect &r)
Returns true if SkIRect intersects r, and sets SkIRect to intersection.
Definition: SkRect.h:513
static bool Intersects(const SkIRect &a, const SkIRect &b)
Returns true if a intersects b.
Definition: SkRect.h:535
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
constexpr int32_t top() const
Returns top edge of SkIRect, if sorted.
Definition: SkRect.h:120
void offsetTo(int32_t newX, int32_t newY)
Offsets SkIRect so that fLeft equals newX, and fTop equals newY.
Definition: SkRect.h:394
bool containsNoEmptyCheck(const SkIRect &r) const
Returns true if SkIRect contains construction.
Definition: SkRect.h:499
constexpr SkISize size() const
Returns spans on the x-axis and y-axis.
Definition: SkRect.h:172
constexpr int32_t bottom() const
Returns bottom edge of SkIRect, if sorted.
Definition: SkRect.h:134
bool intersect(const SkIRect &a, const SkIRect &b)
Returns true if a intersects b, and sets SkIRect to intersection.
constexpr int32_t height() const
Returns span on the y-axis.
Definition: SkRect.h:165
constexpr int32_t right() const
Returns right edge of SkIRect, if sorted.
Definition: SkRect.h:127
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
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:317
static constexpr SkIRect MakeSize(const SkISize &size)
Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:66
static constexpr SkIRect MakeEmpty()
Returns constructed SkIRect set to (0, 0, 0, 0).
Definition: SkRect.h:45
constexpr int32_t width() const
Returns span on the x-axis.
Definition: SkRect.h:158
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:219
constexpr int64_t width64() const
Returns span on the x-axis.
Definition: SkRect.h:180
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:367
void setEmpty()
Sets SkIRect to (0, 0, 0, 0).
Definition: SkRect.h:242
static constexpr SkIRect 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 SkIRect makeOffset(int32_t dx, int32_t dy) const
Returns SkIRect offset by (dx, dy).
Definition: SkRect.h:300
bool isEmpty() const
Returns true if width() or height() are zero or negative.
Definition: SkRect.h:202
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:268
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Returns constructed SkIRect set to (0, 0, w, h).
Definition: SkRect.h:56
constexpr SkIPoint topLeft() const
Definition: SkRect.h:151
void setWH(int32_t width, int32_t height)
Definition: SkRect.h:275
SkIRect makeInset(int32_t dx, int32_t dy) const
Returns SkIRect, inset by (dx, dy).
Definition: SkRect.h:332
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
SkIRect makeSorted() const
Returns SkIRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBot...
Definition: SkRect.h:569
void outset(int32_t dx, int32_t dy)
Outsets SkIRect by (dx, dy).
Definition: SkRect.h:428
static constexpr SkIRect MakePtSize(SkIPoint pt, SkISize size)
Returns constructed SkIRect set to (pt.x(), pt.y(), pt.x() + size.width(), pt.y() + size....
Definition: SkRect.h:78
static constexpr SkIRect 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:91
constexpr int32_t left() const
Returns left edge of SkIRect, if sorted.
Definition: SkRect.h:113
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
Sets SkIRect to (left, top, right, bottom).
Definition: SkRect.h:253
bool contains(int32_t x, int32_t y) const
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
Definition: SkRect.h:463
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35
void setSize(SkISize size)
Definition: SkRect.h:282
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
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
constexpr SkRect makeOffset(SkVector v) const
Returns SkRect offset by v.
Definition: SkRect.h:985
SkRect makeSorted() const
Returns SkRect with fLeft and fRight swapped if fLeft is greater than fRight; and with fTop and fBott...
Definition: SkRect.h:1341
static SkRect Make(const SkISize &size)
Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:669
void offsetTo(float newX, float newY)
Offsets SkRect so that fLeft equals newX, and fTop equals newY.
Definition: SkRect.h:1054
static constexpr SkRect MakeEmpty()
Returns constructed SkRect set to (0, 0, 0, 0).
Definition: SkRect.h:595
bool intersect(const SkRect &a, const SkRect &b)
Returns true if a intersects b, and sets SkRect to intersection.
static bool Intersects(const SkRect &a, const SkRect &b)
Returns true if a intersects b.
Definition: SkRect.h:1144
void toQuad(SkPoint quad[4]) const
Returns four points in quad that enclose SkRect ordered as: top-left, top-right, bottom-right,...
bool contains(float x, float y) const
Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
Definition: SkRect.h:1199
void joinNonEmptyArg(const SkRect &r)
Sets SkRect to the union of itself and r.
Definition: SkRect.h:1169
constexpr float left() const
Returns left edge of SkRect, if sorted.
Definition: SkRect.h:745
float fLeft
smaller x-axis bounds
Definition: SkRect.h:583
void offset(const SkPoint &delta)
Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to fTop,...
Definition: SkRect.h:1044
float fBottom
larger y-axis bounds
Definition: SkRect.h:586
static SkRect Make(const SkIRect &irect)
Returns constructed SkIRect set to irect, promoting integers to float.
Definition: SkRect.h:680
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:815
void inset(float dx, float dy)
Insets SkRect by (dx, dy).
Definition: SkRect.h:1071
void setXYWH(float x, float y, float width, float height)
Sets SkRect to (x, y, x + width, y + height).
Definition: SkRect.h:942
constexpr SkRect makeOffset(float dx, float dy) const
Returns SkRect offset by (dx, dy).
Definition: SkRect.h:976
bool isFinite() const
Returns true if all values in the rectangle are finite.
Definition: SkRect.h:711
constexpr float top() const
Returns top edge of SkRect, if sorted.
Definition: SkRect.h:752
void joinPossiblyEmptyRect(const SkRect &r)
Sets SkRect to the union of itself and the construction.
Definition: SkRect.h:1185
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:1277
bool intersect(const SkRect &r)
Returns true if SkRect intersects r, and sets SkRect to intersection.
constexpr float x() const
Returns left edge of SkRect, if sorted.
Definition: SkRect.h:731
static SkRect MakeIWH(int w, int h)
Returns constructed SkRect set to integer values (0, 0, w, h).
Definition: SkRect.h:623
void outset(float dx, float dy)
Outsets SkRect by (dx, dy).
Definition: SkRect.h:1088
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:1265
constexpr float y() const
Returns top edge of SkRect, if sorted.
Definition: SkRect.h:738
SkRect makeOutset(float dx, float dy) const
Returns SkRect, outset by (dx, dy).
Definition: SkRect.h:1013
void setWH(float width, float height)
Sets SkRect to (0, 0, width, height).
Definition: SkRect.h:955
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Returns constructed SkRect set to (x, y, x + w, y + h).
Definition: SkRect.h:659
bool contains(const SkRect &r) const
Returns true if SkRect contains r.
Definition: SkRect.h:1211
bool intersects(const SkRect &r) const
Returns true if SkRect intersects r.
Definition: SkRect.h:1132
SkRect makeInset(float dx, float dy) const
Returns SkRect, inset by (dx, dy).
Definition: SkRect.h:998
void set(const SkPoint &p0, const SkPoint &p1)
Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1.
Definition: SkRect.h:927
const float * asScalars() const
Returns pointer to first float in SkRect, to treat it as an array with four entries.
Definition: SkRect.h:1351
bool contains(const SkIRect &r) const
Returns true if SkRect contains r.
Definition: SkRect.h:1226
float fTop
smaller y-axis bounds
Definition: SkRect.h:584
SkIRect roundOut() const
Sets SkIRect by discarding the fractional portion of fLeft and fTop; and rounding up fRight and fBott...
Definition: SkRect.h:1302
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:1252
constexpr float centerX() const
Returns average of left edge and right edge.
Definition: SkRect.h:787
void offset(float dx, float dy)
Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Definition: SkRect.h:1027
static constexpr SkRect MakeSize(const SkSize &size)
Returns constructed SkRect set to (0, 0, size.width(), size.height()).
Definition: SkRect.h:633
SkIRect roundIn() const
Sets SkIRect by rounding up fLeft and fTop; and discarding the fractional portion of fRight and fBott...
Definition: SkRect.h:1314
void round(SkIRect *dst) const
Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect members,...
Definition: SkRect.h:1239
constexpr float height() const
Returns span on the y-axis.
Definition: SkRect.h:780
constexpr float right() const
Returns right edge of SkRect, if sorted.
Definition: SkRect.h:759
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:1289
void setIWH(int32_t width, int32_t height)
Definition: SkRect.h:961
void setLTRB(float left, float top, float right, float bottom)
Sets SkRect to (left, top, right, bottom).
Definition: SkRect.h:876
void setBounds(const SkPoint pts[], int count)
Sets to bounds of SkPoint array with count entries.
Definition: SkRect.h:892
constexpr float centerY() const
Returns average of top edge and bottom edge.
Definition: SkRect.h:796
constexpr float width() const
Returns span on the x-axis.
Definition: SkRect.h:773
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:693
float fRight
larger x-axis bounds
Definition: SkRect.h:585
void join(const SkRect &r)
Sets SkRect to the union of itself and r.
void sort()
Swaps fLeft and fRight if fLeft is greater than fRight; and swaps fTop and fBottom if fTop is greater...
Definition: SkRect.h:1324
constexpr SkPoint center() const
Returns the point this->centerX(), this->centerY().
Definition: SkRect.h:803
void dump() const
Writes text representation of SkRect to standard output.
Definition: SkRect.h:1367
void dumpHex() const
Writes text representation of SkRect to standard output.
Definition: SkRect.h:1376
void setBoundsNoCheck(const SkPoint pts[], int count)
Sets to bounds of SkPoint pts array with count entries.
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:832
static constexpr SkRect MakeWH(float w, float h)
Returns constructed SkRect set to float values (0, 0, w, h).
Definition: SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Returns constructed SkRect set to (l, t, r, b).
Definition: SkRect.h:646
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:705
void set(const SkIRect &src)
Sets SkRect to src, promoting src members from integer to float.
Definition: SkRect.h:860
void dump(bool asHex) const
Writes text representation of SkRect to standard output.
constexpr float bottom() const
Returns bottom edge of SkRect, if sorted.
Definition: SkRect.h:766
void setEmpty()
Sets SkRect to (0, 0, 0, 0).
Definition: SkRect.h:853
Definition: SkSize.h:51
SkScalar fHeight
Definition: SkSize.h:53
SkScalar fWidth
Definition: SkSize.h:52