blob: 45b636082dca59f352ccd2f3e78687aa592425ba [file] [log] [blame]
Cary Clark0c5f5462017-12-15 11:21:51 -05001#Topic IRect
Cary Clark2dc84ad2018-01-26 12:56:22 -05002#Alias IRects
Cary Clark0c5f5462017-12-15 11:21:51 -05003#Alias IRect_Reference
4
Cary Clark08895c42018-02-01 09:37:32 -05005#Subtopic Overview
Cary Clark4855f782018-02-06 09:41:53 -05006 #Subtopic Subtopic
Cary Clark08895c42018-02-01 09:37:32 -05007 #Populate
8 ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05009##
10
Cary Clark0c5f5462017-12-15 11:21:51 -050011#Struct SkIRect
12
13SkIRect holds four 32 bit integer coordinates describing the upper and
14lower bounds of a rectangle. SkIRect may be created from outer bounds or
15from position, width, and height. SkIRect describes an area; if its right
16is less than or equal to its left, or if its bottom is less than or equal to
17its top, it is considered empty.
18
Cary Clark4855f782018-02-06 09:41:53 -050019#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050020#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -050021#Subtopic ##
22
Cary Clark4855f782018-02-06 09:41:53 -050023#Subtopic Member_Function
24#Populate
25#Subtopic ##
26
27#Subtopic Member
Cary Clark08895c42018-02-01 09:37:32 -050028#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -050029
30#Member int32_t fLeft
Cary Clark08895c42018-02-01 09:37:32 -050031#Line # smaller x-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050032May contain any value. The smaller of the horizontal values when sorted.
33When equal to or greater than fRight, IRect is empty.
34##
35
36#Member int32_t fTop
Cary Clark08895c42018-02-01 09:37:32 -050037#Line # smaller y-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050038May contain any value. The smaller of the horizontal values when sorted.
39When equal to or greater than fBottom, IRect is empty.
40##
41
42#Member int32_t fRight
Cary Clark08895c42018-02-01 09:37:32 -050043#Line # larger x-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050044May contain any value. The larger of the vertical values when sorted.
45When equal to or less than fLeft, IRect is empty.
46##
47
48#Member int32_t fBottom
Cary Clark08895c42018-02-01 09:37:32 -050049#Line # larger y-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050050May contain any value. The larger of the vertical values when sorted.
51When equal to or less than fTop, IRect is empty.
52##
53
Cary Clark4855f782018-02-06 09:41:53 -050054#Subtopic Member ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050055
Cary Clark4855f782018-02-06 09:41:53 -050056#Subtopic Constructor
Cary Clark08895c42018-02-01 09:37:32 -050057#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -050058
Cary Clark0c5f5462017-12-15 11:21:51 -050059# ------------------------------------------------------------------------------
60
61#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty()
62
Cary Clark4855f782018-02-06 09:41:53 -050063#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -050064#Line # returns bounds of (0, 0, 0, 0) ##
Cary Clark0c5f5462017-12-15 11:21:51 -050065Returns constructed IRect set to (0, 0, 0, 0).
66Many other rectangles are empty; if left is equal to or greater than right,
67or if top is equal to or greater than bottom. Setting all members to zero
68is a convenience, but does not designate a special empty rectangle.
69
70#Return bounds (0, 0, 0, 0) ##
71
72#Example
73 SkIRect rect = SkIRect::MakeEmpty();
74 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
75 rect.offset(10, 10);
76 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
77 rect.inset(10, 10);
78 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
79 rect.outset(20, 20);
80 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
81#StdOut
82MakeEmpty isEmpty: true
83offset rect isEmpty: true
84inset rect isEmpty: true
85outset rect isEmpty: false
86##
87##
88
Mike Reed274218e2018-01-08 15:05:02 -050089#SeeAlso EmptyIRect isEmpty setEmpty SkRect::MakeEmpty
Cary Clark0c5f5462017-12-15 11:21:51 -050090
91##
92
93# ------------------------------------------------------------------------------
94
95#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h)
96
Cary Clark4855f782018-02-06 09:41:53 -050097#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -050098#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -050099Returns constructed IRect set to (0, 0, w, h). Does not validate input; w or h
100may be negative.
101
Cary Clark2dc84ad2018-01-26 12:56:22 -0500102#Param w width of constructed IRect ##
103#Param h height of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500104
105#Return bounds (0, 0, w, h) ##
106
107#Example
108 SkIRect rect1 = SkIRect::MakeWH(25, 35);
109 SkIRect rect2 = SkIRect::MakeSize({25, 35});
110 SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35);
111 SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35);
112 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
113 "" : "not ");
114#StdOut
115all equal
116##
117##
118
119#SeeAlso MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH
120
121##
122
123# ------------------------------------------------------------------------------
124
125#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size)
126
Cary Clark4855f782018-02-06 09:41:53 -0500127#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500128#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500129Returns constructed IRect set to (0, 0, size.width(), size.height()).
130Does not validate input; size.width() or size.height() may be negative.
131
Cary Clark2dc84ad2018-01-26 12:56:22 -0500132#Param size values for IRect width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500133
134#Return bounds (0, 0, size.width(), size.height()) ##
135
136#Example
137 SkSize size = {25.5f, 35.5f};
138 SkIRect rect = SkIRect::MakeSize(size.toRound());
139 SkDebugf("round width: %d height: %d\n", rect.width(), rect.height());
140 rect = SkIRect::MakeSize(size.toFloor());
141 SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height());
142#StdOut
143round width: 26 height: 36
144floor width: 25 height: 35
145##
146##
147
148#SeeAlso MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH
149
150##
151
152# ------------------------------------------------------------------------------
153
154#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
155
Cary Clark4855f782018-02-06 09:41:53 -0500156#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500157#Line # constructs from int left, top, right, bottom ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500158Returns constructed IRect set to (l, t, r, b). Does not sort input; IRect may
Cary Clark0c5f5462017-12-15 11:21:51 -0500159result in fLeft greater than fRight, or fTop greater than fBottom.
160
161#Param l integer stored in fLeft ##
162#Param t integer stored in fTop ##
163#Param r integer stored in fRight ##
164#Param b integer stored in fBottom ##
165
166#Return bounds (l, t, r, b) ##
167
168#Example
169 SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25);
170 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
171 rect.bottom(), rect.isEmpty() ? "true" : "false");
172 rect.sort();
173 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
174 rect.bottom(), rect.isEmpty() ? "true" : "false");
175#StdOut
176rect: 5, 35, 15, 25 isEmpty: true
177rect: 5, 25, 15, 35 isEmpty: false
178##
179##
180
181#SeeAlso MakeXYWH SkRect::MakeLTRB
182
183##
184
185# ------------------------------------------------------------------------------
186
187#Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
188
Cary Clark4855f782018-02-06 09:41:53 -0500189#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500190#Line # constructs from int input returning (x, y, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500191Returns constructed IRect set to:
192#Formula
193(x, y, x + w, y + h)
194##
195. Does not validate input;
196w or h may be negative.
197
198#Param x stored in fLeft ##
199#Param y stored in fTop ##
200#Param w added to x and stored in fRight ##
201#Param h added to y and stored in fBottom ##
202
203#Return bounds at (x, y) with width w and height h ##
204
205#Example
206 SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25);
207 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
208 rect.bottom(), rect.isEmpty() ? "true" : "false");
209 rect.sort();
210 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
211 rect.bottom(), rect.isEmpty() ? "true" : "false");
212#StdOut
213rect: 5, 35, -10, 60 isEmpty: true
214rect: -10, 35, 5, 60 isEmpty: false
215##
216##
217
218#SeeAlso MakeLTRB SkRect::MakeXYWH
219
220##
221
Cary Clark4855f782018-02-06 09:41:53 -0500222#Subtopic Constructor ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500223
Cary Clark4855f782018-02-06 09:41:53 -0500224#Subtopic Property
225#Line # member values, center, validity ##
226#Populate
227##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500228
Cary Clark0c5f5462017-12-15 11:21:51 -0500229# ------------------------------------------------------------------------------
230
Cary Clark6def7202018-01-04 08:13:35 -0500231#Method int32_t left() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500232
Cary Clark4855f782018-02-06 09:41:53 -0500233#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500234#Line # returns smaller bounds in x, if sorted ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500235Returns left edge of IRect, if sorted.
236Call sort() to reverse fLeft and fRight if needed.
237
238#Return fLeft ##
239
240#Example
241 SkIRect unsorted = { 15, 5, 10, 25 };
242 SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left());
243 SkIRect sorted = unsorted.makeSorted();
244 SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left());
245#StdOut
246unsorted.fLeft: 15 unsorted.left(): 15
247sorted.fLeft: 10 sorted.left(): 10
248##
249##
250
251#SeeAlso fLeft x() SkRect::left()
252
253##
254
255# ------------------------------------------------------------------------------
256
Cary Clark6def7202018-01-04 08:13:35 -0500257#Method int32_t top() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500258
Cary Clark4855f782018-02-06 09:41:53 -0500259#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500260#Line # returns smaller bounds in y, if sorted ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500261Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
262and sort() to reverse fTop and fBottom if needed.
263
264#Return fTop ##
265
266#Example
267 SkIRect unsorted = { 15, 25, 10, 5 };
268 SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top());
269 SkIRect sorted = unsorted.makeSorted();
270 SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top());
271#StdOut
272unsorted.fTop: 25 unsorted.top(): 25
273sorted.fTop: 5 sorted.top(): 5
274##
275##
276
277#SeeAlso fTop y() SkRect::top()
278
279##
280
281# ------------------------------------------------------------------------------
282
Cary Clark6def7202018-01-04 08:13:35 -0500283#Method int32_t right() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500284
Cary Clark4855f782018-02-06 09:41:53 -0500285#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500286#Line # returns larger bounds in x, if sorted ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500287Returns right edge of IRect, if sorted.
288Call sort() to reverse fLeft and fRight if needed.
289
290#Return fRight ##
291
292#Example
293 SkIRect unsorted = { 15, 25, 10, 5 };
294 SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right());
295 SkIRect sorted = unsorted.makeSorted();
296 SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right());
297#StdOut
298unsorted.fRight: 10 unsorted.right(): 10
299sorted.fRight: 15 sorted.right(): 15
300##
301##
302
303#SeeAlso fRight SkRect::right()
304
305##
306
307# ------------------------------------------------------------------------------
308
Cary Clark6def7202018-01-04 08:13:35 -0500309#Method int32_t bottom() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500310
Cary Clark4855f782018-02-06 09:41:53 -0500311#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500312#Line # returns larger bounds in y, if sorted ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500313Returns bottom edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
314and sort() to reverse fTop and fBottom if needed.
315
316#Return fBottom ##
317
318#Example
319 SkIRect unsorted = { 15, 25, 10, 5 };
320 SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom());
321 SkIRect sorted = unsorted.makeSorted();
322 SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom());
323#StdOut
324unsorted.fBottom: 5 unsorted.bottom(): 5
325sorted.fBottom: 25 sorted.bottom(): 25
326##
327##
328
329#SeeAlso fBottom SkRect::bottom()
330
331##
332
333# ------------------------------------------------------------------------------
334
Cary Clark6def7202018-01-04 08:13:35 -0500335#Method int32_t x() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500336
Cary Clark4855f782018-02-06 09:41:53 -0500337#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500338#Line # returns bounds left ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500339Returns left edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
340and sort() to reverse fLeft and fRight if needed.
341
342#Return fLeft ##
343
344#Example
345 SkIRect unsorted = { 15, 5, 10, 25 };
346 SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x());
347 SkIRect sorted = unsorted.makeSorted();
348 SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x());
349#StdOut
350unsorted.fLeft: 15 unsorted.x(): 15
351sorted.fLeft: 10 sorted.x(): 10
352##
353##
354
355#SeeAlso fLeft left() y() SkRect::x()
356
357##
358
359# ------------------------------------------------------------------------------
360
Cary Clark6def7202018-01-04 08:13:35 -0500361#Method int32_t y() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500362
Cary Clark4855f782018-02-06 09:41:53 -0500363#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500364#Line # returns bounds top ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500365Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
366and sort() to reverse fTop and fBottom if needed.
367
368#Return fTop ##
369
370#Example
371 SkIRect unsorted = { 15, 25, 10, 5 };
372 SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y());
373 SkIRect sorted = unsorted.makeSorted();
374 SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y());
375#StdOut
376unsorted.fTop: 25 unsorted.y(): 25
377sorted.fTop: 5 sorted.y(): 5
378##
379##
380
381#SeeAlso fTop top() x() SkRect::y()
382
383##
384
385# ------------------------------------------------------------------------------
386
Cary Clark6def7202018-01-04 08:13:35 -0500387#Method int32_t width() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500388
Cary Clark4855f782018-02-06 09:41:53 -0500389#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500390#Line # returns span in x ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500391Returns span on the x-axis. This does not check if IRect is sorted, or if
392result fits in 32-bit signed integer; result may be negative.
393
394#Return fRight minus fLeft ##
395
396#Example
397 SkIRect unsorted = { 15, 25, 10, 5 };
398 SkDebugf("unsorted width: %d\n", unsorted.width());
399 SkIRect large = { -2147483647, 1, 2147483644, 2 };
400 SkDebugf("large width: %d\n", large.width());
401#StdOut
402unsorted width: -5
403large width: -5
404##
405##
406
Mike Reeda766ca92018-01-09 11:31:53 -0500407#SeeAlso height() width64() height64() SkRect::width()
408
409##
410
411# ------------------------------------------------------------------------------
412
413#Method int64_t width64() const
414
Cary Clark4855f782018-02-06 09:41:53 -0500415#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500416#Line # returns span in y as int64_t ##
Mike Reeda766ca92018-01-09 11:31:53 -0500417Returns span on the x-axis. This does not check if IRect is sorted, so the
418result may be negative. This is safer than calling width() since width() might
419overflow in its calculation.
420
421#Return fRight minus fLeft cast to int64_t ##
422
Cary Clark4855f782018-02-06 09:41:53 -0500423#Bug 7489
Cary Clarkac47b882018-01-11 10:35:44 -0500424# width64 is not yet visible to fiddle
425#NoExample
Mike Reeda766ca92018-01-09 11:31:53 -0500426SkIRect large = { -2147483647, 1, 2147483644, 2 };
427SkDebugf("width: %d wdith64: %lld\n", large.width(), large.width64());
428#StdOut
429width: -5 width64: 4294967291
430##
431##
432
433#SeeAlso width() height() height64() SkRect::width()
Cary Clark0c5f5462017-12-15 11:21:51 -0500434
435##
436
437# ------------------------------------------------------------------------------
438
Cary Clark6def7202018-01-04 08:13:35 -0500439#Method int32_t height() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500440
Cary Clark4855f782018-02-06 09:41:53 -0500441#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500442#Line # returns span in y ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500443Returns span on the y-axis. This does not check if IRect is sorted, or if
444result fits in 32-bit signed integer; result may be negative.
445
446#Return fBottom minus fTop ##
447
448#Example
449 SkIRect unsorted = { 15, 25, 10, 20 };
450 SkDebugf("unsorted height: %d\n", unsorted.height());
451 SkIRect large = { 1, -2147483647, 2, 2147483644 };
452 SkDebugf("large height: %d\n", large.height());
453#StdOut
454unsorted height: -5
455large height: -5
456##
457##
458
459#SeeAlso width() SkRect::height()
460
461##
462
463# ------------------------------------------------------------------------------
464
Mike Reeda766ca92018-01-09 11:31:53 -0500465#Method int64_t height64() const
466
Cary Clark4855f782018-02-06 09:41:53 -0500467#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500468#Line # returns span in y as int64_t ##
Mike Reeda766ca92018-01-09 11:31:53 -0500469Returns span on the y-axis. This does not check if IRect is sorted, so the
470result may be negative. This is safer than calling height() since height() might
471overflow in its calculation.
472
473#Return fBottom minus fTop cast to int64_t ##
474
Cary Clark4855f782018-02-06 09:41:53 -0500475#Bug 7489
Cary Clarkac47b882018-01-11 10:35:44 -0500476# height64 not yet visible to fiddle
477#NoExample
Mike Reeda766ca92018-01-09 11:31:53 -0500478SkIRect large = { 1, -2147483647, 2, 2147483644 };
479SkDebugf("height: %d height64: %lld\n", large.height(), large.height64());
480#StdOut
481height: -5 height64: 4294967291
482##
483##
484
485#SeeAlso width() height() width64() SkRect::height()
486
487##
488
489# ------------------------------------------------------------------------------
490
Cary Clark0c5f5462017-12-15 11:21:51 -0500491#Method SkISize size() const
492
Cary Clark4855f782018-02-06 09:41:53 -0500493#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500494#Line # returns ISize (width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500495Returns spans on the x-axis and y-axis. This does not check if IRect is sorted,
496or if result fits in 32-bit signed integer; result may be negative.
497
498#Return ISize (width, height) ##
499
500#Example
501 auto debugster = [](const char* prefix, const SkIRect& rect) -> void {
502 SkISize size = rect.size();
503 SkDebugf("%s ", prefix);
504 SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom());
505 SkDebugf("size: %d, %d\n", size.width(), size.height());
506 };
507 SkIRect rect = {20, 30, 40, 50};
508 debugster("original", rect);
509 rect.offset(20, 20);
510 debugster(" offset", rect);
511 rect.outset(20, 20);
512 debugster(" outset", rect);
513#StdOut
514original rect: 20, 30, 40, 50 size: 20, 20
515 offset rect: 40, 50, 60, 70 size: 20, 20
516 outset rect: 20, 30, 80, 90 size: 60, 60
517##
518##
519
520#SeeAlso height() width() MakeSize
521
522##
523
524# ------------------------------------------------------------------------------
525
Cary Clark6def7202018-01-04 08:13:35 -0500526#Method int32_t centerX() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500527
Cary Clark4855f782018-02-06 09:41:53 -0500528#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500529#Line # returns midpoint in x ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500530Returns average of left edge and right edge. Result does not change if IRect
Cary Clarkedd08952018-03-22 07:58:54 -0400531is sorted.
Cary Clark0c5f5462017-12-15 11:21:51 -0500532
533Result is rounded down.
534
535#Return midpoint in x ##
536
537#Example
538#Description
539Dividing by two rounds towards zero. centerX uses a bit shift and rounds down.
540##
541 SkIRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}, {-10, -10, 11, 11}};
542 for (auto rect : tests) {
543 SkDebugf("left: %3d right: %3d centerX: %3d ", rect.left(), rect.right(), rect.centerX());
544 SkDebugf("div2: %3d\n", (rect.left() + rect.right()) / 2);
545 }
546#StdOut
547left: 20 right: 41 centerX: 30 div2: 30
548left: -20 right: -41 centerX: -31 div2: -30
549left: -10 right: 11 centerX: 0 div2: 0
550##
551##
552
553#SeeAlso centerY SkRect::centerX
554
555##
556
557# ------------------------------------------------------------------------------
558
Cary Clark6def7202018-01-04 08:13:35 -0500559#Method int32_t centerY() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500560
Cary Clark4855f782018-02-06 09:41:53 -0500561#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500562#Line # returns midpoint in y ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500563Returns average of top edge and bottom edge. Result does not change if IRect
Cary Clarkedd08952018-03-22 07:58:54 -0400564is sorted.
Cary Clark0c5f5462017-12-15 11:21:51 -0500565
566Result is rounded down.
567
568#Return midpoint in y ##
569
570#Example
571 SkIRect rect = { 0, 0, 2, 2 };
572 rect.offset(0x40000000, 0x40000000);
573 SkDebugf("left: %d right: %d centerX: %d ", rect.left(), rect.right(), rect.centerX());
Cary Clark0c5f5462017-12-15 11:21:51 -0500574#StdOut
Cary Clarkedd08952018-03-22 07:58:54 -0400575left: 1073741824 right: 1073741826 centerX: 1073741825
Cary Clark0c5f5462017-12-15 11:21:51 -0500576##
577##
578
579#SeeAlso centerX SkRect::centerY
580
581##
582
583# ------------------------------------------------------------------------------
584
585#Method bool isEmpty() const
586
Cary Clark4855f782018-02-06 09:41:53 -0500587#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500588#Line # returns true if width or height are zero or negative or they exceed int32_t ##
Mike Reedd2849492018-01-10 14:31:18 -0500589Returns true if width() or height() .
Cary Clark0c5f5462017-12-15 11:21:51 -0500590
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
Mike Reedd2849492018-01-10 14:31:18 -0500616#Method bool isEmpty64() const
617
Cary Clark4855f782018-02-06 09:41:53 -0500618#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500619#Line # returns true if width or height are zero or negative ##
Mike Reedd2849492018-01-10 14:31:18 -0500620Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
621to or greater than fBottom. Call sort() to reverse rectangles with negative
622width64() or height64().
623
624#Return true if width64() or height64() are zero or negative ##
625
Cary Clark4855f782018-02-06 09:41:53 -0500626#Bug 7489
Cary Clarkac47b882018-01-11 10:35:44 -0500627# isEmpty64 not yet visible to fiddle
628#NoExample
Mike Reedd2849492018-01-10 14:31:18 -0500629SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
630for (auto rect : tests) {
631SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
632rect.bottom(), isEmpty64() ? "" : " not");
633rect.sort();
634SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
635rect.bottom(), isEmpty64() ? "" : " not");
636}
637#StdOut
638rect: {20, 40, 10, 50} is empty
639sorted: {10, 40, 20, 50} is not empty
640rect: {20, 40, 20, 50} is empty
641sorted: {20, 40, 20, 50} is empty
642##
643##
644
645#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
646
647##
648
Cary Clark4855f782018-02-06 09:41:53 -0500649#Subtopic Operator
Cary Clark08895c42018-02-01 09:37:32 -0500650#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500651
Mike Reedd2849492018-01-10 14:31:18 -0500652# ------------------------------------------------------------------------------
653
Cary Clark0c5f5462017-12-15 11:21:51 -0500654#Method bool operator==(const SkIRect& a, const SkIRect& b)
655
Cary Clark4855f782018-02-06 09:41:53 -0500656#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500657#Line # returns true if members are equal ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500658Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
659identical to corresponding members in b.
660
661#Param a IRect to compare ##
662#Param b IRect to compare ##
663
664#Return true if members are equal ##
665
666#Example
667 SkIRect test = {0, 0, 2, 2};
668 SkIRect sorted = test.makeSorted();
669 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!');
670#StdOut
671test == sorted
672##
673##
674
675#SeeAlso operator!=(const SkIRect& a, const SkIRect& b)
676
677##
678
679# ------------------------------------------------------------------------------
680
681#Method bool operator!=(const SkIRect& a, const SkIRect& b)
682
Cary Clark4855f782018-02-06 09:41:53 -0500683#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500684#Line # returns true if members are unequal ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500685Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not
686identical to the corresponding member in b.
687
688#Param a IRect to compare ##
689#Param b IRect to compare ##
690
691#Return true if members are not equal ##
692
693#Example
694 SkIRect test = {2, 2, 0, 0};
695 SkIRect sorted = test.makeSorted();
696 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '=');
697#StdOut
698test != sorted
699##
700##
701
702#SeeAlso operator==(const SkIRect& a, const SkIRect& b)
703
704##
705
Cary Clark4855f782018-02-06 09:41:53 -0500706#Subtopic Operator ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500707
Cary Clark0c5f5462017-12-15 11:21:51 -0500708# ------------------------------------------------------------------------------
709
710#Method bool is16Bit() const
711
Cary Clark4855f782018-02-06 09:41:53 -0500712#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500713#Line # returns true if members fit in 16-bit word ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500714Returns true if all members: fLeft, fTop, fRight, and fBottom; values are
715equal to or larger than -32768 and equal to or smaller than 32767.
716
717#Return true if members fit in 16-bit word ##
718
719#Example
720 SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}};
721 for (auto rect : tests) {
722 SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight,
723 rect.fBottom, rect.is16Bit() ? "fits" : "does not fit");
724}
725#StdOut
726{-32768, -32768, 32767, 32767} fits in 16 bits
727{-32768, -32768, 32768, 32768} does not fit in 16 bits
728##
729##
730
731#SeeAlso SkTFitsIn
732
733##
734
735# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -0500736#Subtopic Set
737#Line # replaces all values ##
738#Populate
739##
Cary Clark0c5f5462017-12-15 11:21:51 -0500740
741#Method void setEmpty()
742
Cary Clark4855f782018-02-06 09:41:53 -0500743#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500744#Line # sets to (0, 0, 0, 0) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500745Sets IRect to (0, 0, 0, 0).
746
747Many other rectangles are empty; if left is equal to or greater than right,
748or if top is equal to or greater than bottom. Setting all members to zero
749is a convenience, but does not designate a special empty rectangle.
750
751#Example
752 SkIRect rect = {3, 4, 1, 2};
753 for (int i = 0; i < 2; ++i) {
754 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop,
755 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
756 rect.setEmpty();
757 }
758#StdOut
759rect: {3, 4, 1, 2} is empty
760rect: {0, 0, 0, 0} is empty
761##
762##
763
764#SeeAlso MakeEmpty SkRect::setEmpty
765
766##
767
768# ------------------------------------------------------------------------------
769
770#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
771
Cary Clark4855f782018-02-06 09:41:53 -0500772#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500773#Line # sets to (left, top, right, bottom) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500774Sets IRect to (left, top, right, bottom).
775left and right are not sorted; left is not necessarily less than right.
776top and bottom are not sorted; top is not necessarily less than bottom.
777
778#Param left assigned to fLeft ##
779#Param top assigned to fTop ##
780#Param right assigned to fRight ##
781#Param bottom assigned to fBottom ##
782
783#Example
784 SkIRect rect1 = {3, 4, 1, 2};
785 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
786 SkIRect rect2;
787 rect2.set(3, 4, 1, 2);
788 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
789#StdOut
790rect1: {3, 4, 1, 2}
791rect2: {3, 4, 1, 2}
792##
793##
794
795#SeeAlso setLTRB setXYWH SkRect::set
796
797##
798
799# ------------------------------------------------------------------------------
800
801#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
802
Cary Clark4855f782018-02-06 09:41:53 -0500803#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500804#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500805Sets IRect to (left, top, right, bottom).
806left and right are not sorted; left is not necessarily less than right.
807top and bottom are not sorted; top is not necessarily less than bottom.
808
809#Param left stored in fLeft ##
810#Param top stored in fTop ##
811#Param right stored in fRight ##
812#Param bottom stored in fBottom ##
813
814#Example
815 SkIRect rect1 = {3, 4, 1, 2};
816 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
817 SkIRect rect2;
818 rect2.setLTRB(3, 4, 1, 2);
819 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
820#StdOut
821rect1: {3, 4, 1, 2}
822rect2: {3, 4, 1, 2}
823##
824##
825
826#SeeAlso set setXYWH SkRect::setLTRB
827
828##
829
830# ------------------------------------------------------------------------------
831
832#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
833
Cary Clark4855f782018-02-06 09:41:53 -0500834#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500835#Line # sets to (x, y, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500836Sets IRect to:
837#Formula
838(x, y, x + width, y + height)
839##
840. Does not validate input;
841width or height may be negative.
842
843#Param x stored in fLeft ##
844#Param y stored in fTop ##
845#Param width added to x and stored in fRight ##
846#Param height added to y and stored in fBottom ##
847
848#Example
849 SkIRect rect;
850 rect.setXYWH(5, 35, -15, 25);
851 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
852 rect.bottom(), rect.isEmpty() ? "true" : "false");
853 rect.sort();
854 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
855 rect.bottom(), rect.isEmpty() ? "true" : "false");
856#StdOut
857rect: 5, 35, -10, 60 isEmpty: true
858rect: -10, 35, 5, 60 isEmpty: false
859##
860##
861
862#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH
863
864##
865
Cary Clark2dc84ad2018-01-26 12:56:22 -0500866#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -0500867#Line # moves sides ##
Cary Clark4855f782018-02-06 09:41:53 -0500868#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500869
Cary Clark0c5f5462017-12-15 11:21:51 -0500870# ------------------------------------------------------------------------------
871
Cary Clark0c5f5462017-12-15 11:21:51 -0500872#Method SkIRect makeOffset(int32_t dx, int32_t dy) const
873
Cary Clarkab2621d2018-01-30 10:08:57 -0500874#In Inset_Outset_Offset
875#Line # constructs from translated sides ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500876Returns IRect offset by (dx, dy).
877
878If dx is negative, IRect returned is moved to the left.
879If dx is positive, IRect returned is moved to the right.
880If dy is negative, IRect returned is moved upward.
881If dy is positive, IRect returned is moved downward.
882
883#Param dx offset added to fLeft and fRight ##
884#Param dy offset added to fTop and fBottom ##
885
Cary Clark2dc84ad2018-01-26 12:56:22 -0500886#Return IRect offset in x or y, with original width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500887
888#Example
889 SkIRect rect = { 10, 50, 20, 60 };
890 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
891 rect.bottom(), rect.isEmpty() ? "true" : "false");
892 rect = rect.makeOffset(15, 32);
893 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
894 rect.bottom(), rect.isEmpty() ? "true" : "false");
895#StdOut
896rect: 10, 50, 20, 60 isEmpty: false
897rect: 25, 82, 35, 92 isEmpty: false
898##
899##
900
901#SeeAlso offset() makeInset makeOutset SkRect::makeOffset
902
903##
904
905# ------------------------------------------------------------------------------
906
907#Method SkIRect makeInset(int32_t dx, int32_t dy) const
908
Cary Clarkab2621d2018-01-30 10:08:57 -0500909#In Inset_Outset_Offset
910#Line # constructs from sides moved symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500911Returns IRect, inset by (dx, dy).
912
913If dx is negative, IRect returned is wider.
914If dx is positive, IRect returned is narrower.
915If dy is negative, IRect returned is taller.
916If dy is positive, IRect returned is shorter.
917
918#Param dx offset added to fLeft and subtracted from fRight ##
919#Param dy offset added to fTop and subtracted from fBottom ##
920
Cary Clark2dc84ad2018-01-26 12:56:22 -0500921#Return IRect inset symmetrically left and right, top and bottom ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500922
923#Example
924 SkIRect rect = { 10, 50, 20, 60 };
925 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
926 rect.bottom(), rect.isEmpty() ? "true" : "false");
927 rect = rect.makeInset(15, 32);
928 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
929 rect.bottom(), rect.isEmpty() ? "true" : "false");
930#StdOut
931rect: 10, 50, 20, 60 isEmpty: false
932rect: 25, 82, 5, 28 isEmpty: true
933##
934##
935
936#SeeAlso inset() makeOffset makeOutset SkRect::makeInset
937
938##
939
940# ------------------------------------------------------------------------------
941
942#Method SkIRect makeOutset(int32_t dx, int32_t dy) const
943
Cary Clarkab2621d2018-01-30 10:08:57 -0500944#In Inset_Outset_Offset
945#Line # constructs from sides moved symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500946Returns IRect, outset by (dx, dy).
947
948If dx is negative, IRect returned is narrower.
949If dx is positive, IRect returned is wider.
950If dy is negative, IRect returned is shorter.
951If dy is positive, IRect returned is taller.
952
953#Param dx offset subtracted to fLeft and added from fRight ##
954#Param dy offset subtracted to fTop and added from fBottom ##
955
Cary Clark2dc84ad2018-01-26 12:56:22 -0500956#Return IRect outset symmetrically left and right, top and bottom ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500957
958#Example
959 SkIRect rect = { 10, 50, 20, 60 };
960 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
961 rect.bottom(), rect.isEmpty() ? "true" : "false");
962 rect = rect.makeOutset(15, 32);
963 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
964 rect.bottom(), rect.isEmpty() ? "true" : "false");
965#StdOut
966rect: 10, 50, 20, 60 isEmpty: false
967rect: -5, 18, 35, 92 isEmpty: false
968##
969##
970
971#SeeAlso outset() makeOffset makeInset SkRect::makeOutset
972
973##
974
975# ------------------------------------------------------------------------------
976
977#Method void offset(int32_t dx, int32_t dy)
978
Cary Clarkab2621d2018-01-30 10:08:57 -0500979#In Inset_Outset_Offset
980#Line # translates sides without changing width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500981Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
982
983If dx is negative, moves IRect returned to the left.
984If dx is positive, moves IRect returned to the right.
985If dy is negative, moves IRect returned upward.
986If dy is positive, moves IRect returned downward.
987
988#Param dx offset added to fLeft and fRight ##
989#Param dy offset added to fTop and fBottom ##
990
991#Example
992 SkIRect rect = { 10, 14, 50, 73 };
993 rect.offset(5, 13);
994 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
995#StdOut
996rect: 15, 27, 55, 86
997##
998##
999
1000#SeeAlso offsetTo makeOffset SkRect::offset
1001
1002##
1003
1004# ------------------------------------------------------------------------------
1005
1006#Method void offset(const SkIPoint& delta)
1007
Cary Clarkab2621d2018-01-30 10:08:57 -05001008#In Inset_Outset_Offset
Cary Clark0c5f5462017-12-15 11:21:51 -05001009Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1010fTop, fBottom.
1011
1012If delta.fX is negative, moves IRect returned to the left.
1013If delta.fX is positive, moves IRect returned to the right.
1014If delta.fY is negative, moves IRect returned upward.
1015If delta.fY is positive, moves IRect returned downward.
1016
1017#Param delta offset added to IRect ##
1018
1019#Example
1020 SkIRect rect = { 10, 14, 50, 73 };
1021 rect.offset({5, 13});
1022 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1023#StdOut
1024rect: 15, 27, 55, 86
1025##
1026##
1027
1028#SeeAlso offsetTo makeOffset SkRect::offset
1029
1030##
1031
1032# ------------------------------------------------------------------------------
1033
1034#Method void offsetTo(int32_t newX, int32_t newY)
1035
Cary Clarkab2621d2018-01-30 10:08:57 -05001036#In Inset_Outset_Offset
1037#Line # translates to (x, y) without changing width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001038Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height
1039are unchanged.
1040
1041#Param newX stored in fLeft, preserving width() ##
1042#Param newY stored in fTop, preserving height() ##
1043
1044#Example
1045 SkIRect rect = { 10, 14, 50, 73 };
1046 rect.offsetTo(15, 27);
1047 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1048#StdOut
1049rect: 15, 27, 55, 86
1050##
1051##
1052
1053#SeeAlso offset makeOffset setXYWH SkRect::offsetTo
1054
1055##
1056
1057# ------------------------------------------------------------------------------
1058
1059#Method void inset(int32_t dx, int32_t dy)
1060
Cary Clarkab2621d2018-01-30 10:08:57 -05001061#In Inset_Outset_Offset
1062#Line # moves the sides symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001063Insets IRect by (dx,dy).
1064
1065If dx is positive, makes IRect narrower.
1066If dx is negative, makes IRect wider.
1067If dy is positive, makes IRect shorter.
1068If dy is negative, makes IRect taller.
1069
1070#Param dx offset added to fLeft and subtracted from fRight ##
1071#Param dy offset added to fTop and subtracted from fBottom ##
1072
1073#Example
1074 SkIRect rect = { 10, 14, 50, 73 };
1075 rect.inset(5, 13);
1076 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1077#StdOut
1078rect: 15, 27, 45, 60
1079##
1080##
1081
1082#SeeAlso outset makeInset SkRect::inset
1083
1084##
1085
1086# ------------------------------------------------------------------------------
1087
1088#Method void outset(int32_t dx, int32_t dy)
1089
Cary Clarkab2621d2018-01-30 10:08:57 -05001090#In Inset_Outset_Offset
1091#Line # moves the sides symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001092Outsets IRect by (dx, dy).
1093
Cary Clark2dc84ad2018-01-26 12:56:22 -05001094If dx is positive, makes IRect wider.
1095If dx is negative, makes IRect narrower.
1096If dy is positive, makes IRect taller.
1097If dy is negative, makes IRect shorter.
Cary Clark0c5f5462017-12-15 11:21:51 -05001098
1099#Param dx subtracted to fLeft and added from fRight ##
1100#Param dy subtracted to fTop and added from fBottom ##
1101
1102#Example
1103 SkIRect rect = { 10, 14, 50, 73 };
1104 rect.outset(5, 13);
1105 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1106#StdOut
1107rect: 5, 1, 55, 86
1108##
1109##
1110
1111#SeeAlso inset makeOutset SkRect::outset
1112
1113##
1114
Cary Clark2dc84ad2018-01-26 12:56:22 -05001115#Subtopic Inset_Outset_Offset ##
1116
1117#Subtopic Intersection
Cary Clark08895c42018-02-01 09:37:32 -05001118#Line # set to shared bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001119
1120IRects intersect when they enclose a common area. To intersect, each of the pair
1121must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1122empty() returns false. The intersection of IRect pair can be described by:
1123
1124#Formula
1125(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1126 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1127##
1128.
1129
1130The intersection is only meaningful if the resulting IRect is not empty and
1131describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1132
Cary Clark4855f782018-02-06 09:41:53 -05001133#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001134
Cary Clark0c5f5462017-12-15 11:21:51 -05001135# ------------------------------------------------------------------------------
1136
1137#Method bool quickReject(int l, int t, int r, int b) const
1138
Cary Clarkab2621d2018-01-30 10:08:57 -05001139#In Intersection
1140#Line # returns true if rectangles do not intersect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001141Constructs IRect (l, t, r, b) and returns true if constructed IRect does not
1142intersect IRect. Does not check to see if construction or IRect is empty.
1143
1144Is implemented with short circuit logic so that true can be returned after
1145a single compare.
1146
Cary Clark2dc84ad2018-01-26 12:56:22 -05001147#Param l x minimum of constructed IRect ##
1148#Param t y minimum of constructed IRect ##
1149#Param r x maximum of constructed IRect ##
1150#Param b y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001151
1152#Return true if construction and IRect have no area in common ##
1153
1154#Example
1155#Description
1156quickReject is the complement of Intersects.
1157##
1158 const SkIRect rect = {7, 11, 13, 17};
1159 const int32_t* r = &rect.fLeft;
1160 const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } };
1161 for (auto& test : tests) {
1162 const int32_t* t = &test.fLeft;
1163 SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n",
1164 r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3],
1165 rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false",
1166 SkIRect::Intersects(rect, test) ? "true" : "false");
1167 }
1168#StdOut
1169rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false
1170rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false
1171rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true
1172##
1173##
1174
1175#SeeAlso Intersects
1176
1177##
1178
1179# ------------------------------------------------------------------------------
1180
1181#Method bool contains(int32_t x, int32_t y) const
1182
Cary Clarkab2621d2018-01-30 10:08:57 -05001183#In Intersection
Cary Clark300cc5b2018-02-20 12:50:35 -05001184#Line # returns true if IPoint (x, y) is equal or inside ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001185Returns true if:
1186#Formula
1187fLeft <= x < fRight && fTop <= y < fBottom
1188##
1189.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001190Returns false if IRect is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001191
1192Considers input to describe constructed IRect:
1193#Formula
1194(x, y, x + 1, y + 1)
1195##
1196and
1197returns true if constructed area is completely enclosed by IRect area.
1198
Cary Clark300cc5b2018-02-20 12:50:35 -05001199#Param x test IPoint x-coordinate ##
1200#Param y test IPoint y-coordinate ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001201
1202#Return true if (x, y) is inside IRect ##
1203
1204#Example
1205 SkIRect rect = { 30, 50, 40, 60 };
1206 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} };
1207 for (auto pt : pts) {
1208 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n",
1209 rect.left(), rect.top(), rect.right(), rect.bottom(),
1210 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y());
1211 }
1212#StdOut
1213rect: (30, 50, 40, 60) contains (30, 50)
1214rect: (30, 50, 40, 60) does not contain (40, 50)
1215rect: (30, 50, 40, 60) does not contain (30, 60)
1216##
1217##
1218
1219#SeeAlso containsNoEmptyCheck SkRect::contains
1220
1221##
1222
1223# ------------------------------------------------------------------------------
1224
1225#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
1226
Cary Clarkab2621d2018-01-30 10:08:57 -05001227#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001228Constructs IRect to intersect from (left, top, right, bottom). Does not sort
Cary Clark0c5f5462017-12-15 11:21:51 -05001229construction.
1230
Cary Clark2dc84ad2018-01-26 12:56:22 -05001231Returns true if IRect contains construction.
1232Returns false if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001233
Cary Clark2dc84ad2018-01-26 12:56:22 -05001234#Param left x minimum of constructed IRect ##
1235#Param top y minimum of constructed IRect ##
1236#Param right x maximum of constructed IRect ##
1237#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001238
1239#Return true if all sides of IRect are outside construction ##
1240
1241#Example
1242 SkIRect rect = { 30, 50, 40, 60 };
1243 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1244 for (auto contained : tests) {
1245 bool success = rect.contains(
1246 contained.left(), contained.top(), contained.right(), contained.bottom());
1247 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1248 rect.left(), rect.top(), rect.right(), rect.bottom(),
1249 success ? "contains" : "does not contain",
1250 contained.left(), contained.top(), contained.right(), contained.bottom());
1251 }
1252#StdOut
1253rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1254rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1255rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1256##
1257##
1258
1259#SeeAlso containsNoEmptyCheck SkRect::contains
1260
1261##
1262
1263# ------------------------------------------------------------------------------
1264
1265#Method bool contains(const SkIRect& r) const
1266
Cary Clarkab2621d2018-01-30 10:08:57 -05001267#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001268Returns true if IRect contains r.
1269Returns false if IRect is empty or r is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001270
Cary Clark2dc84ad2018-01-26 12:56:22 -05001271IRect contains r when IRect area completely includes r area.
Cary Clark0c5f5462017-12-15 11:21:51 -05001272
1273#Param r IRect contained ##
1274
1275#Return true if all sides of IRect are outside r ##
1276
1277#Example
1278 SkIRect rect = { 30, 50, 40, 60 };
1279 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1280 for (auto contained : tests) {
1281 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1282 rect.left(), rect.top(), rect.right(), rect.bottom(),
1283 rect.contains(contained) ? "contains" : "does not contain",
1284 contained.left(), contained.top(), contained.right(), contained.bottom());
1285 }
1286#StdOut
1287rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1288rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1289rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1290##
1291##
1292
1293#SeeAlso containsNoEmptyCheck SkRect::contains
1294
1295##
1296
1297# ------------------------------------------------------------------------------
1298
1299#Method bool contains(const SkRect& r) const
1300
Cary Clarkab2621d2018-01-30 10:08:57 -05001301#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001302Returns true if IRect contains r.
1303Returns false if IRect is empty or r is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001304
Cary Clark2dc84ad2018-01-26 12:56:22 -05001305IRect contains r when IRect area completely includes r area.
Cary Clark0c5f5462017-12-15 11:21:51 -05001306
1307#Param r Rect contained ##
1308
1309#Return true if all sides of IRect are outside r ##
1310
1311#Example
1312 SkIRect rect = { 30, 50, 40, 60 };
1313 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1314 for (auto contained : tests) {
1315 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n",
1316 rect.left(), rect.top(), rect.right(), rect.bottom(),
1317 rect.contains(contained) ? "contains" : "does not contain",
1318 contained.left(), contained.top(), contained.right(), contained.bottom());
1319 }
1320#StdOut
1321rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1322rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1323rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1324##
1325##
1326
1327#SeeAlso containsNoEmptyCheck SkRect::contains
1328
1329##
1330
1331# ------------------------------------------------------------------------------
1332
1333#Method bool containsNoEmptyCheck(int32_t left, int32_t top,
1334 int32_t right, int32_t bottom) const
Cary Clarkab2621d2018-01-30 10:08:57 -05001335#In Intersection
Cary Clark300cc5b2018-02-20 12:50:35 -05001336#Line # returns true if contains unsorted IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001337
1338Constructs IRect from (left, top, right, bottom). Does not sort
1339construction.
1340
Cary Clark2dc84ad2018-01-26 12:56:22 -05001341Returns true if IRect contains construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001342Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1343
Cary Clark2dc84ad2018-01-26 12:56:22 -05001344Return is undefined if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001345
Cary Clark2dc84ad2018-01-26 12:56:22 -05001346#Param left x minimum of constructed IRect ##
1347#Param top y minimum of constructed IRect ##
1348#Param right x maximum of constructed IRect ##
1349#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001350
1351#Return true if all sides of IRect are outside construction ##
1352
1353#Example
1354 SkIRect rect = { 30, 50, 40, 60 };
1355 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1356 for (auto contained : tests) {
1357 bool success = rect.containsNoEmptyCheck(
1358 contained.left(), contained.top(), contained.right(), contained.bottom());
1359 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1360 rect.left(), rect.top(), rect.right(), rect.bottom(),
1361 success ? "contains" : "does not contain",
1362 contained.left(), contained.top(), contained.right(), contained.bottom());
1363 }
1364#StdOut
1365rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1366rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1367rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1368##
1369##
1370
1371#SeeAlso contains SkRect::contains
1372
1373##
1374
1375# ------------------------------------------------------------------------------
1376
1377#Method bool containsNoEmptyCheck(const SkIRect& r) const
1378
Cary Clarkab2621d2018-01-30 10:08:57 -05001379#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001380Returns true if IRect contains construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001381Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1382
Cary Clark2dc84ad2018-01-26 12:56:22 -05001383Return is undefined if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001384
Cary Clark2dc84ad2018-01-26 12:56:22 -05001385#Param r IRect contained ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001386
1387#Return true if all sides of IRect are outside r ##
1388
1389#Example
1390 SkIRect rect = { 30, 50, 40, 60 };
1391 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1392 for (auto contained : tests) {
1393 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1394 rect.left(), rect.top(), rect.right(), rect.bottom(),
1395 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain",
1396 contained.left(), contained.top(), contained.right(), contained.bottom());
1397 }
1398#StdOut
1399rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1400rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1401rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1402##
1403##
1404
1405#SeeAlso contains SkRect::contains
1406
1407##
1408
Cary Clark0c5f5462017-12-15 11:21:51 -05001409# ------------------------------------------------------------------------------
1410
1411#Method bool intersect(const SkIRect& r)
1412
Cary Clarkab2621d2018-01-30 10:08:57 -05001413#In Intersection
1414#Line # sets to shared area; returns true if not empty ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001415Returns true if IRect intersects r, and sets IRect to intersection.
1416Returns false if IRect does not intersect r, and leaves IRect unchanged.
1417
1418Returns false if either r or IRect is empty, leaving IRect unchanged.
1419
1420#Param r limit of result ##
1421
Cary Clark2dc84ad2018-01-26 12:56:22 -05001422#Return true if r and IRect have area in common ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001423
1424#Example
1425#Description
1426Two SkDebugf calls are required. If the calls are combined, their arguments
1427may not be evaluated in left to right order: the printed intersection may
1428be before or after the call to intersect.
1429##
1430 SkIRect leftRect = { 10, 40, 50, 80 };
1431 SkIRect rightRect = { 30, 60, 70, 90 };
1432 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1433 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1434 leftRect.right(), leftRect.bottom());
1435#StdOut
1436 intersection: 30, 60, 50, 80
1437##
1438##
1439
1440#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1441
1442##
1443
1444# ------------------------------------------------------------------------------
1445
1446#Method bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b)
1447
Cary Clarkab2621d2018-01-30 10:08:57 -05001448#In Intersection
Cary Clark0c5f5462017-12-15 11:21:51 -05001449Returns true if a intersects b, and sets IRect to intersection.
1450Returns false if a does not intersect b, and leaves IRect unchanged.
1451
1452Returns false if either a or b is empty, leaving IRect unchanged.
1453
1454#Param a IRect to intersect ##
1455#Param b IRect to intersect ##
1456
1457#Return true if a and b have area in common ##
1458
1459#Example
1460 SkIRect result;
1461 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1462 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ",
1463 result.left(), result.top(), result.right(), result.bottom());
1464#StdOut
1465 intersection: 30, 60, 50, 80
1466##
1467##
1468
1469#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1470
1471##
1472
1473# ------------------------------------------------------------------------------
1474
1475#Method bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1476
Cary Clarkab2621d2018-01-30 10:08:57 -05001477#In Intersection
1478#Line # sets to shared area; returns true if not empty skips empty check ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001479Returns true if a intersects b, and sets IRect to intersection.
1480Returns false if a does not intersect b, and leaves IRect unchanged.
1481
1482Asserts if either a or b is empty, and if SK_DEBUG is defined.
1483
1484#Param a IRect to intersect ##
1485#Param b IRect to intersect ##
1486
1487#Return true if a and b have area in common ##
1488
1489#Example
1490 SkIRect result;
Cary Clark681287e2018-03-16 11:34:15 -04001491 if (result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 })) {
1492 SkDebugf("intersection: %d, %d, %d, %d\n",
1493 result.left(), result.top(), result.right(), result.bottom());
1494 }
Cary Clark0c5f5462017-12-15 11:21:51 -05001495#StdOut
1496 intersection: 30, 60, 50, 80
1497##
1498##
1499
1500#SeeAlso Intersects intersect join SkRect::intersect
1501
1502##
1503
1504# ------------------------------------------------------------------------------
1505
1506#Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
1507
Cary Clarkab2621d2018-01-30 10:08:57 -05001508#In Intersection
Cary Clark0c5f5462017-12-15 11:21:51 -05001509Constructs IRect to intersect from (left, top, right, bottom). Does not sort
1510construction.
1511
1512Returns true if IRect intersects construction, and sets IRect to intersection.
1513Returns false if IRect does not intersect construction, and leaves IRect unchanged.
1514
1515Returns false if either construction or IRect is empty, leaving IRect unchanged.
1516
1517#Param left x minimum of constructed IRect ##
1518#Param top y minimum of constructed IRect ##
1519#Param right x maximum of constructed IRect ##
1520#Param bottom y maximum of constructed IRect ##
1521
1522#Return true if construction and IRect have area in common ##
1523
1524#Example
1525#Description
1526Two SkDebugf calls are required. If the calls are combined, their arguments
1527may not be evaluated in left to right order: the printed intersection may
1528be before or after the call to intersect.
1529##
1530 SkIRect leftRect = { 10, 40, 50, 80 };
1531 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1532 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1533 leftRect.right(), leftRect.bottom());
1534#StdOut
1535 intersection: 30, 60, 50, 80
1536##
1537##
1538
1539#SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect
1540
1541##
1542
1543# ------------------------------------------------------------------------------
1544
1545#Method static bool Intersects(const SkIRect& a, const SkIRect& b)
1546
Cary Clarkab2621d2018-01-30 10:08:57 -05001547#In Intersection
1548#Line # returns true if areas overlap ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001549Returns true if a intersects b.
1550Returns false if either a or b is empty, or do not intersect.
1551
1552#Param a IRect to intersect ##
1553#Param b IRect to intersect ##
1554
1555#Return true if a and b have area in common ##
1556
1557#Example
1558 SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1559#StdOut
1560 intersection
1561##
1562##
1563
1564#SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect
1565
1566##
1567
1568# ------------------------------------------------------------------------------
1569
1570#Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1571
Cary Clarkab2621d2018-01-30 10:08:57 -05001572#In Intersection
1573#Line # returns true if areas overlap skips empty check ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001574Returns true if a intersects b.
1575Asserts if either a or b is empty, and if SK_DEBUG is defined.
1576
1577#Param a IRect to intersect ##
1578#Param b IRect to intersect ##
1579
1580#Return true if a and b have area in common ##
1581
1582#Example
1583 SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck(
1584 {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1585#StdOut
1586 intersection
1587##
1588##
1589
1590#SeeAlso Intersects intersect SkRect::intersect
1591
1592##
1593
Cary Clark2dc84ad2018-01-26 12:56:22 -05001594#Subtopic Intersection ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001595
1596# ------------------------------------------------------------------------------
1597
Cary Clark4855f782018-02-06 09:41:53 -05001598#Subtopic Join
1599#Line # set to union of bounds ##
1600#Populate
1601##
1602
Cary Clark0c5f5462017-12-15 11:21:51 -05001603#Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom)
1604
Cary Clark4855f782018-02-06 09:41:53 -05001605#In Join
Cary Clarkab2621d2018-01-30 10:08:57 -05001606#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001607Constructs IRect to intersect from (left, top, right, bottom). Does not sort
Cary Clark0c5f5462017-12-15 11:21:51 -05001608construction.
1609
Cary Clark2dc84ad2018-01-26 12:56:22 -05001610Sets IRect to the union of itself and the construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001611
Cary Clark2dc84ad2018-01-26 12:56:22 -05001612Has no effect if construction is empty. Otherwise, if IRect is empty, sets
1613IRect to construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001614
Cary Clark2dc84ad2018-01-26 12:56:22 -05001615#Param left x minimum of constructed IRect ##
1616#Param top y minimum of constructed IRect ##
1617#Param right x maximum of constructed IRect ##
1618#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001619
1620#Example
1621 SkIRect rect = { 10, 20, 15, 25};
1622 rect.join(50, 60, 55, 65);
1623 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1624#StdOut
1625 join: 10, 20, 55, 65
1626##
1627##
1628
1629#SeeAlso set SkRect::join
1630
1631##
1632
1633# ------------------------------------------------------------------------------
1634
1635#Method void join(const SkIRect& r)
1636
Cary Clark4855f782018-02-06 09:41:53 -05001637#In Join
Cary Clark2dc84ad2018-01-26 12:56:22 -05001638Sets IRect to the union of itself and r.
Cary Clark0c5f5462017-12-15 11:21:51 -05001639
Cary Clark2dc84ad2018-01-26 12:56:22 -05001640Has no effect if r is empty. Otherwise, if IRect is empty, sets IRect to r.
Cary Clark0c5f5462017-12-15 11:21:51 -05001641
Cary Clark2dc84ad2018-01-26 12:56:22 -05001642#Param r expansion IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001643
1644#Example
1645 SkIRect rect = { 10, 20, 15, 25};
1646 rect.join({50, 60, 55, 65});
1647 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1648#StdOut
1649 join: 10, 20, 55, 65
1650##
1651##
1652
1653#SeeAlso set SkRect::join
1654
1655##
1656
1657# ------------------------------------------------------------------------------
1658
Cary Clark4855f782018-02-06 09:41:53 -05001659#Subtopic Sorting
1660#Line # orders sides ##
1661#Populate
1662##
1663
Cary Clark0c5f5462017-12-15 11:21:51 -05001664#Method void sort()
1665
Cary Clark4855f782018-02-06 09:41:53 -05001666#In Sorting
Cary Clarkab2621d2018-01-30 10:08:57 -05001667#Line # orders sides from smaller to larger ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001668Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
1669fTop and fBottom if fTop is greater than fBottom. Result may be empty,
1670and width() and height() will be zero or positive.
1671
1672#Example
1673 SkIRect rect = { 30, 50, 20, 10 };
1674 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1675 rect.sort();
1676 SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1677#StdOut
1678rect: 30, 50, 20, 10
1679sorted: 20, 10, 30, 50
1680##
1681##
1682
1683#SeeAlso makeSorted SkRect::sort
1684
1685##
1686
1687# ------------------------------------------------------------------------------
1688
1689#Method SkIRect makeSorted() const
1690
Cary Clark4855f782018-02-06 09:41:53 -05001691#In Sorting
1692#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001693#Line # constructs, ordering sides from smaller to larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001694Returns IRect with fLeft and fRight swapped if fLeft is greater than fRight; and
Cary Clark0c5f5462017-12-15 11:21:51 -05001695with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
1696and width() and height() will be zero or positive.
1697
1698#Return sorted IRect ##
1699
1700#Example
1701 SkIRect rect = { 30, 50, 20, 10 };
1702 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1703 SkIRect sort = rect.makeSorted();
1704 SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
1705#StdOut
1706rect: 30, 50, 20, 10
1707sorted: 20, 10, 30, 50
1708##
1709##
1710
1711#SeeAlso sort SkRect::makeSorted
1712
1713##
1714
1715# ------------------------------------------------------------------------------
1716
1717#Method static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect()
1718
Cary Clark4855f782018-02-06 09:41:53 -05001719#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001720#Line # returns immutable bounds of (0, 0, 0, 0) ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001721Returns a reference to immutable empty IRect, set to (0, 0, 0, 0).
1722
1723#Return global IRect set to all zeroes ##
1724
1725#Example
1726 const SkIRect& rect = SkIRect::EmptyIRect();
1727 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1728#StdOut
1729rect: 0, 0, 0, 0
1730##
1731##
1732
1733#SeeAlso MakeEmpty
1734
1735##
1736
Cary Clark0c95aab2018-01-08 16:20:59 -05001737#Method static SkIRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05001738#Deprecated
1739##
1740
Cary Clark0c5f5462017-12-15 11:21:51 -05001741#Struct SkIRect ##
1742
1743#Topic IRect ##