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