blob: 1e59578310e603f8c2b5d774b0449339b297d368 [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 Clark186d08f2018-04-03 08:43:27 -0400423#Example
Mike Reeda766ca92018-01-09 11:31:53 -0500424SkIRect large = { -2147483647, 1, 2147483644, 2 };
Cary Clark186d08f2018-04-03 08:43:27 -0400425SkDebugf("width: %d width64: %lld\n", large.width(), large.width64());
Mike Reeda766ca92018-01-09 11:31:53 -0500426#StdOut
427width: -5 width64: 4294967291
428##
429##
430
431#SeeAlso width() height() height64() SkRect::width()
Cary Clark0c5f5462017-12-15 11:21:51 -0500432
433##
434
435# ------------------------------------------------------------------------------
436
Cary Clark6def7202018-01-04 08:13:35 -0500437#Method int32_t height() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500438
Cary Clark4855f782018-02-06 09:41:53 -0500439#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500440#Line # returns span in y ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500441Returns span on the y-axis. This does not check if IRect is sorted, or if
442result fits in 32-bit signed integer; result may be negative.
443
444#Return fBottom minus fTop ##
445
446#Example
447 SkIRect unsorted = { 15, 25, 10, 20 };
448 SkDebugf("unsorted height: %d\n", unsorted.height());
449 SkIRect large = { 1, -2147483647, 2, 2147483644 };
450 SkDebugf("large height: %d\n", large.height());
451#StdOut
452unsorted height: -5
453large height: -5
454##
455##
456
457#SeeAlso width() SkRect::height()
458
459##
460
461# ------------------------------------------------------------------------------
462
Mike Reeda766ca92018-01-09 11:31:53 -0500463#Method int64_t height64() const
464
Cary Clark4855f782018-02-06 09:41:53 -0500465#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500466#Line # returns span in y as int64_t ##
Mike Reeda766ca92018-01-09 11:31:53 -0500467Returns span on the y-axis. This does not check if IRect is sorted, so the
468result may be negative. This is safer than calling height() since height() might
469overflow in its calculation.
470
471#Return fBottom minus fTop cast to int64_t ##
472
Cary Clark186d08f2018-04-03 08:43:27 -0400473#Example
Mike Reeda766ca92018-01-09 11:31:53 -0500474SkIRect large = { 1, -2147483647, 2, 2147483644 };
475SkDebugf("height: %d height64: %lld\n", large.height(), large.height64());
476#StdOut
477height: -5 height64: 4294967291
478##
479##
480
481#SeeAlso width() height() width64() SkRect::height()
482
483##
484
485# ------------------------------------------------------------------------------
486
Cary Clark0c5f5462017-12-15 11:21:51 -0500487#Method SkISize size() const
488
Cary Clark4855f782018-02-06 09:41:53 -0500489#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500490#Line # returns ISize (width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500491Returns spans on the x-axis and y-axis. This does not check if IRect is sorted,
492or if result fits in 32-bit signed integer; result may be negative.
493
494#Return ISize (width, height) ##
495
496#Example
497 auto debugster = [](const char* prefix, const SkIRect& rect) -> void {
498 SkISize size = rect.size();
499 SkDebugf("%s ", prefix);
500 SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom());
501 SkDebugf("size: %d, %d\n", size.width(), size.height());
502 };
503 SkIRect rect = {20, 30, 40, 50};
504 debugster("original", rect);
505 rect.offset(20, 20);
506 debugster(" offset", rect);
507 rect.outset(20, 20);
508 debugster(" outset", rect);
509#StdOut
510original rect: 20, 30, 40, 50 size: 20, 20
511 offset rect: 40, 50, 60, 70 size: 20, 20
512 outset rect: 20, 30, 80, 90 size: 60, 60
513##
514##
515
516#SeeAlso height() width() MakeSize
517
518##
519
520# ------------------------------------------------------------------------------
521
Cary Clark6def7202018-01-04 08:13:35 -0500522#Method int32_t centerX() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500523
Cary Clark4855f782018-02-06 09:41:53 -0500524#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500525#Line # returns midpoint in x ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500526Returns average of left edge and right edge. Result does not change if IRect
Cary Clarkedd08952018-03-22 07:58:54 -0400527is sorted.
Cary Clark0c5f5462017-12-15 11:21:51 -0500528
529Result is rounded down.
530
531#Return midpoint in x ##
532
533#Example
534#Description
535Dividing by two rounds towards zero. centerX uses a bit shift and rounds down.
536##
537 SkIRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}, {-10, -10, 11, 11}};
538 for (auto rect : tests) {
539 SkDebugf("left: %3d right: %3d centerX: %3d ", rect.left(), rect.right(), rect.centerX());
540 SkDebugf("div2: %3d\n", (rect.left() + rect.right()) / 2);
541 }
542#StdOut
543left: 20 right: 41 centerX: 30 div2: 30
544left: -20 right: -41 centerX: -31 div2: -30
545left: -10 right: 11 centerX: 0 div2: 0
546##
547##
548
549#SeeAlso centerY SkRect::centerX
550
551##
552
553# ------------------------------------------------------------------------------
554
Cary Clark6def7202018-01-04 08:13:35 -0500555#Method int32_t centerY() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500556
Cary Clark4855f782018-02-06 09:41:53 -0500557#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500558#Line # returns midpoint in y ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500559Returns average of top edge and bottom edge. Result does not change if IRect
Cary Clarkedd08952018-03-22 07:58:54 -0400560is sorted.
Cary Clark0c5f5462017-12-15 11:21:51 -0500561
562Result is rounded down.
563
564#Return midpoint in y ##
565
566#Example
567 SkIRect rect = { 0, 0, 2, 2 };
568 rect.offset(0x40000000, 0x40000000);
569 SkDebugf("left: %d right: %d centerX: %d ", rect.left(), rect.right(), rect.centerX());
Cary Clark0c5f5462017-12-15 11:21:51 -0500570#StdOut
Cary Clarkedd08952018-03-22 07:58:54 -0400571left: 1073741824 right: 1073741826 centerX: 1073741825
Cary Clark0c5f5462017-12-15 11:21:51 -0500572##
573##
574
575#SeeAlso centerX SkRect::centerY
576
577##
578
579# ------------------------------------------------------------------------------
580
581#Method bool isEmpty() const
582
Cary Clark4855f782018-02-06 09:41:53 -0500583#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500584#Line # returns true if width or height are zero or negative or they exceed int32_t ##
Mike Reedd2849492018-01-10 14:31:18 -0500585Returns true if width() or height() .
Cary Clark0c5f5462017-12-15 11:21:51 -0500586
587#Return true if width() or height() are zero or negative ##
588
589#Example
590 SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
591 for (auto rect : tests) {
592 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
593 rect.bottom(), rect.isEmpty() ? "" : " not");
594 rect.sort();
595 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
596 rect.bottom(), rect.isEmpty() ? "" : " not");
597 }
598#StdOut
599rect: {20, 40, 10, 50} is empty
600sorted: {10, 40, 20, 50} is not empty
601rect: {20, 40, 20, 50} is empty
602sorted: {20, 40, 20, 50} is empty
603##
604##
605
606#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
607
608##
609
610# ------------------------------------------------------------------------------
611
Mike Reedd2849492018-01-10 14:31:18 -0500612#Method bool isEmpty64() const
613
Cary Clark4855f782018-02-06 09:41:53 -0500614#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500615#Line # returns true if width or height are zero or negative ##
Mike Reedd2849492018-01-10 14:31:18 -0500616Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
617to or greater than fBottom. Call sort() to reverse rectangles with negative
618width64() or height64().
619
620#Return true if width64() or height64() are zero or negative ##
621
Cary Clark186d08f2018-04-03 08:43:27 -0400622#Example
Mike Reedd2849492018-01-10 14:31:18 -0500623SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
624for (auto rect : tests) {
Cary Clark186d08f2018-04-03 08:43:27 -0400625 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
626 rect.bottom(), rect.isEmpty64() ? "" : " not");
627 rect.sort();
628 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
629 rect.bottom(), rect.isEmpty64() ? "" : " not");
Mike Reedd2849492018-01-10 14:31:18 -0500630}
631#StdOut
632rect: {20, 40, 10, 50} is empty
633sorted: {10, 40, 20, 50} is not empty
634rect: {20, 40, 20, 50} is empty
635sorted: {20, 40, 20, 50} is empty
636##
637##
638
639#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
640
641##
642
Cary Clark4855f782018-02-06 09:41:53 -0500643#Subtopic Operator
Cary Clark08895c42018-02-01 09:37:32 -0500644#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500645
Mike Reedd2849492018-01-10 14:31:18 -0500646# ------------------------------------------------------------------------------
647
Cary Clark0c5f5462017-12-15 11:21:51 -0500648#Method bool operator==(const SkIRect& a, const SkIRect& b)
649
Cary Clark4855f782018-02-06 09:41:53 -0500650#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500651#Line # returns true if members are equal ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500652Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
653identical to corresponding members in b.
654
655#Param a IRect to compare ##
656#Param b IRect to compare ##
657
658#Return true if members are equal ##
659
660#Example
661 SkIRect test = {0, 0, 2, 2};
662 SkIRect sorted = test.makeSorted();
663 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!');
664#StdOut
665test == sorted
666##
667##
668
669#SeeAlso operator!=(const SkIRect& a, const SkIRect& b)
670
671##
672
673# ------------------------------------------------------------------------------
674
675#Method bool operator!=(const SkIRect& a, const SkIRect& b)
676
Cary Clark4855f782018-02-06 09:41:53 -0500677#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500678#Line # returns true if members are unequal ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500679Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not
680identical to the corresponding member in b.
681
682#Param a IRect to compare ##
683#Param b IRect to compare ##
684
685#Return true if members are not equal ##
686
687#Example
688 SkIRect test = {2, 2, 0, 0};
689 SkIRect sorted = test.makeSorted();
690 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '=');
691#StdOut
692test != sorted
693##
694##
695
696#SeeAlso operator==(const SkIRect& a, const SkIRect& b)
697
698##
699
Cary Clark4855f782018-02-06 09:41:53 -0500700#Subtopic Operator ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500701
Cary Clark0c5f5462017-12-15 11:21:51 -0500702# ------------------------------------------------------------------------------
703
704#Method bool is16Bit() const
705
Cary Clark4855f782018-02-06 09:41:53 -0500706#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500707#Line # returns true if members fit in 16-bit word ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500708Returns true if all members: fLeft, fTop, fRight, and fBottom; values are
709equal to or larger than -32768 and equal to or smaller than 32767.
710
711#Return true if members fit in 16-bit word ##
712
713#Example
714 SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}};
715 for (auto rect : tests) {
716 SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight,
717 rect.fBottom, rect.is16Bit() ? "fits" : "does not fit");
718}
719#StdOut
720{-32768, -32768, 32767, 32767} fits in 16 bits
721{-32768, -32768, 32768, 32768} does not fit in 16 bits
722##
723##
724
725#SeeAlso SkTFitsIn
726
727##
728
729# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -0500730#Subtopic Set
731#Line # replaces all values ##
732#Populate
733##
Cary Clark0c5f5462017-12-15 11:21:51 -0500734
735#Method void setEmpty()
736
Cary Clark4855f782018-02-06 09:41:53 -0500737#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500738#Line # sets to (0, 0, 0, 0) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500739Sets IRect to (0, 0, 0, 0).
740
741Many other rectangles are empty; if left is equal to or greater than right,
742or if top is equal to or greater than bottom. Setting all members to zero
743is a convenience, but does not designate a special empty rectangle.
744
745#Example
746 SkIRect rect = {3, 4, 1, 2};
747 for (int i = 0; i < 2; ++i) {
748 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop,
749 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
750 rect.setEmpty();
751 }
752#StdOut
753rect: {3, 4, 1, 2} is empty
754rect: {0, 0, 0, 0} is empty
755##
756##
757
758#SeeAlso MakeEmpty SkRect::setEmpty
759
760##
761
762# ------------------------------------------------------------------------------
763
764#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
765
Cary Clark4855f782018-02-06 09:41:53 -0500766#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500767#Line # sets to (left, top, right, bottom) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500768Sets IRect to (left, top, right, bottom).
769left and right are not sorted; left is not necessarily less than right.
770top and bottom are not sorted; top is not necessarily less than bottom.
771
772#Param left assigned to fLeft ##
773#Param top assigned to fTop ##
774#Param right assigned to fRight ##
775#Param bottom assigned to fBottom ##
776
777#Example
778 SkIRect rect1 = {3, 4, 1, 2};
779 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
780 SkIRect rect2;
781 rect2.set(3, 4, 1, 2);
782 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
783#StdOut
784rect1: {3, 4, 1, 2}
785rect2: {3, 4, 1, 2}
786##
787##
788
789#SeeAlso setLTRB setXYWH SkRect::set
790
791##
792
793# ------------------------------------------------------------------------------
794
795#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
796
Cary Clark4855f782018-02-06 09:41:53 -0500797#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500798#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500799Sets IRect to (left, top, right, bottom).
800left and right are not sorted; left is not necessarily less than right.
801top and bottom are not sorted; top is not necessarily less than bottom.
802
803#Param left stored in fLeft ##
804#Param top stored in fTop ##
805#Param right stored in fRight ##
806#Param bottom stored in fBottom ##
807
808#Example
809 SkIRect rect1 = {3, 4, 1, 2};
810 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
811 SkIRect rect2;
812 rect2.setLTRB(3, 4, 1, 2);
813 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
814#StdOut
815rect1: {3, 4, 1, 2}
816rect2: {3, 4, 1, 2}
817##
818##
819
820#SeeAlso set setXYWH SkRect::setLTRB
821
822##
823
824# ------------------------------------------------------------------------------
825
826#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
827
Cary Clark4855f782018-02-06 09:41:53 -0500828#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500829#Line # sets to (x, y, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500830Sets IRect to:
831#Formula
832(x, y, x + width, y + height)
833##
834. Does not validate input;
835width or height may be negative.
836
837#Param x stored in fLeft ##
838#Param y stored in fTop ##
839#Param width added to x and stored in fRight ##
840#Param height added to y and stored in fBottom ##
841
842#Example
843 SkIRect rect;
844 rect.setXYWH(5, 35, -15, 25);
845 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
846 rect.bottom(), rect.isEmpty() ? "true" : "false");
847 rect.sort();
848 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
849 rect.bottom(), rect.isEmpty() ? "true" : "false");
850#StdOut
851rect: 5, 35, -10, 60 isEmpty: true
852rect: -10, 35, 5, 60 isEmpty: false
853##
854##
855
856#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH
857
858##
859
Cary Clark2dc84ad2018-01-26 12:56:22 -0500860#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -0500861#Line # moves sides ##
Cary Clark4855f782018-02-06 09:41:53 -0500862#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500863
Cary Clark0c5f5462017-12-15 11:21:51 -0500864# ------------------------------------------------------------------------------
865
Cary Clark0c5f5462017-12-15 11:21:51 -0500866#Method SkIRect makeOffset(int32_t dx, int32_t dy) const
867
Cary Clarkab2621d2018-01-30 10:08:57 -0500868#In Inset_Outset_Offset
869#Line # constructs from translated sides ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500870Returns IRect offset by (dx, dy).
871
872If dx is negative, IRect returned is moved to the left.
873If dx is positive, IRect returned is moved to the right.
874If dy is negative, IRect returned is moved upward.
875If dy is positive, IRect returned is moved downward.
876
877#Param dx offset added to fLeft and fRight ##
878#Param dy offset added to fTop and fBottom ##
879
Cary Clark2dc84ad2018-01-26 12:56:22 -0500880#Return IRect offset in x or y, with original width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500881
882#Example
883 SkIRect rect = { 10, 50, 20, 60 };
884 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
885 rect.bottom(), rect.isEmpty() ? "true" : "false");
886 rect = rect.makeOffset(15, 32);
887 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
888 rect.bottom(), rect.isEmpty() ? "true" : "false");
889#StdOut
890rect: 10, 50, 20, 60 isEmpty: false
891rect: 25, 82, 35, 92 isEmpty: false
892##
893##
894
895#SeeAlso offset() makeInset makeOutset SkRect::makeOffset
896
897##
898
899# ------------------------------------------------------------------------------
900
901#Method SkIRect makeInset(int32_t dx, int32_t dy) const
902
Cary Clarkab2621d2018-01-30 10:08:57 -0500903#In Inset_Outset_Offset
904#Line # constructs from sides moved symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500905Returns IRect, inset by (dx, dy).
906
907If dx is negative, IRect returned is wider.
908If dx is positive, IRect returned is narrower.
909If dy is negative, IRect returned is taller.
910If dy is positive, IRect returned is shorter.
911
912#Param dx offset added to fLeft and subtracted from fRight ##
913#Param dy offset added to fTop and subtracted from fBottom ##
914
Cary Clark2dc84ad2018-01-26 12:56:22 -0500915#Return IRect inset symmetrically left and right, top and bottom ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500916
917#Example
918 SkIRect rect = { 10, 50, 20, 60 };
919 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
920 rect.bottom(), rect.isEmpty() ? "true" : "false");
921 rect = rect.makeInset(15, 32);
922 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
923 rect.bottom(), rect.isEmpty() ? "true" : "false");
924#StdOut
925rect: 10, 50, 20, 60 isEmpty: false
926rect: 25, 82, 5, 28 isEmpty: true
927##
928##
929
930#SeeAlso inset() makeOffset makeOutset SkRect::makeInset
931
932##
933
934# ------------------------------------------------------------------------------
935
936#Method SkIRect makeOutset(int32_t dx, int32_t dy) const
937
Cary Clarkab2621d2018-01-30 10:08:57 -0500938#In Inset_Outset_Offset
939#Line # constructs from sides moved symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500940Returns IRect, outset by (dx, dy).
941
942If dx is negative, IRect returned is narrower.
943If dx is positive, IRect returned is wider.
944If dy is negative, IRect returned is shorter.
945If dy is positive, IRect returned is taller.
946
947#Param dx offset subtracted to fLeft and added from fRight ##
948#Param dy offset subtracted to fTop and added from fBottom ##
949
Cary Clark2dc84ad2018-01-26 12:56:22 -0500950#Return IRect outset symmetrically left and right, top and bottom ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500951
952#Example
953 SkIRect rect = { 10, 50, 20, 60 };
954 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
955 rect.bottom(), rect.isEmpty() ? "true" : "false");
956 rect = rect.makeOutset(15, 32);
957 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
958 rect.bottom(), rect.isEmpty() ? "true" : "false");
959#StdOut
960rect: 10, 50, 20, 60 isEmpty: false
961rect: -5, 18, 35, 92 isEmpty: false
962##
963##
964
965#SeeAlso outset() makeOffset makeInset SkRect::makeOutset
966
967##
968
969# ------------------------------------------------------------------------------
970
971#Method void offset(int32_t dx, int32_t dy)
972
Cary Clarkab2621d2018-01-30 10:08:57 -0500973#In Inset_Outset_Offset
974#Line # translates sides without changing width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500975Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
976
977If dx is negative, moves IRect returned to the left.
978If dx is positive, moves IRect returned to the right.
979If dy is negative, moves IRect returned upward.
980If dy is positive, moves IRect returned downward.
981
982#Param dx offset added to fLeft and fRight ##
983#Param dy offset added to fTop and fBottom ##
984
985#Example
986 SkIRect rect = { 10, 14, 50, 73 };
987 rect.offset(5, 13);
988 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
989#StdOut
990rect: 15, 27, 55, 86
991##
992##
993
994#SeeAlso offsetTo makeOffset SkRect::offset
995
996##
997
998# ------------------------------------------------------------------------------
999
1000#Method void offset(const SkIPoint& delta)
1001
Cary Clarkab2621d2018-01-30 10:08:57 -05001002#In Inset_Outset_Offset
Cary Clark0c5f5462017-12-15 11:21:51 -05001003Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1004fTop, fBottom.
1005
1006If delta.fX is negative, moves IRect returned to the left.
1007If delta.fX is positive, moves IRect returned to the right.
1008If delta.fY is negative, moves IRect returned upward.
1009If delta.fY is positive, moves IRect returned downward.
1010
1011#Param delta offset added to IRect ##
1012
1013#Example
1014 SkIRect rect = { 10, 14, 50, 73 };
1015 rect.offset({5, 13});
1016 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1017#StdOut
1018rect: 15, 27, 55, 86
1019##
1020##
1021
1022#SeeAlso offsetTo makeOffset SkRect::offset
1023
1024##
1025
1026# ------------------------------------------------------------------------------
1027
1028#Method void offsetTo(int32_t newX, int32_t newY)
1029
Cary Clarkab2621d2018-01-30 10:08:57 -05001030#In Inset_Outset_Offset
1031#Line # translates to (x, y) without changing width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001032Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height
1033are unchanged.
1034
1035#Param newX stored in fLeft, preserving width() ##
1036#Param newY stored in fTop, preserving height() ##
1037
1038#Example
1039 SkIRect rect = { 10, 14, 50, 73 };
1040 rect.offsetTo(15, 27);
1041 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1042#StdOut
1043rect: 15, 27, 55, 86
1044##
1045##
1046
1047#SeeAlso offset makeOffset setXYWH SkRect::offsetTo
1048
1049##
1050
1051# ------------------------------------------------------------------------------
1052
1053#Method void inset(int32_t dx, int32_t dy)
1054
Cary Clarkab2621d2018-01-30 10:08:57 -05001055#In Inset_Outset_Offset
1056#Line # moves the sides symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001057Insets IRect by (dx,dy).
1058
1059If dx is positive, makes IRect narrower.
1060If dx is negative, makes IRect wider.
1061If dy is positive, makes IRect shorter.
1062If dy is negative, makes IRect taller.
1063
1064#Param dx offset added to fLeft and subtracted from fRight ##
1065#Param dy offset added to fTop and subtracted from fBottom ##
1066
1067#Example
1068 SkIRect rect = { 10, 14, 50, 73 };
1069 rect.inset(5, 13);
1070 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1071#StdOut
1072rect: 15, 27, 45, 60
1073##
1074##
1075
1076#SeeAlso outset makeInset SkRect::inset
1077
1078##
1079
1080# ------------------------------------------------------------------------------
1081
1082#Method void outset(int32_t dx, int32_t dy)
1083
Cary Clarkab2621d2018-01-30 10:08:57 -05001084#In Inset_Outset_Offset
1085#Line # moves the sides symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001086Outsets IRect by (dx, dy).
1087
Cary Clark2dc84ad2018-01-26 12:56:22 -05001088If dx is positive, makes IRect wider.
1089If dx is negative, makes IRect narrower.
1090If dy is positive, makes IRect taller.
1091If dy is negative, makes IRect shorter.
Cary Clark0c5f5462017-12-15 11:21:51 -05001092
1093#Param dx subtracted to fLeft and added from fRight ##
1094#Param dy subtracted to fTop and added from fBottom ##
1095
1096#Example
1097 SkIRect rect = { 10, 14, 50, 73 };
1098 rect.outset(5, 13);
1099 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1100#StdOut
1101rect: 5, 1, 55, 86
1102##
1103##
1104
1105#SeeAlso inset makeOutset SkRect::outset
1106
1107##
1108
Cary Clark2dc84ad2018-01-26 12:56:22 -05001109#Subtopic Inset_Outset_Offset ##
1110
1111#Subtopic Intersection
Cary Clark08895c42018-02-01 09:37:32 -05001112#Line # set to shared bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001113
1114IRects intersect when they enclose a common area. To intersect, each of the pair
1115must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1116empty() returns false. The intersection of IRect pair can be described by:
1117
1118#Formula
1119(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1120 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1121##
1122.
1123
1124The intersection is only meaningful if the resulting IRect is not empty and
1125describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1126
Cary Clark4855f782018-02-06 09:41:53 -05001127#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001128
Cary Clark0c5f5462017-12-15 11:21:51 -05001129# ------------------------------------------------------------------------------
1130
1131#Method bool quickReject(int l, int t, int r, int b) const
1132
Cary Clarkab2621d2018-01-30 10:08:57 -05001133#In Intersection
1134#Line # returns true if rectangles do not intersect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001135Constructs IRect (l, t, r, b) and returns true if constructed IRect does not
1136intersect IRect. Does not check to see if construction or IRect is empty.
1137
1138Is implemented with short circuit logic so that true can be returned after
1139a single compare.
1140
Cary Clark2dc84ad2018-01-26 12:56:22 -05001141#Param l x minimum of constructed IRect ##
1142#Param t y minimum of constructed IRect ##
1143#Param r x maximum of constructed IRect ##
1144#Param b y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001145
1146#Return true if construction and IRect have no area in common ##
1147
1148#Example
1149#Description
1150quickReject is the complement of Intersects.
1151##
1152 const SkIRect rect = {7, 11, 13, 17};
1153 const int32_t* r = &rect.fLeft;
1154 const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } };
1155 for (auto& test : tests) {
1156 const int32_t* t = &test.fLeft;
1157 SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n",
1158 r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3],
1159 rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false",
1160 SkIRect::Intersects(rect, test) ? "true" : "false");
1161 }
1162#StdOut
1163rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false
1164rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false
1165rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true
1166##
1167##
1168
1169#SeeAlso Intersects
1170
1171##
1172
1173# ------------------------------------------------------------------------------
1174
1175#Method bool contains(int32_t x, int32_t y) const
1176
Cary Clarkab2621d2018-01-30 10:08:57 -05001177#In Intersection
Cary Clark300cc5b2018-02-20 12:50:35 -05001178#Line # returns true if IPoint (x, y) is equal or inside ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001179Returns true if:
1180#Formula
1181fLeft <= x < fRight && fTop <= y < fBottom
1182##
1183.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001184Returns false if IRect is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001185
1186Considers input to describe constructed IRect:
1187#Formula
1188(x, y, x + 1, y + 1)
1189##
1190and
1191returns true if constructed area is completely enclosed by IRect area.
1192
Cary Clark300cc5b2018-02-20 12:50:35 -05001193#Param x test IPoint x-coordinate ##
1194#Param y test IPoint y-coordinate ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001195
1196#Return true if (x, y) is inside IRect ##
1197
1198#Example
1199 SkIRect rect = { 30, 50, 40, 60 };
1200 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} };
1201 for (auto pt : pts) {
1202 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n",
1203 rect.left(), rect.top(), rect.right(), rect.bottom(),
1204 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y());
1205 }
1206#StdOut
1207rect: (30, 50, 40, 60) contains (30, 50)
1208rect: (30, 50, 40, 60) does not contain (40, 50)
1209rect: (30, 50, 40, 60) does not contain (30, 60)
1210##
1211##
1212
1213#SeeAlso containsNoEmptyCheck SkRect::contains
1214
1215##
1216
1217# ------------------------------------------------------------------------------
1218
1219#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
1220
Cary Clarkab2621d2018-01-30 10:08:57 -05001221#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001222Constructs IRect to intersect from (left, top, right, bottom). Does not sort
Cary Clark0c5f5462017-12-15 11:21:51 -05001223construction.
1224
Cary Clark2dc84ad2018-01-26 12:56:22 -05001225Returns true if IRect contains construction.
1226Returns false if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001227
Cary Clark2dc84ad2018-01-26 12:56:22 -05001228#Param left x minimum of constructed IRect ##
1229#Param top y minimum of constructed IRect ##
1230#Param right x maximum of constructed IRect ##
1231#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001232
1233#Return true if all sides of IRect are outside construction ##
1234
1235#Example
1236 SkIRect rect = { 30, 50, 40, 60 };
1237 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1238 for (auto contained : tests) {
1239 bool success = rect.contains(
1240 contained.left(), contained.top(), contained.right(), contained.bottom());
1241 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1242 rect.left(), rect.top(), rect.right(), rect.bottom(),
1243 success ? "contains" : "does not contain",
1244 contained.left(), contained.top(), contained.right(), contained.bottom());
1245 }
1246#StdOut
1247rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1248rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1249rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1250##
1251##
1252
1253#SeeAlso containsNoEmptyCheck SkRect::contains
1254
1255##
1256
1257# ------------------------------------------------------------------------------
1258
1259#Method bool contains(const SkIRect& r) const
1260
Cary Clarkab2621d2018-01-30 10:08:57 -05001261#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001262Returns true if IRect contains r.
1263Returns false if IRect is empty or r is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001264
Cary Clark2dc84ad2018-01-26 12:56:22 -05001265IRect contains r when IRect area completely includes r area.
Cary Clark0c5f5462017-12-15 11:21:51 -05001266
1267#Param r IRect contained ##
1268
1269#Return true if all sides of IRect are outside r ##
1270
1271#Example
1272 SkIRect rect = { 30, 50, 40, 60 };
1273 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1274 for (auto contained : tests) {
1275 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1276 rect.left(), rect.top(), rect.right(), rect.bottom(),
1277 rect.contains(contained) ? "contains" : "does not contain",
1278 contained.left(), contained.top(), contained.right(), contained.bottom());
1279 }
1280#StdOut
1281rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1282rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1283rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1284##
1285##
1286
1287#SeeAlso containsNoEmptyCheck SkRect::contains
1288
1289##
1290
1291# ------------------------------------------------------------------------------
1292
1293#Method bool contains(const SkRect& r) const
1294
Cary Clarkab2621d2018-01-30 10:08:57 -05001295#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001296Returns true if IRect contains r.
1297Returns false if IRect is empty or r is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001298
Cary Clark2dc84ad2018-01-26 12:56:22 -05001299IRect contains r when IRect area completely includes r area.
Cary Clark0c5f5462017-12-15 11:21:51 -05001300
1301#Param r Rect contained ##
1302
1303#Return true if all sides of IRect are outside r ##
1304
1305#Example
1306 SkIRect rect = { 30, 50, 40, 60 };
1307 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1308 for (auto contained : tests) {
1309 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n",
1310 rect.left(), rect.top(), rect.right(), rect.bottom(),
1311 rect.contains(contained) ? "contains" : "does not contain",
1312 contained.left(), contained.top(), contained.right(), contained.bottom());
1313 }
1314#StdOut
1315rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1316rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1317rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1318##
1319##
1320
1321#SeeAlso containsNoEmptyCheck SkRect::contains
1322
1323##
1324
1325# ------------------------------------------------------------------------------
1326
1327#Method bool containsNoEmptyCheck(int32_t left, int32_t top,
1328 int32_t right, int32_t bottom) const
Cary Clarkab2621d2018-01-30 10:08:57 -05001329#In Intersection
Cary Clark300cc5b2018-02-20 12:50:35 -05001330#Line # returns true if contains unsorted IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001331
1332Constructs IRect from (left, top, right, bottom). Does not sort
1333construction.
1334
Cary Clark2dc84ad2018-01-26 12:56:22 -05001335Returns true if IRect contains construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001336Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1337
Cary Clark2dc84ad2018-01-26 12:56:22 -05001338Return is undefined if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001339
Cary Clark2dc84ad2018-01-26 12:56:22 -05001340#Param left x minimum of constructed IRect ##
1341#Param top y minimum of constructed IRect ##
1342#Param right x maximum of constructed IRect ##
1343#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001344
1345#Return true if all sides of IRect are outside construction ##
1346
1347#Example
1348 SkIRect rect = { 30, 50, 40, 60 };
1349 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1350 for (auto contained : tests) {
1351 bool success = rect.containsNoEmptyCheck(
1352 contained.left(), contained.top(), contained.right(), contained.bottom());
1353 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1354 rect.left(), rect.top(), rect.right(), rect.bottom(),
1355 success ? "contains" : "does not contain",
1356 contained.left(), contained.top(), contained.right(), contained.bottom());
1357 }
1358#StdOut
1359rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1360rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1361rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1362##
1363##
1364
1365#SeeAlso contains SkRect::contains
1366
1367##
1368
1369# ------------------------------------------------------------------------------
1370
1371#Method bool containsNoEmptyCheck(const SkIRect& r) const
1372
Cary Clarkab2621d2018-01-30 10:08:57 -05001373#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001374Returns true if IRect contains construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001375Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1376
Cary Clark2dc84ad2018-01-26 12:56:22 -05001377Return is undefined if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001378
Cary Clark2dc84ad2018-01-26 12:56:22 -05001379#Param r IRect contained ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001380
1381#Return true if all sides of IRect are outside r ##
1382
1383#Example
1384 SkIRect rect = { 30, 50, 40, 60 };
1385 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1386 for (auto contained : tests) {
1387 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1388 rect.left(), rect.top(), rect.right(), rect.bottom(),
1389 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain",
1390 contained.left(), contained.top(), contained.right(), contained.bottom());
1391 }
1392#StdOut
1393rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1394rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1395rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1396##
1397##
1398
1399#SeeAlso contains SkRect::contains
1400
1401##
1402
Cary Clark0c5f5462017-12-15 11:21:51 -05001403# ------------------------------------------------------------------------------
1404
1405#Method bool intersect(const SkIRect& r)
1406
Cary Clarkab2621d2018-01-30 10:08:57 -05001407#In Intersection
1408#Line # sets to shared area; returns true if not empty ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001409Returns true if IRect intersects r, and sets IRect to intersection.
1410Returns false if IRect does not intersect r, and leaves IRect unchanged.
1411
1412Returns false if either r or IRect is empty, leaving IRect unchanged.
1413
1414#Param r limit of result ##
1415
Cary Clark2dc84ad2018-01-26 12:56:22 -05001416#Return true if r and IRect have area in common ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001417
1418#Example
1419#Description
1420Two SkDebugf calls are required. If the calls are combined, their arguments
1421may not be evaluated in left to right order: the printed intersection may
1422be before or after the call to intersect.
1423##
1424 SkIRect leftRect = { 10, 40, 50, 80 };
1425 SkIRect rightRect = { 30, 60, 70, 90 };
1426 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1427 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1428 leftRect.right(), leftRect.bottom());
1429#StdOut
1430 intersection: 30, 60, 50, 80
1431##
1432##
1433
1434#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1435
1436##
1437
1438# ------------------------------------------------------------------------------
1439
1440#Method bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b)
1441
Cary Clarkab2621d2018-01-30 10:08:57 -05001442#In Intersection
Cary Clark0c5f5462017-12-15 11:21:51 -05001443Returns true if a intersects b, and sets IRect to intersection.
1444Returns false if a does not intersect b, and leaves IRect unchanged.
1445
1446Returns false if either a or b is empty, leaving IRect unchanged.
1447
1448#Param a IRect to intersect ##
1449#Param b IRect to intersect ##
1450
1451#Return true if a and b have area in common ##
1452
1453#Example
1454 SkIRect result;
1455 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1456 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ",
1457 result.left(), result.top(), result.right(), result.bottom());
1458#StdOut
1459 intersection: 30, 60, 50, 80
1460##
1461##
1462
1463#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1464
1465##
1466
1467# ------------------------------------------------------------------------------
1468
1469#Method bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1470
Cary Clarkab2621d2018-01-30 10:08:57 -05001471#In Intersection
1472#Line # sets to shared area; returns true if not empty skips empty check ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001473Returns true if a intersects b, and sets IRect to intersection.
1474Returns false if a does not intersect b, and leaves IRect unchanged.
1475
1476Asserts if either a or b is empty, and if SK_DEBUG is defined.
1477
1478#Param a IRect to intersect ##
1479#Param b IRect to intersect ##
1480
1481#Return true if a and b have area in common ##
1482
1483#Example
1484 SkIRect result;
Cary Clark681287e2018-03-16 11:34:15 -04001485 if (result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 })) {
1486 SkDebugf("intersection: %d, %d, %d, %d\n",
1487 result.left(), result.top(), result.right(), result.bottom());
1488 }
Cary Clark0c5f5462017-12-15 11:21:51 -05001489#StdOut
1490 intersection: 30, 60, 50, 80
1491##
1492##
1493
1494#SeeAlso Intersects intersect join SkRect::intersect
1495
1496##
1497
1498# ------------------------------------------------------------------------------
1499
1500#Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
1501
Cary Clarkab2621d2018-01-30 10:08:57 -05001502#In Intersection
Cary Clark0c5f5462017-12-15 11:21:51 -05001503Constructs IRect to intersect from (left, top, right, bottom). Does not sort
1504construction.
1505
1506Returns true if IRect intersects construction, and sets IRect to intersection.
1507Returns false if IRect does not intersect construction, and leaves IRect unchanged.
1508
1509Returns false if either construction or IRect is empty, leaving IRect unchanged.
1510
1511#Param left x minimum of constructed IRect ##
1512#Param top y minimum of constructed IRect ##
1513#Param right x maximum of constructed IRect ##
1514#Param bottom y maximum of constructed IRect ##
1515
1516#Return true if construction and IRect have area in common ##
1517
1518#Example
1519#Description
1520Two SkDebugf calls are required. If the calls are combined, their arguments
1521may not be evaluated in left to right order: the printed intersection may
1522be before or after the call to intersect.
1523##
1524 SkIRect leftRect = { 10, 40, 50, 80 };
1525 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1526 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1527 leftRect.right(), leftRect.bottom());
1528#StdOut
1529 intersection: 30, 60, 50, 80
1530##
1531##
1532
1533#SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect
1534
1535##
1536
1537# ------------------------------------------------------------------------------
1538
1539#Method static bool Intersects(const SkIRect& a, const SkIRect& b)
1540
Cary Clarkab2621d2018-01-30 10:08:57 -05001541#In Intersection
1542#Line # returns true if areas overlap ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001543Returns true if a intersects b.
1544Returns false if either a or b is empty, or do not intersect.
1545
1546#Param a IRect to intersect ##
1547#Param b IRect to intersect ##
1548
1549#Return true if a and b have area in common ##
1550
1551#Example
1552 SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1553#StdOut
1554 intersection
1555##
1556##
1557
1558#SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect
1559
1560##
1561
1562# ------------------------------------------------------------------------------
1563
1564#Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1565
Cary Clarkab2621d2018-01-30 10:08:57 -05001566#In Intersection
1567#Line # returns true if areas overlap skips empty check ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001568Returns true if a intersects b.
1569Asserts if either a or b is empty, and if SK_DEBUG is defined.
1570
1571#Param a IRect to intersect ##
1572#Param b IRect to intersect ##
1573
1574#Return true if a and b have area in common ##
1575
1576#Example
1577 SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck(
1578 {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1579#StdOut
1580 intersection
1581##
1582##
1583
1584#SeeAlso Intersects intersect SkRect::intersect
1585
1586##
1587
Cary Clark2dc84ad2018-01-26 12:56:22 -05001588#Subtopic Intersection ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001589
1590# ------------------------------------------------------------------------------
1591
Cary Clark4855f782018-02-06 09:41:53 -05001592#Subtopic Join
1593#Line # set to union of bounds ##
1594#Populate
1595##
1596
Cary Clark0c5f5462017-12-15 11:21:51 -05001597#Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom)
1598
Cary Clark4855f782018-02-06 09:41:53 -05001599#In Join
Cary Clarkab2621d2018-01-30 10:08:57 -05001600#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001601Constructs IRect to intersect from (left, top, right, bottom). Does not sort
Cary Clark0c5f5462017-12-15 11:21:51 -05001602construction.
1603
Cary Clark2dc84ad2018-01-26 12:56:22 -05001604Sets IRect to the union of itself and the construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001605
Cary Clark2dc84ad2018-01-26 12:56:22 -05001606Has no effect if construction is empty. Otherwise, if IRect is empty, sets
1607IRect to construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001608
Cary Clark2dc84ad2018-01-26 12:56:22 -05001609#Param left x minimum of constructed IRect ##
1610#Param top y minimum of constructed IRect ##
1611#Param right x maximum of constructed IRect ##
1612#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001613
1614#Example
1615 SkIRect rect = { 10, 20, 15, 25};
1616 rect.join(50, 60, 55, 65);
1617 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1618#StdOut
1619 join: 10, 20, 55, 65
1620##
1621##
1622
1623#SeeAlso set SkRect::join
1624
1625##
1626
1627# ------------------------------------------------------------------------------
1628
1629#Method void join(const SkIRect& r)
1630
Cary Clark4855f782018-02-06 09:41:53 -05001631#In Join
Cary Clark2dc84ad2018-01-26 12:56:22 -05001632Sets IRect to the union of itself and r.
Cary Clark0c5f5462017-12-15 11:21:51 -05001633
Cary Clark2dc84ad2018-01-26 12:56:22 -05001634Has no effect if r is empty. Otherwise, if IRect is empty, sets IRect to r.
Cary Clark0c5f5462017-12-15 11:21:51 -05001635
Cary Clark2dc84ad2018-01-26 12:56:22 -05001636#Param r expansion IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001637
1638#Example
1639 SkIRect rect = { 10, 20, 15, 25};
1640 rect.join({50, 60, 55, 65});
1641 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1642#StdOut
1643 join: 10, 20, 55, 65
1644##
1645##
1646
1647#SeeAlso set SkRect::join
1648
1649##
1650
1651# ------------------------------------------------------------------------------
1652
Cary Clark4855f782018-02-06 09:41:53 -05001653#Subtopic Sorting
1654#Line # orders sides ##
1655#Populate
1656##
1657
Cary Clark0c5f5462017-12-15 11:21:51 -05001658#Method void sort()
1659
Cary Clark4855f782018-02-06 09:41:53 -05001660#In Sorting
Cary Clarkab2621d2018-01-30 10:08:57 -05001661#Line # orders sides from smaller to larger ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001662Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
1663fTop and fBottom if fTop is greater than fBottom. Result may be empty,
1664and width() and height() will be zero or positive.
1665
1666#Example
1667 SkIRect rect = { 30, 50, 20, 10 };
1668 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1669 rect.sort();
1670 SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1671#StdOut
1672rect: 30, 50, 20, 10
1673sorted: 20, 10, 30, 50
1674##
1675##
1676
1677#SeeAlso makeSorted SkRect::sort
1678
1679##
1680
1681# ------------------------------------------------------------------------------
1682
1683#Method SkIRect makeSorted() const
1684
Cary Clark4855f782018-02-06 09:41:53 -05001685#In Sorting
1686#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001687#Line # constructs, ordering sides from smaller to larger ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001688Returns IRect with fLeft and fRight swapped if fLeft is greater than fRight; and
Cary Clark0c5f5462017-12-15 11:21:51 -05001689with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
1690and width() and height() will be zero or positive.
1691
1692#Return sorted IRect ##
1693
1694#Example
1695 SkIRect rect = { 30, 50, 20, 10 };
1696 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1697 SkIRect sort = rect.makeSorted();
1698 SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
1699#StdOut
1700rect: 30, 50, 20, 10
1701sorted: 20, 10, 30, 50
1702##
1703##
1704
1705#SeeAlso sort SkRect::makeSorted
1706
1707##
1708
1709# ------------------------------------------------------------------------------
1710
1711#Method static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect()
1712
Cary Clark4855f782018-02-06 09:41:53 -05001713#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05001714#Line # returns immutable bounds of (0, 0, 0, 0) ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001715Returns a reference to immutable empty IRect, set to (0, 0, 0, 0).
1716
1717#Return global IRect set to all zeroes ##
1718
1719#Example
1720 const SkIRect& rect = SkIRect::EmptyIRect();
1721 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1722#StdOut
1723rect: 0, 0, 0, 0
1724##
1725##
1726
1727#SeeAlso MakeEmpty
1728
1729##
1730
Cary Clark0c95aab2018-01-08 16:20:59 -05001731#Method static SkIRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05001732#Deprecated
1733##
1734
Cary Clark0c5f5462017-12-15 11:21:51 -05001735#Struct SkIRect ##
1736
1737#Topic IRect ##