blob: bdaa4a69d41f5fa4d2385b2ebadd67f17158e7b1 [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
531is sorted. Result may be incorrect if IRect is far from the origin.
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
564is sorted. Result may be incorrect if IRect is far from the origin.
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());
574 SkDebugf("safe mid x: %d\n", rect.left() / 2 + rect.right() / 2);
575#StdOut
576left: 1073741824 right: 1073741826 centerX: -1073741823 safe mid x: 1073741825
577##
578##
579
580#SeeAlso centerX SkRect::centerY
581
582##
583
584# ------------------------------------------------------------------------------
585
586#Method bool isEmpty() const
587
Cary Clark4855f782018-02-06 09:41:53 -0500588#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500589#Line # returns true if width or height are zero or negative or they exceed int32_t ##
Mike Reedd2849492018-01-10 14:31:18 -0500590Returns true if width() or height() .
Cary Clark0c5f5462017-12-15 11:21:51 -0500591
592#Return true if width() or height() are zero or negative ##
593
594#Example
595 SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
596 for (auto rect : tests) {
597 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
598 rect.bottom(), rect.isEmpty() ? "" : " not");
599 rect.sort();
600 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
601 rect.bottom(), rect.isEmpty() ? "" : " not");
602 }
603#StdOut
604rect: {20, 40, 10, 50} is empty
605sorted: {10, 40, 20, 50} is not empty
606rect: {20, 40, 20, 50} is empty
607sorted: {20, 40, 20, 50} is empty
608##
609##
610
611#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
612
613##
614
615# ------------------------------------------------------------------------------
616
Mike Reedd2849492018-01-10 14:31:18 -0500617#Method bool isEmpty64() const
618
Cary Clark4855f782018-02-06 09:41:53 -0500619#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500620#Line # returns true if width or height are zero or negative ##
Mike Reedd2849492018-01-10 14:31:18 -0500621Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
622to or greater than fBottom. Call sort() to reverse rectangles with negative
623width64() or height64().
624
625#Return true if width64() or height64() are zero or negative ##
626
Cary Clark4855f782018-02-06 09:41:53 -0500627#Bug 7489
Cary Clarkac47b882018-01-11 10:35:44 -0500628# isEmpty64 not yet visible to fiddle
629#NoExample
Mike Reedd2849492018-01-10 14:31:18 -0500630SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
631for (auto rect : tests) {
632SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
633rect.bottom(), isEmpty64() ? "" : " not");
634rect.sort();
635SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
636rect.bottom(), isEmpty64() ? "" : " not");
637}
638#StdOut
639rect: {20, 40, 10, 50} is empty
640sorted: {10, 40, 20, 50} is not empty
641rect: {20, 40, 20, 50} is empty
642sorted: {20, 40, 20, 50} is empty
643##
644##
645
646#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
647
648##
649
Cary Clark4855f782018-02-06 09:41:53 -0500650#Subtopic Operator
Cary Clark08895c42018-02-01 09:37:32 -0500651#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500652
Mike Reedd2849492018-01-10 14:31:18 -0500653# ------------------------------------------------------------------------------
654
Cary Clark0c5f5462017-12-15 11:21:51 -0500655#Method bool operator==(const SkIRect& a, const SkIRect& b)
656
Cary Clark4855f782018-02-06 09:41:53 -0500657#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500658#Line # returns true if members are equal ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500659Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
660identical to corresponding members in b.
661
662#Param a IRect to compare ##
663#Param b IRect to compare ##
664
665#Return true if members are equal ##
666
667#Example
668 SkIRect test = {0, 0, 2, 2};
669 SkIRect sorted = test.makeSorted();
670 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!');
671#StdOut
672test == sorted
673##
674##
675
676#SeeAlso operator!=(const SkIRect& a, const SkIRect& b)
677
678##
679
680# ------------------------------------------------------------------------------
681
682#Method bool operator!=(const SkIRect& a, const SkIRect& b)
683
Cary Clark4855f782018-02-06 09:41:53 -0500684#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500685#Line # returns true if members are unequal ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500686Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not
687identical to the corresponding member in b.
688
689#Param a IRect to compare ##
690#Param b IRect to compare ##
691
692#Return true if members are not equal ##
693
694#Example
695 SkIRect test = {2, 2, 0, 0};
696 SkIRect sorted = test.makeSorted();
697 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '=');
698#StdOut
699test != sorted
700##
701##
702
703#SeeAlso operator==(const SkIRect& a, const SkIRect& b)
704
705##
706
Cary Clark4855f782018-02-06 09:41:53 -0500707#Subtopic Operator ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500708
Cary Clark0c5f5462017-12-15 11:21:51 -0500709# ------------------------------------------------------------------------------
710
711#Method bool is16Bit() const
712
Cary Clark4855f782018-02-06 09:41:53 -0500713#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500714#Line # returns true if members fit in 16-bit word ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500715Returns true if all members: fLeft, fTop, fRight, and fBottom; values are
716equal to or larger than -32768 and equal to or smaller than 32767.
717
718#Return true if members fit in 16-bit word ##
719
720#Example
721 SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}};
722 for (auto rect : tests) {
723 SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight,
724 rect.fBottom, rect.is16Bit() ? "fits" : "does not fit");
725}
726#StdOut
727{-32768, -32768, 32767, 32767} fits in 16 bits
728{-32768, -32768, 32768, 32768} does not fit in 16 bits
729##
730##
731
732#SeeAlso SkTFitsIn
733
734##
735
736# ------------------------------------------------------------------------------
Cary Clark78de7512018-02-07 07:27:09 -0500737#Subtopic Set
738#Line # replaces all values ##
739#Populate
740##
Cary Clark0c5f5462017-12-15 11:21:51 -0500741
742#Method void setEmpty()
743
Cary Clark4855f782018-02-06 09:41:53 -0500744#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500745#Line # sets to (0, 0, 0, 0) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500746Sets IRect to (0, 0, 0, 0).
747
748Many other rectangles are empty; if left is equal to or greater than right,
749or if top is equal to or greater than bottom. Setting all members to zero
750is a convenience, but does not designate a special empty rectangle.
751
752#Example
753 SkIRect rect = {3, 4, 1, 2};
754 for (int i = 0; i < 2; ++i) {
755 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop,
756 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
757 rect.setEmpty();
758 }
759#StdOut
760rect: {3, 4, 1, 2} is empty
761rect: {0, 0, 0, 0} is empty
762##
763##
764
765#SeeAlso MakeEmpty SkRect::setEmpty
766
767##
768
769# ------------------------------------------------------------------------------
770
771#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
772
Cary Clark4855f782018-02-06 09:41:53 -0500773#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500774#Line # sets to (left, top, right, bottom) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500775Sets IRect to (left, top, right, bottom).
776left and right are not sorted; left is not necessarily less than right.
777top and bottom are not sorted; top is not necessarily less than bottom.
778
779#Param left assigned to fLeft ##
780#Param top assigned to fTop ##
781#Param right assigned to fRight ##
782#Param bottom assigned to fBottom ##
783
784#Example
785 SkIRect rect1 = {3, 4, 1, 2};
786 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
787 SkIRect rect2;
788 rect2.set(3, 4, 1, 2);
789 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
790#StdOut
791rect1: {3, 4, 1, 2}
792rect2: {3, 4, 1, 2}
793##
794##
795
796#SeeAlso setLTRB setXYWH SkRect::set
797
798##
799
800# ------------------------------------------------------------------------------
801
802#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
803
Cary Clark4855f782018-02-06 09:41:53 -0500804#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500805#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500806Sets IRect to (left, top, right, bottom).
807left and right are not sorted; left is not necessarily less than right.
808top and bottom are not sorted; top is not necessarily less than bottom.
809
810#Param left stored in fLeft ##
811#Param top stored in fTop ##
812#Param right stored in fRight ##
813#Param bottom stored in fBottom ##
814
815#Example
816 SkIRect rect1 = {3, 4, 1, 2};
817 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
818 SkIRect rect2;
819 rect2.setLTRB(3, 4, 1, 2);
820 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
821#StdOut
822rect1: {3, 4, 1, 2}
823rect2: {3, 4, 1, 2}
824##
825##
826
827#SeeAlso set setXYWH SkRect::setLTRB
828
829##
830
831# ------------------------------------------------------------------------------
832
833#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
834
Cary Clark4855f782018-02-06 09:41:53 -0500835#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500836#Line # sets to (x, y, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500837Sets IRect to:
838#Formula
839(x, y, x + width, y + height)
840##
841. Does not validate input;
842width or height may be negative.
843
844#Param x stored in fLeft ##
845#Param y stored in fTop ##
846#Param width added to x and stored in fRight ##
847#Param height added to y and stored in fBottom ##
848
849#Example
850 SkIRect rect;
851 rect.setXYWH(5, 35, -15, 25);
852 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
853 rect.bottom(), rect.isEmpty() ? "true" : "false");
854 rect.sort();
855 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
856 rect.bottom(), rect.isEmpty() ? "true" : "false");
857#StdOut
858rect: 5, 35, -10, 60 isEmpty: true
859rect: -10, 35, 5, 60 isEmpty: false
860##
861##
862
863#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH
864
865##
866
Cary Clark2dc84ad2018-01-26 12:56:22 -0500867#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -0500868#Line # moves sides ##
Cary Clark4855f782018-02-06 09:41:53 -0500869#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500870
Cary Clark0c5f5462017-12-15 11:21:51 -0500871# ------------------------------------------------------------------------------
872
Cary Clark0c5f5462017-12-15 11:21:51 -0500873#Method SkIRect makeOffset(int32_t dx, int32_t dy) const
874
Cary Clarkab2621d2018-01-30 10:08:57 -0500875#In Inset_Outset_Offset
876#Line # constructs from translated sides ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500877Returns IRect offset by (dx, dy).
878
879If dx is negative, IRect returned is moved to the left.
880If dx is positive, IRect returned is moved to the right.
881If dy is negative, IRect returned is moved upward.
882If dy is positive, IRect returned is moved downward.
883
884#Param dx offset added to fLeft and fRight ##
885#Param dy offset added to fTop and fBottom ##
886
Cary Clark2dc84ad2018-01-26 12:56:22 -0500887#Return IRect offset in x or y, with original width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500888
889#Example
890 SkIRect rect = { 10, 50, 20, 60 };
891 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
892 rect.bottom(), rect.isEmpty() ? "true" : "false");
893 rect = rect.makeOffset(15, 32);
894 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
895 rect.bottom(), rect.isEmpty() ? "true" : "false");
896#StdOut
897rect: 10, 50, 20, 60 isEmpty: false
898rect: 25, 82, 35, 92 isEmpty: false
899##
900##
901
902#SeeAlso offset() makeInset makeOutset SkRect::makeOffset
903
904##
905
906# ------------------------------------------------------------------------------
907
908#Method SkIRect makeInset(int32_t dx, int32_t dy) const
909
Cary Clarkab2621d2018-01-30 10:08:57 -0500910#In Inset_Outset_Offset
911#Line # constructs from sides moved symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500912Returns IRect, inset by (dx, dy).
913
914If dx is negative, IRect returned is wider.
915If dx is positive, IRect returned is narrower.
916If dy is negative, IRect returned is taller.
917If dy is positive, IRect returned is shorter.
918
919#Param dx offset added to fLeft and subtracted from fRight ##
920#Param dy offset added to fTop and subtracted from fBottom ##
921
Cary Clark2dc84ad2018-01-26 12:56:22 -0500922#Return IRect inset symmetrically left and right, top and bottom ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500923
924#Example
925 SkIRect rect = { 10, 50, 20, 60 };
926 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
927 rect.bottom(), rect.isEmpty() ? "true" : "false");
928 rect = rect.makeInset(15, 32);
929 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
930 rect.bottom(), rect.isEmpty() ? "true" : "false");
931#StdOut
932rect: 10, 50, 20, 60 isEmpty: false
933rect: 25, 82, 5, 28 isEmpty: true
934##
935##
936
937#SeeAlso inset() makeOffset makeOutset SkRect::makeInset
938
939##
940
941# ------------------------------------------------------------------------------
942
943#Method SkIRect makeOutset(int32_t dx, int32_t dy) const
944
Cary Clarkab2621d2018-01-30 10:08:57 -0500945#In Inset_Outset_Offset
946#Line # constructs from sides moved symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500947Returns IRect, outset by (dx, dy).
948
949If dx is negative, IRect returned is narrower.
950If dx is positive, IRect returned is wider.
951If dy is negative, IRect returned is shorter.
952If dy is positive, IRect returned is taller.
953
954#Param dx offset subtracted to fLeft and added from fRight ##
955#Param dy offset subtracted to fTop and added from fBottom ##
956
Cary Clark2dc84ad2018-01-26 12:56:22 -0500957#Return IRect outset symmetrically left and right, top and bottom ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500958
959#Example
960 SkIRect rect = { 10, 50, 20, 60 };
961 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
962 rect.bottom(), rect.isEmpty() ? "true" : "false");
963 rect = rect.makeOutset(15, 32);
964 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
965 rect.bottom(), rect.isEmpty() ? "true" : "false");
966#StdOut
967rect: 10, 50, 20, 60 isEmpty: false
968rect: -5, 18, 35, 92 isEmpty: false
969##
970##
971
972#SeeAlso outset() makeOffset makeInset SkRect::makeOutset
973
974##
975
976# ------------------------------------------------------------------------------
977
978#Method void offset(int32_t dx, int32_t dy)
979
Cary Clarkab2621d2018-01-30 10:08:57 -0500980#In Inset_Outset_Offset
981#Line # translates sides without changing width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500982Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
983
984If dx is negative, moves IRect returned to the left.
985If dx is positive, moves IRect returned to the right.
986If dy is negative, moves IRect returned upward.
987If dy is positive, moves IRect returned downward.
988
989#Param dx offset added to fLeft and fRight ##
990#Param dy offset added to fTop and fBottom ##
991
992#Example
993 SkIRect rect = { 10, 14, 50, 73 };
994 rect.offset(5, 13);
995 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
996#StdOut
997rect: 15, 27, 55, 86
998##
999##
1000
1001#SeeAlso offsetTo makeOffset SkRect::offset
1002
1003##
1004
1005# ------------------------------------------------------------------------------
1006
1007#Method void offset(const SkIPoint& delta)
1008
Cary Clarkab2621d2018-01-30 10:08:57 -05001009#In Inset_Outset_Offset
Cary Clark0c5f5462017-12-15 11:21:51 -05001010Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1011fTop, fBottom.
1012
1013If delta.fX is negative, moves IRect returned to the left.
1014If delta.fX is positive, moves IRect returned to the right.
1015If delta.fY is negative, moves IRect returned upward.
1016If delta.fY is positive, moves IRect returned downward.
1017
1018#Param delta offset added to IRect ##
1019
1020#Example
1021 SkIRect rect = { 10, 14, 50, 73 };
1022 rect.offset({5, 13});
1023 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1024#StdOut
1025rect: 15, 27, 55, 86
1026##
1027##
1028
1029#SeeAlso offsetTo makeOffset SkRect::offset
1030
1031##
1032
1033# ------------------------------------------------------------------------------
1034
1035#Method void offsetTo(int32_t newX, int32_t newY)
1036
Cary Clarkab2621d2018-01-30 10:08:57 -05001037#In Inset_Outset_Offset
1038#Line # translates to (x, y) without changing width and height ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001039Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height
1040are unchanged.
1041
1042#Param newX stored in fLeft, preserving width() ##
1043#Param newY stored in fTop, preserving height() ##
1044
1045#Example
1046 SkIRect rect = { 10, 14, 50, 73 };
1047 rect.offsetTo(15, 27);
1048 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1049#StdOut
1050rect: 15, 27, 55, 86
1051##
1052##
1053
1054#SeeAlso offset makeOffset setXYWH SkRect::offsetTo
1055
1056##
1057
1058# ------------------------------------------------------------------------------
1059
1060#Method void inset(int32_t dx, int32_t dy)
1061
Cary Clarkab2621d2018-01-30 10:08:57 -05001062#In Inset_Outset_Offset
1063#Line # moves the sides symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001064Insets IRect by (dx,dy).
1065
1066If dx is positive, makes IRect narrower.
1067If dx is negative, makes IRect wider.
1068If dy is positive, makes IRect shorter.
1069If dy is negative, makes IRect taller.
1070
1071#Param dx offset added to fLeft and subtracted from fRight ##
1072#Param dy offset added to fTop and subtracted from fBottom ##
1073
1074#Example
1075 SkIRect rect = { 10, 14, 50, 73 };
1076 rect.inset(5, 13);
1077 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1078#StdOut
1079rect: 15, 27, 45, 60
1080##
1081##
1082
1083#SeeAlso outset makeInset SkRect::inset
1084
1085##
1086
1087# ------------------------------------------------------------------------------
1088
1089#Method void outset(int32_t dx, int32_t dy)
1090
Cary Clarkab2621d2018-01-30 10:08:57 -05001091#In Inset_Outset_Offset
1092#Line # moves the sides symmetrically about the center ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001093Outsets IRect by (dx, dy).
1094
Cary Clark2dc84ad2018-01-26 12:56:22 -05001095If dx is positive, makes IRect wider.
1096If dx is negative, makes IRect narrower.
1097If dy is positive, makes IRect taller.
1098If dy is negative, makes IRect shorter.
Cary Clark0c5f5462017-12-15 11:21:51 -05001099
1100#Param dx subtracted to fLeft and added from fRight ##
1101#Param dy subtracted to fTop and added from fBottom ##
1102
1103#Example
1104 SkIRect rect = { 10, 14, 50, 73 };
1105 rect.outset(5, 13);
1106 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1107#StdOut
1108rect: 5, 1, 55, 86
1109##
1110##
1111
1112#SeeAlso inset makeOutset SkRect::outset
1113
1114##
1115
Cary Clark2dc84ad2018-01-26 12:56:22 -05001116#Subtopic Inset_Outset_Offset ##
1117
1118#Subtopic Intersection
Cary Clark08895c42018-02-01 09:37:32 -05001119#Line # set to shared bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001120
1121IRects intersect when they enclose a common area. To intersect, each of the pair
1122must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1123empty() returns false. The intersection of IRect pair can be described by:
1124
1125#Formula
1126(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1127 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1128##
1129.
1130
1131The intersection is only meaningful if the resulting IRect is not empty and
1132describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1133
Cary Clark4855f782018-02-06 09:41:53 -05001134#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001135
Cary Clark0c5f5462017-12-15 11:21:51 -05001136# ------------------------------------------------------------------------------
1137
1138#Method bool quickReject(int l, int t, int r, int b) const
1139
Cary Clarkab2621d2018-01-30 10:08:57 -05001140#In Intersection
1141#Line # returns true if rectangles do not intersect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001142Constructs IRect (l, t, r, b) and returns true if constructed IRect does not
1143intersect IRect. Does not check to see if construction or IRect is empty.
1144
1145Is implemented with short circuit logic so that true can be returned after
1146a single compare.
1147
Cary Clark2dc84ad2018-01-26 12:56:22 -05001148#Param l x minimum of constructed IRect ##
1149#Param t y minimum of constructed IRect ##
1150#Param r x maximum of constructed IRect ##
1151#Param b y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001152
1153#Return true if construction and IRect have no area in common ##
1154
1155#Example
1156#Description
1157quickReject is the complement of Intersects.
1158##
1159 const SkIRect rect = {7, 11, 13, 17};
1160 const int32_t* r = &rect.fLeft;
1161 const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } };
1162 for (auto& test : tests) {
1163 const int32_t* t = &test.fLeft;
1164 SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n",
1165 r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3],
1166 rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false",
1167 SkIRect::Intersects(rect, test) ? "true" : "false");
1168 }
1169#StdOut
1170rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false
1171rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false
1172rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true
1173##
1174##
1175
1176#SeeAlso Intersects
1177
1178##
1179
1180# ------------------------------------------------------------------------------
1181
1182#Method bool contains(int32_t x, int32_t y) const
1183
Cary Clarkab2621d2018-01-30 10:08:57 -05001184#In Intersection
1185#Line # returns true if points are equal or inside ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001186Returns true if:
1187#Formula
1188fLeft <= x < fRight && fTop <= y < fBottom
1189##
1190.
Cary Clark2dc84ad2018-01-26 12:56:22 -05001191Returns false if IRect is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001192
1193Considers input to describe constructed IRect:
1194#Formula
1195(x, y, x + 1, y + 1)
1196##
1197and
1198returns true if constructed area is completely enclosed by IRect area.
1199
1200#Param x test Point x-coordinate ##
1201#Param y test Point y-coordinate ##
1202
1203#Return true if (x, y) is inside IRect ##
1204
1205#Example
1206 SkIRect rect = { 30, 50, 40, 60 };
1207 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} };
1208 for (auto pt : pts) {
1209 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n",
1210 rect.left(), rect.top(), rect.right(), rect.bottom(),
1211 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y());
1212 }
1213#StdOut
1214rect: (30, 50, 40, 60) contains (30, 50)
1215rect: (30, 50, 40, 60) does not contain (40, 50)
1216rect: (30, 50, 40, 60) does not contain (30, 60)
1217##
1218##
1219
1220#SeeAlso containsNoEmptyCheck SkRect::contains
1221
1222##
1223
1224# ------------------------------------------------------------------------------
1225
1226#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
1227
Cary Clarkab2621d2018-01-30 10:08:57 -05001228#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001229Constructs IRect to intersect from (left, top, right, bottom). Does not sort
Cary Clark0c5f5462017-12-15 11:21:51 -05001230construction.
1231
Cary Clark2dc84ad2018-01-26 12:56:22 -05001232Returns true if IRect contains construction.
1233Returns false if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001234
Cary Clark2dc84ad2018-01-26 12:56:22 -05001235#Param left x minimum of constructed IRect ##
1236#Param top y minimum of constructed IRect ##
1237#Param right x maximum of constructed IRect ##
1238#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001239
1240#Return true if all sides of IRect are outside construction ##
1241
1242#Example
1243 SkIRect rect = { 30, 50, 40, 60 };
1244 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1245 for (auto contained : tests) {
1246 bool success = rect.contains(
1247 contained.left(), contained.top(), contained.right(), contained.bottom());
1248 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1249 rect.left(), rect.top(), rect.right(), rect.bottom(),
1250 success ? "contains" : "does not contain",
1251 contained.left(), contained.top(), contained.right(), contained.bottom());
1252 }
1253#StdOut
1254rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1255rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1256rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1257##
1258##
1259
1260#SeeAlso containsNoEmptyCheck SkRect::contains
1261
1262##
1263
1264# ------------------------------------------------------------------------------
1265
1266#Method bool contains(const SkIRect& r) const
1267
Cary Clarkab2621d2018-01-30 10:08:57 -05001268#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001269Returns true if IRect contains r.
1270Returns false if IRect is empty or r is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001271
Cary Clark2dc84ad2018-01-26 12:56:22 -05001272IRect contains r when IRect area completely includes r area.
Cary Clark0c5f5462017-12-15 11:21:51 -05001273
1274#Param r IRect contained ##
1275
1276#Return true if all sides of IRect are outside r ##
1277
1278#Example
1279 SkIRect rect = { 30, 50, 40, 60 };
1280 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1281 for (auto contained : tests) {
1282 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1283 rect.left(), rect.top(), rect.right(), rect.bottom(),
1284 rect.contains(contained) ? "contains" : "does not contain",
1285 contained.left(), contained.top(), contained.right(), contained.bottom());
1286 }
1287#StdOut
1288rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1289rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1290rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1291##
1292##
1293
1294#SeeAlso containsNoEmptyCheck SkRect::contains
1295
1296##
1297
1298# ------------------------------------------------------------------------------
1299
1300#Method bool contains(const SkRect& r) const
1301
Cary Clarkab2621d2018-01-30 10:08:57 -05001302#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001303Returns true if IRect contains r.
1304Returns false if IRect is empty or r is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001305
Cary Clark2dc84ad2018-01-26 12:56:22 -05001306IRect contains r when IRect area completely includes r area.
Cary Clark0c5f5462017-12-15 11:21:51 -05001307
1308#Param r Rect contained ##
1309
1310#Return true if all sides of IRect are outside r ##
1311
1312#Example
1313 SkIRect rect = { 30, 50, 40, 60 };
1314 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1315 for (auto contained : tests) {
1316 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n",
1317 rect.left(), rect.top(), rect.right(), rect.bottom(),
1318 rect.contains(contained) ? "contains" : "does not contain",
1319 contained.left(), contained.top(), contained.right(), contained.bottom());
1320 }
1321#StdOut
1322rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1323rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1324rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1325##
1326##
1327
1328#SeeAlso containsNoEmptyCheck SkRect::contains
1329
1330##
1331
1332# ------------------------------------------------------------------------------
1333
1334#Method bool containsNoEmptyCheck(int32_t left, int32_t top,
1335 int32_t right, int32_t bottom) const
Cary Clarkab2621d2018-01-30 10:08:57 -05001336#In Intersection
1337#Line # returns true if points are equal or inside skips empty check ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001338
1339Constructs IRect from (left, top, right, bottom). Does not sort
1340construction.
1341
Cary Clark2dc84ad2018-01-26 12:56:22 -05001342Returns true if IRect contains construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001343Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1344
Cary Clark2dc84ad2018-01-26 12:56:22 -05001345Return is undefined if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001346
Cary Clark2dc84ad2018-01-26 12:56:22 -05001347#Param left x minimum of constructed IRect ##
1348#Param top y minimum of constructed IRect ##
1349#Param right x maximum of constructed IRect ##
1350#Param bottom y maximum of constructed IRect ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001351
1352#Return true if all sides of IRect are outside construction ##
1353
1354#Example
1355 SkIRect rect = { 30, 50, 40, 60 };
1356 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1357 for (auto contained : tests) {
1358 bool success = rect.containsNoEmptyCheck(
1359 contained.left(), contained.top(), contained.right(), contained.bottom());
1360 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1361 rect.left(), rect.top(), rect.right(), rect.bottom(),
1362 success ? "contains" : "does not contain",
1363 contained.left(), contained.top(), contained.right(), contained.bottom());
1364 }
1365#StdOut
1366rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1367rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1368rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1369##
1370##
1371
1372#SeeAlso contains SkRect::contains
1373
1374##
1375
1376# ------------------------------------------------------------------------------
1377
1378#Method bool containsNoEmptyCheck(const SkIRect& r) const
1379
Cary Clarkab2621d2018-01-30 10:08:57 -05001380#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001381Returns true if IRect contains construction.
Cary Clark0c5f5462017-12-15 11:21:51 -05001382Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
1383
Cary Clark2dc84ad2018-01-26 12:56:22 -05001384Return is undefined if IRect is empty or construction is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -05001385
Cary Clark2dc84ad2018-01-26 12:56:22 -05001386#Param r IRect contained ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001387
1388#Return true if all sides of IRect are outside r ##
1389
1390#Example
1391 SkIRect rect = { 30, 50, 40, 60 };
1392 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1393 for (auto contained : tests) {
1394 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1395 rect.left(), rect.top(), rect.right(), rect.bottom(),
1396 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain",
1397 contained.left(), contained.top(), contained.right(), contained.bottom());
1398 }
1399#StdOut
1400rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1401rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1402rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1403##
1404##
1405
1406#SeeAlso contains SkRect::contains
1407
1408##
1409
Cary Clark0c5f5462017-12-15 11:21:51 -05001410# ------------------------------------------------------------------------------
1411
1412#Method bool intersect(const SkIRect& r)
1413
Cary Clarkab2621d2018-01-30 10:08:57 -05001414#In Intersection
1415#Line # sets to shared area; returns true if not empty ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001416Returns true if IRect intersects r, and sets IRect to intersection.
1417Returns false if IRect does not intersect r, and leaves IRect unchanged.
1418
1419Returns false if either r or IRect is empty, leaving IRect unchanged.
1420
1421#Param r limit of result ##
1422
Cary Clark2dc84ad2018-01-26 12:56:22 -05001423#Return true if r and IRect have area in common ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001424
1425#Example
1426#Description
1427Two SkDebugf calls are required. If the calls are combined, their arguments
1428may not be evaluated in left to right order: the printed intersection may
1429be before or after the call to intersect.
1430##
1431 SkIRect leftRect = { 10, 40, 50, 80 };
1432 SkIRect rightRect = { 30, 60, 70, 90 };
1433 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1434 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1435 leftRect.right(), leftRect.bottom());
1436#StdOut
1437 intersection: 30, 60, 50, 80
1438##
1439##
1440
1441#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1442
1443##
1444
1445# ------------------------------------------------------------------------------
1446
1447#Method bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b)
1448
Cary Clarkab2621d2018-01-30 10:08:57 -05001449#In Intersection
Cary Clark0c5f5462017-12-15 11:21:51 -05001450Returns true if a intersects b, and sets IRect to intersection.
1451Returns false if a does not intersect b, and leaves IRect unchanged.
1452
1453Returns false if either a or b is empty, leaving IRect unchanged.
1454
1455#Param a IRect to intersect ##
1456#Param b IRect to intersect ##
1457
1458#Return true if a and b have area in common ##
1459
1460#Example
1461 SkIRect result;
1462 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1463 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ",
1464 result.left(), result.top(), result.right(), result.bottom());
1465#StdOut
1466 intersection: 30, 60, 50, 80
1467##
1468##
1469
1470#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1471
1472##
1473
1474# ------------------------------------------------------------------------------
1475
1476#Method bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1477
Cary Clarkab2621d2018-01-30 10:08:57 -05001478#In Intersection
1479#Line # sets to shared area; returns true if not empty skips empty check ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001480Returns true if a intersects b, and sets IRect to intersection.
1481Returns false if a does not intersect b, and leaves IRect unchanged.
1482
1483Asserts if either a or b is empty, and if SK_DEBUG is defined.
1484
1485#Param a IRect to intersect ##
1486#Param b IRect to intersect ##
1487
1488#Return true if a and b have area in common ##
1489
1490#Example
1491 SkIRect result;
1492 bool intersected = result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1493 SkDebugf("intersection: %d, %d, %d, %d\n",
1494 result.left(), result.top(), result.right(), result.bottom());
1495#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 ##