blob: b308f533078bcebdca9b6a7d6a3632599ea67fb1 [file] [log] [blame]
Cary Clark0c5f5462017-12-15 11:21:51 -05001#Topic IRect
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias IRects ##
3#Alias IRect_Reference ##
Cary Clark0c5f5462017-12-15 11:21:51 -05004
5#Struct SkIRect
6
Cary Clark61313f32018-10-08 14:57:48 -04007#Code
8#Populate
9##
10
Cary Clark682c58d2018-05-16 07:07:07 -040011SkIRect holds four 32-bit integer coordinates describing the upper and
12lower bounds of a rectangle. SkIRect may be created from outer bounds or
Cary Clark0c5f5462017-12-15 11:21:51 -050013from position, width, and height. SkIRect describes an area; if its right
14is less than or equal to its left, or if its bottom is less than or equal to
Cary Clark682c58d2018-05-16 07:07:07 -040015its top, it is considered empty.
16
Cary Clark0c5f5462017-12-15 11:21:51 -050017#Member int32_t fLeft
Cary Clark08895c42018-02-01 09:37:32 -050018#Line # smaller x-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050019May contain any value. The smaller of the horizontal values when sorted.
20When equal to or greater than fRight, IRect is empty.
21##
22
23#Member int32_t fTop
Cary Clark08895c42018-02-01 09:37:32 -050024#Line # smaller y-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050025May contain any value. The smaller of the horizontal values when sorted.
26When equal to or greater than fBottom, IRect is empty.
27##
28
29#Member int32_t fRight
Cary Clark08895c42018-02-01 09:37:32 -050030#Line # larger x-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050031May contain any value. The larger of the vertical values when sorted.
32When equal to or less than fLeft, IRect is empty.
33##
34
35#Member int32_t fBottom
Cary Clark08895c42018-02-01 09:37:32 -050036#Line # larger y-axis bounds ##
Cary Clark0c5f5462017-12-15 11:21:51 -050037May contain any value. The larger of the vertical values when sorted.
38When equal to or less than fTop, IRect is empty.
39##
40
41# ------------------------------------------------------------------------------
42
Cary Clark61313f32018-10-08 14:57:48 -040043#Method static constexpr SkIRect MakeEmpty()
Cary Clark0c5f5462017-12-15 11:21:51 -050044
Cary Clark61313f32018-10-08 14:57:48 -040045#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050046#Line # returns bounds of (0, 0, 0, 0) ##
Cary Clark09d80c02018-10-31 12:14:03 -040047#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -050048
49#Example
50 SkIRect rect = SkIRect::MakeEmpty();
51 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
52 rect.offset(10, 10);
53 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
54 rect.inset(10, 10);
55 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
56 rect.outset(20, 20);
57 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
58#StdOut
59MakeEmpty isEmpty: true
60offset rect isEmpty: true
61inset rect isEmpty: true
62outset rect isEmpty: false
63##
64##
65
Mike Reed274218e2018-01-08 15:05:02 -050066#SeeAlso EmptyIRect isEmpty setEmpty SkRect::MakeEmpty
Cary Clark0c5f5462017-12-15 11:21:51 -050067
68##
69
70# ------------------------------------------------------------------------------
71
Cary Clark61313f32018-10-08 14:57:48 -040072#Method static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Cary Clark0c5f5462017-12-15 11:21:51 -050073
Cary Clark61313f32018-10-08 14:57:48 -040074#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050075#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -040076#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -050077
78#Example
79 SkIRect rect1 = SkIRect::MakeWH(25, 35);
80 SkIRect rect2 = SkIRect::MakeSize({25, 35});
81 SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35);
82 SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35);
83 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
84 "" : "not ");
85#StdOut
86all equal
87##
88##
89
90#SeeAlso MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH
91
92##
93
94# ------------------------------------------------------------------------------
95
Cary Clark61313f32018-10-08 14:57:48 -040096#Method static constexpr SkIRect MakeSize(const SkISize& size)
Cary Clark0c5f5462017-12-15 11:21:51 -050097
Cary Clark61313f32018-10-08 14:57:48 -040098#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050099#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400100#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500101
102#Example
103 SkSize size = {25.5f, 35.5f};
104 SkIRect rect = SkIRect::MakeSize(size.toRound());
105 SkDebugf("round width: %d height: %d\n", rect.width(), rect.height());
106 rect = SkIRect::MakeSize(size.toFloor());
107 SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height());
108#StdOut
109round width: 26 height: 36
110floor width: 25 height: 35
111##
112##
113
Cary Clark682c58d2018-05-16 07:07:07 -0400114#SeeAlso MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH
Cary Clark0c5f5462017-12-15 11:21:51 -0500115
116##
117
118# ------------------------------------------------------------------------------
119
Cary Clark61313f32018-10-08 14:57:48 -0400120#Method static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Cary Clark0c5f5462017-12-15 11:21:51 -0500121
Cary Clark61313f32018-10-08 14:57:48 -0400122#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500123#Line # constructs from int left, top, right, bottom ##
Cary Clark09d80c02018-10-31 12:14:03 -0400124#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500125
126#Example
127 SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25);
128 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
129 rect.bottom(), rect.isEmpty() ? "true" : "false");
130 rect.sort();
131 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
132 rect.bottom(), rect.isEmpty() ? "true" : "false");
133#StdOut
134rect: 5, 35, 15, 25 isEmpty: true
135rect: 5, 25, 15, 35 isEmpty: false
136##
137##
138
139#SeeAlso MakeXYWH SkRect::MakeLTRB
140
141##
142
143# ------------------------------------------------------------------------------
144
Cary Clark61313f32018-10-08 14:57:48 -0400145#Method static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Cary Clark0c5f5462017-12-15 11:21:51 -0500146
Cary Clark61313f32018-10-08 14:57:48 -0400147#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500148#Line # constructs from int input returning (x, y, width, height) ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500149
Cary Clark09d80c02018-10-31 12:14:03 -0400150#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500151
152#Example
153 SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25);
154 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
155 rect.bottom(), rect.isEmpty() ? "true" : "false");
156 rect.sort();
157 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
158 rect.bottom(), rect.isEmpty() ? "true" : "false");
159#StdOut
160rect: 5, 35, -10, 60 isEmpty: true
161rect: -10, 35, 5, 60 isEmpty: false
162##
163##
164
165#SeeAlso MakeLTRB SkRect::MakeXYWH
166
167##
168
Cary Clark4855f782018-02-06 09:41:53 -0500169#Subtopic Property
170#Line # member values, center, validity ##
Cary Clark4855f782018-02-06 09:41:53 -0500171##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500172
Cary Clark0c5f5462017-12-15 11:21:51 -0500173# ------------------------------------------------------------------------------
174
Cary Clark6def7202018-01-04 08:13:35 -0500175#Method int32_t left() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500176
Cary Clark4855f782018-02-06 09:41:53 -0500177#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500178#Line # returns smaller bounds in x, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400179#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500180
181#Example
182 SkIRect unsorted = { 15, 5, 10, 25 };
183 SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left());
184 SkIRect sorted = unsorted.makeSorted();
185 SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left());
186#StdOut
187unsorted.fLeft: 15 unsorted.left(): 15
188sorted.fLeft: 10 sorted.left(): 10
189##
190##
191
192#SeeAlso fLeft x() SkRect::left()
193
194##
195
196# ------------------------------------------------------------------------------
197
Cary Clark6def7202018-01-04 08:13:35 -0500198#Method int32_t top() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500199
Cary Clark4855f782018-02-06 09:41:53 -0500200#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500201#Line # returns smaller bounds in y, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400202#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500203
204#Example
205 SkIRect unsorted = { 15, 25, 10, 5 };
206 SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top());
207 SkIRect sorted = unsorted.makeSorted();
208 SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top());
209#StdOut
210unsorted.fTop: 25 unsorted.top(): 25
211sorted.fTop: 5 sorted.top(): 5
212##
213##
214
215#SeeAlso fTop y() SkRect::top()
216
217##
218
219# ------------------------------------------------------------------------------
220
Cary Clark6def7202018-01-04 08:13:35 -0500221#Method int32_t right() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500222
Cary Clark4855f782018-02-06 09:41:53 -0500223#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500224#Line # returns larger bounds in x, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400225#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500226
227#Example
228 SkIRect unsorted = { 15, 25, 10, 5 };
229 SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right());
230 SkIRect sorted = unsorted.makeSorted();
231 SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right());
232#StdOut
233unsorted.fRight: 10 unsorted.right(): 10
234sorted.fRight: 15 sorted.right(): 15
235##
236##
237
238#SeeAlso fRight SkRect::right()
239
240##
241
242# ------------------------------------------------------------------------------
243
Cary Clark6def7202018-01-04 08:13:35 -0500244#Method int32_t bottom() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500245
Cary Clark4855f782018-02-06 09:41:53 -0500246#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500247#Line # returns larger bounds in y, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400248#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500249
250#Example
251 SkIRect unsorted = { 15, 25, 10, 5 };
252 SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom());
253 SkIRect sorted = unsorted.makeSorted();
254 SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom());
255#StdOut
256unsorted.fBottom: 5 unsorted.bottom(): 5
257sorted.fBottom: 25 sorted.bottom(): 25
258##
259##
260
261#SeeAlso fBottom SkRect::bottom()
262
263##
264
265# ------------------------------------------------------------------------------
266
Cary Clark6def7202018-01-04 08:13:35 -0500267#Method int32_t x() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500268
Cary Clark4855f782018-02-06 09:41:53 -0500269#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500270#Line # returns bounds left ##
Cary Clark09d80c02018-10-31 12:14:03 -0400271#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500272
273#Example
274 SkIRect unsorted = { 15, 5, 10, 25 };
275 SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x());
276 SkIRect sorted = unsorted.makeSorted();
277 SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x());
278#StdOut
279unsorted.fLeft: 15 unsorted.x(): 15
280sorted.fLeft: 10 sorted.x(): 10
281##
282##
283
284#SeeAlso fLeft left() y() SkRect::x()
285
286##
287
288# ------------------------------------------------------------------------------
289
Cary Clark6def7202018-01-04 08:13:35 -0500290#Method int32_t y() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500291
Cary Clark4855f782018-02-06 09:41:53 -0500292#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500293#Line # returns bounds top ##
Cary Clark09d80c02018-10-31 12:14:03 -0400294#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500295
296#Example
297 SkIRect unsorted = { 15, 25, 10, 5 };
298 SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y());
299 SkIRect sorted = unsorted.makeSorted();
300 SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y());
301#StdOut
302unsorted.fTop: 25 unsorted.y(): 25
303sorted.fTop: 5 sorted.y(): 5
304##
305##
306
307#SeeAlso fTop top() x() SkRect::y()
308
309##
310
311# ------------------------------------------------------------------------------
312
Cary Clark6def7202018-01-04 08:13:35 -0500313#Method int32_t width() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500314
Cary Clark4855f782018-02-06 09:41:53 -0500315#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500316#Line # returns span in x ##
Cary Clark09d80c02018-10-31 12:14:03 -0400317#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500318
319#Example
320 SkIRect unsorted = { 15, 25, 10, 5 };
321 SkDebugf("unsorted width: %d\n", unsorted.width());
322 SkIRect large = { -2147483647, 1, 2147483644, 2 };
323 SkDebugf("large width: %d\n", large.width());
324#StdOut
325unsorted width: -5
326large width: -5
327##
328##
329
Mike Reeda766ca92018-01-09 11:31:53 -0500330#SeeAlso height() width64() height64() SkRect::width()
331
332##
333
334# ------------------------------------------------------------------------------
335
336#Method int64_t width64() const
337
Cary Clark4855f782018-02-06 09:41:53 -0500338#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500339#Line # returns span in y as int64_t ##
Cary Clark09d80c02018-10-31 12:14:03 -0400340#Populate
Mike Reeda766ca92018-01-09 11:31:53 -0500341
Cary Clark186d08f2018-04-03 08:43:27 -0400342#Example
Mike Reeda766ca92018-01-09 11:31:53 -0500343SkIRect large = { -2147483647, 1, 2147483644, 2 };
Cary Clark186d08f2018-04-03 08:43:27 -0400344SkDebugf("width: %d width64: %lld\n", large.width(), large.width64());
Mike Reeda766ca92018-01-09 11:31:53 -0500345#StdOut
346width: -5 width64: 4294967291
347##
348##
349
350#SeeAlso width() height() height64() SkRect::width()
Cary Clark0c5f5462017-12-15 11:21:51 -0500351
352##
353
354# ------------------------------------------------------------------------------
355
Cary Clark6def7202018-01-04 08:13:35 -0500356#Method int32_t height() const
Cary Clark0c5f5462017-12-15 11:21:51 -0500357
Cary Clark4855f782018-02-06 09:41:53 -0500358#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500359#Line # returns span in y ##
Cary Clark09d80c02018-10-31 12:14:03 -0400360#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500361
362#Example
363 SkIRect unsorted = { 15, 25, 10, 20 };
364 SkDebugf("unsorted height: %d\n", unsorted.height());
365 SkIRect large = { 1, -2147483647, 2, 2147483644 };
366 SkDebugf("large height: %d\n", large.height());
367#StdOut
368unsorted height: -5
369large height: -5
370##
371##
372
373#SeeAlso width() SkRect::height()
374
375##
376
377# ------------------------------------------------------------------------------
378
Mike Reeda766ca92018-01-09 11:31:53 -0500379#Method int64_t height64() const
380
Cary Clark4855f782018-02-06 09:41:53 -0500381#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500382#Line # returns span in y as int64_t ##
Cary Clark09d80c02018-10-31 12:14:03 -0400383#Populate
Mike Reeda766ca92018-01-09 11:31:53 -0500384
Cary Clark186d08f2018-04-03 08:43:27 -0400385#Example
Mike Reeda766ca92018-01-09 11:31:53 -0500386SkIRect large = { 1, -2147483647, 2, 2147483644 };
387SkDebugf("height: %d height64: %lld\n", large.height(), large.height64());
388#StdOut
389height: -5 height64: 4294967291
390##
391##
392
393#SeeAlso width() height() width64() SkRect::height()
394
395##
396
397# ------------------------------------------------------------------------------
398
Cary Clark0c5f5462017-12-15 11:21:51 -0500399#Method SkISize size() const
400
Cary Clark4855f782018-02-06 09:41:53 -0500401#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500402#Line # returns ISize (width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400403#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500404
405#Example
406 auto debugster = [](const char* prefix, const SkIRect& rect) -> void {
407 SkISize size = rect.size();
408 SkDebugf("%s ", prefix);
409 SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom());
410 SkDebugf("size: %d, %d\n", size.width(), size.height());
411 };
412 SkIRect rect = {20, 30, 40, 50};
413 debugster("original", rect);
414 rect.offset(20, 20);
415 debugster(" offset", rect);
416 rect.outset(20, 20);
417 debugster(" outset", rect);
418#StdOut
419original rect: 20, 30, 40, 50 size: 20, 20
420 offset rect: 40, 50, 60, 70 size: 20, 20
421 outset rect: 20, 30, 80, 90 size: 60, 60
422##
423##
424
425#SeeAlso height() width() MakeSize
426
427##
428
429# ------------------------------------------------------------------------------
430
Cary Clark0c5f5462017-12-15 11:21:51 -0500431#Method bool isEmpty() const
432
Cary Clark4855f782018-02-06 09:41:53 -0500433#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500434#Line # returns true if width or height are zero or negative or they exceed int32_t ##
Cary Clark09d80c02018-10-31 12:14:03 -0400435#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500436
437#Example
438 SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
439 for (auto rect : tests) {
440 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
441 rect.bottom(), rect.isEmpty() ? "" : " not");
442 rect.sort();
443 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
444 rect.bottom(), rect.isEmpty() ? "" : " not");
445 }
446#StdOut
447rect: {20, 40, 10, 50} is empty
448sorted: {10, 40, 20, 50} is not empty
449rect: {20, 40, 20, 50} is empty
450sorted: {20, 40, 20, 50} is empty
451##
452##
453
454#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
455
456##
457
458# ------------------------------------------------------------------------------
459
Mike Reedd2849492018-01-10 14:31:18 -0500460#Method bool isEmpty64() const
461
Cary Clark4855f782018-02-06 09:41:53 -0500462#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500463#Line # returns true if width or height are zero or negative ##
Cary Clark09d80c02018-10-31 12:14:03 -0400464#Populate
Mike Reedd2849492018-01-10 14:31:18 -0500465
Cary Clark186d08f2018-04-03 08:43:27 -0400466#Example
Mike Reedd2849492018-01-10 14:31:18 -0500467SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
468for (auto rect : tests) {
Cary Clark186d08f2018-04-03 08:43:27 -0400469 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
470 rect.bottom(), rect.isEmpty64() ? "" : " not");
471 rect.sort();
472 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
473 rect.bottom(), rect.isEmpty64() ? "" : " not");
Mike Reedd2849492018-01-10 14:31:18 -0500474}
475#StdOut
476rect: {20, 40, 10, 50} is empty
477sorted: {10, 40, 20, 50} is not empty
478rect: {20, 40, 20, 50} is empty
479sorted: {20, 40, 20, 50} is empty
480##
481##
482
483#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
484
485##
486
Cary Clark61313f32018-10-08 14:57:48 -0400487#Subtopic Operators
Cary Clark2dc84ad2018-01-26 12:56:22 -0500488
Mike Reedd2849492018-01-10 14:31:18 -0500489# ------------------------------------------------------------------------------
490
Cary Clark0c5f5462017-12-15 11:21:51 -0500491#Method bool operator==(const SkIRect& a, const SkIRect& b)
492
Cary Clark61313f32018-10-08 14:57:48 -0400493#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500494#Line # returns true if members are equal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400495#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500496
497#Example
498 SkIRect test = {0, 0, 2, 2};
499 SkIRect sorted = test.makeSorted();
500 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!');
501#StdOut
502test == sorted
503##
504##
505
506#SeeAlso operator!=(const SkIRect& a, const SkIRect& b)
507
508##
509
510# ------------------------------------------------------------------------------
511
512#Method bool operator!=(const SkIRect& a, const SkIRect& b)
513
Cary Clark61313f32018-10-08 14:57:48 -0400514#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500515#Line # returns true if members are unequal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400516#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500517
518#Example
519 SkIRect test = {2, 2, 0, 0};
520 SkIRect sorted = test.makeSorted();
521 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '=');
522#StdOut
523test != sorted
524##
525##
526
527#SeeAlso operator==(const SkIRect& a, const SkIRect& b)
528
529##
530
Cary Clark61313f32018-10-08 14:57:48 -0400531#Subtopic Operators ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500532
Cary Clark0c5f5462017-12-15 11:21:51 -0500533# ------------------------------------------------------------------------------
534
Cary Clark78de7512018-02-07 07:27:09 -0500535#Subtopic Set
536#Line # replaces all values ##
Cary Clark78de7512018-02-07 07:27:09 -0500537##
Cary Clark0c5f5462017-12-15 11:21:51 -0500538
539#Method void setEmpty()
540
Cary Clark4855f782018-02-06 09:41:53 -0500541#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500542#Line # sets to (0, 0, 0, 0) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400543#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500544
545#Example
546 SkIRect rect = {3, 4, 1, 2};
547 for (int i = 0; i < 2; ++i) {
548 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop,
549 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
550 rect.setEmpty();
551 }
552#StdOut
553rect: {3, 4, 1, 2} is empty
554rect: {0, 0, 0, 0} is empty
555##
556##
557
558#SeeAlso MakeEmpty SkRect::setEmpty
559
560##
561
562# ------------------------------------------------------------------------------
563
564#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
565
Cary Clark4855f782018-02-06 09:41:53 -0500566#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500567#Line # sets to (left, top, right, bottom) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400568#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500569
570#Example
571 SkIRect rect1 = {3, 4, 1, 2};
572 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
573 SkIRect rect2;
574 rect2.set(3, 4, 1, 2);
575 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
576#StdOut
577rect1: {3, 4, 1, 2}
578rect2: {3, 4, 1, 2}
579##
580##
581
582#SeeAlso setLTRB setXYWH SkRect::set
583
584##
585
586# ------------------------------------------------------------------------------
587
588#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
589
Cary Clark4855f782018-02-06 09:41:53 -0500590#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500591#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400592#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500593
594#Example
595 SkIRect rect1 = {3, 4, 1, 2};
596 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
597 SkIRect rect2;
598 rect2.setLTRB(3, 4, 1, 2);
599 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
600#StdOut
601rect1: {3, 4, 1, 2}
602rect2: {3, 4, 1, 2}
603##
604##
605
606#SeeAlso set setXYWH SkRect::setLTRB
607
608##
609
610# ------------------------------------------------------------------------------
611
612#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
613
Cary Clark4855f782018-02-06 09:41:53 -0500614#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500615#Line # sets to (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400616Sets IRect to: #Formula # (x, y, x + width, y + height) ##.
617Does not validate input; width or height may be negative.
Cary Clark0c5f5462017-12-15 11:21:51 -0500618
619#Param x stored in fLeft ##
620#Param y stored in fTop ##
621#Param width added to x and stored in fRight ##
622#Param height added to y and stored in fBottom ##
623
624#Example
625 SkIRect rect;
626 rect.setXYWH(5, 35, -15, 25);
627 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
628 rect.bottom(), rect.isEmpty() ? "true" : "false");
629 rect.sort();
630 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
631 rect.bottom(), rect.isEmpty() ? "true" : "false");
632#StdOut
633rect: 5, 35, -10, 60 isEmpty: true
634rect: -10, 35, 5, 60 isEmpty: false
635##
636##
637
638#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH
639
640##
641
Cary Clark2dc84ad2018-01-26 12:56:22 -0500642#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -0500643#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500644
Cary Clark0c5f5462017-12-15 11:21:51 -0500645# ------------------------------------------------------------------------------
646
Cary Clark0c5f5462017-12-15 11:21:51 -0500647#Method SkIRect makeOffset(int32_t dx, int32_t dy) const
648
Cary Clarkab2621d2018-01-30 10:08:57 -0500649#In Inset_Outset_Offset
650#Line # constructs from translated sides ##
Cary Clark09d80c02018-10-31 12:14:03 -0400651#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500652
653#Example
654 SkIRect rect = { 10, 50, 20, 60 };
655 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
656 rect.bottom(), rect.isEmpty() ? "true" : "false");
657 rect = rect.makeOffset(15, 32);
658 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
659 rect.bottom(), rect.isEmpty() ? "true" : "false");
660#StdOut
661rect: 10, 50, 20, 60 isEmpty: false
662rect: 25, 82, 35, 92 isEmpty: false
663##
664##
665
666#SeeAlso offset() makeInset makeOutset SkRect::makeOffset
667
668##
669
670# ------------------------------------------------------------------------------
671
672#Method SkIRect makeInset(int32_t dx, int32_t dy) const
673
Cary Clarkab2621d2018-01-30 10:08:57 -0500674#In Inset_Outset_Offset
675#Line # constructs from sides moved symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -0400676#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500677
678#Example
679 SkIRect rect = { 10, 50, 20, 60 };
680 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
681 rect.bottom(), rect.isEmpty() ? "true" : "false");
682 rect = rect.makeInset(15, 32);
683 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
684 rect.bottom(), rect.isEmpty() ? "true" : "false");
685#StdOut
686rect: 10, 50, 20, 60 isEmpty: false
687rect: 25, 82, 5, 28 isEmpty: true
688##
689##
690
691#SeeAlso inset() makeOffset makeOutset SkRect::makeInset
692
693##
694
695# ------------------------------------------------------------------------------
696
697#Method SkIRect makeOutset(int32_t dx, int32_t dy) const
698
Cary Clarkab2621d2018-01-30 10:08:57 -0500699#In Inset_Outset_Offset
700#Line # constructs from sides moved symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -0400701#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500702
703#Example
704 SkIRect rect = { 10, 50, 20, 60 };
705 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
706 rect.bottom(), rect.isEmpty() ? "true" : "false");
707 rect = rect.makeOutset(15, 32);
708 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
709 rect.bottom(), rect.isEmpty() ? "true" : "false");
710#StdOut
711rect: 10, 50, 20, 60 isEmpty: false
712rect: -5, 18, 35, 92 isEmpty: false
713##
714##
715
716#SeeAlso outset() makeOffset makeInset SkRect::makeOutset
717
718##
719
720# ------------------------------------------------------------------------------
721
722#Method void offset(int32_t dx, int32_t dy)
723
Cary Clarkab2621d2018-01-30 10:08:57 -0500724#In Inset_Outset_Offset
725#Line # translates sides without changing width and height ##
Cary Clark09d80c02018-10-31 12:14:03 -0400726#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500727
728#Example
729 SkIRect rect = { 10, 14, 50, 73 };
730 rect.offset(5, 13);
731 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
732#StdOut
733rect: 15, 27, 55, 86
734##
735##
736
737#SeeAlso offsetTo makeOffset SkRect::offset
738
739##
740
741# ------------------------------------------------------------------------------
742
743#Method void offset(const SkIPoint& delta)
744
Cary Clarkab2621d2018-01-30 10:08:57 -0500745#In Inset_Outset_Offset
Cary Clark09d80c02018-10-31 12:14:03 -0400746#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500747
748#Example
749 SkIRect rect = { 10, 14, 50, 73 };
750 rect.offset({5, 13});
751 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
752#StdOut
753rect: 15, 27, 55, 86
754##
755##
756
757#SeeAlso offsetTo makeOffset SkRect::offset
758
759##
760
761# ------------------------------------------------------------------------------
762
763#Method void offsetTo(int32_t newX, int32_t newY)
764
Cary Clarkab2621d2018-01-30 10:08:57 -0500765#In Inset_Outset_Offset
766#Line # translates to (x, y) without changing width and height ##
Cary Clark09d80c02018-10-31 12:14:03 -0400767#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500768
769#Example
770 SkIRect rect = { 10, 14, 50, 73 };
771 rect.offsetTo(15, 27);
772 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
773#StdOut
774rect: 15, 27, 55, 86
775##
776##
777
778#SeeAlso offset makeOffset setXYWH SkRect::offsetTo
779
780##
781
782# ------------------------------------------------------------------------------
783
784#Method void inset(int32_t dx, int32_t dy)
785
Cary Clarkab2621d2018-01-30 10:08:57 -0500786#In Inset_Outset_Offset
787#Line # moves the sides symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -0400788#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500789
790#Example
791 SkIRect rect = { 10, 14, 50, 73 };
792 rect.inset(5, 13);
793 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
794#StdOut
795rect: 15, 27, 45, 60
796##
797##
798
799#SeeAlso outset makeInset SkRect::inset
800
801##
802
803# ------------------------------------------------------------------------------
804
805#Method void outset(int32_t dx, int32_t dy)
806
Cary Clarkab2621d2018-01-30 10:08:57 -0500807#In Inset_Outset_Offset
808#Line # moves the sides symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -0400809#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500810
811#Example
812 SkIRect rect = { 10, 14, 50, 73 };
813 rect.outset(5, 13);
814 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
815#StdOut
816rect: 5, 1, 55, 86
817##
818##
819
820#SeeAlso inset makeOutset SkRect::outset
821
822##
823
Cary Clark2dc84ad2018-01-26 12:56:22 -0500824#Subtopic Inset_Outset_Offset ##
825
826#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -0400827#Line # sets to shared bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500828
Cary Clark682c58d2018-05-16 07:07:07 -0400829IRects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark2dc84ad2018-01-26 12:56:22 -0500830must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark77b3f3a2018-11-07 14:59:03 -0500831SkIRect::isEmpty() returns false. The intersection of IRect pair can be described by:
Cary Clark2be81cf2018-09-13 12:04:30 -0400832#Formula # (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
833 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) ##.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500834
835The intersection is only meaningful if the resulting IRect is not empty and
836describes an area: fLeft is less than fRight, and fTop is less than fBottom.
837
Cary Clark0c5f5462017-12-15 11:21:51 -0500838# ------------------------------------------------------------------------------
839
Robert Phillips8f8d4812018-05-18 10:19:05 -0400840#Method void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB)
841
842#In Inset_Outset_Offset
843#Line # moves the sides independently relative to their original locations ##
Cary Clark09d80c02018-10-31 12:14:03 -0400844#Populate
Robert Phillips8f8d4812018-05-18 10:19:05 -0400845
846#Example
847 SkIRect rect = { 8, 11, 19, 22 };
848 rect.adjust(2, -1, 1, -2);
849 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
850#StdOut
851rect: 10, 10, 20, 20
852##
853##
854
855#SeeAlso inset outset
856
857##
858
859# ------------------------------------------------------------------------------
860
Cary Clark0c5f5462017-12-15 11:21:51 -0500861#Method bool contains(int32_t x, int32_t y) const
862
Cary Clarkab2621d2018-01-30 10:08:57 -0500863#In Intersection
Cary Clark300cc5b2018-02-20 12:50:35 -0500864#Line # returns true if IPoint (x, y) is equal or inside ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400865Returns true if: #Formula # fLeft <= x < fRight && fTop <= y < fBottom ##.
Cary Clark2dc84ad2018-01-26 12:56:22 -0500866Returns false if IRect is empty.
Cary Clark0c5f5462017-12-15 11:21:51 -0500867
Cary Clark2be81cf2018-09-13 12:04:30 -0400868Considers input to describe constructed IRect: #Formula # (x, y, x + 1, y + 1) ## and
Cary Clark0c5f5462017-12-15 11:21:51 -0500869returns true if constructed area is completely enclosed by IRect area.
870
Cary Clark300cc5b2018-02-20 12:50:35 -0500871#Param x test IPoint x-coordinate ##
872#Param y test IPoint y-coordinate ##
Cary Clark0c5f5462017-12-15 11:21:51 -0500873
874#Return true if (x, y) is inside IRect ##
875
876#Example
877 SkIRect rect = { 30, 50, 40, 60 };
878 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} };
879 for (auto pt : pts) {
880 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n",
881 rect.left(), rect.top(), rect.right(), rect.bottom(),
882 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y());
883 }
884#StdOut
885rect: (30, 50, 40, 60) contains (30, 50)
886rect: (30, 50, 40, 60) does not contain (40, 50)
887rect: (30, 50, 40, 60) does not contain (30, 60)
888##
889##
890
891#SeeAlso containsNoEmptyCheck SkRect::contains
892
893##
894
895# ------------------------------------------------------------------------------
896
897#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
898
Cary Clarkab2621d2018-01-30 10:08:57 -0500899#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -0400900#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500901
902#Example
903 SkIRect rect = { 30, 50, 40, 60 };
904 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
905 for (auto contained : tests) {
906 bool success = rect.contains(
907 contained.left(), contained.top(), contained.right(), contained.bottom());
908 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
909 rect.left(), rect.top(), rect.right(), rect.bottom(),
910 success ? "contains" : "does not contain",
911 contained.left(), contained.top(), contained.right(), contained.bottom());
912 }
913#StdOut
914rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
915rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
916rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
917##
918##
919
920#SeeAlso containsNoEmptyCheck SkRect::contains
921
922##
923
924# ------------------------------------------------------------------------------
925
926#Method bool contains(const SkIRect& r) const
927
Cary Clarkab2621d2018-01-30 10:08:57 -0500928#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -0400929#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500930
931#Example
932 SkIRect rect = { 30, 50, 40, 60 };
933 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
934 for (auto contained : tests) {
935 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
936 rect.left(), rect.top(), rect.right(), rect.bottom(),
937 rect.contains(contained) ? "contains" : "does not contain",
938 contained.left(), contained.top(), contained.right(), contained.bottom());
939 }
940#StdOut
941rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
942rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
943rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
944##
945##
946
947#SeeAlso containsNoEmptyCheck SkRect::contains
948
949##
950
951# ------------------------------------------------------------------------------
952
953#Method bool contains(const SkRect& r) const
954
Cary Clarkab2621d2018-01-30 10:08:57 -0500955#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -0400956#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500957
958#Example
959 SkIRect rect = { 30, 50, 40, 60 };
960 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
961 for (auto contained : tests) {
962 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n",
963 rect.left(), rect.top(), rect.right(), rect.bottom(),
964 rect.contains(contained) ? "contains" : "does not contain",
965 contained.left(), contained.top(), contained.right(), contained.bottom());
966 }
967#StdOut
968rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
969rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
970rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
971##
972##
973
974#SeeAlso containsNoEmptyCheck SkRect::contains
975
976##
977
978# ------------------------------------------------------------------------------
979
980#Method bool containsNoEmptyCheck(int32_t left, int32_t top,
981 int32_t right, int32_t bottom) const
Cary Clarkab2621d2018-01-30 10:08:57 -0500982#In Intersection
Cary Clark300cc5b2018-02-20 12:50:35 -0500983#Line # returns true if contains unsorted IRect ##
Cary Clark09d80c02018-10-31 12:14:03 -0400984#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -0500985
986#Example
987 SkIRect rect = { 30, 50, 40, 60 };
988 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
989 for (auto contained : tests) {
990 bool success = rect.containsNoEmptyCheck(
991 contained.left(), contained.top(), contained.right(), contained.bottom());
992 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
993 rect.left(), rect.top(), rect.right(), rect.bottom(),
994 success ? "contains" : "does not contain",
995 contained.left(), contained.top(), contained.right(), contained.bottom());
996 }
997#StdOut
998rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
999rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1000rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1001##
1002##
1003
1004#SeeAlso contains SkRect::contains
1005
1006##
1007
1008# ------------------------------------------------------------------------------
1009
1010#Method bool containsNoEmptyCheck(const SkIRect& r) const
1011
Cary Clarkab2621d2018-01-30 10:08:57 -05001012#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001013#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001014
1015#Example
1016 SkIRect rect = { 30, 50, 40, 60 };
1017 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1018 for (auto contained : tests) {
1019 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1020 rect.left(), rect.top(), rect.right(), rect.bottom(),
1021 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain",
1022 contained.left(), contained.top(), contained.right(), contained.bottom());
1023 }
1024#StdOut
1025rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1026rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1027rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1028##
1029##
1030
1031#SeeAlso contains SkRect::contains
1032
1033##
1034
Cary Clark0c5f5462017-12-15 11:21:51 -05001035# ------------------------------------------------------------------------------
1036
1037#Method bool intersect(const SkIRect& r)
1038
Cary Clarkab2621d2018-01-30 10:08:57 -05001039#In Intersection
1040#Line # sets to shared area; returns true if not empty ##
Cary Clark09d80c02018-10-31 12:14:03 -04001041#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001042
1043#Example
1044#Description
1045Two SkDebugf calls are required. If the calls are combined, their arguments
1046may not be evaluated in left to right order: the printed intersection may
1047be before or after the call to intersect.
1048##
1049 SkIRect leftRect = { 10, 40, 50, 80 };
1050 SkIRect rightRect = { 30, 60, 70, 90 };
1051 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001052 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
Cary Clark0c5f5462017-12-15 11:21:51 -05001053 leftRect.right(), leftRect.bottom());
1054#StdOut
1055 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001056##
Cary Clark0c5f5462017-12-15 11:21:51 -05001057##
1058
1059#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1060
1061##
1062
1063# ------------------------------------------------------------------------------
1064
Cary Clark61313f32018-10-08 14:57:48 -04001065#Method bool intersect(const SkIRect& a, const SkIRect& b)
Cary Clark0c5f5462017-12-15 11:21:51 -05001066
Cary Clarkab2621d2018-01-30 10:08:57 -05001067#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001068#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001069
1070#Example
1071 SkIRect result;
1072 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1073 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ",
1074 result.left(), result.top(), result.right(), result.bottom());
1075#StdOut
1076 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001077##
Cary Clark0c5f5462017-12-15 11:21:51 -05001078##
1079
1080#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
1081
1082##
1083
1084# ------------------------------------------------------------------------------
1085
Cary Clark61313f32018-10-08 14:57:48 -04001086#Method bool intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)
Cary Clark0c5f5462017-12-15 11:21:51 -05001087
Cary Clarkab2621d2018-01-30 10:08:57 -05001088#In Intersection
1089#Line # sets to shared area; returns true if not empty skips empty check ##
Cary Clark09d80c02018-10-31 12:14:03 -04001090#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001091
1092#Example
1093 SkIRect result;
Cary Clark681287e2018-03-16 11:34:15 -04001094 if (result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 })) {
1095 SkDebugf("intersection: %d, %d, %d, %d\n",
1096 result.left(), result.top(), result.right(), result.bottom());
1097 }
Cary Clark0c5f5462017-12-15 11:21:51 -05001098#StdOut
1099 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001100##
Cary Clark0c5f5462017-12-15 11:21:51 -05001101##
1102
1103#SeeAlso Intersects intersect join SkRect::intersect
1104
1105##
1106
1107# ------------------------------------------------------------------------------
1108
1109#Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
1110
Cary Clarkab2621d2018-01-30 10:08:57 -05001111#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001112#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001113
1114#Example
1115#Description
1116Two SkDebugf calls are required. If the calls are combined, their arguments
1117may not be evaluated in left to right order: the printed intersection may
1118be before or after the call to intersect.
1119##
1120 SkIRect leftRect = { 10, 40, 50, 80 };
1121 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001122 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
Cary Clark0c5f5462017-12-15 11:21:51 -05001123 leftRect.right(), leftRect.bottom());
1124#StdOut
1125 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001126##
Cary Clark0c5f5462017-12-15 11:21:51 -05001127##
1128
1129#SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect
1130
1131##
1132
1133# ------------------------------------------------------------------------------
1134
1135#Method static bool Intersects(const SkIRect& a, const SkIRect& b)
1136
Cary Clarkab2621d2018-01-30 10:08:57 -05001137#In Intersection
1138#Line # returns true if areas overlap ##
Cary Clark09d80c02018-10-31 12:14:03 -04001139#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001140
1141#Example
1142 SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1143#StdOut
1144 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001145##
Cary Clark0c5f5462017-12-15 11:21:51 -05001146##
1147
1148#SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect
1149
1150##
1151
1152# ------------------------------------------------------------------------------
1153
1154#Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1155
Cary Clarkab2621d2018-01-30 10:08:57 -05001156#In Intersection
1157#Line # returns true if areas overlap skips empty check ##
Cary Clark09d80c02018-10-31 12:14:03 -04001158#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001159
1160#Example
1161 SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck(
1162 {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1163#StdOut
1164 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001165##
Cary Clark0c5f5462017-12-15 11:21:51 -05001166##
1167
1168#SeeAlso Intersects intersect SkRect::intersect
1169
1170##
1171
Cary Clark2dc84ad2018-01-26 12:56:22 -05001172#Subtopic Intersection ##
Cary Clark0c5f5462017-12-15 11:21:51 -05001173
1174# ------------------------------------------------------------------------------
1175
Cary Clark4855f782018-02-06 09:41:53 -05001176#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001177#Line # sets to union of bounds ##
Cary Clark4855f782018-02-06 09:41:53 -05001178##
1179
Cary Clark0c5f5462017-12-15 11:21:51 -05001180#Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom)
1181
Cary Clark4855f782018-02-06 09:41:53 -05001182#In Join
Cary Clarkab2621d2018-01-30 10:08:57 -05001183#Line # sets to union of bounds ##
Cary Clark09d80c02018-10-31 12:14:03 -04001184#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001185
1186#Example
1187 SkIRect rect = { 10, 20, 15, 25};
1188 rect.join(50, 60, 55, 65);
1189 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1190#StdOut
1191 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001192##
Cary Clark0c5f5462017-12-15 11:21:51 -05001193##
1194
1195#SeeAlso set SkRect::join
1196
1197##
1198
1199# ------------------------------------------------------------------------------
1200
1201#Method void join(const SkIRect& r)
1202
Cary Clark4855f782018-02-06 09:41:53 -05001203#In Join
Cary Clark09d80c02018-10-31 12:14:03 -04001204#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001205
1206#Example
1207 SkIRect rect = { 10, 20, 15, 25};
1208 rect.join({50, 60, 55, 65});
1209 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1210#StdOut
1211 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001212##
Cary Clark0c5f5462017-12-15 11:21:51 -05001213##
1214
1215#SeeAlso set SkRect::join
1216
1217##
1218
1219# ------------------------------------------------------------------------------
1220
Cary Clark4855f782018-02-06 09:41:53 -05001221#Subtopic Sorting
1222#Line # orders sides ##
Cary Clark4855f782018-02-06 09:41:53 -05001223##
1224
Cary Clark0c5f5462017-12-15 11:21:51 -05001225#Method void sort()
1226
Cary Clark4855f782018-02-06 09:41:53 -05001227#In Sorting
Cary Clarkab2621d2018-01-30 10:08:57 -05001228#Line # orders sides from smaller to larger ##
Cary Clark09d80c02018-10-31 12:14:03 -04001229#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001230
1231#Example
1232 SkIRect rect = { 30, 50, 20, 10 };
1233 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1234 rect.sort();
1235 SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1236#StdOut
1237rect: 30, 50, 20, 10
1238sorted: 20, 10, 30, 50
1239##
1240##
1241
1242#SeeAlso makeSorted SkRect::sort
1243
1244##
1245
1246# ------------------------------------------------------------------------------
1247
1248#Method SkIRect makeSorted() const
1249
Cary Clark4855f782018-02-06 09:41:53 -05001250#In Sorting
Cary Clark61313f32018-10-08 14:57:48 -04001251#In Constructors
Cary Clark682c58d2018-05-16 07:07:07 -04001252#Line # constructs IRect, ordering sides from smaller to larger ##
Cary Clark09d80c02018-10-31 12:14:03 -04001253#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001254
1255#Example
1256 SkIRect rect = { 30, 50, 20, 10 };
1257 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1258 SkIRect sort = rect.makeSorted();
1259 SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
1260#StdOut
1261rect: 30, 50, 20, 10
1262sorted: 20, 10, 30, 50
1263##
1264##
1265
1266#SeeAlso sort SkRect::makeSorted
1267
1268##
1269
1270# ------------------------------------------------------------------------------
1271
Cary Clark61313f32018-10-08 14:57:48 -04001272#Method static const SkIRect& EmptyIRect()
Cary Clark0c5f5462017-12-15 11:21:51 -05001273
Cary Clark61313f32018-10-08 14:57:48 -04001274#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -05001275#Line # returns immutable bounds of (0, 0, 0, 0) ##
Cary Clark09d80c02018-10-31 12:14:03 -04001276#Populate
Cary Clark0c5f5462017-12-15 11:21:51 -05001277
1278#Example
1279 const SkIRect& rect = SkIRect::EmptyIRect();
1280 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1281#StdOut
1282rect: 0, 0, 0, 0
1283##
1284##
1285
1286#SeeAlso MakeEmpty
Cary Clark69261ba2018-10-11 15:28:31 -04001287
1288##
1289
1290#Struct SkIRect ##
1291
1292#Topic IRect ##