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