blob: b29020bb1be3daab8fbc421adc92175b33fdf6f1 [file] [log] [blame]
Cary Clark0c5f5462017-12-15 11:21:51 -05001#Topic IRect
2#Alias IRect_Reference
3
4#Struct SkIRect
5
6SkIRect holds four 32 bit integer coordinates describing the upper and
7lower bounds of a rectangle. SkIRect may be created from outer bounds or
8from position, width, and height. SkIRect describes an area; if its right
9is less than or equal to its left, or if its bottom is less than or equal to
10its top, it is considered empty.
11
12#Topic Overview
13
14#Subtopic Subtopics
15#ToDo manually add subtopics ##
16#Table
17#Legend
18# topics # description ##
19#Legend ##
20#Table ##
21##
22
23#Subtopic Operators
24#Table
25#Legend
26# description # function ##
27#Legend ##
28# bool operator!=(const SkIRect& a, const SkIRect& b) # Returns true if members are unequal. ##
29# bool operator==(const SkIRect& a, const SkIRect& b) # Returns true if members are equal. ##
30#Table ##
31#Subtopic ##
32
33#Subtopic Member_Functions
34#Table
35#Legend
36# description # function ##
37#Legend ##
38# EmptyIRect # Returns immutable bounds of (0, 0, 0, 0). ##
39# Intersects # Returns true if areas overlap. ##
40# IntersectsNoEmptyCheck # Returns true if areas overlap. Skips empty check. ##
41# MakeEmpty # Returns bounds of (0, 0, 0, 0). ##
42# MakeLTRB # Constructs from int left, top, right, bottom. ##
43# MakeLargest # Constructs from (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32). ##
44# MakeSize # Constructs from ISize returning (0, 0, width, height). ##
45# MakeWH # Constructs from int input returning (0, 0, width, height). ##
46# MakeXYWH # Constructs from int input returning (x, y, width, height). ##
47# bottom() # Returns larger bounds in y, if sorted. ##
48# centerX # Returns midpoint in x. ##
49# centerY # Returns midpoint in y. ##
50# contains() # Returns true if points are equal or inside. ##
51# containsNoEmptyCheck # Returns true if points are equal or inside. Skips empty check. ##
52# height() # Returns span in y. ##
53# inset() # Moves the sides symmetrically about the center. ##
54# intersect # Sets to shared area; returns true if not empty. ##
55# intersectNoEmptyCheck # Sets to shared area; returns true if not empty. Skips empty check. ##
56# is16Bit # Returns true if members fit in 16-bit word. ##
57# isEmpty # Returns true if width or height are zero or negative. ##
58# isLargest # Returns true if equal to (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32). ##
59# join() # Sets to union of bounds. ##
60# left() # Returns smaller bounds in x, if sorted. ##
61# makeInset # Constructs from sides moved symmetrically about the center. ##
62# makeOffset # Constructs from translated sides. ##
63# makeOutset # Constructs from sides moved symmetrically about the center. ##
64# makeSorted # Constructs, ordering sides from smaller to larger. ##
65# offset() # Translates sides without changing width and height. ##
66# offsetTo # Translates to (x, y) without changing width and height. ##
67# outset() # Moves the sides symmetrically about the center. ##
68# quickReject # Returns true if rectangles do not intersect. ##
69# right() # Returns larger bounds in x, if sorted. ##
70# set() # Sets to (left, top, right, bottom). ##
71# setEmpty # Sets to (0, 0, 0, 0). ##
72# setLTRB # Sets to SkScalar input (left, top, right, bottom). ##
73# setLargest # Sets to (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32). ##
74# setLargestInverted # Sets to (SK_MaxS32, SK_MaxS32, SK_MinS32, SK_MinS32). ##
75# setXYWH # Sets to (x, y, width, height). ##
76# size() # Returns ISize (width, height). ##
77# sort() # Orders sides from smaller to larger. ##
78# top() # Returns smaller bounds in y, if sorted. ##
79# width() # Returns span in x. ##
80# x() # Returns bounds left. ##
81# y() # Returns bounds top. ##
82#Table ##
83#Subtopic ##
84
85#Topic ##
86
87#Member int32_t fLeft
88May contain any value. The smaller of the horizontal values when sorted.
89When equal to or greater than fRight, IRect is empty.
90##
91
92#Member int32_t fTop
93May contain any value. The smaller of the horizontal values when sorted.
94When equal to or greater than fBottom, IRect is empty.
95##
96
97#Member int32_t fRight
98May contain any value. The larger of the vertical values when sorted.
99When equal to or less than fLeft, IRect is empty.
100##
101
102#Member int32_t fBottom
103May contain any value. The larger of the vertical values when sorted.
104When equal to or less than fTop, IRect is empty.
105##
106
107# ------------------------------------------------------------------------------
108
109#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty()
110
111Returns constructed IRect set to (0, 0, 0, 0).
112Many other rectangles are empty; if left is equal to or greater than right,
113or if top is equal to or greater than bottom. Setting all members to zero
114is a convenience, but does not designate a special empty rectangle.
115
116#Return bounds (0, 0, 0, 0) ##
117
118#Example
119 SkIRect rect = SkIRect::MakeEmpty();
120 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
121 rect.offset(10, 10);
122 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
123 rect.inset(10, 10);
124 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
125 rect.outset(20, 20);
126 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
127#StdOut
128MakeEmpty isEmpty: true
129offset rect isEmpty: true
130inset rect isEmpty: true
131outset rect isEmpty: false
132##
133##
134
135#SeeAlso EmptyIRect isEmpty setEmpty setLargestInverted SkRect::MakeEmpty
136
137##
138
139# ------------------------------------------------------------------------------
140
141#Method static SkIRect SK_WARN_UNUSED_RESULT MakeLargest()
142
143Returns constructed IRect setting left and top to most negative value, and
144setting right and bottom to most positive value.
145
146#Return bounds (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32) ##
147
148#Example
149 SkIRect rect = SkIRect::MakeLargest();
150 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
151 SkDebugf("MakeLargest isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
152 rect.outset(1, 1);
153 SkDebugf("outset isLargest: %s\n", rect.isLargest() ? "true" : "false");
154 SkDebugf("outset isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
155#StdOut
156MakeLargest isLargest: true
157MakeLargest isEmpty: false
158outset isLargest: false
159outset isEmpty: true
160##
161##
162
163#SeeAlso isLargest setLargest SkRect::MakeLargest
164
165##
166
167# ------------------------------------------------------------------------------
168
169#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h)
170
171Returns constructed IRect set to (0, 0, w, h). Does not validate input; w or h
172may be negative.
173
174#Param w width of constructed Rect ##
175#Param h height of constructed Rect ##
176
177#Return bounds (0, 0, w, h) ##
178
179#Example
180 SkIRect rect1 = SkIRect::MakeWH(25, 35);
181 SkIRect rect2 = SkIRect::MakeSize({25, 35});
182 SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35);
183 SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35);
184 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
185 "" : "not ");
186#StdOut
187all equal
188##
189##
190
191#SeeAlso MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH
192
193##
194
195# ------------------------------------------------------------------------------
196
197#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size)
198
199Returns constructed IRect set to (0, 0, size.width(), size.height()).
200Does not validate input; size.width() or size.height() may be negative.
201
202#Param size values for Rect width and height ##
203
204#Return bounds (0, 0, size.width(), size.height()) ##
205
206#Example
207 SkSize size = {25.5f, 35.5f};
208 SkIRect rect = SkIRect::MakeSize(size.toRound());
209 SkDebugf("round width: %d height: %d\n", rect.width(), rect.height());
210 rect = SkIRect::MakeSize(size.toFloor());
211 SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height());
212#StdOut
213round width: 26 height: 36
214floor width: 25 height: 35
215##
216##
217
218#SeeAlso MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH
219
220##
221
222# ------------------------------------------------------------------------------
223
224#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
225
226Returns constructed IRect set to (l, t, r, b). Does not sort input; Rect may
227result in fLeft greater than fRight, or fTop greater than fBottom.
228
229#Param l integer stored in fLeft ##
230#Param t integer stored in fTop ##
231#Param r integer stored in fRight ##
232#Param b integer stored in fBottom ##
233
234#Return bounds (l, t, r, b) ##
235
236#Example
237 SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25);
238 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
239 rect.bottom(), rect.isEmpty() ? "true" : "false");
240 rect.sort();
241 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
242 rect.bottom(), rect.isEmpty() ? "true" : "false");
243#StdOut
244rect: 5, 35, 15, 25 isEmpty: true
245rect: 5, 25, 15, 35 isEmpty: false
246##
247##
248
249#SeeAlso MakeXYWH SkRect::MakeLTRB
250
251##
252
253# ------------------------------------------------------------------------------
254
255#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
256
257Returns constructed IRect set to:
258#Formula
259(x, y, x + w, y + h)
260##
261. Does not validate input;
262w or h may be negative.
263
264#Param x stored in fLeft ##
265#Param y stored in fTop ##
266#Param w added to x and stored in fRight ##
267#Param h added to y and stored in fBottom ##
268
269#Return bounds at (x, y) with width w and height h ##
270
271#Example
272 SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25);
273 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
274 rect.bottom(), rect.isEmpty() ? "true" : "false");
275 rect.sort();
276 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
277 rect.bottom(), rect.isEmpty() ? "true" : "false");
278#StdOut
279rect: 5, 35, -10, 60 isEmpty: true
280rect: -10, 35, 5, 60 isEmpty: false
281##
282##
283
284#SeeAlso MakeLTRB SkRect::MakeXYWH
285
286##
287
288# ------------------------------------------------------------------------------
289
290#Method int left() const
291
292Returns left edge of IRect, if sorted.
293Call sort() to reverse fLeft and fRight if needed.
294
295#Return fLeft ##
296
297#Example
298 SkIRect unsorted = { 15, 5, 10, 25 };
299 SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left());
300 SkIRect sorted = unsorted.makeSorted();
301 SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left());
302#StdOut
303unsorted.fLeft: 15 unsorted.left(): 15
304sorted.fLeft: 10 sorted.left(): 10
305##
306##
307
308#SeeAlso fLeft x() SkRect::left()
309
310##
311
312# ------------------------------------------------------------------------------
313
314#Method int top() const
315
316Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
317and sort() to reverse fTop and fBottom if needed.
318
319#Return fTop ##
320
321#Example
322 SkIRect unsorted = { 15, 25, 10, 5 };
323 SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top());
324 SkIRect sorted = unsorted.makeSorted();
325 SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top());
326#StdOut
327unsorted.fTop: 25 unsorted.top(): 25
328sorted.fTop: 5 sorted.top(): 5
329##
330##
331
332#SeeAlso fTop y() SkRect::top()
333
334##
335
336# ------------------------------------------------------------------------------
337
338#Method int right() const
339
340Returns right edge of IRect, if sorted.
341Call sort() to reverse fLeft and fRight if needed.
342
343#Return fRight ##
344
345#Example
346 SkIRect unsorted = { 15, 25, 10, 5 };
347 SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right());
348 SkIRect sorted = unsorted.makeSorted();
349 SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right());
350#StdOut
351unsorted.fRight: 10 unsorted.right(): 10
352sorted.fRight: 15 sorted.right(): 15
353##
354##
355
356#SeeAlso fRight SkRect::right()
357
358##
359
360# ------------------------------------------------------------------------------
361
362#Method int bottom() const
363
364Returns bottom edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
365and sort() to reverse fTop and fBottom if needed.
366
367#Return fBottom ##
368
369#Example
370 SkIRect unsorted = { 15, 25, 10, 5 };
371 SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom());
372 SkIRect sorted = unsorted.makeSorted();
373 SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom());
374#StdOut
375unsorted.fBottom: 5 unsorted.bottom(): 5
376sorted.fBottom: 25 sorted.bottom(): 25
377##
378##
379
380#SeeAlso fBottom SkRect::bottom()
381
382##
383
384# ------------------------------------------------------------------------------
385
386#Method int x() const
387
388Returns left edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
389and sort() to reverse fLeft and fRight if needed.
390
391#Return fLeft ##
392
393#Example
394 SkIRect unsorted = { 15, 5, 10, 25 };
395 SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x());
396 SkIRect sorted = unsorted.makeSorted();
397 SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x());
398#StdOut
399unsorted.fLeft: 15 unsorted.x(): 15
400sorted.fLeft: 10 sorted.x(): 10
401##
402##
403
404#SeeAlso fLeft left() y() SkRect::x()
405
406##
407
408# ------------------------------------------------------------------------------
409
410#Method int y() const
411
412Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
413and sort() to reverse fTop and fBottom if needed.
414
415#Return fTop ##
416
417#Example
418 SkIRect unsorted = { 15, 25, 10, 5 };
419 SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y());
420 SkIRect sorted = unsorted.makeSorted();
421 SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y());
422#StdOut
423unsorted.fTop: 25 unsorted.y(): 25
424sorted.fTop: 5 sorted.y(): 5
425##
426##
427
428#SeeAlso fTop top() x() SkRect::y()
429
430##
431
432# ------------------------------------------------------------------------------
433
434#Method int width() const
435
436Returns span on the x-axis. This does not check if IRect is sorted, or if
437result fits in 32-bit signed integer; result may be negative.
438
439#Return fRight minus fLeft ##
440
441#Example
442 SkIRect unsorted = { 15, 25, 10, 5 };
443 SkDebugf("unsorted width: %d\n", unsorted.width());
444 SkIRect large = { -2147483647, 1, 2147483644, 2 };
445 SkDebugf("large width: %d\n", large.width());
446#StdOut
447unsorted width: -5
448large width: -5
449##
450##
451
452#SeeAlso height() SkRect::width()
453
454##
455
456# ------------------------------------------------------------------------------
457
458#Method int height() const
459
460Returns span on the y-axis. This does not check if IRect is sorted, or if
461result fits in 32-bit signed integer; result may be negative.
462
463#Return fBottom minus fTop ##
464
465#Example
466 SkIRect unsorted = { 15, 25, 10, 20 };
467 SkDebugf("unsorted height: %d\n", unsorted.height());
468 SkIRect large = { 1, -2147483647, 2, 2147483644 };
469 SkDebugf("large height: %d\n", large.height());
470#StdOut
471unsorted height: -5
472large height: -5
473##
474##
475
476#SeeAlso width() SkRect::height()
477
478##
479
480# ------------------------------------------------------------------------------
481
482#Method SkISize size() const
483
484Returns spans on the x-axis and y-axis. This does not check if IRect is sorted,
485or if result fits in 32-bit signed integer; result may be negative.
486
487#Return ISize (width, height) ##
488
489#Example
490 auto debugster = [](const char* prefix, const SkIRect& rect) -> void {
491 SkISize size = rect.size();
492 SkDebugf("%s ", prefix);
493 SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom());
494 SkDebugf("size: %d, %d\n", size.width(), size.height());
495 };
496 SkIRect rect = {20, 30, 40, 50};
497 debugster("original", rect);
498 rect.offset(20, 20);
499 debugster(" offset", rect);
500 rect.outset(20, 20);
501 debugster(" outset", rect);
502#StdOut
503original rect: 20, 30, 40, 50 size: 20, 20
504 offset rect: 40, 50, 60, 70 size: 20, 20
505 outset rect: 20, 30, 80, 90 size: 60, 60
506##
507##
508
509#SeeAlso height() width() MakeSize
510
511##
512
513# ------------------------------------------------------------------------------
514
515#Method int centerX() const
516
517Returns average of left edge and right edge. Result does not change if Rect
518is sorted. Result may be incorrect if Rect is far from the origin.
519
520Result is rounded down.
521
522#Return midpoint in x ##
523
524#Example
525#Description
526Dividing by two rounds towards zero. centerX uses a bit shift and rounds down.
527##
528 SkIRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}, {-10, -10, 11, 11}};
529 for (auto rect : tests) {
530 SkDebugf("left: %3d right: %3d centerX: %3d ", rect.left(), rect.right(), rect.centerX());
531 SkDebugf("div2: %3d\n", (rect.left() + rect.right()) / 2);
532 }
533#StdOut
534left: 20 right: 41 centerX: 30 div2: 30
535left: -20 right: -41 centerX: -31 div2: -30
536left: -10 right: 11 centerX: 0 div2: 0
537##
538##
539
540#SeeAlso centerY SkRect::centerX
541
542##
543
544# ------------------------------------------------------------------------------
545
546#Method int centerY() const
547
548Returns average of top edge and bottom edge. Result does not change if Rect
549is sorted. Result may be incorrect if Rect is far from the origin.
550
551Result is rounded down.
552
553#Return midpoint in y ##
554
555#Example
556 SkIRect rect = { 0, 0, 2, 2 };
557 rect.offset(0x40000000, 0x40000000);
558 SkDebugf("left: %d right: %d centerX: %d ", rect.left(), rect.right(), rect.centerX());
559 SkDebugf("safe mid x: %d\n", rect.left() / 2 + rect.right() / 2);
560#StdOut
561left: 1073741824 right: 1073741826 centerX: -1073741823 safe mid x: 1073741825
562##
563##
564
565#SeeAlso centerX SkRect::centerY
566
567##
568
569# ------------------------------------------------------------------------------
570
571#Method bool isEmpty() const
572
573Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
574to or greater than fBottom. Call sort() to reverse rectangles with negative
575width() or height().
576
577#Return true if width() or height() are zero or negative ##
578
579#Example
580 SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
581 for (auto rect : tests) {
582 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
583 rect.bottom(), rect.isEmpty() ? "" : " not");
584 rect.sort();
585 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
586 rect.bottom(), rect.isEmpty() ? "" : " not");
587 }
588#StdOut
589rect: {20, 40, 10, 50} is empty
590sorted: {10, 40, 20, 50} is not empty
591rect: {20, 40, 20, 50} is empty
592sorted: {20, 40, 20, 50} is empty
593##
594##
595
596#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
597
598##
599
600# ------------------------------------------------------------------------------
601
602#Method bool isLargest() const
603
604Returns true if IRect encloses largest possible area.
605
606#Return true if equal to (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32) ##
607
608#Example
609#Description
610Note that the width is not negative, yet it cannot be represented as a 32-bit
611signed integer.
612##
613 SkIRect large = SkIRect::MakeLargest();
614 SkDebugf("large is largest: %s\n" ,large.isLargest() ? "true" : "false");
615 SkDebugf("large width %d\n", large.width());
616 SkDebugf("large is empty: %s\n", large.isEmpty() ? "true" : "false");
617#StdOut
618large is largest: true
619large width -2
620large is empty: false
621##
622##
623
624#SeeAlso MakeLargest SkRect::isLargest
625
626##
627
628# ------------------------------------------------------------------------------
629
630#Method bool operator==(const SkIRect& a, const SkIRect& b)
631
632Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
633identical to corresponding members in b.
634
635#Param a IRect to compare ##
636#Param b IRect to compare ##
637
638#Return true if members are equal ##
639
640#Example
641 SkIRect test = {0, 0, 2, 2};
642 SkIRect sorted = test.makeSorted();
643 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!');
644#StdOut
645test == sorted
646##
647##
648
649#SeeAlso operator!=(const SkIRect& a, const SkIRect& b)
650
651##
652
653# ------------------------------------------------------------------------------
654
655#Method bool operator!=(const SkIRect& a, const SkIRect& b)
656
657Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not
658identical to the corresponding member in b.
659
660#Param a IRect to compare ##
661#Param b IRect to compare ##
662
663#Return true if members are not equal ##
664
665#Example
666 SkIRect test = {2, 2, 0, 0};
667 SkIRect sorted = test.makeSorted();
668 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '=');
669#StdOut
670test != sorted
671##
672##
673
674#SeeAlso operator==(const SkIRect& a, const SkIRect& b)
675
676##
677
678# ------------------------------------------------------------------------------
679
680#Method bool is16Bit() const
681
682Returns true if all members: fLeft, fTop, fRight, and fBottom; values are
683equal to or larger than -32768 and equal to or smaller than 32767.
684
685#Return true if members fit in 16-bit word ##
686
687#Example
688 SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}};
689 for (auto rect : tests) {
690 SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight,
691 rect.fBottom, rect.is16Bit() ? "fits" : "does not fit");
692}
693#StdOut
694{-32768, -32768, 32767, 32767} fits in 16 bits
695{-32768, -32768, 32768, 32768} does not fit in 16 bits
696##
697##
698
699#SeeAlso SkTFitsIn
700
701##
702
703# ------------------------------------------------------------------------------
704
705#Method void setEmpty()
706
707Sets IRect to (0, 0, 0, 0).
708
709Many other rectangles are empty; if left is equal to or greater than right,
710or if top is equal to or greater than bottom. Setting all members to zero
711is a convenience, but does not designate a special empty rectangle.
712
713#Example
714 SkIRect rect = {3, 4, 1, 2};
715 for (int i = 0; i < 2; ++i) {
716 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop,
717 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
718 rect.setEmpty();
719 }
720#StdOut
721rect: {3, 4, 1, 2} is empty
722rect: {0, 0, 0, 0} is empty
723##
724##
725
726#SeeAlso MakeEmpty SkRect::setEmpty
727
728##
729
730# ------------------------------------------------------------------------------
731
732#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
733
734Sets IRect to (left, top, right, bottom).
735left and right are not sorted; left is not necessarily less than right.
736top and bottom are not sorted; top is not necessarily less than bottom.
737
738#Param left assigned to fLeft ##
739#Param top assigned to fTop ##
740#Param right assigned to fRight ##
741#Param bottom assigned to fBottom ##
742
743#Example
744 SkIRect rect1 = {3, 4, 1, 2};
745 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
746 SkIRect rect2;
747 rect2.set(3, 4, 1, 2);
748 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
749#StdOut
750rect1: {3, 4, 1, 2}
751rect2: {3, 4, 1, 2}
752##
753##
754
755#SeeAlso setLTRB setXYWH SkRect::set
756
757##
758
759# ------------------------------------------------------------------------------
760
761#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
762
763Sets IRect to (left, top, right, bottom).
764left and right are not sorted; left is not necessarily less than right.
765top and bottom are not sorted; top is not necessarily less than bottom.
766
767#Param left stored in fLeft ##
768#Param top stored in fTop ##
769#Param right stored in fRight ##
770#Param bottom stored in fBottom ##
771
772#Example
773 SkIRect rect1 = {3, 4, 1, 2};
774 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
775 SkIRect rect2;
776 rect2.setLTRB(3, 4, 1, 2);
777 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
778#StdOut
779rect1: {3, 4, 1, 2}
780rect2: {3, 4, 1, 2}
781##
782##
783
784#SeeAlso set setXYWH SkRect::setLTRB
785
786##
787
788# ------------------------------------------------------------------------------
789
790#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
791
792Sets IRect to:
793#Formula
794(x, y, x + width, y + height)
795##
796. Does not validate input;
797width or height may be negative.
798
799#Param x stored in fLeft ##
800#Param y stored in fTop ##
801#Param width added to x and stored in fRight ##
802#Param height added to y and stored in fBottom ##
803
804#Example
805 SkIRect rect;
806 rect.setXYWH(5, 35, -15, 25);
807 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
808 rect.bottom(), rect.isEmpty() ? "true" : "false");
809 rect.sort();
810 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
811 rect.bottom(), rect.isEmpty() ? "true" : "false");
812#StdOut
813rect: 5, 35, -10, 60 isEmpty: true
814rect: -10, 35, 5, 60 isEmpty: false
815##
816##
817
818#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH
819
820##
821
822# ------------------------------------------------------------------------------
823
824#Method void setLargest()
825
826Sets rectangle left and top to most negative value, and sets
827right and bottom to most positive value.
828
829#Example
830 SkIRect rect;
831 rect.setLargest();
832 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
833 SkDebugf("MakeLargest isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
834 rect.outset(1, 1);
835 SkDebugf("outset isLargest: %s\n", rect.isLargest() ? "true" : "false");
836 SkDebugf("outset isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
837#StdOut
838MakeLargest isLargest: true
839MakeLargest isEmpty: false
840outset isLargest: false
841outset isEmpty: true
842##
843##
844
845#SeeAlso MakeLargest isLargest setLargestInverted SK_MinS32 SK_MaxS32
846
847##
848
849# ------------------------------------------------------------------------------
850
851#Method void setLargestInverted()
852#ToDo move this to private
853##
854
855Sets rectangle left and top to most positive value, and sets
856right and bottom to most negative value. This is used internally to
857flag that a condition is met, but otherwise has no special purpose.
858
859#NoExample
860##
861
862#SeeAlso setEmpty setLargest
863
864##
865
866# ------------------------------------------------------------------------------
867
868#Method SkIRect makeOffset(int32_t dx, int32_t dy) const
869
870Returns IRect offset by (dx, dy).
871
872If dx is negative, IRect returned is moved to the left.
873If dx is positive, IRect returned is moved to the right.
874If dy is negative, IRect returned is moved upward.
875If dy is positive, IRect returned is moved downward.
876
877#Param dx offset added to fLeft and fRight ##
878#Param dy offset added to fTop and fBottom ##
879
880#Return Rect offset in x or y, with original width and height ##
881
882#Example
883 SkIRect rect = { 10, 50, 20, 60 };
884 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
885 rect.bottom(), rect.isEmpty() ? "true" : "false");
886 rect = rect.makeOffset(15, 32);
887 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
888 rect.bottom(), rect.isEmpty() ? "true" : "false");
889#StdOut
890rect: 10, 50, 20, 60 isEmpty: false
891rect: 25, 82, 35, 92 isEmpty: false
892##
893##
894
895#SeeAlso offset() makeInset makeOutset SkRect::makeOffset
896
897##
898
899# ------------------------------------------------------------------------------
900
901#Method SkIRect makeInset(int32_t dx, int32_t dy) const
902
903Returns IRect, inset by (dx, dy).
904
905If dx is negative, IRect returned is wider.
906If dx is positive, IRect returned is narrower.
907If dy is negative, IRect returned is taller.
908If dy is positive, IRect returned is shorter.
909
910#Param dx offset added to fLeft and subtracted from fRight ##
911#Param dy offset added to fTop and subtracted from fBottom ##
912
913#Return Rect inset symmetrically left and right, top and bottom ##
914
915#Example
916 SkIRect rect = { 10, 50, 20, 60 };
917 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
918 rect.bottom(), rect.isEmpty() ? "true" : "false");
919 rect = rect.makeInset(15, 32);
920 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
921 rect.bottom(), rect.isEmpty() ? "true" : "false");
922#StdOut
923rect: 10, 50, 20, 60 isEmpty: false
924rect: 25, 82, 5, 28 isEmpty: true
925##
926##
927
928#SeeAlso inset() makeOffset makeOutset SkRect::makeInset
929
930##
931
932# ------------------------------------------------------------------------------
933
934#Method SkIRect makeOutset(int32_t dx, int32_t dy) const
935
936Returns IRect, outset by (dx, dy).
937
938If dx is negative, IRect returned is narrower.
939If dx is positive, IRect returned is wider.
940If dy is negative, IRect returned is shorter.
941If dy is positive, IRect returned is taller.
942
943#Param dx offset subtracted to fLeft and added from fRight ##
944#Param dy offset subtracted to fTop and added from fBottom ##
945
946#Return Rect outset symmetrically left and right, top and bottom ##
947
948#Example
949 SkIRect rect = { 10, 50, 20, 60 };
950 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
951 rect.bottom(), rect.isEmpty() ? "true" : "false");
952 rect = rect.makeOutset(15, 32);
953 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
954 rect.bottom(), rect.isEmpty() ? "true" : "false");
955#StdOut
956rect: 10, 50, 20, 60 isEmpty: false
957rect: -5, 18, 35, 92 isEmpty: false
958##
959##
960
961#SeeAlso outset() makeOffset makeInset SkRect::makeOutset
962
963##
964
965# ------------------------------------------------------------------------------
966
967#Method void offset(int32_t dx, int32_t dy)
968
969Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
970
971If dx is negative, moves IRect returned to the left.
972If dx is positive, moves IRect returned to the right.
973If dy is negative, moves IRect returned upward.
974If dy is positive, moves IRect returned downward.
975
976#Param dx offset added to fLeft and fRight ##
977#Param dy offset added to fTop and fBottom ##
978
979#Example
980 SkIRect rect = { 10, 14, 50, 73 };
981 rect.offset(5, 13);
982 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
983#StdOut
984rect: 15, 27, 55, 86
985##
986##
987
988#SeeAlso offsetTo makeOffset SkRect::offset
989
990##
991
992# ------------------------------------------------------------------------------
993
994#Method void offset(const SkIPoint& delta)
995
996Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
997fTop, fBottom.
998
999If delta.fX is negative, moves IRect returned to the left.
1000If delta.fX is positive, moves IRect returned to the right.
1001If delta.fY is negative, moves IRect returned upward.
1002If delta.fY is positive, moves IRect returned downward.
1003
1004#Param delta offset added to IRect ##
1005
1006#Example
1007 SkIRect rect = { 10, 14, 50, 73 };
1008 rect.offset({5, 13});
1009 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1010#StdOut
1011rect: 15, 27, 55, 86
1012##
1013##
1014
1015#SeeAlso offsetTo makeOffset SkRect::offset
1016
1017##
1018
1019# ------------------------------------------------------------------------------
1020
1021#Method void offsetTo(int32_t newX, int32_t newY)
1022
1023Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height
1024are unchanged.
1025
1026#Param newX stored in fLeft, preserving width() ##
1027#Param newY stored in fTop, preserving height() ##
1028
1029#Example
1030 SkIRect rect = { 10, 14, 50, 73 };
1031 rect.offsetTo(15, 27);
1032 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1033#StdOut
1034rect: 15, 27, 55, 86
1035##
1036##
1037
1038#SeeAlso offset makeOffset setXYWH SkRect::offsetTo
1039
1040##
1041
1042# ------------------------------------------------------------------------------
1043
1044#Method void inset(int32_t dx, int32_t dy)
1045
1046Insets IRect by (dx,dy).
1047
1048If dx is positive, makes IRect narrower.
1049If dx is negative, makes IRect wider.
1050If dy is positive, makes IRect shorter.
1051If dy is negative, makes IRect taller.
1052
1053#Param dx offset added to fLeft and subtracted from fRight ##
1054#Param dy offset added to fTop and subtracted from fBottom ##
1055
1056#Example
1057 SkIRect rect = { 10, 14, 50, 73 };
1058 rect.inset(5, 13);
1059 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1060#StdOut
1061rect: 15, 27, 45, 60
1062##
1063##
1064
1065#SeeAlso outset makeInset SkRect::inset
1066
1067##
1068
1069# ------------------------------------------------------------------------------
1070
1071#Method void outset(int32_t dx, int32_t dy)
1072
1073Outsets IRect by (dx, dy).
1074
1075If dx is positive, makes Rect wider.
1076If dx is negative, makes Rect narrower.
1077If dy is positive, makes Rect taller.
1078If dy is negative, makes Rect shorter.
1079
1080#Param dx subtracted to fLeft and added from fRight ##
1081#Param dy subtracted to fTop and added from fBottom ##
1082
1083#Example
1084 SkIRect rect = { 10, 14, 50, 73 };
1085 rect.outset(5, 13);
1086 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1087#StdOut
1088rect: 5, 1, 55, 86
1089##
1090##
1091
1092#SeeAlso inset makeOutset SkRect::outset
1093
1094##
1095
1096# ------------------------------------------------------------------------------
1097
1098#Method bool quickReject(int l, int t, int r, int b) const
1099
1100Constructs IRect (l, t, r, b) and returns true if constructed IRect does not
1101intersect IRect. Does not check to see if construction or IRect is empty.
1102
1103Is implemented with short circuit logic so that true can be returned after
1104a single compare.
1105
1106#Param l x minimum of constructed Rect ##
1107#Param t y minimum of constructed Rect ##
1108#Param r x maximum of constructed Rect ##
1109#Param b y maximum of constructed Rect ##
1110
1111#Return true if construction and IRect have no area in common ##
1112
1113#Example
1114#Description
1115quickReject is the complement of Intersects.
1116##
1117 const SkIRect rect = {7, 11, 13, 17};
1118 const int32_t* r = &rect.fLeft;
1119 const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } };
1120 for (auto& test : tests) {
1121 const int32_t* t = &test.fLeft;
1122 SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n",
1123 r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3],
1124 rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false",
1125 SkIRect::Intersects(rect, test) ? "true" : "false");
1126 }
1127#StdOut
1128rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false
1129rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false
1130rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true
1131##
1132##
1133
1134#SeeAlso Intersects
1135
1136##
1137
1138# ------------------------------------------------------------------------------
1139
1140#Method bool contains(int32_t x, int32_t y) const
1141
1142Returns true if:
1143#Formula
1144fLeft <= x < fRight && fTop <= y < fBottom
1145##
1146.
1147Returns false if Rect is empty.
1148
1149Considers input to describe constructed IRect:
1150#Formula
1151(x, y, x + 1, y + 1)
1152##
1153and
1154returns true if constructed area is completely enclosed by IRect area.
1155
1156#Param x test Point x-coordinate ##
1157#Param y test Point y-coordinate ##
1158
1159#Return true if (x, y) is inside IRect ##
1160
1161#Example
1162 SkIRect rect = { 30, 50, 40, 60 };
1163 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} };
1164 for (auto pt : pts) {
1165 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n",
1166 rect.left(), rect.top(), rect.right(), rect.bottom(),
1167 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y());
1168 }
1169#StdOut
1170rect: (30, 50, 40, 60) contains (30, 50)
1171rect: (30, 50, 40, 60) does not contain (40, 50)
1172rect: (30, 50, 40, 60) does not contain (30, 60)
1173##
1174##
1175
1176#SeeAlso containsNoEmptyCheck SkRect::contains
1177
1178##
1179
1180# ------------------------------------------------------------------------------
1181
1182#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
1183
1184Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1185construction.
1186
1187Returns true if Rect contains construction.
1188Returns false if Rect is empty or construction is empty.
1189
1190#Param left x minimum of constructed Rect ##
1191#Param top y minimum of constructed Rect ##
1192#Param right x maximum of constructed Rect ##
1193#Param bottom y maximum of constructed Rect ##
1194
1195#Return true if all sides of IRect are outside construction ##
1196
1197#Example
1198 SkIRect rect = { 30, 50, 40, 60 };
1199 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1200 for (auto contained : tests) {
1201 bool success = rect.contains(
1202 contained.left(), contained.top(), contained.right(), contained.bottom());
1203 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1204 rect.left(), rect.top(), rect.right(), rect.bottom(),
1205 success ? "contains" : "does not contain",
1206 contained.left(), contained.top(), contained.right(), contained.bottom());
1207 }
1208#StdOut
1209rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1210rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1211rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1212##
1213##
1214
1215#SeeAlso containsNoEmptyCheck SkRect::contains
1216
1217##
1218
1219# ------------------------------------------------------------------------------
1220
1221#Method bool contains(const SkIRect& r) const
1222
1223Returns true if Rect contains r.
1224Returns false if Rect is empty or r is empty.
1225
1226Rect contains r when Rect area completely includes r area.
1227
1228#Param r IRect contained ##
1229
1230#Return true if all sides of IRect are outside r ##
1231
1232#Example
1233 SkIRect rect = { 30, 50, 40, 60 };
1234 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1235 for (auto contained : tests) {
1236 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1237 rect.left(), rect.top(), rect.right(), rect.bottom(),
1238 rect.contains(contained) ? "contains" : "does not contain",
1239 contained.left(), contained.top(), contained.right(), contained.bottom());
1240 }
1241#StdOut
1242rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1243rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1244rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1245##
1246##
1247
1248#SeeAlso containsNoEmptyCheck SkRect::contains
1249
1250##
1251
1252# ------------------------------------------------------------------------------
1253
1254#Method bool contains(const SkRect& r) const
1255
1256Returns true if Rect contains r.
1257Returns false if Rect is empty or r is empty.
1258
1259Rect contains r when Rect area completely includes r area.
1260
1261#Param r Rect contained ##
1262
1263#Return true if all sides of IRect are outside r ##
1264
1265#Example
1266 SkIRect rect = { 30, 50, 40, 60 };
1267 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1268 for (auto contained : tests) {
1269 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n",
1270 rect.left(), rect.top(), rect.right(), rect.bottom(),
1271 rect.contains(contained) ? "contains" : "does not contain",
1272 contained.left(), contained.top(), contained.right(), contained.bottom());
1273 }
1274#StdOut
1275rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1276rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1277rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1278##
1279##
1280
1281#SeeAlso containsNoEmptyCheck SkRect::contains
1282
1283##
1284
1285# ------------------------------------------------------------------------------
1286
1287#Method bool containsNoEmptyCheck(int32_t left, int32_t top,
1288 int32_t right, int32_t bottom) const
1289
1290Constructs IRect from (left, top, right, bottom). Does not sort
1291construction.
1292
1293Returns true if Rect contains construction.
1294Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1295
1296Return is undefined if Rect is empty or construction is empty.
1297
1298#Param left x minimum of constructed Rect ##
1299#Param top y minimum of constructed Rect ##
1300#Param right x maximum of constructed Rect ##
1301#Param bottom y maximum of constructed Rect ##
1302
1303#Return true if all sides of IRect are outside construction ##
1304
1305#Example
1306 SkIRect rect = { 30, 50, 40, 60 };
1307 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1308 for (auto contained : tests) {
1309 bool success = rect.containsNoEmptyCheck(
1310 contained.left(), contained.top(), contained.right(), contained.bottom());
1311 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1312 rect.left(), rect.top(), rect.right(), rect.bottom(),
1313 success ? "contains" : "does not contain",
1314 contained.left(), contained.top(), contained.right(), contained.bottom());
1315 }
1316#StdOut
1317rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1318rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1319rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1320##
1321##
1322
1323#SeeAlso contains SkRect::contains
1324
1325##
1326
1327# ------------------------------------------------------------------------------
1328
1329#Method bool containsNoEmptyCheck(const SkIRect& r) const
1330
1331Returns true if Rect contains construction.
1332Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1333
1334Return is undefined if Rect is empty or construction is empty.
1335
1336#Param r Rect contained ##
1337
1338#Return true if all sides of IRect are outside r ##
1339
1340#Example
1341 SkIRect rect = { 30, 50, 40, 60 };
1342 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1343 for (auto contained : tests) {
1344 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1345 rect.left(), rect.top(), rect.right(), rect.bottom(),
1346 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain",
1347 contained.left(), contained.top(), contained.right(), contained.bottom());
1348 }
1349#StdOut
1350rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1351rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1352rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1353##
1354##
1355
1356#SeeAlso contains SkRect::contains
1357
1358##
1359
1360#Topic Intersection
1361
1362IRects intersect when they enclose a common area. To intersect, each of the pair
1363must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1364empty() returns false. The intersection of IRect pair can be described by:
1365#Formula
1366(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1367 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1368##
1369The intersection is only meaningful if the resulting IRect is not empty and
1370describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1371
1372# ------------------------------------------------------------------------------
1373
1374#Method bool intersect(const SkIRect& r)
1375
1376Returns true if IRect intersects r, and sets IRect to intersection.
1377Returns false if IRect does not intersect r, and leaves IRect unchanged.
1378
1379Returns false if either r or IRect is empty, leaving IRect unchanged.
1380
1381#Param r limit of result ##
1382
1383#Return true if r and Rect have area in common ##
1384
1385#Example
1386#Description
1387Two SkDebugf calls are required. If the calls are combined, their arguments
1388may not be evaluated in left to right order: the printed intersection may
1389be before or after the call to intersect.
1390##
1391 SkIRect leftRect = { 10, 40, 50, 80 };
1392 SkIRect rightRect = { 30, 60, 70, 90 };
1393 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1394 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1395 leftRect.right(), leftRect.bottom());
1396#StdOut
1397 intersection: 30, 60, 50, 80
1398##
1399##
1400
1401#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1402
1403##
1404
1405# ------------------------------------------------------------------------------
1406
1407#Method bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b)
1408
1409Returns true if a intersects b, and sets IRect to intersection.
1410Returns false if a does not intersect b, and leaves IRect unchanged.
1411
1412Returns false if either a or b is empty, leaving IRect unchanged.
1413
1414#Param a IRect to intersect ##
1415#Param b IRect to intersect ##
1416
1417#Return true if a and b have area in common ##
1418
1419#Example
1420 SkIRect result;
1421 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1422 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ",
1423 result.left(), result.top(), result.right(), result.bottom());
1424#StdOut
1425 intersection: 30, 60, 50, 80
1426##
1427##
1428
1429#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1430
1431##
1432
1433# ------------------------------------------------------------------------------
1434
1435#Method bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1436
1437Returns true if a intersects b, and sets IRect to intersection.
1438Returns false if a does not intersect b, and leaves IRect unchanged.
1439
1440Asserts if either a or b is empty, and if SK_DEBUG is defined.
1441
1442#Param a IRect to intersect ##
1443#Param b IRect to intersect ##
1444
1445#Return true if a and b have area in common ##
1446
1447#Example
1448 SkIRect result;
1449 bool intersected = result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1450 SkDebugf("intersection: %d, %d, %d, %d\n",
1451 result.left(), result.top(), result.right(), result.bottom());
1452#StdOut
1453 intersection: 30, 60, 50, 80
1454##
1455##
1456
1457#SeeAlso Intersects intersect join SkRect::intersect
1458
1459##
1460
1461# ------------------------------------------------------------------------------
1462
1463#Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
1464
1465Constructs IRect to intersect from (left, top, right, bottom). Does not sort
1466construction.
1467
1468Returns true if IRect intersects construction, and sets IRect to intersection.
1469Returns false if IRect does not intersect construction, and leaves IRect unchanged.
1470
1471Returns false if either construction or IRect is empty, leaving IRect unchanged.
1472
1473#Param left x minimum of constructed IRect ##
1474#Param top y minimum of constructed IRect ##
1475#Param right x maximum of constructed IRect ##
1476#Param bottom y maximum of constructed IRect ##
1477
1478#Return true if construction and IRect have area in common ##
1479
1480#Example
1481#Description
1482Two SkDebugf calls are required. If the calls are combined, their arguments
1483may not be evaluated in left to right order: the printed intersection may
1484be before or after the call to intersect.
1485##
1486 SkIRect leftRect = { 10, 40, 50, 80 };
1487 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1488 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1489 leftRect.right(), leftRect.bottom());
1490#StdOut
1491 intersection: 30, 60, 50, 80
1492##
1493##
1494
1495#SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect
1496
1497##
1498
1499# ------------------------------------------------------------------------------
1500
1501#Method static bool Intersects(const SkIRect& a, const SkIRect& b)
1502
1503Returns true if a intersects b.
1504Returns false if either a or b is empty, or do not intersect.
1505
1506#Param a IRect to intersect ##
1507#Param b IRect to intersect ##
1508
1509#Return true if a and b have area in common ##
1510
1511#Example
1512 SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1513#StdOut
1514 intersection
1515##
1516##
1517
1518#SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect
1519
1520##
1521
1522# ------------------------------------------------------------------------------
1523
1524#Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1525
1526Returns true if a intersects b.
1527Asserts if either a or b is empty, and if SK_DEBUG is defined.
1528
1529#Param a IRect to intersect ##
1530#Param b IRect to intersect ##
1531
1532#Return true if a and b have area in common ##
1533
1534#Example
1535 SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck(
1536 {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1537#StdOut
1538 intersection
1539##
1540##
1541
1542#SeeAlso Intersects intersect SkRect::intersect
1543
1544##
1545
1546#Topic Intersection ##
1547
1548# ------------------------------------------------------------------------------
1549
1550#Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom)
1551
1552Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1553construction.
1554
1555Sets Rect to the union of itself and the construction.
1556
1557Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1558Rect to construction.
1559
1560#Param left x minimum of constructed Rect ##
1561#Param top y minimum of constructed Rect ##
1562#Param right x maximum of constructed Rect ##
1563#Param bottom y maximum of constructed Rect ##
1564
1565#Example
1566 SkIRect rect = { 10, 20, 15, 25};
1567 rect.join(50, 60, 55, 65);
1568 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1569#StdOut
1570 join: 10, 20, 55, 65
1571##
1572##
1573
1574#SeeAlso set SkRect::join
1575
1576##
1577
1578# ------------------------------------------------------------------------------
1579
1580#Method void join(const SkIRect& r)
1581
1582Sets Rect to the union of itself and r.
1583
1584Has no effect if r is empty. Otherwise, if Rect is empty, sets Rect to r.
1585
1586#Param r expansion Rect ##
1587
1588#Example
1589 SkIRect rect = { 10, 20, 15, 25};
1590 rect.join({50, 60, 55, 65});
1591 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1592#StdOut
1593 join: 10, 20, 55, 65
1594##
1595##
1596
1597#SeeAlso set SkRect::join
1598
1599##
1600
1601# ------------------------------------------------------------------------------
1602
1603#Method void sort()
1604
1605Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
1606fTop and fBottom if fTop is greater than fBottom. Result may be empty,
1607and width() and height() will be zero or positive.
1608
1609#Example
1610 SkIRect rect = { 30, 50, 20, 10 };
1611 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1612 rect.sort();
1613 SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1614#StdOut
1615rect: 30, 50, 20, 10
1616sorted: 20, 10, 30, 50
1617##
1618##
1619
1620#SeeAlso makeSorted SkRect::sort
1621
1622##
1623
1624# ------------------------------------------------------------------------------
1625
1626#Method SkIRect makeSorted() const
1627
1628Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
1629with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
1630and width() and height() will be zero or positive.
1631
1632#Return sorted IRect ##
1633
1634#Example
1635 SkIRect rect = { 30, 50, 20, 10 };
1636 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1637 SkIRect sort = rect.makeSorted();
1638 SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
1639#StdOut
1640rect: 30, 50, 20, 10
1641sorted: 20, 10, 30, 50
1642##
1643##
1644
1645#SeeAlso sort SkRect::makeSorted
1646
1647##
1648
1649# ------------------------------------------------------------------------------
1650
1651#Method static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect()
1652
1653Returns a reference to immutable empty IRect, set to (0, 0, 0, 0).
1654
1655#Return global IRect set to all zeroes ##
1656
1657#Example
1658 const SkIRect& rect = SkIRect::EmptyIRect();
1659 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1660#StdOut
1661rect: 0, 0, 0, 0
1662##
1663##
1664
1665#SeeAlso MakeEmpty
1666
1667##
1668
1669#Struct SkIRect ##
1670
1671#Topic IRect ##