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