Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkRect.h
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 "SkPoint.h"
12 #include "SkSize.h"
13 
14 struct SkRect;
15 
20 struct SK_API SkIRect {
21  int32_t fLeft, fTop, fRight, fBottom;
22 
23  static SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() {
24  SkIRect r;
25  r.setEmpty();
26  return r;
27  }
28 
29  static SkIRect SK_WARN_UNUSED_RESULT MakeLargest() {
30  SkIRect r;
31  r.setLargest();
32  return r;
33  }
34 
35  static SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
36  SkIRect r;
37  r.set(0, 0, w, h);
38  return r;
39  }
40 
41  static SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) {
42  SkIRect r;
43  r.set(0, 0, size.width(), size.height());
44  return r;
45  }
46 
47  static SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) {
48  SkIRect rect;
49  rect.set(l, t, r, b);
50  return rect;
51  }
52 
53  static SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) {
54  SkIRect r;
55  r.set(x, y, x + w, y + h);
56  return r;
57  }
58 
59  int left() const { return fLeft; }
60  int top() const { return fTop; }
61  int right() const { return fRight; }
62  int bottom() const { return fBottom; }
63 
65  int x() const { return fLeft; }
67  int y() const { return fTop; }
72  int width() const { return fRight - fLeft; }
73 
78  int height() const { return fBottom - fTop; }
79 
80  SkISize size() const { return SkISize::Make(this->width(), this->height()); }
81 
89  int centerX() const { return (fRight + fLeft) >> 1; }
90 
98  int centerY() const { return (fBottom + fTop) >> 1; }
99 
103  bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
104 
105  bool isLargest() const { return SK_MinS32 == fLeft &&
106  SK_MinS32 == fTop &&
107  SK_MaxS32 == fRight &&
108  SK_MaxS32 == fBottom; }
109 
110  friend bool operator==(const SkIRect& a, const SkIRect& b) {
111  return !memcmp(&a, &b, sizeof(a));
112  }
113 
114  friend bool operator!=(const SkIRect& a, const SkIRect& b) {
115  return !(a == b);
116  }
117 
118  bool is16Bit() const {
119  return SkIsS16(fLeft) && SkIsS16(fTop) &&
120  SkIsS16(fRight) && SkIsS16(fBottom);
121  }
122 
125  void setEmpty() { memset(this, 0, sizeof(*this)); }
126 
127  void set(int32_t left, int32_t top, int32_t right, int32_t bottom) {
128  fLeft = left;
129  fTop = top;
130  fRight = right;
131  fBottom = bottom;
132  }
133  // alias for set(l, t, r, b)
134  void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) {
135  this->set(left, top, right, bottom);
136  }
137 
138  void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) {
139  fLeft = x;
140  fTop = y;
141  fRight = x + width;
142  fBottom = y + height;
143  }
144 
148  void setLargest() {
149  fLeft = fTop = SK_MinS32;
150  fRight = fBottom = SK_MaxS32;
151  }
152 
158  fLeft = fTop = SK_MaxS32;
159  fRight = fBottom = SK_MinS32;
160  }
161 
165  SkIRect makeOffset(int32_t dx, int32_t dy) const {
166  return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
167  }
168 
172  SkIRect makeInset(int32_t dx, int32_t dy) const {
173  return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
174  }
175 
179  SkIRect makeOutset(int32_t dx, int32_t dy) const {
180  return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
181  }
182 
186  void offset(int32_t dx, int32_t dy) {
187  fLeft += dx;
188  fTop += dy;
189  fRight += dx;
190  fBottom += dy;
191  }
192 
193  void offset(const SkIPoint& delta) {
194  this->offset(delta.fX, delta.fY);
195  }
196 
200  void offsetTo(int32_t newX, int32_t newY) {
201  fRight += newX - fLeft;
202  fBottom += newY - fTop;
203  fLeft = newX;
204  fTop = newY;
205  }
206 
211  void inset(int32_t dx, int32_t dy) {
212  fLeft += dx;
213  fTop += dy;
214  fRight -= dx;
215  fBottom -= dy;
216  }
217 
223  void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
224 
225  bool quickReject(int l, int t, int r, int b) const {
226  return l >= fRight || fLeft >= r || t >= fBottom || fTop >= b;
227  }
228 
234  bool contains(int32_t x, int32_t y) const {
235  return (unsigned)(x - fLeft) < (unsigned)(fRight - fLeft) &&
236  (unsigned)(y - fTop) < (unsigned)(fBottom - fTop);
237  }
238 
242  bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const {
243  return left < right && top < bottom && !this->isEmpty() && // check for empties
244  fLeft <= left && fTop <= top &&
245  fRight >= right && fBottom >= bottom;
246  }
247 
250  bool contains(const SkIRect& r) const {
251  return !r.isEmpty() && !this->isEmpty() && // check for empties
252  fLeft <= r.fLeft && fTop <= r.fTop &&
253  fRight >= r.fRight && fBottom >= r.fBottom;
254  }
255 
258  bool contains(const SkRect& r) const;
259 
266  bool containsNoEmptyCheck(int32_t left, int32_t top,
267  int32_t right, int32_t bottom) const {
268  SkASSERT(fLeft < fRight && fTop < fBottom);
269  SkASSERT(left < right && top < bottom);
270 
271  return fLeft <= left && fTop <= top &&
272  fRight >= right && fBottom >= bottom;
273  }
274 
275  bool containsNoEmptyCheck(const SkIRect& r) const {
276  return containsNoEmptyCheck(r.fLeft, r.fTop, r.fRight, r.fBottom);
277  }
278 
283  bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& r) {
284  return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
285  }
286 
291  bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b) {
292 
293  if (!a.isEmpty() && !b.isEmpty() &&
294  a.fLeft < b.fRight && b.fLeft < a.fRight &&
295  a.fTop < b.fBottom && b.fTop < a.fBottom) {
296  fLeft = SkMax32(a.fLeft, b.fLeft);
297  fTop = SkMax32(a.fTop, b.fTop);
298  fRight = SkMin32(a.fRight, b.fRight);
299  fBottom = SkMin32(a.fBottom, b.fBottom);
300  return true;
301  }
302  return false;
303  }
304 
311  bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) {
312  SkASSERT(!a.isEmpty() && !b.isEmpty());
313 
314  if (a.fLeft < b.fRight && b.fLeft < a.fRight &&
315  a.fTop < b.fBottom && b.fTop < a.fBottom) {
316  fLeft = SkMax32(a.fLeft, b.fLeft);
317  fTop = SkMax32(a.fTop, b.fTop);
318  fRight = SkMin32(a.fRight, b.fRight);
319  fBottom = SkMin32(a.fBottom, b.fBottom);
320  return true;
321  }
322  return false;
323  }
324 
330  bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top,
331  int32_t right, int32_t bottom) {
332  if (left < right && top < bottom && !this->isEmpty() &&
333  fLeft < right && left < fRight && fTop < bottom && top < fBottom) {
334  if (fLeft < left) fLeft = left;
335  if (fTop < top) fTop = top;
336  if (fRight > right) fRight = right;
337  if (fBottom > bottom) fBottom = bottom;
338  return true;
339  }
340  return false;
341  }
342 
345  static bool Intersects(const SkIRect& a, const SkIRect& b) {
346  return !a.isEmpty() && !b.isEmpty() && // check for empties
347  a.fLeft < b.fRight && b.fLeft < a.fRight &&
348  a.fTop < b.fBottom && b.fTop < a.fBottom;
349  }
350 
354  static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) {
355  SkASSERT(!a.isEmpty());
356  SkASSERT(!b.isEmpty());
357  return a.fLeft < b.fRight && b.fLeft < a.fRight &&
358  a.fTop < b.fBottom && b.fTop < a.fBottom;
359  }
360 
365  void join(int32_t left, int32_t top, int32_t right, int32_t bottom);
366 
371  void join(const SkIRect& r) {
372  this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
373  }
374 
380  void sort();
381 
382  static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect() {
383  static const SkIRect gEmpty = { 0, 0, 0, 0 };
384  return gEmpty;
385  }
386 };
387 
390 struct SK_API SkRect {
391  SkScalar fLeft, fTop, fRight, fBottom;
392 
393  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty() {
394  return SkRect{0, 0, 0, 0};
395  }
396 
397  static SkRect SK_WARN_UNUSED_RESULT MakeLargest() {
398  SkRect r;
399  r.setLargest();
400  return r;
401  }
402 
403  static SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) {
404  SkRect r;
405  r.set(0, 0, w, h);
406  return r;
407  }
408 
409  static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) {
410  SkRect r;
411  r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
412  return r;
413  }
414 
415  static SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) {
416  SkRect r;
417  r.set(0, 0, size.width(), size.height());
418  return r;
419  }
420 
421  static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
422  SkScalar b) {
423  return SkRect {l, t, r, b};
424  }
425 
426  static SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) {
427  SkRect r;
428  r.set(x, y, x + w, y + h);
429  return r;
430  }
431 
432  SK_ATTR_DEPRECATED("use Make()")
433  static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect) {
434  SkRect r;
435  r.set(SkIntToScalar(irect.fLeft),
436  SkIntToScalar(irect.fTop),
437  SkIntToScalar(irect.fRight),
438  SkIntToScalar(irect.fBottom));
439  return r;
440  }
441 
442  static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) {
443  SkRect r;
444  r.set(SkIntToScalar(irect.fLeft),
445  SkIntToScalar(irect.fTop),
446  SkIntToScalar(irect.fRight),
447  SkIntToScalar(irect.fBottom));
448  return r;
449  }
450 
454  bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
455 
456  bool isLargest() const { return SK_ScalarMin == fLeft &&
457  SK_ScalarMin == fTop &&
458  SK_ScalarMax == fRight &&
459  SK_ScalarMax == fBottom; }
460 
465  bool isFinite() const {
466  float accum = 0;
467  accum *= fLeft;
468  accum *= fTop;
469  accum *= fRight;
470  accum *= fBottom;
471 
472  // accum is either NaN or it is finite (zero).
473  SkASSERT(0 == accum || SkScalarIsNaN(accum));
474 
475  // value==value will be true iff value is not NaN
476  // TODO: is it faster to say !accum or accum==accum?
477  return !SkScalarIsNaN(accum);
478  }
479 
480  SkScalar x() const { return fLeft; }
481  SkScalar y() const { return fTop; }
482  SkScalar left() const { return fLeft; }
483  SkScalar top() const { return fTop; }
484  SkScalar right() const { return fRight; }
485  SkScalar bottom() const { return fBottom; }
486  SkScalar width() const { return fRight - fLeft; }
487  SkScalar height() const { return fBottom - fTop; }
488  SkScalar centerX() const { return SkScalarHalf(fLeft + fRight); }
489  SkScalar centerY() const { return SkScalarHalf(fTop + fBottom); }
490 
491  friend bool operator==(const SkRect& a, const SkRect& b) {
492  return SkScalarsEqual((SkScalar*)&a, (SkScalar*)&b, 4);
493  }
494 
495  friend bool operator!=(const SkRect& a, const SkRect& b) {
496  return !SkScalarsEqual((SkScalar*)&a, (SkScalar*)&b, 4);
497  }
498 
502  void toQuad(SkPoint quad[4]) const;
503 
506  void setEmpty() { *this = MakeEmpty(); }
507 
508  void set(const SkIRect& src) {
509  fLeft = SkIntToScalar(src.fLeft);
510  fTop = SkIntToScalar(src.fTop);
511  fRight = SkIntToScalar(src.fRight);
512  fBottom = SkIntToScalar(src.fBottom);
513  }
514 
515  void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
516  fLeft = left;
517  fTop = top;
518  fRight = right;
519  fBottom = bottom;
520  }
521  // alias for set(l, t, r, b)
522  void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
523  this->set(left, top, right, bottom);
524  }
525 
529  void iset(int left, int top, int right, int bottom) {
530  fLeft = SkIntToScalar(left);
531  fTop = SkIntToScalar(top);
532  fRight = SkIntToScalar(right);
533  fBottom = SkIntToScalar(bottom);
534  }
535 
540  void isetWH(int width, int height) {
541  fLeft = fTop = 0;
542  fRight = SkIntToScalar(width);
543  fBottom = SkIntToScalar(height);
544  }
545 
550  void set(const SkPoint pts[], int count) {
551  // set() had been checking for non-finite values, so keep that behavior
552  // for now. Now that we have setBoundsCheck(), we may decide to make
553  // set() be simpler/faster, and not check for those.
554  (void)this->setBoundsCheck(pts, count);
555  }
556 
557  // alias for set(pts, count)
558  void setBounds(const SkPoint pts[], int count) {
559  (void)this->setBoundsCheck(pts, count);
560  }
561 
567  bool setBoundsCheck(const SkPoint pts[], int count);
568 
569  void set(const SkPoint& p0, const SkPoint& p1) {
570  fLeft = SkMinScalar(p0.fX, p1.fX);
571  fRight = SkMaxScalar(p0.fX, p1.fX);
572  fTop = SkMinScalar(p0.fY, p1.fY);
573  fBottom = SkMaxScalar(p0.fY, p1.fY);
574  }
575 
576  void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) {
577  fLeft = x;
578  fTop = y;
579  fRight = x + width;
580  fBottom = y + height;
581  }
582 
583  void setWH(SkScalar width, SkScalar height) {
584  fLeft = 0;
585  fTop = 0;
586  fRight = width;
587  fBottom = height;
588  }
589 
593  void setLargest() {
594  fLeft = fTop = SK_ScalarMin;
595  fRight = fBottom = SK_ScalarMax;
596  }
597 
603  fLeft = fTop = SK_ScalarMax;
604  fRight = fBottom = SK_ScalarMin;
605  }
606 
610  SkRect makeOffset(SkScalar dx, SkScalar dy) const {
611  return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
612  }
613 
617  SkRect makeInset(SkScalar dx, SkScalar dy) const {
618  return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
619  }
620 
624  SkRect makeOutset(SkScalar dx, SkScalar dy) const {
625  return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
626  }
627 
631  void offset(SkScalar dx, SkScalar dy) {
632  fLeft += dx;
633  fTop += dy;
634  fRight += dx;
635  fBottom += dy;
636  }
637 
638  void offset(const SkPoint& delta) {
639  this->offset(delta.fX, delta.fY);
640  }
641 
645  void offsetTo(SkScalar newX, SkScalar newY) {
646  fRight += newX - fLeft;
647  fBottom += newY - fTop;
648  fLeft = newX;
649  fTop = newY;
650  }
651 
657  void inset(SkScalar dx, SkScalar dy) {
658  fLeft += dx;
659  fTop += dy;
660  fRight -= dx;
661  fBottom -= dy;
662  }
663 
669  void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); }
670 
675  bool SK_WARN_UNUSED_RESULT intersect(const SkRect& r);
676 
682  bool SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top,
683  SkScalar right, SkScalar bottom);
684 
690  bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b);
691 
692 
693 private:
694  static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab,
695  SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) {
696  SkScalar L = SkMaxScalar(al, bl);
697  SkScalar R = SkMinScalar(ar, br);
698  SkScalar T = SkMaxScalar(at, bt);
699  SkScalar B = SkMinScalar(ab, bb);
700  return L < R && T < B;
701  }
702 
703 public:
708  bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const {
709  return Intersects(fLeft, fTop, fRight, fBottom, left, top, right, bottom);
710  }
711 
712  bool intersects(const SkRect& r) const {
713  return Intersects(fLeft, fTop, fRight, fBottom,
714  r.fLeft, r.fTop, r.fRight, r.fBottom);
715  }
716 
720  static bool Intersects(const SkRect& a, const SkRect& b) {
721  return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
722  b.fLeft, b.fTop, b.fRight, b.fBottom);
723  }
724 
730  void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
731 
736  void join(const SkRect& r) {
737  this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
738  }
739 
740  void joinNonEmptyArg(const SkRect& r) {
741  SkASSERT(!r.isEmpty());
742  // if we are empty, just assign
743  if (fLeft >= fRight || fTop >= fBottom) {
744  *this = r;
745  } else {
746  this->joinPossiblyEmptyRect(r);
747  }
748  }
749 
754  void joinPossiblyEmptyRect(const SkRect& r) {
755  fLeft = SkMinScalar(fLeft, r.left());
756  fTop = SkMinScalar(fTop, r.top());
757  fRight = SkMaxScalar(fRight, r.right());
758  fBottom = SkMaxScalar(fBottom, r.bottom());
759  }
760 
770  void growToInclude(SkScalar x, SkScalar y) {
771  fLeft = SkMinScalar(x, fLeft);
772  fRight = SkMaxScalar(x, fRight);
773  fTop = SkMinScalar(y, fTop);
774  fBottom = SkMaxScalar(y, fBottom);
775  }
776 
778  void growToInclude(const SkPoint pts[], int count) {
779  this->growToInclude(pts, sizeof(SkPoint), count);
780  }
781 
783  void growToInclude(const SkPoint pts[], size_t stride, int count) {
784  SkASSERT(count >= 0);
785  SkASSERT(stride >= sizeof(SkPoint));
786  const SkPoint* end = (const SkPoint*)((intptr_t)pts + count * stride);
787  for (; pts < end; pts = (const SkPoint*)((intptr_t)pts + stride)) {
788  this->growToInclude(pts->fX, pts->fY);
789  }
790  }
791 
796  bool contains(const SkRect& r) const {
797  // todo: can we eliminate the this->isEmpty check?
798  return !r.isEmpty() && !this->isEmpty() &&
799  fLeft <= r.fLeft && fTop <= r.fTop &&
800  fRight >= r.fRight && fBottom >= r.fBottom;
801  }
802 
806  bool contains(const SkIRect& r) const {
807  // todo: can we eliminate the this->isEmpty check?
808  return !r.isEmpty() && !this->isEmpty() &&
809  fLeft <= SkIntToScalar(r.fLeft) && fTop <= SkIntToScalar(r.fTop) &&
810  fRight >= SkIntToScalar(r.fRight) && fBottom >= SkIntToScalar(r.fBottom);
811  }
812 
817  void round(SkIRect* dst) const {
818  SkASSERT(dst);
819  dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
820  SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
821  }
822 
827  void roundOut(SkIRect* dst) const {
828  SkASSERT(dst);
829  dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
830  SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
831  }
832 
839  void roundOut(SkRect* dst) const {
840  dst->set(SkScalarFloorToScalar(fLeft),
841  SkScalarFloorToScalar(fTop),
842  SkScalarCeilToScalar(fRight),
843  SkScalarCeilToScalar(fBottom));
844  }
845 
852  void roundIn(SkIRect* dst) const {
853  SkASSERT(dst);
854  dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
855  SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
856  }
857 
859  SkIRect round() const {
860  SkIRect ir;
861  this->round(&ir);
862  return ir;
863  }
864 
866  SkIRect roundOut() const {
867  SkIRect ir;
868  this->roundOut(&ir);
869  return ir;
870  }
871 
878  void sort() {
879  if (fLeft > fRight) {
880  SkTSwap<SkScalar>(fLeft, fRight);
881  }
882 
883  if (fTop > fBottom) {
884  SkTSwap<SkScalar>(fTop, fBottom);
885  }
886  }
887 
891  const SkScalar* asScalars() const { return &fLeft; }
892 
893  void dump(bool asHex) const;
894  void dump() const { this->dump(false); }
895  void dumpHex() const { this->dump(true); }
896 };
897 
898 inline bool SkIRect::contains(const SkRect& r) const {
899  return !r.isEmpty() && !this->isEmpty() && // check for empties
900  (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop &&
901  (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom;
902 }
903 
904 #endif
static bool Intersects(const SkIRect &a, const SkIRect &b)
Returns true if a and b are not empty, and they intersect.
Definition: SkRect.h:345
void growToInclude(const SkPoint pts[], int count)
Bulk version of growToInclude.
Definition: SkRect.h:778
void inset(int32_t dx, int32_t dy)
Inset the rectangle by (dx,dy).
Definition: SkRect.h:211
SkIRect makeOffset(int32_t dx, int32_t dy) const
Return a new IRect, built as an offset of this rect.
Definition: SkRect.h:165
void outset(SkScalar dx, SkScalar dy)
Outset the rectangle by (dx,dy).
Definition: SkRect.h:669
void setLargest()
Make the largest representable rectangle.
Definition: SkRect.h:593
void isetWH(int width, int height)
Set this rectangle to be left/top at 0,0, and have the specified width and height (automatically conv...
Definition: SkRect.h:540
bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect &a, const SkIRect &b)
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:311
void set(const SkPoint pts[], int count)
Set this rectangle to be the bounds of the array of points.
Definition: SkRect.h:550
void sort()
Swap top/bottom or left/right if there are flipped (i.e.
Definition: SkRect.h:878
void roundOut(SkRect *dst) const
Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloorToScalar of top and...
Definition: SkRect.h:839
bool contains(const SkRect &r) const
Return true if this rectangle contains r, and if both rectangles are not empty.
Definition: SkRect.h:796
bool containsNoEmptyCheck(int32_t left, int32_t top, int32_t right, int32_t bottom) const
Return true if this rectangle contains the specified rectangle.
Definition: SkRect.h:266
void iset(int left, int top, int right, int bottom)
Initialize the rect with the 4 specified integers.
Definition: SkRect.h:529
void offsetTo(SkScalar newX, SkScalar newY)
Offset this rect such its new x() and y() will equal newX and newY.
Definition: SkRect.h:645
Definition: SkPoint.h:156
void growToInclude(const SkPoint pts[], size_t stride, int count)
Bulk version of growToInclude with stride.
Definition: SkRect.h:783
const SkScalar * asScalars() const
cast-safe way to treat the rect as an array of (4) SkScalars.
Definition: SkRect.h:891
bool contains(const SkIRect &r) const
Returns true if the specified rectangle r is inside or equal to this rectangle.
Definition: SkRect.h:806
void setEmpty()
Set the rectangle to (0,0,0,0)
Definition: SkRect.h:125
SkRect makeInset(SkScalar dx, SkScalar dy) const
Return a new Rect, built as an inset of this rect.
Definition: SkRect.h:617
void setLargestInverted()
Make the largest representable rectangle, but inverted (e.g.
Definition: SkRect.h:602
void outset(int32_t dx, int32_t dy)
Outset the rectangle by (dx,dy).
Definition: SkRect.h:223
void inset(SkScalar dx, SkScalar dy)
Inset the rectangle by (dx,dy).
Definition: SkRect.h:657
int centerY() const
Since the center of an integer rect may fall on a factional value, this method is defined to return (...
Definition: SkRect.h:98
bool isFinite() const
Returns true iff all values in the rect are finite.
Definition: SkRect.h:465
int x() const
return the left edge of the rect
Definition: SkRect.h:65
bool contains(int32_t x, int32_t y) const
Returns true if (x,y) is inside the rectangle and the rectangle is not empty.
Definition: SkRect.h:234
void offset(SkScalar dx, SkScalar dy)
Offset set the rectangle by adding dx to its left and right, and adding dy to its top and bottom...
Definition: SkRect.h:631
int height() const
Returns the rectangle's height.
Definition: SkRect.h:78
bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
Returns true if the 4 specified sides of a rectangle are inside or equal to this rectangle.
Definition: SkRect.h:242
static bool Intersects(const SkRect &a, const SkRect &b)
Return true if rectangles a and b are not empty and intersect.
Definition: SkRect.h:720
void growToInclude(SkScalar x, SkScalar y)
Grow the rect to include the specified (x,y).
Definition: SkRect.h:770
bool isEmpty() const
Return true if the rectangle's width or height are <= 0.
Definition: SkRect.h:103
bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set th...
Definition: SkRect.h:330
static bool SkIsS16(long x)
Returns true if the value can be represented with signed 16bits.
Definition: SkTypes.h:301
static bool IntersectsNoEmptyCheck(const SkIRect &a, const SkIRect &b)
Returns true if a and b intersect.
Definition: SkRect.h:354
int centerX() const
Since the center of an integer rect may fall on a factional value, this method is defined to return (...
Definition: SkRect.h:89
SkRect makeOutset(SkScalar dx, SkScalar dy) const
Return a new Rect, built as an outset of this rect.
Definition: SkRect.h:624
SkIRect roundOut() const
Returns the result of calling roundOut(&dst)
Definition: SkRect.h:866
SkIRect round() const
Returns the result of calling round(&dst)
Definition: SkRect.h:859
void setLargest()
Make the largest representable rectangle.
Definition: SkRect.h:148
SkIRect makeOutset(int32_t dx, int32_t dy) const
Return a new Rect, built as an outset of this rect.
Definition: SkRect.h:179
void setEmpty()
Set this rectangle to the empty rectangle (0,0,0,0)
Definition: SkRect.h:506
void offset(int32_t dx, int32_t dy)
Offset set the rectangle by adding dx to its left and right, and adding dy to its top and bottom...
Definition: SkRect.h:186
void roundIn(SkIRect *dst) const
Set the dst rectangle by rounding "in" this rectangle, choosing the ceil of top and left...
Definition: SkRect.h:852
int width() const
Returns the rectangle's width.
Definition: SkRect.h:72
Definition: SkRect.h:390
void roundOut(SkIRect *dst) const
Set the dst rectangle by rounding "out" this rectangle, choosing the SkScalarFloor of top and left...
Definition: SkRect.h:827
void offsetTo(int32_t newX, int32_t newY)
Offset this rect such its new x() and y() will equal newX and newY.
Definition: SkRect.h:200
bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
Return true if this rectangle is not empty, and the specified sides of a rectangle are not empty...
Definition: SkRect.h:708
void join(const SkIRect &r)
Update this rectangle to enclose itself and the specified rectangle.
Definition: SkRect.h:371
bool contains(const SkIRect &r) const
Returns true if the specified rectangle r is inside or equal to this rectangle.
Definition: SkRect.h:250
void round(SkIRect *dst) const
Set the dst rectangle by rounding this rectangle's coordinates to their nearest integer values using ...
Definition: SkRect.h:817
void join(const SkRect &r)
Update this rectangle to enclose itself and the specified rectangle.
Definition: SkRect.h:736
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &r)
If r intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:283
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Definition: SkSize.h:77
bool isEmpty() const
Return true if the rectangle's width or height are <= 0.
Definition: SkRect.h:454
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40
int y() const
return the top edge of the rect
Definition: SkRect.h:67
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect &a, const SkIRect &b)
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Definition: SkRect.h:291
SkRect makeOffset(SkScalar dx, SkScalar dy) const
Return a new Rect, built as an offset of this rect.
Definition: SkRect.h:610
SkIRect makeInset(int32_t dx, int32_t dy) const
Return a new IRect, built as an inset of this rect.
Definition: SkRect.h:172
void setLargestInverted()
Make the largest representable rectangle, but inverted (e.g.
Definition: SkRect.h:157
void joinPossiblyEmptyRect(const SkRect &r)
Joins the rectangle with another without checking if either are empty (may produce unexpected results...
Definition: SkRect.h:754