blob: 0a9ddf8bf46cd867e56bf81bc4faa90a64fc0a9e [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic IRect
2#Alias IRect_Reference
3
4#Struct SkIRect
5
Cary Clark7fc1d122017-10-09 14:07:42 -04006SkIRect 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.
Cary Clarkbc5697d2017-10-04 14:31:33 -040011
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 ##
Cary Clark7fc1d122017-10-09 14:07:42 -040028# friend bool operator!=(const SkIRect& a, const SkIRect& b) # Returns true if members are unequal. ##
29# friend bool operator==(const SkIRect& a, const SkIRect& b) # Returns true if members are equal. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040030#Table ##
31#Subtopic ##
32
33#Subtopic Member_Functions
34#Table
35#Legend
36# description # function ##
37#Legend ##
Cary Clark7fc1d122017-10-09 14:07:42 -040038# 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. ##
43# MakeLargest # Constructs from (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32). ##
44# MakeSize # Constructs from ISize returning (0, 0, width, height). ##
45# MakeWH # Constructs from int input returning (0, 0, width, height). ##
46# MakeXYWH # Constructs from int input returning (x, y, width, height). ##
47# bottom() # Returns larger bounds in y, if sorted. ##
48# centerX # Returns midpoint in x. ##
49# centerY # Returns midpoint in y. ##
50# contains() # Returns true if points are equal or inside. ##
51# containsNoEmptyCheck # Returns true if points are equal or inside. Skips empty check. ##
52# height() # Returns span in y. ##
53# 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. ##
57# isEmpty # Returns true if width or height are zero or negative. ##
58# isLargest # Returns true if equal to (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32). ##
59# 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). ##
73# setLargest # Sets to (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32). ##
74# setLargestInverted # Sets to (SK_MaxS32, SK_MaxS32, SK_MinS32, SK_MinS32). ##
75# setXYWH # Sets to (x, y, width, height). ##
76# size() # Returns ISize (width, height). ##
77# sort() # Orders sides from smaller to larger. ##
78# top() # Returns smaller bounds in y, if sorted. ##
79# width() # Returns span in x. ##
80# x() # Returns bounds left. ##
81# y() # Returns bounds top. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040082#Table ##
83#Subtopic ##
84
85#Topic ##
86
87#Member int32_t fLeft
Cary Clark7fc1d122017-10-09 14:07:42 -040088May contain any value. The smaller of the horizontal values when sorted.
89When equal to or greater than fRight, IRect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040090##
91
92#Member int32_t fTop
Cary Clark7fc1d122017-10-09 14:07:42 -040093May contain any value. The smaller of the horizontal values when sorted.
94When equal to or greater than fBottom, IRect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040095##
96
97#Member int32_t fRight
Cary Clark7fc1d122017-10-09 14:07:42 -040098May contain any value. The larger of the vertical values when sorted.
99When equal to or less than fLeft, IRect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400100##
101
102#Member int32_t fBottom
Cary Clark7fc1d122017-10-09 14:07:42 -0400103May contain any value. The larger of the vertical values when sorted.
104When equal to or less than fTop, IRect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400105##
106
107# ------------------------------------------------------------------------------
108
109#Method static SkIRect SK_WARN_UNUSED_RESULT MakeEmpty()
110
Cary Clark7fc1d122017-10-09 14:07:42 -0400111Returns constructed IRect set to (0, 0, 0, 0).
112Many other rectangles are empty; if left is equal to or greater than right,
113or if top is equal to or greater than bottom. Setting all members to zero
114is a convenience, but does not designate a special empty rectangle.
115
116#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400117
118#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400119 SkIRect rect = SkIRect::MakeEmpty();
120 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
121 rect.offset(10, 10);
122 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
123 rect.inset(10, 10);
124 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
125 rect.outset(20, 20);
126 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
127#StdOut
128MakeEmpty isEmpty: true
129offset rect isEmpty: true
130inset rect isEmpty: true
131outset rect isEmpty: false
132##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400133##
134
Cary Clark7fc1d122017-10-09 14:07:42 -0400135#SeeAlso EmptyIRect isEmpty setEmpty setLargestInverted SkRect::MakeEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400136
137##
138
139# ------------------------------------------------------------------------------
140
141#Method static SkIRect SK_WARN_UNUSED_RESULT MakeLargest()
142
Cary Clark7fc1d122017-10-09 14:07:42 -0400143Returns constructed IRect setting left and top to most negative value, and
144setting right and bottom to most positive value.
145
146#Return bounds (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400147
148#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400149 SkIRect rect = SkIRect::MakeLargest();
150 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
151 SkDebugf("MakeLargest isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
152 rect.outset(1, 1);
153 SkDebugf("outset isLargest: %s\n", rect.isLargest() ? "true" : "false");
154 SkDebugf("outset isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
155#StdOut
156MakeLargest isLargest: true
157MakeLargest isEmpty: false
158outset isLargest: false
159outset isEmpty: true
160##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400161##
162
Cary Clark7fc1d122017-10-09 14:07:42 -0400163#SeeAlso isLargest setLargest SkRect::MakeLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400164
165##
166
167# ------------------------------------------------------------------------------
168
169#Method static SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h)
170
Cary Clark7fc1d122017-10-09 14:07:42 -0400171Returns constructed IRect set to (0, 0, w, h). Does not validate input; w or h
172may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400173
Cary Clark7fc1d122017-10-09 14:07:42 -0400174#Param w width of constructed Rect ##
175#Param h height of constructed Rect ##
176
177#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400178
179#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400180 SkIRect rect1 = SkIRect::MakeWH(25, 35);
181 SkIRect rect2 = SkIRect::MakeSize({25, 35});
182 SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35);
183 SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35);
184 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
185 "" : "not ");
186#StdOut
187all equal
188##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400189##
190
Cary Clark7fc1d122017-10-09 14:07:42 -0400191#SeeAlso MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400192
193##
194
195# ------------------------------------------------------------------------------
196
197#Method static SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size)
198
Cary Clark7fc1d122017-10-09 14:07:42 -0400199Returns constructed IRect set to (0, 0, size.width(), size.height()).
200Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400201
Cary Clark7fc1d122017-10-09 14:07:42 -0400202#Param size values for Rect width and height ##
203
204#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400205
206#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400207 SkSize size = {25.5f, 35.5f};
208 SkIRect rect = SkIRect::MakeSize(size.toRound());
209 SkDebugf("round width: %d height: %d\n", rect.width(), rect.height());
210 rect = SkIRect::MakeSize(size.toFloor());
211 SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height());
212#StdOut
213round width: 26 height: 36
214floor width: 25 height: 35
215##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400216##
217
Cary Clark7fc1d122017-10-09 14:07:42 -0400218#SeeAlso MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400219
220##
221
222# ------------------------------------------------------------------------------
223
224#Method static SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
225
Cary Clark7fc1d122017-10-09 14:07:42 -0400226Returns constructed IRect set to (l, t, r, b). Does not sort input; Rect may
227result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400228
Cary Clark7fc1d122017-10-09 14:07:42 -0400229#Param l integer stored in fLeft ##
230#Param t integer stored in fTop ##
231#Param r integer stored in fRight ##
232#Param b integer stored in fBottom ##
233
234#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400235
236#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400237 SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25);
238 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
239 rect.bottom(), rect.isEmpty() ? "true" : "false");
240 rect.sort();
241 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
242 rect.bottom(), rect.isEmpty() ? "true" : "false");
243#StdOut
244rect: 5, 35, 15, 25 isEmpty: true
245rect: 5, 25, 15, 35 isEmpty: false
246##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400247##
248
Cary Clark7fc1d122017-10-09 14:07:42 -0400249#SeeAlso MakeXYWH SkRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400250
251##
252
253# ------------------------------------------------------------------------------
254
255#Method static SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
256
Cary Clark7fc1d122017-10-09 14:07:42 -0400257Returns constructed IRect set to
258#Formula
259(x, y, x + w, y + h)
260##
261. Does not validate input;
262w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400263
Cary Clark7fc1d122017-10-09 14:07:42 -0400264#Param x stored in fLeft ##
265#Param y stored in fTop ##
266#Param w added to x and stored in fRight ##
267#Param h added to y and stored in fBottom ##
268
269#Return bounds (x, y, x + w, y + h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400270
271#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400272 SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25);
273 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
274 rect.bottom(), rect.isEmpty() ? "true" : "false");
275 rect.sort();
276 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
277 rect.bottom(), rect.isEmpty() ? "true" : "false");
278#StdOut
279rect: 5, 35, -10, 60 isEmpty: true
280rect: -10, 35, 5, 60 isEmpty: false
281##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400282##
283
Cary Clark7fc1d122017-10-09 14:07:42 -0400284#SeeAlso MakeLTRB SkRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400285
286##
287
288# ------------------------------------------------------------------------------
289
290#Method int left() const
291
Cary Clark7fc1d122017-10-09 14:07:42 -0400292Returns left edge of IRect, if sorted.
293Call sort() to reverse fLeft and fRight if needed.
294
295#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400296
297#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400298 SkIRect unsorted = { 15, 5, 10, 25 };
299 SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left());
300 SkIRect sorted = unsorted.makeSorted();
301 SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left());
302#StdOut
303unsorted.fLeft: 15 unsorted.left(): 15
304sorted.fLeft: 10 sorted.left(): 10
305##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400306##
307
Cary Clark7fc1d122017-10-09 14:07:42 -0400308#SeeAlso fLeft x() SkRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309
310##
311
312# ------------------------------------------------------------------------------
313
314#Method int top() const
315
Cary Clark7fc1d122017-10-09 14:07:42 -0400316Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
317and sort() to reverse fTop and fBottom if needed.
318
319#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400320
321#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400322 SkIRect unsorted = { 15, 25, 10, 5 };
323 SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top());
324 SkIRect sorted = unsorted.makeSorted();
325 SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top());
326#StdOut
327unsorted.fTop: 25 unsorted.top(): 25
328sorted.fTop: 5 sorted.top(): 5
329##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400330##
331
Cary Clark7fc1d122017-10-09 14:07:42 -0400332#SeeAlso fTop y() SkRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400333
334##
335
336# ------------------------------------------------------------------------------
337
338#Method int right() const
339
Cary Clark7fc1d122017-10-09 14:07:42 -0400340Returns right edge of IRect, if sorted.
341Call sort() to reverse fLeft and fRight if needed.
342
343#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400344
345#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400346 SkIRect unsorted = { 15, 25, 10, 5 };
347 SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right());
348 SkIRect sorted = unsorted.makeSorted();
349 SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right());
350#StdOut
351unsorted.fRight: 10 unsorted.right(): 10
352sorted.fRight: 15 sorted.right(): 15
353##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400354##
355
Cary Clark7fc1d122017-10-09 14:07:42 -0400356#SeeAlso fRight SkRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400357
358##
359
360# ------------------------------------------------------------------------------
361
362#Method int bottom() const
363
Cary Clark7fc1d122017-10-09 14:07:42 -0400364Returns bottom edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
365and sort() to reverse fTop and fBottom if needed.
366
367#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400368
369#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400370 SkIRect unsorted = { 15, 25, 10, 5 };
371 SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom());
372 SkIRect sorted = unsorted.makeSorted();
373 SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom());
374#StdOut
375unsorted.fBottom: 5 unsorted.bottom(): 5
376sorted.fBottom: 25 sorted.bottom(): 25
377##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400378##
379
Cary Clark7fc1d122017-10-09 14:07:42 -0400380#SeeAlso fBottom SkRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400381
382##
383
384# ------------------------------------------------------------------------------
385
386#Method int x() const
387
Cary Clark7fc1d122017-10-09 14:07:42 -0400388Returns left edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
389and sort() to reverse fLeft and fRight if needed.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400390
Cary Clark7fc1d122017-10-09 14:07:42 -0400391#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400392
393#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400394 SkIRect unsorted = { 15, 5, 10, 25 };
395 SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x());
396 SkIRect sorted = unsorted.makeSorted();
397 SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x());
398#StdOut
399unsorted.fLeft: 15 unsorted.x(): 15
400sorted.fLeft: 10 sorted.x(): 10
401##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400402##
403
Cary Clark7fc1d122017-10-09 14:07:42 -0400404#SeeAlso fLeft left() y() SkRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400405
406##
407
408# ------------------------------------------------------------------------------
409
410#Method int y() const
411
Cary Clark7fc1d122017-10-09 14:07:42 -0400412Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid,
413and sort() to reverse fTop and fBottom if needed.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400414
Cary Clark7fc1d122017-10-09 14:07:42 -0400415#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400416
417#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400418 SkIRect unsorted = { 15, 25, 10, 5 };
419 SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y());
420 SkIRect sorted = unsorted.makeSorted();
421 SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y());
422#StdOut
423unsorted.fTop: 25 unsorted.y(): 25
424sorted.fTop: 5 sorted.y(): 5
425##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400426##
427
Cary Clark7fc1d122017-10-09 14:07:42 -0400428#SeeAlso fTop top() x() SkRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400429
430##
431
432# ------------------------------------------------------------------------------
433
434#Method int width() const
435
Cary Clark7fc1d122017-10-09 14:07:42 -0400436Returns span on the x-axis. This does not check if IRect is sorted, or if
437result fits in 32-bit signed integer; result may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400438
Cary Clark7fc1d122017-10-09 14:07:42 -0400439#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400440
441#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400442 SkIRect unsorted = { 15, 25, 10, 5 };
443 SkDebugf("unsorted width: %d\n", unsorted.width());
444 SkIRect large = { -2147483647, 1, 2147483644, 2 };
445 SkDebugf("large width: %d\n", large.width());
446#StdOut
447unsorted width: -5
448large width: -5
449##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400450##
451
Cary Clark7fc1d122017-10-09 14:07:42 -0400452#SeeAlso height() SkRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400453
454##
455
456# ------------------------------------------------------------------------------
457
458#Method int height() const
459
Cary Clark7fc1d122017-10-09 14:07:42 -0400460Returns span on the y-axis. This does not check if IRect is sorted, or if
461result fits in 32-bit signed integer; result may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400462
Cary Clark7fc1d122017-10-09 14:07:42 -0400463#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400464
465#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400466 SkIRect unsorted = { 15, 25, 10, 20 };
467 SkDebugf("unsorted height: %d\n", unsorted.height());
468 SkIRect large = { 1, -2147483647, 2, 2147483644 };
469 SkDebugf("large height: %d\n", large.height());
470#StdOut
471unsorted height: -5
472large height: -5
473##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400474##
475
Cary Clark7fc1d122017-10-09 14:07:42 -0400476#SeeAlso width() SkRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400477
478##
479
480# ------------------------------------------------------------------------------
481
482#Method SkISize size() const
483
Cary Clark7fc1d122017-10-09 14:07:42 -0400484Returns spans on the x-axis and y-axis. This does not check if IRect is sorted,
485or if result fits in 32-bit signed integer; result may be negative.
486
487#Return ISize (width, height) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400488
489#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400490 auto debugster = [](const char* prefix, const SkIRect& rect) -> void {
491 SkISize size = rect.size();
492 SkDebugf("%s ", prefix);
493 SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom());
494 SkDebugf("size: %d, %d\n", size.width(), size.height());
495 };
496 SkIRect rect = {20, 30, 40, 50};
497 debugster("original", rect);
498 rect.offset(20, 20);
499 debugster(" offset", rect);
500 rect.outset(20, 20);
501 debugster(" outset", rect);
502#StdOut
503original rect: 20, 30, 40, 50 size: 20, 20
504 offset rect: 40, 50, 60, 70 size: 20, 20
505 outset rect: 20, 30, 80, 90 size: 60, 60
506##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400507##
508
Cary Clark7fc1d122017-10-09 14:07:42 -0400509#SeeAlso height() width() MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400510
511##
512
513# ------------------------------------------------------------------------------
514
515#Method int centerX() const
516
Cary Clark7fc1d122017-10-09 14:07:42 -0400517Returns average of left edge and right edge. Result does not change if Rect
518is sorted. Result may be incorrect if Rect is far from the origin.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400519
Cary Clark7fc1d122017-10-09 14:07:42 -0400520Result is rounded down.
521
522#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400523
524#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400525#Description
526Dividing by two rounds towards zero. centerX uses a bit shift and rounds down.
527##
528 SkIRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}, {-10, -10, 11, 11}};
529 for (auto rect : tests) {
530 SkDebugf("left: %3d right: %3d centerX: %3d ", rect.left(), rect.right(), rect.centerX());
531 SkDebugf("div2: %3d\n", (rect.left() + rect.right()) / 2);
532 }
533#StdOut
534left: 20 right: 41 centerX: 30 div2: 30
535left: -20 right: -41 centerX: -31 div2: -30
536left: -10 right: 11 centerX: 0 div2: 0
537##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400538##
539
Cary Clark7fc1d122017-10-09 14:07:42 -0400540#SeeAlso centerY SkRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400541
542##
543
544# ------------------------------------------------------------------------------
545
546#Method int centerY() const
547
Cary Clark7fc1d122017-10-09 14:07:42 -0400548Returns average of top edge and bottom edge. Result does not change if Rect
549is sorted. Result may be incorrect if Rect is far from the origin.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400550
Cary Clark7fc1d122017-10-09 14:07:42 -0400551Result is rounded down.
552
553#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400554
555#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400556 SkIRect rect = { 0, 0, 2, 2 };
557 rect.offset(0x40000000, 0x40000000);
558 SkDebugf("left: %d right: %d centerX: %d ", rect.left(), rect.right(), rect.centerX());
559 SkDebugf("safe mid x: %d\n", rect.left() / 2 + rect.right() / 2);
560#StdOut
561left: 1073741824 right: 1073741826 centerX: -1073741823 safe mid x: 1073741825
562##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400563##
564
Cary Clark7fc1d122017-10-09 14:07:42 -0400565#SeeAlso centerX SkRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400566
567##
568
569# ------------------------------------------------------------------------------
570
571#Method bool isEmpty() const
572
Cary Clark7fc1d122017-10-09 14:07:42 -0400573Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
574to or greater than fBottom. Call sort() to reverse rectangles with negative
575width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400576
Cary Clark7fc1d122017-10-09 14:07:42 -0400577#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400578
579#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400580 SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
581 for (auto rect : tests) {
582 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
583 rect.bottom(), rect.isEmpty() ? "" : " not");
584 rect.sort();
585 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
586 rect.bottom(), rect.isEmpty() ? "" : " not");
587 }
588#StdOut
589rect: {20, 40, 10, 50} is empty
590sorted: {10, 40, 20, 50} is not empty
591rect: {20, 40, 20, 50} is empty
592sorted: {20, 40, 20, 50} is empty
593##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400594##
595
Cary Clark7fc1d122017-10-09 14:07:42 -0400596#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400597
598##
599
600# ------------------------------------------------------------------------------
601
602#Method bool isLargest() const
603
Cary Clark7fc1d122017-10-09 14:07:42 -0400604Returns true if IRect encloses largest possible area.
605
606#Return true if equal to (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400607
608#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400609#Description
610Note that the width is not negative, yet it cannot be represented as a 32-bit
611signed integer.
612##
613 SkIRect large = SkIRect::MakeLargest();
614 SkDebugf("large is largest: %s\n" ,large.isLargest() ? "true" : "false");
615 SkDebugf("large width %d\n", large.width());
616 SkDebugf("large is empty: %s\n", large.isEmpty() ? "true" : "false");
617#StdOut
618large is largest: true
619large width -2
620large is empty: false
621##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400622##
623
Cary Clark7fc1d122017-10-09 14:07:42 -0400624#SeeAlso MakeLargest SkRect::isLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400625
626##
627
628# ------------------------------------------------------------------------------
629
630#Method friend bool operator==(const SkIRect& a, const SkIRect& b)
631
Cary Clark7fc1d122017-10-09 14:07:42 -0400632Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
633identical to corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400634
Cary Clark7fc1d122017-10-09 14:07:42 -0400635#Param a IRect to compare ##
636#Param b IRect to compare ##
637
638#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400639
640#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400641 SkIRect test = {0, 0, 2, 2};
642 SkIRect sorted = test.makeSorted();
643 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!');
644#StdOut
645test == sorted
646##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400647##
648
Cary Clark7fc1d122017-10-09 14:07:42 -0400649#SeeAlso operator!=(const SkIRect& a, const SkIRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400650
651##
652
653# ------------------------------------------------------------------------------
654
655#Method friend bool operator!=(const SkIRect& a, const SkIRect& b)
656
Cary Clark7fc1d122017-10-09 14:07:42 -0400657Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not
658identical to the corresponding member in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400659
Cary Clark7fc1d122017-10-09 14:07:42 -0400660#Param a IRect to compare ##
661#Param b IRect to compare ##
662
663#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400664
665#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400666 SkIRect test = {2, 2, 0, 0};
667 SkIRect sorted = test.makeSorted();
668 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '=');
669#StdOut
670test != sorted
671##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400672##
673
Cary Clark7fc1d122017-10-09 14:07:42 -0400674#SeeAlso operator==(const SkIRect& a, const SkIRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400675
676##
677
678# ------------------------------------------------------------------------------
679
680#Method bool is16Bit() const
681
Cary Clark7fc1d122017-10-09 14:07:42 -0400682Returns true if all members: fLeft, fTop, fRight, and fBottom; values are
683equal to or larger than -32768 and equal to or smaller than 32767.
684
685#Return true if members fit in 16-bit word ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400686
687#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400688 SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}};
689 for (auto rect : tests) {
690 SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight,
691 rect.fBottom, rect.is16Bit() ? "fits" : "does not fit");
692}
693#StdOut
694{-32768, -32768, 32767, 32767} fits in 16 bits
695{-32768, -32768, 32768, 32768} does not fit in 16 bits
696##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400697##
698
Cary Clark7fc1d122017-10-09 14:07:42 -0400699#SeeAlso SkTFitsIn
Cary Clarkbc5697d2017-10-04 14:31:33 -0400700
701##
702
703# ------------------------------------------------------------------------------
704
705#Method void setEmpty()
706
Cary Clark7fc1d122017-10-09 14:07:42 -0400707Sets IRect to (0, 0, 0, 0).
708
709Many other rectangles are empty; if left is equal to or greater than right,
710or if top is equal to or greater than bottom. Setting all members to zero
711is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400712
713#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400714 SkIRect rect = {3, 4, 1, 2};
715 for (int i = 0; i < 2; ++i) {
716 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop,
717 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
718 rect.setEmpty();
719 }
720#StdOut
721rect: {3, 4, 1, 2} is empty
722rect: {0, 0, 0, 0} is empty
723##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400724##
725
Cary Clark7fc1d122017-10-09 14:07:42 -0400726#SeeAlso MakeEmpty SkRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400727
728##
729
730# ------------------------------------------------------------------------------
731
732#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom)
733
Cary Clark7fc1d122017-10-09 14:07:42 -0400734Sets IRect to (left, top, right, bottom).
735left and right are not sorted; left is not necessarily less than right.
736top and bottom are not sorted; top is not necessarily less than bottom.
737
738#Param left assigned to fLeft ##
739#Param top assigned to fTop ##
740#Param right assigned to fRight ##
741#Param bottom assigned to fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400742
743#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400744 SkIRect rect1 = {3, 4, 1, 2};
745 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
746 SkIRect rect2;
747 rect2.set(3, 4, 1, 2);
748 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
749#StdOut
750rect1: {3, 4, 1, 2}
751rect2: {3, 4, 1, 2}
752##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400753##
754
Cary Clark7fc1d122017-10-09 14:07:42 -0400755#SeeAlso setLTRB setXYWH SkRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400756
757##
758
759# ------------------------------------------------------------------------------
760
761#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom)
762
Cary Clark7fc1d122017-10-09 14:07:42 -0400763Sets IRect to (left, top, right, bottom).
764left and right are not sorted; left is not necessarily less than right.
765top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400766
Cary Clark7fc1d122017-10-09 14:07:42 -0400767#Param left stored in fLeft ##
768#Param top stored in fTop ##
769#Param right stored in fRight ##
770#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400771
772#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400773 SkIRect rect1 = {3, 4, 1, 2};
774 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
775 SkIRect rect2;
776 rect2.setLTRB(3, 4, 1, 2);
777 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
778#StdOut
779rect1: {3, 4, 1, 2}
780rect2: {3, 4, 1, 2}
781##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400782##
783
Cary Clark7fc1d122017-10-09 14:07:42 -0400784#SeeAlso set setXYWH SkRect::setLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400785
786##
787
788# ------------------------------------------------------------------------------
789
790#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
791
Cary Clark7fc1d122017-10-09 14:07:42 -0400792Sets IRect to
793#Formula
794(x, y, x + width, y + height)
795##
796. Does not validate input;
797width or height may be negative.
798
799#Param x stored in fLeft ##
800#Param y stored in fTop ##
801#Param width added to x and stored in fRight ##
802#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400803
804#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400805 SkIRect rect;
806 rect.setXYWH(5, 35, -15, 25);
807 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
808 rect.bottom(), rect.isEmpty() ? "true" : "false");
809 rect.sort();
810 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
811 rect.bottom(), rect.isEmpty() ? "true" : "false");
812#StdOut
813rect: 5, 35, -10, 60 isEmpty: true
814rect: -10, 35, 5, 60 isEmpty: false
815##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400816##
817
Cary Clark7fc1d122017-10-09 14:07:42 -0400818#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400819
820##
821
822# ------------------------------------------------------------------------------
823
824#Method void setLargest()
825
826Sets rectangle left and top to most negative value, and sets
827right and bottom to most positive value.
828
829#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400830 SkIRect rect;
831 rect.setLargest();
832 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
833 SkDebugf("MakeLargest isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
834 rect.outset(1, 1);
835 SkDebugf("outset isLargest: %s\n", rect.isLargest() ? "true" : "false");
836 SkDebugf("outset isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
837#StdOut
838MakeLargest isLargest: true
839MakeLargest isEmpty: false
840outset isLargest: false
841outset isEmpty: true
842##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400843##
844
Cary Clark7fc1d122017-10-09 14:07:42 -0400845#SeeAlso MakeLargest isLargest setLargestInverted SK_MinS32 SK_MaxS32
Cary Clarkbc5697d2017-10-04 14:31:33 -0400846
847##
848
849# ------------------------------------------------------------------------------
850
851#Method void setLargestInverted()
Cary Clark7fc1d122017-10-09 14:07:42 -0400852#ToDo move this to private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400853##
854
Cary Clark7fc1d122017-10-09 14:07:42 -0400855Sets rectangle left and top to most positive value, and sets
856right and bottom to most negative value. This is used internally to
857flag that a condition is met, but otherwise has no special purpose.
858
859#NoExample
860##
861
862#SeeAlso setEmpty setLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400863
864##
865
866# ------------------------------------------------------------------------------
867
868#Method SkIRect makeOffset(int32_t dx, int32_t dy) const
869
Cary Clark7fc1d122017-10-09 14:07:42 -0400870Returns IRect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -0400871
Cary Clark7fc1d122017-10-09 14:07:42 -0400872If dx is negative, IRect returned is moved to the left.
873If dx is positive, IRect returned is moved to the right.
874If dy is negative, IRect returned is moved upward.
875If dy is positive, IRect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400876
Cary Clark7fc1d122017-10-09 14:07:42 -0400877#Param dx offset added to fLeft and fRight ##
878#Param dy offset added to fTop and fBottom ##
879
880#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400881
882#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400883 SkIRect rect = { 10, 50, 20, 60 };
884 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
885 rect.bottom(), rect.isEmpty() ? "true" : "false");
886 rect = rect.makeOffset(15, 32);
887 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
888 rect.bottom(), rect.isEmpty() ? "true" : "false");
889#StdOut
890rect: 10, 50, 20, 60 isEmpty: false
891rect: 25, 82, 35, 92 isEmpty: false
892##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400893##
894
Cary Clark7fc1d122017-10-09 14:07:42 -0400895#SeeAlso offset() makeInset makeOutset SkRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -0400896
897##
898
899# ------------------------------------------------------------------------------
900
901#Method SkIRect makeInset(int32_t dx, int32_t dy) const
902
Cary Clark7fc1d122017-10-09 14:07:42 -0400903Returns IRect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -0400904
Cary Clark7fc1d122017-10-09 14:07:42 -0400905If dx is negative, IRect returned is wider.
906If dx is positive, IRect returned is narrower.
907If dy is negative, IRect returned is taller.
908If dy is positive, IRect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400909
Cary Clark7fc1d122017-10-09 14:07:42 -0400910#Param dx offset added to fLeft and subtracted from fRight ##
911#Param dy offset added to fTop and subtracted from fBottom ##
912
913#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400914
915#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400916 SkIRect rect = { 10, 50, 20, 60 };
917 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
918 rect.bottom(), rect.isEmpty() ? "true" : "false");
919 rect = rect.makeInset(15, 32);
920 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
921 rect.bottom(), rect.isEmpty() ? "true" : "false");
922#StdOut
923rect: 10, 50, 20, 60 isEmpty: false
924rect: 25, 82, 5, 28 isEmpty: true
925##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400926##
927
Cary Clark7fc1d122017-10-09 14:07:42 -0400928#SeeAlso inset() makeOffset makeOutset SkRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -0400929
930##
931
932# ------------------------------------------------------------------------------
933
934#Method SkIRect makeOutset(int32_t dx, int32_t dy) const
935
Cary Clark7fc1d122017-10-09 14:07:42 -0400936Returns IRect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -0400937
Cary Clark7fc1d122017-10-09 14:07:42 -0400938If dx is negative, IRect returned is narrower.
939If dx is positive, IRect returned is wider.
940If dy is negative, IRect returned is shorter.
941If dy is positive, IRect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400942
Cary Clark7fc1d122017-10-09 14:07:42 -0400943#Param dx offset subtracted to fLeft and added from fRight ##
944#Param dy offset subtracted to fTop and added from fBottom ##
945
946#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400947
948#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400949 SkIRect rect = { 10, 50, 20, 60 };
950 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
951 rect.bottom(), rect.isEmpty() ? "true" : "false");
952 rect = rect.makeOutset(15, 32);
953 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
954 rect.bottom(), rect.isEmpty() ? "true" : "false");
955#StdOut
956rect: 10, 50, 20, 60 isEmpty: false
957rect: -5, 18, 35, 92 isEmpty: false
958##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400959##
960
Cary Clark7fc1d122017-10-09 14:07:42 -0400961#SeeAlso outset() makeOffset makeInset SkRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -0400962
963##
964
965# ------------------------------------------------------------------------------
966
967#Method void offset(int32_t dx, int32_t dy)
968
Cary Clark7fc1d122017-10-09 14:07:42 -0400969Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400970
Cary Clark7fc1d122017-10-09 14:07:42 -0400971If dx is negative, moves IRect returned to the left.
972If dx is positive, moves IRect returned to the right.
973If dy is negative, moves IRect returned upward.
974If dy is positive, moves IRect returned downward.
975
976#Param dx offset added to fLeft and fRight ##
977#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400978
979#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400980 SkIRect rect = { 10, 14, 50, 73 };
981 rect.offset(5, 13);
982 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
983#StdOut
984rect: 15, 27, 55, 86
985##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400986##
987
Cary Clark7fc1d122017-10-09 14:07:42 -0400988#SeeAlso offsetTo makeOffset SkRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -0400989
990##
991
992# ------------------------------------------------------------------------------
993
994#Method void offset(const SkIPoint& delta)
995
Cary Clark7fc1d122017-10-09 14:07:42 -0400996Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
997fTop, fBottom.
998
999If delta.fX is negative, moves IRect returned to the left.
1000If delta.fX is positive, moves IRect returned to the right.
1001If delta.fY is negative, moves IRect returned upward.
1002If delta.fY is positive, moves IRect returned downward.
1003
1004#Param delta offset added to IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001005
1006#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001007 SkIRect rect = { 10, 14, 50, 73 };
1008 rect.offset({5, 13});
1009 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1010#StdOut
1011rect: 15, 27, 55, 86
1012##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001013##
1014
Cary Clark7fc1d122017-10-09 14:07:42 -04001015#SeeAlso offsetTo makeOffset SkRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001016
1017##
1018
1019# ------------------------------------------------------------------------------
1020
1021#Method void offsetTo(int32_t newX, int32_t newY)
1022
Cary Clark7fc1d122017-10-09 14:07:42 -04001023Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height
1024are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001025
Cary Clark7fc1d122017-10-09 14:07:42 -04001026#Param newX stored in fLeft, preserving width() ##
1027#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001028
1029#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001030 SkIRect rect = { 10, 14, 50, 73 };
1031 rect.offsetTo(15, 27);
1032 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1033#StdOut
1034rect: 15, 27, 55, 86
1035##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001036##
1037
Cary Clark7fc1d122017-10-09 14:07:42 -04001038#SeeAlso offset makeOffset setXYWH SkRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001039
1040##
1041
1042# ------------------------------------------------------------------------------
1043
1044#Method void inset(int32_t dx, int32_t dy)
1045
Cary Clark7fc1d122017-10-09 14:07:42 -04001046Insets IRect by (dx,dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001047
Cary Clark7fc1d122017-10-09 14:07:42 -04001048If dx is positive, makes IRect narrower.
1049If dx is negative, makes IRect wider.
1050If dy is positive, makes IRect shorter.
1051If dy is negative, makes IRect taller.
1052
1053#Param dx offset added to fLeft and subtracted from fRight ##
1054#Param dy offset added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001055
1056#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001057 SkIRect rect = { 10, 14, 50, 73 };
1058 rect.inset(5, 13);
1059 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1060#StdOut
1061rect: 15, 27, 45, 60
1062##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001063##
1064
Cary Clark7fc1d122017-10-09 14:07:42 -04001065#SeeAlso outset makeInset SkRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001066
1067##
1068
1069# ------------------------------------------------------------------------------
1070
1071#Method void outset(int32_t dx, int32_t dy)
1072
Cary Clark7fc1d122017-10-09 14:07:42 -04001073Outsets IRect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001074
Cary Clark7fc1d122017-10-09 14:07:42 -04001075If dx is positive, makes Rect wider.
1076If dx is negative, makes Rect narrower.
1077If dy is positive, makes Rect taller.
1078If dy is negative, makes Rect shorter.
1079
1080#Param dx subtracted to fLeft and added from fRight ##
1081#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001082
1083#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001084 SkIRect rect = { 10, 14, 50, 73 };
1085 rect.outset(5, 13);
1086 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1087#StdOut
1088rect: 5, 1, 55, 86
1089##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001090##
1091
Cary Clark7fc1d122017-10-09 14:07:42 -04001092#SeeAlso inset makeOutset SkRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001093
1094##
1095
1096# ------------------------------------------------------------------------------
1097
1098#Method bool quickReject(int l, int t, int r, int b) const
1099
Cary Clark7fc1d122017-10-09 14:07:42 -04001100Constructs IRect (l, t, r, b) and returns true if constructed IRect does not
1101intersect IRect. Does not check to see if construction or IRect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001102
Cary Clark7fc1d122017-10-09 14:07:42 -04001103Is implemented with short circuit logic so that true can be returned after
1104a single compare.
1105
1106#Param l x minimum of constructed Rect ##
1107#Param t y minimum of constructed Rect ##
1108#Param r x maximum of constructed Rect ##
1109#Param b y maximum of constructed Rect ##
1110
1111#Return true if construction and IRect have no area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001112
1113#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001114#Description
1115quickReject is the complement of Intersects.
1116##
1117 const SkIRect rect = {7, 11, 13, 17};
1118 const int32_t* r = &rect.fLeft;
1119 const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } };
1120 for (auto& test : tests) {
1121 const int32_t* t = &test.fLeft;
1122 SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n",
1123 r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3],
1124 rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false",
1125 SkIRect::Intersects(rect, test) ? "true" : "false");
1126 }
1127#StdOut
1128rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false
1129rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false
1130rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true
1131##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001132##
1133
Cary Clark7fc1d122017-10-09 14:07:42 -04001134#SeeAlso Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001135
1136##
1137
1138# ------------------------------------------------------------------------------
1139
1140#Method bool contains(int32_t x, int32_t y) const
1141
Cary Clark7fc1d122017-10-09 14:07:42 -04001142Returns true if
1143#Formula
1144fLeft <= x < fRight && fTop <= y < fBottom
1145##
1146.
1147Returns false if Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001148
Cary Clark7fc1d122017-10-09 14:07:42 -04001149Considers input to describe constructed IRect (x, y, x + 1, y + 1) and
1150returns true if constructed area is completely enclosed by IRect area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001151
Cary Clark7fc1d122017-10-09 14:07:42 -04001152#Param x test Point x-coordinate ##
1153#Param y test Point y-coordinate ##
1154
1155#Return true if (x, y) is inside IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001156
1157#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001158 SkIRect rect = { 30, 50, 40, 60 };
1159 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} };
1160 for (auto pt : pts) {
1161 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n",
1162 rect.left(), rect.top(), rect.right(), rect.bottom(),
1163 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y());
1164 }
1165#StdOut
1166rect: (30, 50, 40, 60) contains (30, 50)
1167rect: (30, 50, 40, 60) does not contain (40, 50)
1168rect: (30, 50, 40, 60) does not contain (30, 60)
1169##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001170##
1171
Cary Clark7fc1d122017-10-09 14:07:42 -04001172#SeeAlso containsNoEmptyCheck SkRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001173
1174##
1175
1176# ------------------------------------------------------------------------------
1177
1178#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const
1179
Cary Clark7fc1d122017-10-09 14:07:42 -04001180Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1181construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001182
Cary Clark7fc1d122017-10-09 14:07:42 -04001183Returns true if Rect contains construction.
1184Returns false if Rect is empty or construction is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001185
Cary Clark7fc1d122017-10-09 14:07:42 -04001186#Param left x minimum of constructed Rect ##
1187#Param top y minimum of constructed Rect ##
1188#Param right x maximum of constructed Rect ##
1189#Param bottom y maximum of constructed Rect ##
1190
1191#Return true if all sides of IRect are outside construction ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001192
1193#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001194 SkIRect rect = { 30, 50, 40, 60 };
1195 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1196 for (auto contained : tests) {
1197 bool success = rect.contains(
1198 contained.left(), contained.top(), contained.right(), contained.bottom());
1199 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1200 rect.left(), rect.top(), rect.right(), rect.bottom(),
1201 success ? "contains" : "does not contain",
1202 contained.left(), contained.top(), contained.right(), contained.bottom());
1203 }
1204#StdOut
1205rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1206rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1207rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1208##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001209##
1210
Cary Clark7fc1d122017-10-09 14:07:42 -04001211#SeeAlso containsNoEmptyCheck SkRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001212
1213##
1214
1215# ------------------------------------------------------------------------------
1216
1217#Method bool contains(const SkIRect& r) const
1218
Cary Clark7fc1d122017-10-09 14:07:42 -04001219Returns true if Rect contains r.
1220Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001221
Cary Clark7fc1d122017-10-09 14:07:42 -04001222Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001223
Cary Clark7fc1d122017-10-09 14:07:42 -04001224#Param r IRect contained ##
1225
1226#Return true if all sides of IRect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001227
1228#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001229 SkIRect rect = { 30, 50, 40, 60 };
1230 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1231 for (auto contained : tests) {
1232 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1233 rect.left(), rect.top(), rect.right(), rect.bottom(),
1234 rect.contains(contained) ? "contains" : "does not contain",
1235 contained.left(), contained.top(), contained.right(), contained.bottom());
1236 }
1237#StdOut
1238rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1239rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1240rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1241##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001242##
1243
Cary Clark7fc1d122017-10-09 14:07:42 -04001244#SeeAlso containsNoEmptyCheck SkRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001245
1246##
1247
1248# ------------------------------------------------------------------------------
1249
1250#Method bool contains(const SkRect& r) const
1251
Cary Clark7fc1d122017-10-09 14:07:42 -04001252Returns true if Rect contains r.
1253Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001254
Cary Clark7fc1d122017-10-09 14:07:42 -04001255Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001256
Cary Clark7fc1d122017-10-09 14:07:42 -04001257#Param r Rect contained ##
1258
1259#Return true if all sides of IRect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001260
1261#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001262 SkIRect rect = { 30, 50, 40, 60 };
1263 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1264 for (auto contained : tests) {
1265 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n",
1266 rect.left(), rect.top(), rect.right(), rect.bottom(),
1267 rect.contains(contained) ? "contains" : "does not contain",
1268 contained.left(), contained.top(), contained.right(), contained.bottom());
1269 }
1270#StdOut
1271rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1272rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1273rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1274##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001275##
1276
Cary Clark7fc1d122017-10-09 14:07:42 -04001277#SeeAlso containsNoEmptyCheck SkRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001278
1279##
1280
1281# ------------------------------------------------------------------------------
1282
1283#Method bool containsNoEmptyCheck(int32_t left, int32_t top,
1284 int32_t right, int32_t bottom) const
1285
Cary Clark7fc1d122017-10-09 14:07:42 -04001286Constructs IRect from (left, top, right, bottom). Does not sort
1287construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001288
Cary Clark7fc1d122017-10-09 14:07:42 -04001289Returns true if Rect contains construction.
1290Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001291
Cary Clark7fc1d122017-10-09 14:07:42 -04001292Return is undefined if Rect is empty or construction is empty.
1293
1294#Param left x minimum of constructed Rect ##
1295#Param top y minimum of constructed Rect ##
1296#Param right x maximum of constructed Rect ##
1297#Param bottom y maximum of constructed Rect ##
1298
1299#Return true if all sides of IRect are outside construction ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001300
1301#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001302 SkIRect rect = { 30, 50, 40, 60 };
1303 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1304 for (auto contained : tests) {
1305 bool success = rect.containsNoEmptyCheck(
1306 contained.left(), contained.top(), contained.right(), contained.bottom());
1307 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1308 rect.left(), rect.top(), rect.right(), rect.bottom(),
1309 success ? "contains" : "does not contain",
1310 contained.left(), contained.top(), contained.right(), contained.bottom());
1311 }
1312#StdOut
1313rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1314rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1315rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1316##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001317##
1318
Cary Clark7fc1d122017-10-09 14:07:42 -04001319#SeeAlso contains SkRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001320
1321##
1322
1323# ------------------------------------------------------------------------------
1324
1325#Method bool containsNoEmptyCheck(const SkIRect& r) const
1326
Cary Clark7fc1d122017-10-09 14:07:42 -04001327Returns true if Rect contains construction.
1328Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001329
Cary Clark7fc1d122017-10-09 14:07:42 -04001330Return is undefined if Rect is empty or construction is empty.
1331
1332#Param r Rect contained ##
1333
1334#Return true if all sides of IRect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001335
1336#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001337 SkIRect rect = { 30, 50, 40, 60 };
1338 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1339 for (auto contained : tests) {
1340 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n",
1341 rect.left(), rect.top(), rect.right(), rect.bottom(),
1342 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain",
1343 contained.left(), contained.top(), contained.right(), contained.bottom());
1344 }
1345#StdOut
1346rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1347rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1348rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1349##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001350##
1351
Cary Clark7fc1d122017-10-09 14:07:42 -04001352#SeeAlso contains SkRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001353
1354##
1355
Cary Clark7fc1d122017-10-09 14:07:42 -04001356#Topic Intersection
1357
1358IRects intersect when they enclose a common area. To intersect, each of the pair
1359must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1360empty() returns false. The intersection of IRect a and IRect b can be described by:
1361#Formula
1362(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1363 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1364##
1365The intersection is only meaningful if the resulting IRect is not empty and
1366describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1367
Cary Clarkbc5697d2017-10-04 14:31:33 -04001368# ------------------------------------------------------------------------------
1369
1370#Method bool intersect(const SkIRect& r)
1371
Cary Clark7fc1d122017-10-09 14:07:42 -04001372Returns true if IRect intersects r, and sets IRect to intersection.
1373Returns false if IRect does not intersect r, and leaves IRect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001374
Cary Clark7fc1d122017-10-09 14:07:42 -04001375Returns false if either r or IRect is empty, leaving IRect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001376
Cary Clark7fc1d122017-10-09 14:07:42 -04001377#Param r limit of result ##
1378
1379#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001380
1381#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001382#Description
1383Two SkDebugf calls are required. If the calls are combined, their arguments
1384may not be evaluated in left to right order: the printed intersection may
1385be before or after the call to intersect.
1386##
1387 SkIRect leftRect = { 10, 40, 50, 80 };
1388 SkIRect rightRect = { 30, 60, 70, 90 };
1389 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1390 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1391 leftRect.right(), leftRect.bottom());
1392#StdOut
1393 intersection: 30, 60, 50, 80
1394##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001395##
1396
Cary Clark7fc1d122017-10-09 14:07:42 -04001397#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001398
1399##
1400
1401# ------------------------------------------------------------------------------
1402
1403#Method bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b)
1404
Cary Clark7fc1d122017-10-09 14:07:42 -04001405Returns true if a intersects b, and sets IRect to intersection.
1406Returns false if a does not intersect b, and leaves IRect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001407
Cary Clark7fc1d122017-10-09 14:07:42 -04001408Returns false if either a or b is empty, leaving IRect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001409
Cary Clark7fc1d122017-10-09 14:07:42 -04001410#Param a IRect to intersect ##
1411#Param b IRect to intersect ##
1412
1413#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001414
1415#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001416 SkIRect result;
1417 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1418 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ",
1419 result.left(), result.top(), result.right(), result.bottom());
1420#StdOut
1421 intersection: 30, 60, 50, 80
1422##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001423##
1424
Cary Clark7fc1d122017-10-09 14:07:42 -04001425#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001426
1427##
1428
1429# ------------------------------------------------------------------------------
1430
1431#Method bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1432
Cary Clark7fc1d122017-10-09 14:07:42 -04001433Returns true if a intersects b, and sets IRect to intersection.
1434Returns false if a does not intersect b, and leaves IRect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001435
Cary Clark7fc1d122017-10-09 14:07:42 -04001436Asserts if either a or b is empty, and if SK_DEBUG is defined.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001437
Cary Clark7fc1d122017-10-09 14:07:42 -04001438#Param a IRect to intersect ##
1439#Param b IRect to intersect ##
1440
1441#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001442
1443#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001444 SkIRect result;
1445 bool intersected = result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1446 SkDebugf("intersection: %d, %d, %d, %d\n",
1447 result.left(), result.top(), result.right(), result.bottom());
1448#StdOut
1449 intersection: 30, 60, 50, 80
1450##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001451##
1452
Cary Clark7fc1d122017-10-09 14:07:42 -04001453#SeeAlso Intersects intersect join SkRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001454
1455##
1456
1457# ------------------------------------------------------------------------------
1458
1459#Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom)
1460
Cary Clark7fc1d122017-10-09 14:07:42 -04001461Constructs IRect to intersect from (left, top, right, bottom). Does not sort
1462construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001463
Cary Clark7fc1d122017-10-09 14:07:42 -04001464Returns true if IRect intersects construction, and sets IRect to intersection.
1465Returns false if IRect does not intersect construction, and leaves IRect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001466
Cary Clark7fc1d122017-10-09 14:07:42 -04001467Returns false if either construction or IRect is empty, leaving IRect unchanged.
1468
1469#Param left x minimum of constructed IRect ##
1470#Param top y minimum of constructed IRect ##
1471#Param right x maximum of constructed IRect ##
1472#Param bottom y maximum of constructed IRect ##
1473
1474#Return true if construction and IRect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001475
1476#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001477#Description
1478Two SkDebugf calls are required. If the calls are combined, their arguments
1479may not be evaluated in left to right order: the printed intersection may
1480be before or after the call to intersect.
1481##
1482 SkIRect leftRect = { 10, 40, 50, 80 };
1483 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1484 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(),
1485 leftRect.right(), leftRect.bottom());
1486#StdOut
1487 intersection: 30, 60, 50, 80
1488##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001489##
1490
Cary Clark7fc1d122017-10-09 14:07:42 -04001491#SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001492
1493##
1494
1495# ------------------------------------------------------------------------------
1496
1497#Method static bool Intersects(const SkIRect& a, const SkIRect& b)
1498
Cary Clark7fc1d122017-10-09 14:07:42 -04001499Returns true if a intersects b.
1500Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001501
Cary Clark7fc1d122017-10-09 14:07:42 -04001502#Param a IRect to intersect ##
1503#Param b IRect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001504
Cary Clark7fc1d122017-10-09 14:07:42 -04001505#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001506
1507#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001508 SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1509#StdOut
1510 intersection
1511##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001512##
1513
Cary Clark7fc1d122017-10-09 14:07:42 -04001514#SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001515
1516##
1517
1518# ------------------------------------------------------------------------------
1519
1520#Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b)
1521
Cary Clark7fc1d122017-10-09 14:07:42 -04001522Returns true if a intersects b.
1523Asserts if either a or b is empty, and if SK_DEBUG is defined.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001524
Cary Clark7fc1d122017-10-09 14:07:42 -04001525#Param a IRect to intersect ##
1526#Param b IRect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001527
Cary Clark7fc1d122017-10-09 14:07:42 -04001528#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001529
1530#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001531 SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck(
1532 {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1533#StdOut
1534 intersection
1535##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001536##
1537
Cary Clark7fc1d122017-10-09 14:07:42 -04001538#SeeAlso Intersects intersect SkRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001539
1540##
1541
Cary Clark7fc1d122017-10-09 14:07:42 -04001542#Topic Intersection ##
1543
Cary Clarkbc5697d2017-10-04 14:31:33 -04001544# ------------------------------------------------------------------------------
1545
1546#Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom)
1547
Cary Clark7fc1d122017-10-09 14:07:42 -04001548Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1549construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001550
Cary Clark7fc1d122017-10-09 14:07:42 -04001551Sets Rect to the union of itself and the construction.
1552
1553Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1554Rect to construction.
1555
1556#Param left x minimum of constructed Rect ##
1557#Param top y minimum of constructed Rect ##
1558#Param right x maximum of constructed Rect ##
1559#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001560
1561#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001562 SkIRect rect = { 10, 20, 15, 25};
1563 rect.join(50, 60, 55, 65);
1564 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1565#StdOut
1566 join: 10, 20, 55, 65
1567##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001568##
1569
Cary Clark7fc1d122017-10-09 14:07:42 -04001570#SeeAlso set SkRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001571
1572##
1573
1574# ------------------------------------------------------------------------------
1575
1576#Method void join(const SkIRect& r)
1577
Cary Clark7fc1d122017-10-09 14:07:42 -04001578Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001579
Cary Clark7fc1d122017-10-09 14:07:42 -04001580Has no effect if r is empty. Otherwise, if Rect is empty, sets Rect to r.
1581
1582#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001583
1584#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001585 SkIRect rect = { 10, 20, 15, 25};
1586 rect.join({50, 60, 55, 65});
1587 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1588#StdOut
1589 join: 10, 20, 55, 65
1590##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001591##
1592
Cary Clark7fc1d122017-10-09 14:07:42 -04001593#SeeAlso set SkRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001594
1595##
1596
1597# ------------------------------------------------------------------------------
1598
1599#Method void sort()
1600
Cary Clark7fc1d122017-10-09 14:07:42 -04001601Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
1602fTop and fBottom if fTop is greater than fBottom. Result may be empty,
1603and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001604
1605#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001606 SkIRect rect = { 30, 50, 20, 10 };
1607 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1608 rect.sort();
1609 SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1610#StdOut
1611rect: 30, 50, 20, 10
1612sorted: 20, 10, 30, 50
1613##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001614##
1615
Cary Clark7fc1d122017-10-09 14:07:42 -04001616#SeeAlso makeSorted SkRect::sort
Cary Clarkbc5697d2017-10-04 14:31:33 -04001617
1618##
1619
1620# ------------------------------------------------------------------------------
1621
1622#Method SkIRect makeSorted() const
1623
Cary Clark7fc1d122017-10-09 14:07:42 -04001624Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
1625with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
1626and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001627
Cary Clark7fc1d122017-10-09 14:07:42 -04001628#Return sorted IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001629
1630#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001631 SkIRect rect = { 30, 50, 20, 10 };
1632 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1633 SkIRect sort = rect.makeSorted();
1634 SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
1635#StdOut
1636rect: 30, 50, 20, 10
1637sorted: 20, 10, 30, 50
1638##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001639##
1640
Cary Clark7fc1d122017-10-09 14:07:42 -04001641#SeeAlso sort SkRect::makeSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04001642
1643##
1644
1645# ------------------------------------------------------------------------------
1646
1647#Method static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect()
1648
Cary Clark7fc1d122017-10-09 14:07:42 -04001649Returns a reference to immutable empty IRect, set to (0, 0, 0, 0).
1650
1651#Return global IRect set to all zeroes ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001652
1653#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001654 const SkIRect& rect = SkIRect::EmptyIRect();
1655 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1656#StdOut
1657rect: 0, 0, 0, 0
1658##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001659##
1660
Cary Clark7fc1d122017-10-09 14:07:42 -04001661#SeeAlso MakeEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -04001662
1663##
1664
1665#Struct SkIRect ##
1666
1667#Topic IRect ##