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