blob: 7dc1e3776afa50307d70d7911b173e2f81892cfd [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Rect
2#Alias Rects
3#Alias Rect_Reference
4
5#Struct SkRect
6
Cary Clark7fc1d122017-10-09 14:07:42 -04007SkRect holds four SkScalar coordinates describing the upper and
8lower bounds of a rectangle. SkRect may be created from outer bounds or
9from position, width, and height. SkRect describes an area; if its right
10is less than or equal to its left, or if its bottom is less than or equal to
11its top, it is considered empty.
12
13# move to topic about MakeIWH and friends
14SkRect can be constructed from int values to avoid compiler warnings that
15integer input cannot convert to SkScalar without loss of precision.
16
Cary Clarkbc5697d2017-10-04 14:31:33 -040017#Topic Overview
18
19#Subtopic Subtopics
20#ToDo manually add subtopics ##
21#Table
22#Legend
23# topics # description ##
24#Legend ##
25#Table ##
26##
27
28#Subtopic Operators
29#Table
30#Legend
Cary Clark884dd7d2017-10-11 10:37:52 -040031# description # function ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040032#Legend ##
Cary Clark884dd7d2017-10-11 10:37:52 -040033# bool operator!=(const SkRect& a, const SkRect& b) # Returns true if member bits are unequal. ##
34# bool operator==(const SkRect& a, const SkRect& b) # Returns true if member bits are equal. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040035#Table ##
36#Subtopic ##
37
38#Subtopic Member_Functions
39#Table
40#Legend
Cary Clark7fc1d122017-10-09 14:07:42 -040041# description # function ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040042#Legend ##
Cary Clark7fc1d122017-10-09 14:07:42 -040043# Intersects # Returns true if areas overlap. ##
44# Make # Constructs from ISize returning (0, 0, width, height). ##
45# MakeEmpty # Constructs from bounds of (0, 0, 0, 0). ##
46# MakeFromIRect # Deprecated. ##
47# MakeIWH # Constructs from int input returning (0, 0, width, height). ##
48# MakeLTRB # Constructs from SkScalar left, top, right, bottom. ##
49# MakeLargest # Constructs (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
Cary Clark884dd7d2017-10-11 10:37:52 -040050# MakeLargestS32 # Constructs largest signed integers that fit in 32-bit float. ##
Cary Clark7fc1d122017-10-09 14:07:42 -040051# MakeSize # Constructs from Size returning (0, 0, width, height). ##
52# MakeWH # Constructs from SkScalar input returning (0, 0, width, height). ##
53# MakeXYWH # Constructs from SkScalar input returning (x, y, width, height). ##
54# asScalars # Returns pointer to members as array. ##
55# bottom() # Returns larger bounds in y, if sorted. ##
56# centerX # Returns midpoint in x. ##
57# centerY # Returns midpoint in y. ##
58# contains() # Returns true if points are equal or inside. ##
59# dump() # Sends text representation using floats to standard output. ##
60# dumpHex # Sends text representation using hexadecimal to standard output. ##
61# growToInclude # Sets to union of bounds and one or more Points. ##
62# height # Returns span in y. ##
63# inset() # Moves the sides symmetrically about the center. ##
64# intersect() # Sets to shared area; returns true if not empty. ##
65# intersects() # Returns true if areas overlap. ##
66# isEmpty # Returns true if width or height are zero or negative. ##
67# isFinite # Returns true if no member is infinite or NaN. ##
68# isLargest # Returns equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
69# isSorted # Returns true if width or height are zero or positive. ##
70# iset() # Sets to int input (left, top, right, bottom). ##
71# isetWH # Sets to int input (0, 0, width, height). ##
72# join() # Sets to union of bounds. ##
73# joinNonEmptyArg # Sets to union of bounds, asserting that argument is not empty. ##
74# joinPossiblyEmptyRect # Sets to union of bounds. Skips empty check for both. ##
75# left() # Returns smaller bounds in x, if sorted. ##
76# makeInset # Constructs from sides moved symmetrically about the center. ##
77# makeOffset # Constructs from translated sides. ##
78# makeOutset # Constructs from sides moved symmetrically about the center. ##
79# makeSorted # Constructs, ordering sides from smaller to larger. ##
80# offset() # Translates sides without changing width and height. ##
81# offsetTo # Translates to (x, y) without changing width and height. ##
82# outset() # Moves the sides symmetrically about the center. ##
83# right() # Returns larger bounds in x, if sorted. ##
84# round() # Sets members to nearest integer value. ##
85# roundIn # Sets members to nearest integer value towards opposite. ##
86# roundOut # Sets members to nearest integer value away from opposite. ##
87# set() # Sets to SkScalar input (left, top, right, bottom) and others. ##
88# setBounds # Sets to upper and lower limits of Point array. ##
89# setBoundsCheck # Sets to upper and lower limits of Point array. ##
90# setEmpty # Sets to (0, 0, 0, 0). ##
91# setLTRB # Sets to SkScalar input (left, top, right, bottom). ##
92# setLargest # Sets to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
93# setLargestInverted # Sets to (SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin). ##
94# setWH # Sets to SkScalar input (0, 0, width, height). ##
95# setXYWH # Sets to SkScalar input (x, y, width, height). ##
96# sort() # Orders sides from smaller to larger. ##
97# toQuad # Returns four corners as Point. ##
98# top() # Returns smaller bounds in y, if sorted. ##
99# width() # Returns span in x. ##
100# x() # Returns bounds left. ##
101# y() # Returns bounds top. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400102#Table ##
103#Subtopic ##
104
105#Topic ##
106
107#Member SkScalar fLeft
Cary Clark7fc1d122017-10-09 14:07:42 -0400108May contain any value, including infinities and NaN. The smaller of the
109horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400110##
111
112#Member SkScalar fTop
Cary Clark7fc1d122017-10-09 14:07:42 -0400113May contain any value, including infinities and NaN. The smaller of the
114vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400115##
116
117#Member SkScalar fRight
Cary Clark7fc1d122017-10-09 14:07:42 -0400118May contain any value, including infinities and NaN. The larger of the
119horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400120##
121
122#Member SkScalar fBottom
Cary Clark7fc1d122017-10-09 14:07:42 -0400123May contain any value, including infinities and NaN. The larger of the
124vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400125##
126
127# ------------------------------------------------------------------------------
128
129#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
130
Cary Clark7fc1d122017-10-09 14:07:42 -0400131Returns constructed Rect set to (0, 0, 0, 0).
132Many other rectangles are empty; if left is equal to or greater than right,
133or if top is equal to or greater than bottom. Setting all members to zero
134is a convenience, but does not designate a special empty rectangle.
135
136#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400137
138#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400139 SkRect rect = SkRect::MakeEmpty();
140 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
141 rect.offset(10, 10);
142 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
143 rect.inset(10, 10);
144 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
145 rect.outset(20, 20);
146 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
147#StdOut
148MakeEmpty isEmpty: true
149offset rect isEmpty: true
150inset rect isEmpty: true
151outset rect isEmpty: false
152##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400153##
154
Cary Clark7fc1d122017-10-09 14:07:42 -0400155#SeeAlso isEmpty setEmpty setLargestInverted SkIRect::MakeEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400156
157##
158
159# ------------------------------------------------------------------------------
160
161#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
162
Cary Clark7fc1d122017-10-09 14:07:42 -0400163Returns constructed Rect setting left and top to most negative finite value, and
164setting right and bottom to most positive finite value.
165
166#Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400167
168#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400169 SkRect rect = SkRect::MakeLargest();
170 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
171 SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
172 rect.outset(1e31, 1e31);
173 SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
174 SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
175 rect.outset(1e32, 1e32);
176 SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
177 SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
178#StdOut
179MakeLargest isLargest: true
180MakeLargest isFinite: true
181outset a little isLargest: true
182outset a little isFinite: true
183outset a little more isLargest: false
184outset a little more isFinite: false
185##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400186##
187
Cary Clark884dd7d2017-10-11 10:37:52 -0400188#SeeAlso MakeLargestS32 isLargest setLargest SkIRect::MakeLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400189
190##
191
192# ------------------------------------------------------------------------------
193
Cary Clark884dd7d2017-10-11 10:37:52 -0400194#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargestS32()
195
196Returns constructed Rect that can be represented exactly with IRect. The left
197and top are set to the most negative integer value that fits in a 32-bit float,
198and the right and bottom are set to the most positive finite value that fits in
199a 32-bit float.
200
201These are the largest values for which round() is well defined.
202
203#Return bounds (SK_MinS32FitsInFloat, SK_MinS32FitsInFloat,
204 SK_MaxS32FitsInFloat, SK_MaxS32FitsInFloat)
205##
206
207#Example
208 SkRect f_rect = SkRect::MakeLargestS32();
209 SkIRect i_rect = f_rect.round();
210 SkRect r_rect = SkRect::Make(i_rect);
211 SkDebugf("f_rect %c= r_rect\n", f_rect == r_rect ? '=' : '!');
212#StdOut
213f_rect == r_rect
214##
215##
216
217#SeeAlso MakeLargest isLargest setLargest SkIRect::MakeLargest
218
219##
220
221# ------------------------------------------------------------------------------
222
223#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400224
Cary Clark7fc1d122017-10-09 14:07:42 -0400225Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
226validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400227
Cary Clark7fc1d122017-10-09 14:07:42 -0400228Passing integer values may generate a compiler warning since Rect cannot
229represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
230
231#Param w SkScalar width of constructed Rect ##
232#Param h SkScalar height of constructed Rect ##
233
234#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400235
236#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400237 SkRect rect1 = SkRect::MakeWH(25, 35);
238 SkRect rect2 = SkRect::MakeIWH(25, 35);
239 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
240 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
241 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
242 "" : "not ");
243#StdOut
244all equal
245##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400246##
247
Cary Clark7fc1d122017-10-09 14:07:42 -0400248#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400249
250##
251
252# ------------------------------------------------------------------------------
253
254#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
255
Cary Clark7fc1d122017-10-09 14:07:42 -0400256Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
257input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400258
Cary Clark7fc1d122017-10-09 14:07:42 -0400259Use to avoid a compiler warning that input may lose precision when stored.
260Use SkIRect for an exact integer rectangle.
261
262#Param w integer width of constructed Rect ##
263#Param h integer height of constructed Rect ##
264
265#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400266
267#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400268 SkIRect i_rect = SkIRect::MakeWH(25, 35);
269 SkRect f_rect = SkRect::MakeIWH(25, 35);
270 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
271 i_rect = SkIRect::MakeWH(125000111, 0);
272 f_rect = SkRect::MakeIWH(125000111, 0);
273 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
274#StdOut
275i_rect width: 25 f_rect width:25
276i_rect width: 125000111 f_rect width:125000112
277##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400278##
279
Cary Clark7fc1d122017-10-09 14:07:42 -0400280#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400281
282##
283
284# ------------------------------------------------------------------------------
285
Cary Clark884dd7d2017-10-11 10:37:52 -0400286#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400287
Cary Clark7fc1d122017-10-09 14:07:42 -0400288Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
289validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400290
Cary Clark7fc1d122017-10-09 14:07:42 -0400291#Param size SkScalar values for Rect width and height ##
292
293#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
295#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400296 SkSize size = {25.5f, 35.5f};
297 SkRect rect = SkRect::MakeSize(size);
298 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
299 SkISize floor = size.toFloor();
300 rect = SkRect::MakeSize(SkSize::Make(floor));
301 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
302#StdOut
303rect width: 25.5 height: 35.5
304floor width: 25 height: 35
305##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400306##
307
Cary Clark7fc1d122017-10-09 14:07:42 -0400308#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309
310##
311
312# ------------------------------------------------------------------------------
313
314#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
315 SkScalar b)
316
Cary Clark7fc1d122017-10-09 14:07:42 -0400317Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
318result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400319
Cary Clark7fc1d122017-10-09 14:07:42 -0400320#Param l SkScalar stored in fLeft ##
321#Param t SkScalar stored in fTop ##
322#Param r SkScalar stored in fRight ##
323#Param b SkScalar stored in fBottom ##
324
325#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400326
327#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400328 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
329 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
330 rect.bottom(), rect.isEmpty() ? "true" : "false");
331 rect.sort();
332 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
333 rect.bottom(), rect.isEmpty() ? "true" : "false");
334#StdOut
335rect: 5, 35, 15, 25 isEmpty: true
336rect: 5, 25, 15, 35 isEmpty: false
337##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400338##
339
Cary Clark7fc1d122017-10-09 14:07:42 -0400340#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400341
342##
343
344# ------------------------------------------------------------------------------
345
Cary Clark884dd7d2017-10-11 10:37:52 -0400346#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400347
Cary Clark7fc1d122017-10-09 14:07:42 -0400348Returns constructed Rect set to
349#Formula
350(x, y, x + w, y + h)
351##
352. Does not validate input;
353w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400354
Cary Clark7fc1d122017-10-09 14:07:42 -0400355#Param x stored in fLeft ##
356#Param y stored in fTop ##
357#Param w added to x and stored in fRight ##
358#Param h added to y and stored in fBottom ##
359
Cary Clark884dd7d2017-10-11 10:37:52 -0400360#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400361
362#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400363 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
364 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
365 rect.bottom(), rect.isEmpty() ? "true" : "false");
366 rect.sort();
367 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
368 rect.bottom(), rect.isEmpty() ? "true" : "false");
369#StdOut
370rect: 5, 35, -10, 60 isEmpty: true
371rect: -10, 35, 5, 60 isEmpty: false
372##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400373##
374
Cary Clark7fc1d122017-10-09 14:07:42 -0400375#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400376
377##
378
379# ------------------------------------------------------------------------------
380
381#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
382
Cary Clark7fc1d122017-10-09 14:07:42 -0400383Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400384
Cary Clark7fc1d122017-10-09 14:07:42 -0400385#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400386##
387
Cary Clark7fc1d122017-10-09 14:07:42 -0400388#Param irect integer rect ##
389
390#Return irect as SkRect ##
391
392#NoExample
393##
394
395#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400396
397##
398
399# ------------------------------------------------------------------------------
400
401#Method static SkRect Make(const SkISize& size)
402
Cary Clark7fc1d122017-10-09 14:07:42 -0400403Returns constructed IRect set to (0, 0, size.width(), size.height()).
404Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400405
Cary Clark7fc1d122017-10-09 14:07:42 -0400406#Param size integer values for Rect width and height ##
407
408#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400409
410#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400411 SkRect rect1 = SkRect::MakeSize({2, 35});
412 SkRect rect2 = SkRect::MakeIWH(2, 35);
413 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
414#StdOut
415rect1 == rect2
416##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400417##
418
Cary Clark7fc1d122017-10-09 14:07:42 -0400419#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400420
421##
422
423# ------------------------------------------------------------------------------
424
425#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
426
Cary Clark7fc1d122017-10-09 14:07:42 -0400427Returns constructed IRect set to irect, promoting integers to Scalar.
428Does not validate input; fLeft may be greater than fRight, fTop may be greater
429than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400430
Cary Clark7fc1d122017-10-09 14:07:42 -0400431#Param irect integer unsorted bounds ##
432
433#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400434
435#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400436 SkIRect i_rect1 = {2, 35, 22, 53};
437 SkRect f_rect = SkRect::Make(i_rect1);
438 f_rect.offset(0.49f, 0.49f);
439 SkIRect i_rect2;
440 f_rect.round(&i_rect2);
441 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400442##
443
Cary Clark7fc1d122017-10-09 14:07:42 -0400444#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400445
446##
447
448# ------------------------------------------------------------------------------
449
450#Method bool isEmpty() const
451
Cary Clark7fc1d122017-10-09 14:07:42 -0400452Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
453to or greater than fBottom. Call sort() to reverse rectangles with negative
454width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400455
Cary Clark7fc1d122017-10-09 14:07:42 -0400456#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400457
458#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400459 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
460 for (auto rect : tests) {
461 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
462 rect.bottom(), rect.isEmpty() ? "" : " not");
463 rect.sort();
464 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
465 rect.bottom(), rect.isEmpty() ? "" : " not");
466 }
467#StdOut
468rect: {20, 40, 10, 50} is empty
469sorted: {10, 40, 20, 50} is not empty
470rect: {20, 40, 20, 50} is empty
471sorted: {20, 40, 20, 50} is empty
472##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400473##
474
Cary Clark7fc1d122017-10-09 14:07:42 -0400475#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400476
477##
478
479# ------------------------------------------------------------------------------
480
481#Method bool isSorted() const
482
Cary Clark7fc1d122017-10-09 14:07:42 -0400483Returns true if fLeft is equal to or less than fRight, or if fTop is equal
484to or less than fBottom. Call sort() to reverse rectangles with negative
485width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400486
Cary Clark7fc1d122017-10-09 14:07:42 -0400487#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400488
489#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400490 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
491 for (auto rect : tests) {
492 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
493 rect.bottom(), rect.isSorted() ? "" : " not");
494 rect.sort();
495 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
496 rect.bottom(), rect.isSorted() ? "" : " not");
497 }
498#StdOut
499rect: {20, 40, 10, 50} is not sorted
500sorted: {10, 40, 20, 50} is sorted
501rect: {20, 40, 20, 50} is sorted
502sorted: {20, 40, 20, 50} is sorted
503##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400504##
505
Cary Clark7fc1d122017-10-09 14:07:42 -0400506#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400507
508##
509
510# ------------------------------------------------------------------------------
511
512#Method bool isLargest() const
513
Cary Clark7fc1d122017-10-09 14:07:42 -0400514Returns true if Rect encloses largest possible area.
515
516#Return true if equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400517
518#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400519#Description
520Note that the width cannot be represented as a 32-bit finite value.
521##
522 SkRect large = SkRect::MakeLargest();
523 SkDebugf("large is largest: %s\n" ,large.isLargest() ? "true" : "false");
524 SkDebugf("large width %g\n", large.width());
525 SkDebugf("large is empty: %s\n", large.isEmpty() ? "true" : "false");
526 SkDebugf("large is sorted: %s\n", large.isSorted() ? "true" : "false");
527 SkDebugf("large is finite: %s\n", large.isFinite() ? "true" : "false");
528#StdOut
529large is largest: true
530large width inf
531large is empty: false
532large is sorted: true
533large is finite: true
534##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400535##
536
Cary Clark7fc1d122017-10-09 14:07:42 -0400537#SeeAlso MakeLargest SkIRect::isLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400538
539##
540
541# ------------------------------------------------------------------------------
542
543#Method bool isFinite() const
544
Cary Clark7fc1d122017-10-09 14:07:42 -0400545Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
546and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400547
Cary Clark7fc1d122017-10-09 14:07:42 -0400548#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400549
550#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400551 SkRect largest = SkRect::MakeLargest();
552 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
553 SkDebugf("large width %g\n", largest.width());
554 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
555 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
556#StdOut
557largest is finite: true
558large width inf
559widest is finite: false
560##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400561##
562
Cary Clark7fc1d122017-10-09 14:07:42 -0400563#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400564
565##
566
567# ------------------------------------------------------------------------------
568
569#Method SkScalar x() const
570
Cary Clark7fc1d122017-10-09 14:07:42 -0400571Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
572Call sort() to reverse fLeft and fRight if needed.
573
574#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400575
576#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400577 SkRect unsorted = { 15, 5, 10, 25 };
578 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
579 SkRect sorted = unsorted.makeSorted();
580 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
581#StdOut
582unsorted.fLeft: 15 unsorted.x(): 15
583sorted.fLeft: 10 sorted.x(): 10
584##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400585##
586
Cary Clark7fc1d122017-10-09 14:07:42 -0400587#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400588
589##
590
591# ------------------------------------------------------------------------------
592
593#Method SkScalar y() const
594
Cary Clark7fc1d122017-10-09 14:07:42 -0400595Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
596and sort() to reverse fTop and fBottom if needed.
597
598#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400599
600#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400601 SkRect unsorted = { 15, 25, 10, 5 };
602 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
603 SkRect sorted = unsorted.makeSorted();
604 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
605#StdOut
606unsorted.fTop: 25 unsorted.y(): 25
607sorted.fTop: 5 sorted.y(): 5
608##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400609##
610
Cary Clark7fc1d122017-10-09 14:07:42 -0400611#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400612
613##
614
615# ------------------------------------------------------------------------------
616
617#Method SkScalar left() const
618
Cary Clark7fc1d122017-10-09 14:07:42 -0400619Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
620Call sort() to reverse fLeft and fRight if needed.
621
622#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400623
624#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400625 SkRect unsorted = { 15, 5, 10, 25 };
626 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
627 SkRect sorted = unsorted.makeSorted();
628 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
629#StdOut
630unsorted.fLeft: 15 unsorted.left(): 15
631sorted.fLeft: 10 sorted.left(): 10
632##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400633##
634
Cary Clark7fc1d122017-10-09 14:07:42 -0400635#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400636
637##
638
639# ------------------------------------------------------------------------------
640
641#Method SkScalar top() const
642
Cary Clark7fc1d122017-10-09 14:07:42 -0400643Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
644and sort() to reverse fTop and fBottom if needed.
645
646#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400647
648#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400649 SkRect unsorted = { 15, 25, 10, 5 };
650 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
651 SkRect sorted = unsorted.makeSorted();
652 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
653#StdOut
654unsorted.fTop: 25 unsorted.top(): 25
655sorted.fTop: 5 sorted.top(): 5
656##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400657##
658
Cary Clark7fc1d122017-10-09 14:07:42 -0400659#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400660
661##
662
663# ------------------------------------------------------------------------------
664
665#Method SkScalar right() const
666
Cary Clark7fc1d122017-10-09 14:07:42 -0400667Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
668Call sort() to reverse fLeft and fRight if needed.
669
670#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400671
672#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400673 SkRect unsorted = { 15, 25, 10, 5 };
674 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
675 SkRect sorted = unsorted.makeSorted();
676 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
677#StdOut
678unsorted.fRight: 10 unsorted.right(): 10
679sorted.fRight: 15 sorted.right(): 15
680##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400681##
682
Cary Clark7fc1d122017-10-09 14:07:42 -0400683#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400684
685##
686
687# ------------------------------------------------------------------------------
688
689#Method SkScalar bottom() const
690
Cary Clark7fc1d122017-10-09 14:07:42 -0400691Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
692and sort() to reverse fTop and fBottom if needed.
693
694#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400695
696#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400697 SkRect unsorted = { 15, 25, 10, 5 };
698 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
699 SkRect sorted = unsorted.makeSorted();
700 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
701#StdOut
702unsorted.fBottom: 5 unsorted.bottom(): 5
703sorted.fBottom: 25 sorted.bottom(): 25
704##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400705##
706
Cary Clark7fc1d122017-10-09 14:07:42 -0400707#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400708
709##
710
711# ------------------------------------------------------------------------------
712
713#Method SkScalar width() const
714
Cary Clark7fc1d122017-10-09 14:07:42 -0400715Returns span on the x-axis. This does not check if Rect is sorted, or if
716result fits in 32-bit float; result may be negative or infinity.
717
718#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400719
720#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400721#Description
722Compare with SkIRect::width() example.
723##
724 SkRect unsorted = { 15, 25, 10, 5 };
725 SkDebugf("unsorted width: %g\n", unsorted.width());
726 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
727 SkDebugf("large width: %.0f\n", large.width());
728#StdOut
729unsorted width: -5
730large width: 4294967296
731##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400732##
733
Cary Clark7fc1d122017-10-09 14:07:42 -0400734#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400735
736##
737
738# ------------------------------------------------------------------------------
739
740#Method SkScalar height() const
741
Cary Clark7fc1d122017-10-09 14:07:42 -0400742Returns span on the y-axis. This does not check if IRect is sorted, or if
743result fits in 32-bit float; result may be negative or infinity.
744
745#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400746
747#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400748#Description
749Compare with SkIRect::height() example.
750##
751 SkRect unsorted = { 15, 25, 10, 20 };
752 SkDebugf("unsorted height: %g\n", unsorted.height());
753 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
754 SkDebugf("large height: %.0f\n", large.height());
755#StdOut
756unsorted height: -5
757large height: 4294967296
758##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400759##
760
Cary Clark7fc1d122017-10-09 14:07:42 -0400761#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400762
763##
764
765# ------------------------------------------------------------------------------
766
767#Method SkScalar centerX() const
768
Cary Clark7fc1d122017-10-09 14:07:42 -0400769Returns average of left edge and right edge. Result does not change if Rect
770is sorted. Result may overflow to infinity if Rect is far from the origin.
771
772#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400773
774#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400775 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
776 for (auto rect : tests) {
777 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
778 rect.sort();
779 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
780 }
781#StdOut
782left: 20 right: 41 centerX: 30.5
783left: 20 right: 41 centerX: 30.5
784left: -20 right: -41 centerX: -30.5
785left: -41 right: -20 centerX: -30.5
786##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400787##
788
Cary Clark7fc1d122017-10-09 14:07:42 -0400789#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400790
791##
792
793# ------------------------------------------------------------------------------
794
795#Method SkScalar centerY() const
796
Cary Clark7fc1d122017-10-09 14:07:42 -0400797Returns average of top edge and bottom edge. Result does not change if Rect
798is sorted. Result may overflow to infinity if Rect is far from the origin.
799
800#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400801
802#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400803 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
804 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
805 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
806#StdOut
807left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
808##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400809##
810
Cary Clark7fc1d122017-10-09 14:07:42 -0400811#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400812
813##
814
815# ------------------------------------------------------------------------------
816
Cary Clark884dd7d2017-10-11 10:37:52 -0400817#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400818
Cary Clark7fc1d122017-10-09 14:07:42 -0400819Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
820equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400821
Cary Clark7fc1d122017-10-09 14:07:42 -0400822a and b are not equal if either contain NaN. a and b are equal if members
823contain zeroes width different signs.
824
825#Param a Rect to compare ##
826#Param b Rect to compare ##
827
828#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400829
830#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400831 auto debugster = [](const SkRect& test) -> void {
832 SkRect negZero = {-0.0f, -0.0f, 2, 2};
833 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
834 test.fLeft, test.fTop, test.fRight, test.fBottom,
835 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
836 test == negZero ? '=' : '!',
837 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
838 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
839 "and are" : "yet are not");
840 };
841 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
842 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
843 for (auto rect : tests) {
844 debugster(rect);
845 }
846#StdOut
847tests are equal
848{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
849{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
850{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
851##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400852##
853
Cary Clark7fc1d122017-10-09 14:07:42 -0400854#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400855
856##
857
858# ------------------------------------------------------------------------------
859
Cary Clark884dd7d2017-10-11 10:37:52 -0400860#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400861
Cary Clark7fc1d122017-10-09 14:07:42 -0400862Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
863equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400864
Cary Clark7fc1d122017-10-09 14:07:42 -0400865a and b are not equal if either contain NaN. a and b are equal if members
866contain zeroes width different signs.
867
868#Param a Rect to compare ##
869#Param b Rect to compare ##
870
871#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400872
873#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400874 SkRect test = {0, 0, 2, SK_ScalarNaN};
875 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
876#StdOut
877test with NaN is not equal to itself
878##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400879##
880
Cary Clark7fc1d122017-10-09 14:07:42 -0400881#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400882
883##
884
885# ------------------------------------------------------------------------------
886
887#Method void toQuad(SkPoint quad[4]) const
888
Cary Clark7fc1d122017-10-09 14:07:42 -0400889Returns four points in quad that enclose Rect ordered as: top-left, top-right,
890bottom-right, bottom-left.
891
892#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400893Consider adding param to control whether quad is CW or CCW.
894##
895
Cary Clark7fc1d122017-10-09 14:07:42 -0400896#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400897
898#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400899 SkRect rect = {1, 2, 3, 4};
900 SkPoint corners[4];
901 rect.toQuad(corners);
902 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
903 SkDebugf("corners:");
904 for (auto corner : corners) {
905 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
906 }
907 SkDebugf("\n");
908#StdOut
909rect: {1, 2, 3, 4}
910corners: {1, 2} {3, 2} {3, 4} {1, 4}
911##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400912##
913
Cary Clark7fc1d122017-10-09 14:07:42 -0400914#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400915
916##
917
918# ------------------------------------------------------------------------------
919
920#Method void setEmpty()
921
Cary Clark7fc1d122017-10-09 14:07:42 -0400922Sets Rect to (0, 0, 0, 0).
923
924Many other rectangles are empty; if left is equal to or greater than right,
925or if top is equal to or greater than bottom. Setting all members to zero
926is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400927
928#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400929 SkRect rect = {3, 4, 1, 2};
930 for (int i = 0; i < 2; ++i) {
931 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
932 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
933 rect.setEmpty();
934 }
935#StdOut
936rect: {3, 4, 1, 2} is empty
937rect: {0, 0, 0, 0} is empty
938##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400939##
940
Cary Clark7fc1d122017-10-09 14:07:42 -0400941#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400942
943##
944
945# ------------------------------------------------------------------------------
946
947#Method void set(const SkIRect& src)
948
Cary Clark7fc1d122017-10-09 14:07:42 -0400949Sets Rect to src, promoting src members from integer to Scalar.
950Very large values in src may lose precision.
951
952#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400953
954#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400955 SkIRect i_rect = {3, 4, 1, 2};
956 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
957 SkRect f_rect;
958 f_rect.set(i_rect);
959 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
960#StdOut
961i_rect: {3, 4, 1, 2}
962f_rect: {3, 4, 1, 2}
963##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400964##
965
Cary Clark7fc1d122017-10-09 14:07:42 -0400966#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400967
968##
969
970# ------------------------------------------------------------------------------
971
972#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
973
Cary Clark7fc1d122017-10-09 14:07:42 -0400974Sets Rect to (left, top, right, bottom).
975left and right are not sorted; left is not necessarily less than right.
976top and bottom are not sorted; top is not necessarily less than bottom.
977
978#Param left stored in fLeft ##
979#Param top stored in fTop ##
980#Param right stored in fRight ##
981#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400982
983#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400984 SkRect rect1 = {3, 4, 1, 2};
985 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
986 SkRect rect2;
987 rect2.set(3, 4, 1, 2);
988 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
989#StdOut
990rect1: {3, 4, 1, 2}
991rect2: {3, 4, 1, 2}
992##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400993##
994
Cary Clark7fc1d122017-10-09 14:07:42 -0400995#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400996
997##
998
999# ------------------------------------------------------------------------------
1000
1001#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1002
Cary Clark7fc1d122017-10-09 14:07:42 -04001003Sets Rect to (left, top, right, bottom).
1004left and right are not sorted; left is not necessarily less than right.
1005top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001006
Cary Clark7fc1d122017-10-09 14:07:42 -04001007#Param left stored in fLeft ##
1008#Param top stored in fTop ##
1009#Param right stored in fRight ##
1010#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001011
1012#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001013 SkRect rect1 = {3, 4, 1, 2};
1014 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1015 SkRect rect2;
1016 rect2.setLTRB(3, 4, 1, 2);
1017 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1018#StdOut
1019rect1: {3, 4, 1, 2}
1020rect2: {3, 4, 1, 2}
1021##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001022##
1023
Cary Clark7fc1d122017-10-09 14:07:42 -04001024#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001025
1026##
1027
1028# ------------------------------------------------------------------------------
1029
1030#Method void iset(int left, int top, int right, int bottom)
1031
Cary Clark7fc1d122017-10-09 14:07:42 -04001032Sets Rect to (left, top, right, bottom).
1033All parameters are promoted from integer to Scalar.
1034left and right are not sorted; left is not necessarily less than right.
1035top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001036
Cary Clark7fc1d122017-10-09 14:07:42 -04001037#Param left promoted to SkScalar and stored in fLeft ##
1038#Param top promoted to SkScalar and stored in fTop ##
1039#Param right promoted to SkScalar and stored in fRight ##
1040#Param bottom promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001041
1042#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001043 SkRect rect1 = {3, 4, 1, 2};
1044 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1045 SkRect rect2;
1046 rect2.iset(3, 4, 1, 2);
1047 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1048#StdOut
1049rect1: {3, 4, 1, 2}
1050rect2: {3, 4, 1, 2}
1051##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001052##
1053
Cary Clark7fc1d122017-10-09 14:07:42 -04001054#SeeAlso set setLTRB SkIRect::set SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -04001055
1056##
1057
1058# ------------------------------------------------------------------------------
1059
1060#Method void isetWH(int width, int height)
1061
Cary Clark7fc1d122017-10-09 14:07:42 -04001062Sets Rect to (0, 0, width, height).
1063width and height may be zero or negative. width and height are promoted from
1064integer to SkScalar, large values may lose precision.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001065
Cary Clark7fc1d122017-10-09 14:07:42 -04001066#Param width promoted to SkScalar and stored in fRight ##
1067#Param height promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001068
1069#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001070 SkRect rect1 = {0, 0, 1, 2};
1071 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1072 SkRect rect2;
1073 rect2.isetWH(1, 2);
1074 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1075#StdOut
1076rect1: {0, 0, 1, 2}
1077rect2: {0, 0, 1, 2}
1078##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001079##
1080
Cary Clark7fc1d122017-10-09 14:07:42 -04001081#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001082
1083##
1084
1085# ------------------------------------------------------------------------------
1086
1087#Method void set(const SkPoint pts[], int count)
1088
Cary Clark7fc1d122017-10-09 14:07:42 -04001089Sets to bounds of Point array with count entries. If count is zero or smaller,
1090or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001091
Cary Clark7fc1d122017-10-09 14:07:42 -04001092Result is either empty or sorted: fLeft is less than or equal to fRight, and
1093fTop is less than or equal to fBottom.
1094
1095#Param pts Point array ##
1096#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001097
1098#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001099 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1100 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1101 SkRect rect;
1102 rect.set(points, count);
1103 if (count > 0) {
1104 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1105 } else {
1106 SkDebugf("%14s", " ");
1107 }
1108 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1109 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1110 }
1111#StdOut
1112 count: 0 rect: 0, 0, 0, 0
1113added: 3, 4 count: 1 rect: 3, 4, 3, 4
1114added: 1, 2 count: 2 rect: 1, 2, 3, 4
1115added: 5, 6 count: 3 rect: 1, 2, 5, 6
1116added: nan, 8 count: 4 rect: 0, 0, 0, 0
1117##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001118##
1119
Cary Clark7fc1d122017-10-09 14:07:42 -04001120#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001121
1122##
1123
1124# ------------------------------------------------------------------------------
1125
1126#Method void setBounds(const SkPoint pts[], int count)
1127
Cary Clark7fc1d122017-10-09 14:07:42 -04001128Sets to bounds of Point array with count entries. If count is zero or smaller,
1129or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001130
Cary Clark7fc1d122017-10-09 14:07:42 -04001131Result is either empty or sorted: fLeft is less than or equal to fRight, and
1132fTop is less than or equal to fBottom.
1133
1134#Param pts Point array ##
1135#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001136
1137#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001138 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1139 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1140 SkRect rect;
1141 rect.setBounds(points, count);
1142 if (count > 0) {
1143 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1144 } else {
1145 SkDebugf("%14s", " ");
1146 }
1147 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1148 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1149 }
1150#StdOut
1151 count: 0 rect: 0, 0, 0, 0
1152added: 3, 4 count: 1 rect: 3, 4, 3, 4
1153added: 1, 2 count: 2 rect: 1, 2, 3, 4
1154added: 5, 6 count: 3 rect: 1, 2, 5, 6
1155added: nan, 8 count: 4 rect: 0, 0, 0, 0
1156##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001157##
1158
Cary Clark7fc1d122017-10-09 14:07:42 -04001159#SeeAlso set setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001160
1161##
1162
1163# ------------------------------------------------------------------------------
1164
1165#Method bool setBoundsCheck(const SkPoint pts[], int count)
1166
Cary Clark7fc1d122017-10-09 14:07:42 -04001167Sets to bounds of Point array with count entries. Returns false if count is
1168zero or smaller, or if Point array contains an infinity or NaN; in these cases
1169sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001170
Cary Clark7fc1d122017-10-09 14:07:42 -04001171Result is either empty or sorted: fLeft is less than or equal to fRight, and
1172fTop is less than or equal to fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001173
Cary Clark7fc1d122017-10-09 14:07:42 -04001174#Param pts Point array ##
1175#Param count entries in array ##
1176
1177#Return true if all Point values are finite ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001178
1179#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001180 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1181 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1182 SkRect rect;
1183 bool success = rect.setBoundsCheck(points, count);
1184 if (count > 0) {
1185 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1186 } else {
1187 SkDebugf("%14s", " ");
1188 }
1189 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
1190 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
1191 }
1192#StdOut
1193 count: 0 rect: 0, 0, 0, 0 success: true
1194added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
1195added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
1196added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
1197added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
1198##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001199##
1200
Cary Clark7fc1d122017-10-09 14:07:42 -04001201#SeeAlso set setBounds SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001202
1203##
1204
1205# ------------------------------------------------------------------------------
1206
1207#Method void set(const SkPoint& p0, const SkPoint& p1)
1208
Cary Clark7fc1d122017-10-09 14:07:42 -04001209Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1210sorted and may be empty. Does not check to see if values are finite.
1211
1212#Param p0 corner to include ##
1213#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001214
1215#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001216#Description
1217p0 and p1 may be swapped and have the same effect unless one contains NaN.
1218##
1219 SkPoint point1 = {SK_ScalarNaN, 8};
1220 SkPoint point2 = {3, 4};
1221 SkRect rect;
1222 rect.set(point1, point2);
1223 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1224 rect.set(point2, point1);
1225 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001226##
1227
Cary Clark7fc1d122017-10-09 14:07:42 -04001228#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001229
1230##
1231
1232# ------------------------------------------------------------------------------
1233
1234#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1235
Cary Clark7fc1d122017-10-09 14:07:42 -04001236Sets Rect to
1237#Formula
1238(x, y, x + width, y + height)
1239##
1240. Does not validate input;
1241width or height may be negative.
1242
1243#Param x stored in fLeft ##
1244#Param y stored in fTop ##
1245#Param width added to x and stored in fRight ##
1246#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001247
1248#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001249 SkRect rect;
1250 rect.setXYWH(5, 35, -15, 25);
1251 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1252 rect.bottom(), rect.isEmpty() ? "true" : "false");
1253 rect.sort();
1254 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1255 rect.bottom(), rect.isEmpty() ? "true" : "false");
1256#StdOut
1257rect: 5, 35, -10, 60 isEmpty: true
1258rect: -10, 35, 5, 60 isEmpty: false
1259##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001260##
1261
Cary Clark7fc1d122017-10-09 14:07:42 -04001262#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001263
1264##
1265
1266# ------------------------------------------------------------------------------
1267
1268#Method void setWH(SkScalar width, SkScalar height)
1269
Cary Clark7fc1d122017-10-09 14:07:42 -04001270Sets Rect to (0, 0, width, height). Does not validate input;
1271width or height may be negative.
1272
1273#Param width stored in fRight ##
1274#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001275
1276#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001277 SkRect rect;
1278 rect.setWH(-15, 25);
1279 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1280 rect.bottom(), rect.isEmpty() ? "true" : "false");
1281 rect.sort();
1282 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1283 rect.bottom(), rect.isEmpty() ? "true" : "false");
1284#StdOut
1285rect: 0, 0, -15, 25 isEmpty: true
1286rect: -15, 0, 0, 25 isEmpty: false
1287##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001288##
1289
Cary Clark7fc1d122017-10-09 14:07:42 -04001290#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001291
1292##
1293
1294# ------------------------------------------------------------------------------
1295
1296#Method void setLargest()
1297
Cary Clark7fc1d122017-10-09 14:07:42 -04001298Sets rectangle left and top to most negative finite value, and sets
1299right and bottom to most positive finite value.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001300
1301#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001302 SkRect rect;
1303 rect.setLargest();
1304 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
1305 SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
1306 rect.outset(1e31, 1e31);
1307 SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
1308 SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
1309 rect.outset(1e32, 1e32);
1310 SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
1311 SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
1312#StdOut
1313MakeLargest isLargest: true
1314MakeLargest isFinite: true
1315outset a little isLargest: true
1316outset a little isFinite: true
1317outset a little more isLargest: false
1318outset a little more isFinite: false
1319##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001320##
1321
Cary Clark7fc1d122017-10-09 14:07:42 -04001322#SeeAlso MakeLargest isLargest setLargestInverted SK_ScalarMin SK_ScalarMax
Cary Clarkbc5697d2017-10-04 14:31:33 -04001323
1324##
1325
1326# ------------------------------------------------------------------------------
1327
1328#Method void setLargestInverted()
1329
Cary Clark7fc1d122017-10-09 14:07:42 -04001330Sets rectangle left and top to most positive finite value, and sets
1331right and bottom to most negative finite value.
1332
1333Use to initial Rect before one or more calls to growToInclude.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001334
1335#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001336 auto debugster = [](const char* prefix, const SkRect& rect) -> void {
1337 SkDebugf("%s ", prefix);
1338 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1339 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
1340 };
1341 SkRect ptBounds;
1342 ptBounds.setLargestInverted();
1343 debugster("original", ptBounds);
1344 ptBounds.growToInclude( { 42, 24 } );
1345 debugster("grown", ptBounds);
1346#StdOut
1347original rect: 3.40282e+38, 3.40282e+38, -3.40282e+38, -3.40282e+38 isEmpty: true
1348grown rect: 42, 24, 42, 24 isEmpty: true
1349##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001350##
1351
Cary Clark7fc1d122017-10-09 14:07:42 -04001352#SeeAlso growToInclude setEmpty setLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -04001353
1354##
1355
1356# ------------------------------------------------------------------------------
1357
1358#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1359
Cary Clark7fc1d122017-10-09 14:07:42 -04001360Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001361
Cary Clark7fc1d122017-10-09 14:07:42 -04001362If dx is negative, Rect returned is moved to the left.
1363If dx is positive, Rect returned is moved to the right.
1364If dy is negative, Rect returned is moved upward.
1365If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001366
Cary Clark7fc1d122017-10-09 14:07:42 -04001367#Param dx added to fLeft and fRight ##
1368#Param dy added to fTop and fBottom ##
1369
1370#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001371
1372#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001373 SkRect rect = { 10, 50, 20, 60 };
1374 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1375 rect.bottom(), rect.isEmpty() ? "true" : "false");
1376 rect = rect.makeOffset(15, 32);
1377 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1378 rect.bottom(), rect.isEmpty() ? "true" : "false");
1379#StdOut
1380rect: 10, 50, 20, 60 isEmpty: false
1381rect: 25, 82, 35, 92 isEmpty: false
1382##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001383##
1384
Cary Clark7fc1d122017-10-09 14:07:42 -04001385#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001386
1387##
1388
1389# ------------------------------------------------------------------------------
1390
1391#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1392
Cary Clark7fc1d122017-10-09 14:07:42 -04001393Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001394
Cary Clark7fc1d122017-10-09 14:07:42 -04001395If dx is negative, Rect returned is wider.
1396If dx is positive, Rect returned is narrower.
1397If dy is negative, Rect returned is taller.
1398If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001399
Cary Clark7fc1d122017-10-09 14:07:42 -04001400#Param dx added to fLeft and subtracted from fRight ##
1401#Param dy added to fTop and subtracted from fBottom ##
1402
1403#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001404
1405#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001406 SkRect rect = { 10, 50, 20, 60 };
1407 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1408 rect.bottom(), rect.isEmpty() ? "true" : "false");
1409 rect = rect.makeInset(15, 32);
1410 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1411 rect.bottom(), rect.isEmpty() ? "true" : "false");
1412#StdOut
1413rect: 10, 50, 20, 60 isEmpty: false
1414rect: 25, 82, 5, 28 isEmpty: true
1415##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001416##
1417
Cary Clark7fc1d122017-10-09 14:07:42 -04001418#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001419
1420##
1421
1422# ------------------------------------------------------------------------------
1423
1424#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1425
Cary Clark7fc1d122017-10-09 14:07:42 -04001426Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001427
Cary Clark7fc1d122017-10-09 14:07:42 -04001428If dx is negative, Rect returned is narrower.
1429If dx is positive, Rect returned is wider.
1430If dy is negative, Rect returned is shorter.
1431If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001432
Cary Clark7fc1d122017-10-09 14:07:42 -04001433#Param dx subtracted to fLeft and added from fRight ##
1434#Param dy subtracted to fTop and added from fBottom ##
1435
1436#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001437
1438#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001439 SkRect rect = { 10, 50, 20, 60 };
1440 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1441 rect.bottom(), rect.isEmpty() ? "true" : "false");
1442 rect = rect.makeOutset(15, 32);
1443 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1444 rect.bottom(), rect.isEmpty() ? "true" : "false");
1445#StdOut
1446rect: 10, 50, 20, 60 isEmpty: false
1447rect: -5, 18, 35, 92 isEmpty: false
1448##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001449##
1450
Cary Clark7fc1d122017-10-09 14:07:42 -04001451#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001452
1453##
1454
1455# ------------------------------------------------------------------------------
1456
1457#Method void offset(SkScalar dx, SkScalar dy)
1458
Cary Clark7fc1d122017-10-09 14:07:42 -04001459Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001460
Cary Clark7fc1d122017-10-09 14:07:42 -04001461If dx is negative, moves Rect to the left.
1462If dx is positive, moves Rect to the right.
1463If dy is negative, moves Rect upward.
1464If dy is positive, moves Rect downward.
1465
1466#Param dx offset added to fLeft and fRight ##
1467#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001468
1469#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001470 SkRect rect = { 10, 14, 50, 73 };
1471 rect.offset(5, 13);
1472 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1473#StdOut
1474rect: 15, 27, 55, 86
1475##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001476##
1477
Cary Clark7fc1d122017-10-09 14:07:42 -04001478#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001479
1480##
1481
1482# ------------------------------------------------------------------------------
1483
1484#Method void offset(const SkPoint& delta)
1485
Cary Clark7fc1d122017-10-09 14:07:42 -04001486Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1487fTop, fBottom.
1488
1489If delta.fX is negative, moves Rect to the left.
1490If delta.fX is positive, moves Rect to the right.
1491If delta.fY is negative, moves Rect upward.
1492If delta.fY is positive, moves Rect downward.
1493
1494#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001495
1496#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001497 SkRect rect = { 10, 14, 50, 73 };
1498 rect.offset({5, 13});
1499 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1500#StdOut
1501rect: 15, 27, 55, 86
1502##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001503##
1504
Cary Clark7fc1d122017-10-09 14:07:42 -04001505#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001506
1507##
1508
1509# ------------------------------------------------------------------------------
1510
1511#Method void offsetTo(SkScalar newX, SkScalar newY)
1512
Cary Clark7fc1d122017-10-09 14:07:42 -04001513Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1514are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001515
Cary Clark7fc1d122017-10-09 14:07:42 -04001516#Param newX stored in fLeft, preserving width() ##
1517#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001518
1519#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001520 SkRect rect = { 10, 14, 50, 73 };
1521 rect.offsetTo(15, 27);
1522 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1523#StdOut
1524rect: 15, 27, 55, 86
1525##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001526##
1527
Cary Clark7fc1d122017-10-09 14:07:42 -04001528#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001529
1530##
1531
1532# ------------------------------------------------------------------------------
1533
1534#Method void inset(SkScalar dx, SkScalar dy)
1535
Cary Clark7fc1d122017-10-09 14:07:42 -04001536Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001537
Cary Clark7fc1d122017-10-09 14:07:42 -04001538If dx is positive, makes Rect narrower.
1539If dx is negative, makes Rect wider.
1540If dy is positive, makes Rect shorter.
1541If dy is negative, makes Rect taller.
1542
1543#Param dx added to fLeft and subtracted from fRight ##
1544#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001545
1546#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001547 SkRect rect = { 10, 14, 50, 73 };
1548 rect.inset(5, 13);
1549 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1550#StdOut
1551rect: 15, 27, 45, 60
1552##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001553##
1554
Cary Clark7fc1d122017-10-09 14:07:42 -04001555#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001556
1557##
1558
1559# ------------------------------------------------------------------------------
1560
1561#Method void outset(SkScalar dx, SkScalar dy)
1562
Cary Clark7fc1d122017-10-09 14:07:42 -04001563Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001564
Cary Clark7fc1d122017-10-09 14:07:42 -04001565If dx is positive, makes Rect wider.
1566If dx is negative, makes Rect narrower.
1567If dy is positive, makes Rect taller.
1568If dy is negative, makes Rect shorter.
1569
1570#Param dx subtracted to fLeft and added from fRight ##
1571#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001572
1573#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001574 SkRect rect = { 10, 14, 50, 73 };
1575 rect.outset(5, 13);
1576 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1577#StdOut
1578rect: 5, 1, 55, 86
1579##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001580##
1581
Cary Clark7fc1d122017-10-09 14:07:42 -04001582#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001583
1584##
1585
Cary Clark7fc1d122017-10-09 14:07:42 -04001586#Topic Intersection
1587
1588Rects intersect when they enclose a common area. To intersect, each of the pair
1589must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1590empty() returns false. The intersection of Rect a and Rect b can be described by:
1591#Formula
1592(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1593 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1594##
1595The intersection is only meaningful if the resulting Rect is not empty and
1596describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1597
Cary Clarkbc5697d2017-10-04 14:31:33 -04001598# ------------------------------------------------------------------------------
1599
1600#Method bool intersect(const SkRect& r)
1601
Cary Clark7fc1d122017-10-09 14:07:42 -04001602Returns true if Rect intersects r, and sets Rect to intersection.
1603Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001604
Cary Clark7fc1d122017-10-09 14:07:42 -04001605Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001606
Cary Clark7fc1d122017-10-09 14:07:42 -04001607#Param r limit of result ##
1608
1609#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001610
1611#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001612#Description
1613Two SkDebugf calls are required. If the calls are combined, their arguments
1614may not be evaluated in left to right order: the printed intersection may
1615be before or after the call to intersect.
1616##
1617 SkRect leftRect = { 10, 40, 50, 80 };
1618 SkRect rightRect = { 30, 60, 70, 90 };
1619 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1620 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
1621 leftRect.right(), leftRect.bottom());
1622#StdOut
1623 intersection: 30, 60, 50, 80
1624##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001625##
1626
Cary Clark7fc1d122017-10-09 14:07:42 -04001627#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001628
1629##
1630
1631# ------------------------------------------------------------------------------
1632
1633#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1634
Cary Clark7fc1d122017-10-09 14:07:42 -04001635Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1636construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001637
Cary Clark7fc1d122017-10-09 14:07:42 -04001638Returns true if Rect intersects construction, and sets Rect to intersection.
1639Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001640
Cary Clark7fc1d122017-10-09 14:07:42 -04001641Returns false if either construction or Rect is empty, leaving Rect unchanged.
1642
1643#Param left x minimum of constructed Rect ##
1644#Param top y minimum of constructed Rect ##
1645#Param right x maximum of constructed Rect ##
1646#Param bottom y maximum of constructed Rect ##
1647
1648#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001649
1650#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001651#Description
1652Two SkDebugf calls are required. If the calls are combined, their arguments
1653may not be evaluated in left to right order: the printed intersection may
1654be before or after the call to intersect.
1655##
1656 SkRect leftRect = { 10, 40, 50, 80 };
1657 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1658 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
1659 leftRect.right(), leftRect.bottom());
1660#StdOut
1661 intersection: 30, 60, 50, 80
1662##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001663##
1664
Cary Clark7fc1d122017-10-09 14:07:42 -04001665#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001666
1667##
1668
1669# ------------------------------------------------------------------------------
1670
1671#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1672
Cary Clark7fc1d122017-10-09 14:07:42 -04001673Returns true if a intersects b, and sets Rect to intersection.
1674Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001675
Cary Clark7fc1d122017-10-09 14:07:42 -04001676Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001677
Cary Clark7fc1d122017-10-09 14:07:42 -04001678#Param a Rect to intersect ##
1679#Param b Rect to intersect ##
1680
1681#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001682
1683#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001684 SkRect result;
1685 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1686 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1687 result.left(), result.top(), result.right(), result.bottom());
1688#StdOut
1689 intersection: 30, 60, 50, 80
1690##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001691##
1692
Cary Clark7fc1d122017-10-09 14:07:42 -04001693#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001694
1695##
1696
Cary Clark7fc1d122017-10-09 14:07:42 -04001697# ------------------------------------------------------------------------------
1698
Cary Clarkbc5697d2017-10-04 14:31:33 -04001699#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1700
Cary Clark7fc1d122017-10-09 14:07:42 -04001701Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1702construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001703
Cary Clark7fc1d122017-10-09 14:07:42 -04001704Returns true if Rect intersects construction.
1705Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001706
Cary Clark7fc1d122017-10-09 14:07:42 -04001707#Param left x minimum of constructed Rect ##
1708#Param top y minimum of constructed Rect ##
1709#Param right x maximum of constructed Rect ##
1710#Param bottom y maximum of constructed Rect ##
1711
1712#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001713
1714#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001715 SkRect rect = { 10, 40, 50, 80 };
1716 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
1717#StdOut
1718 intersection
1719##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001720##
1721
Cary Clark7fc1d122017-10-09 14:07:42 -04001722#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723
1724##
1725
Cary Clark7fc1d122017-10-09 14:07:42 -04001726# ------------------------------------------------------------------------------
1727
Cary Clarkbc5697d2017-10-04 14:31:33 -04001728#Method bool intersects(const SkRect& r) const
1729
Cary Clark7fc1d122017-10-09 14:07:42 -04001730Returns true if Rect intersects r.
1731Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001732
Cary Clark7fc1d122017-10-09 14:07:42 -04001733#Param r Rect to intersect ##
1734
1735#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001736
1737#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001738 SkRect rect = { 10, 40, 50, 80 };
1739 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
1740#StdOut
1741 intersection
1742##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001743##
1744
Cary Clark7fc1d122017-10-09 14:07:42 -04001745#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746
1747##
1748
Cary Clark7fc1d122017-10-09 14:07:42 -04001749# ------------------------------------------------------------------------------
1750
Cary Clarkbc5697d2017-10-04 14:31:33 -04001751#Method static bool Intersects(const SkRect& a, const SkRect& b)
1752
Cary Clark7fc1d122017-10-09 14:07:42 -04001753Returns true if a intersects b.
1754Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001755
Cary Clark7fc1d122017-10-09 14:07:42 -04001756#Param a Rect to intersect ##
1757#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001758
Cary Clark7fc1d122017-10-09 14:07:42 -04001759#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001760
1761#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001762 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1763#StdOut
1764 intersection
1765##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001766##
1767
Cary Clark7fc1d122017-10-09 14:07:42 -04001768#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769
1770##
1771
Cary Clark7fc1d122017-10-09 14:07:42 -04001772#Topic Intersection ##
1773
1774
1775# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001776
1777#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1778
Cary Clark7fc1d122017-10-09 14:07:42 -04001779Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1780construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001781
Cary Clark7fc1d122017-10-09 14:07:42 -04001782Sets Rect to the union of itself and the construction.
1783
1784Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1785Rect to construction.
1786
1787#Param left x minimum of constructed Rect ##
1788#Param top y minimum of constructed Rect ##
1789#Param right x maximum of constructed Rect ##
1790#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001791
1792#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001793 SkRect rect = { 10, 20, 15, 25};
1794 rect.join(50, 60, 55, 65);
1795 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1796#StdOut
1797 join: 10, 20, 55, 65
1798##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001799##
1800
Cary Clark7fc1d122017-10-09 14:07:42 -04001801#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001802
1803##
1804
Cary Clark7fc1d122017-10-09 14:07:42 -04001805# ------------------------------------------------------------------------------
1806
Cary Clarkbc5697d2017-10-04 14:31:33 -04001807#Method void join(const SkRect& r)
1808
Cary Clark7fc1d122017-10-09 14:07:42 -04001809Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001810
Cary Clark7fc1d122017-10-09 14:07:42 -04001811Has no effect if r is empty. Otherwise, if Rect is empty, sets
1812Rect to r.
1813
1814#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001815
1816#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001817 SkRect rect = { 10, 20, 15, 25};
1818 rect.join({50, 60, 55, 65});
1819 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1820#StdOut
1821 join: 10, 20, 55, 65
1822##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001823##
1824
Cary Clark7fc1d122017-10-09 14:07:42 -04001825#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001826
1827##
1828
Cary Clark7fc1d122017-10-09 14:07:42 -04001829# ------------------------------------------------------------------------------
1830
Cary Clarkbc5697d2017-10-04 14:31:33 -04001831#Method void joinNonEmptyArg(const SkRect& r)
1832
Cary Clark7fc1d122017-10-09 14:07:42 -04001833Sets Rect to the union of itself and r.
1834
1835Asserts if r is empty and SK_DEBUG is defined.
1836If Rect is empty, sets Rect to r.
1837
1838May produce incorrect results if r is empty.
1839
1840#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001841
1842#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001843#Description
1844Since Rect is not sorted, first result is copy of toJoin.
1845##
1846 SkRect rect = { 10, 100, 15, 0};
1847 SkRect sorted = rect.makeSorted();
1848 SkRect toJoin = { 50, 60, 55, 65 };
1849 rect.joinNonEmptyArg(toJoin);
1850 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1851 sorted.joinNonEmptyArg(toJoin);
1852 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1853#StdOut
1854rect: 50, 60, 55, 65
1855sorted: 10, 0, 55, 100
1856##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001857##
1858
Cary Clark7fc1d122017-10-09 14:07:42 -04001859#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001860
1861##
1862
Cary Clark7fc1d122017-10-09 14:07:42 -04001863# ------------------------------------------------------------------------------
1864
Cary Clarkbc5697d2017-10-04 14:31:33 -04001865#Method void joinPossiblyEmptyRect(const SkRect& r)
1866
Cary Clark7fc1d122017-10-09 14:07:42 -04001867Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001868
Cary Clark7fc1d122017-10-09 14:07:42 -04001869May produce incorrect results if Rect or r is empty.
1870
1871#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001872
1873#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001874#Description
1875Since Rect is not sorted, first result is not useful.
1876##
1877 SkRect rect = { 10, 100, 15, 0};
1878 SkRect sorted = rect.makeSorted();
1879 SkRect toJoin = { 50, 60, 55, 65 };
1880 rect.joinPossiblyEmptyRect(toJoin);
1881 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1882 sorted.joinPossiblyEmptyRect(toJoin);
1883 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1884#StdOut
1885rect: 10, 60, 55, 65
1886sorted: 10, 0, 55, 100
1887##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001888##
1889
Cary Clark7fc1d122017-10-09 14:07:42 -04001890#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001891
1892##
1893
Cary Clark7fc1d122017-10-09 14:07:42 -04001894# ------------------------------------------------------------------------------
1895
Cary Clarkbc5697d2017-10-04 14:31:33 -04001896#Method void growToInclude(SkPoint pt)
1897
Cary Clark7fc1d122017-10-09 14:07:42 -04001898Grows Rect to include (pt.fX, pt.fY), modifying it so that:
1899#Formula
1900fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1901##
1902.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001903
Cary Clark7fc1d122017-10-09 14:07:42 -04001904If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1905Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001906
Cary Clark7fc1d122017-10-09 14:07:42 -04001907#Param pt Point to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001908
1909#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001910 SkRect rect;
1911 rect.setLargestInverted();
1912 rect.growToInclude( { 42, 24 } );
1913 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1914 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
1915#StdOut
1916rect: 42, 24, 42, 24 isEmpty: true
1917##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918##
1919
Cary Clark7fc1d122017-10-09 14:07:42 -04001920#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001921
1922##
1923
Cary Clark7fc1d122017-10-09 14:07:42 -04001924# ------------------------------------------------------------------------------
1925
Cary Clarkbc5697d2017-10-04 14:31:33 -04001926#Method void growToInclude(const SkPoint pts[], int count)
1927
Cary Clark7fc1d122017-10-09 14:07:42 -04001928For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1929it so that:
1930#Formula
1931fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1932##
1933.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001934
Cary Clark7fc1d122017-10-09 14:07:42 -04001935If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1936Points after one or more calls. In this case, Rect is empty after first call.
1937
1938#Param pts Point array ##
1939#Param count number of points in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001940
1941#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001942 SkPoint pts[] = { { 30, 50 }, { 40, 50 }, { 30, 60 } };
1943 SkRect rect = { pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY };
1944 rect.growToInclude( pts[1] );
1945 rect.growToInclude( pts[2] );
1946 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1947#StdOut
1948rect: 30, 50, 40, 60
1949##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001950##
1951
Cary Clark7fc1d122017-10-09 14:07:42 -04001952#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001953
1954##
1955
Cary Clark7fc1d122017-10-09 14:07:42 -04001956# ------------------------------------------------------------------------------
1957
Cary Clarkbc5697d2017-10-04 14:31:33 -04001958#Method void growToInclude(const SkPoint pts[], size_t stride, int count)
1959
Cary Clark7fc1d122017-10-09 14:07:42 -04001960For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1961it so that:
1962#Formula
1963fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1964##
1965. Point may be followed with other data in each array element. stride is number
1966 of bytes in element; the interval to skip to advance from one Point to
1967the next.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001968
Cary Clark7fc1d122017-10-09 14:07:42 -04001969If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1970Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001971
Cary Clark7fc1d122017-10-09 14:07:42 -04001972#Param pts array of elements beginning with Point ##
1973#Param stride size of pts elements in 32-bit words; zero or greater ##
1974#Param count number of elements in array ##
1975
1976#Bug 7142 ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001978 SkPoint3 pts[] = { { 30, 50, -1 }, { 40, 50, -1 }, { 30, 60, -1 } };
1979 SkRect rect;
1980 rect.setLargestInverted();
1981 rect.growToInclude((SkPoint* ) &pts[0].fX, sizeof(SkPoint3), SK_ARRAY_COUNT(pts));
1982 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1983#StdOut
1984#Volatile
1985rect: 30, 50, 40, 60
1986##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001987##
1988
Cary Clark7fc1d122017-10-09 14:07:42 -04001989#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001990
1991##
1992
Cary Clark7fc1d122017-10-09 14:07:42 -04001993# ------------------------------------------------------------------------------
1994
Cary Clark884dd7d2017-10-11 10:37:52 -04001995#Method bool contains(const SkRect& r) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001996
Cary Clark7fc1d122017-10-09 14:07:42 -04001997Returns true if Rect contains r.
1998Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001999
Cary Clark7fc1d122017-10-09 14:07:42 -04002000Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002001
Cary Clark7fc1d122017-10-09 14:07:42 -04002002#Param r Rect contained ##
2003
2004#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002005
2006#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002007 SkRect rect = { 30, 50, 40, 60 };
2008 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
2009 for (auto contained : tests) {
2010 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
2011 rect.left(), rect.top(), rect.right(), rect.bottom(),
2012 rect.contains(contained) ? "contains" : "does not contain",
2013 contained.left(), contained.top(), contained.right(), contained.bottom());
2014 }
2015#StdOut
2016rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
2017rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
2018rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
2019##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002020##
2021
Cary Clark7fc1d122017-10-09 14:07:42 -04002022#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04002023
2024##
2025
Cary Clark7fc1d122017-10-09 14:07:42 -04002026# ------------------------------------------------------------------------------
2027
Cary Clarkbc5697d2017-10-04 14:31:33 -04002028#Method bool contains(const SkIRect& r) const
2029
Cary Clark7fc1d122017-10-09 14:07:42 -04002030Returns true if Rect contains r.
2031Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002032
Cary Clark7fc1d122017-10-09 14:07:42 -04002033Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002034
Cary Clark7fc1d122017-10-09 14:07:42 -04002035#Param r IRect contained ##
2036
2037#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002038
2039#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002040 SkRect rect = { 30, 50, 40, 60 };
2041 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
2042 for (auto contained : tests) {
2043 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
2044 rect.left(), rect.top(), rect.right(), rect.bottom(),
2045 rect.contains(contained) ? "contains" : "does not contain",
2046 contained.left(), contained.top(), contained.right(), contained.bottom());
2047 }
2048#StdOut
2049rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
2050rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
2051rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
2052##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002053##
2054
Cary Clark7fc1d122017-10-09 14:07:42 -04002055#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04002056
2057##
2058
Cary Clark7fc1d122017-10-09 14:07:42 -04002059#Topic Round
2060
2061# ------------------------------------------------------------------------------
2062
Cary Clarkbc5697d2017-10-04 14:31:33 -04002063#Method void round(SkIRect* dst) const
2064
Cary Clark7fc1d122017-10-09 14:07:42 -04002065Sets IRect by adding 0.5 and discarding the fractional portion of Rect
2066members, using
2067#Formula
2068(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2069 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2070##
2071.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002072
Cary Clark7fc1d122017-10-09 14:07:42 -04002073#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002074
2075#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002076 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2077 SkIRect round;
2078 rect.round(&round);
2079 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2080#StdOut
2081round: 31, 51, 41, 61
2082##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002083##
2084
Cary Clark7fc1d122017-10-09 14:07:42 -04002085#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002086
2087##
2088
Cary Clark7fc1d122017-10-09 14:07:42 -04002089# ------------------------------------------------------------------------------
2090
Cary Clarkbc5697d2017-10-04 14:31:33 -04002091#Method void roundOut(SkIRect* dst) const
2092
Cary Clark7fc1d122017-10-09 14:07:42 -04002093Sets IRect by discarding the fractional portion of fLeft and fTop; and
2094rounding up fRight and FBottom, using
2095#Formula
2096(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2097 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2098##
2099.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002100
Cary Clark7fc1d122017-10-09 14:07:42 -04002101#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002102
2103#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002104 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2105 SkIRect round;
2106 rect.roundOut(&round);
2107 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2108#StdOut
2109round: 30, 50, 41, 61
2110##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002111##
2112
Cary Clark7fc1d122017-10-09 14:07:42 -04002113#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002114
2115##
2116
Cary Clark7fc1d122017-10-09 14:07:42 -04002117# ------------------------------------------------------------------------------
2118
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119#Method void roundOut(SkRect* dst) const
2120
Cary Clark7fc1d122017-10-09 14:07:42 -04002121Sets Rect by discarding the fractional portion of fLeft and fTop; and
2122rounding up fRight and FBottom, using
2123#Formula
2124(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2125 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2126##
2127.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002128
Cary Clark7fc1d122017-10-09 14:07:42 -04002129#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002130
2131#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002132 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2133 SkRect round;
2134 rect.roundOut(&round);
2135 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2136#StdOut
2137round: 30, 50, 41, 61
2138##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002139##
2140
Cary Clark7fc1d122017-10-09 14:07:42 -04002141#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002142
2143##
2144
Cary Clark7fc1d122017-10-09 14:07:42 -04002145# ------------------------------------------------------------------------------
2146
Cary Clarkbc5697d2017-10-04 14:31:33 -04002147#Method void roundIn(SkIRect* dst) const
2148
Cary Clark7fc1d122017-10-09 14:07:42 -04002149Sets Rect by rounding up fLeft and fTop; and
2150discarding the fractional portion of fRight and FBottom, using
2151#Formula
2152(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2153 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2154##
2155.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002156
Cary Clark7fc1d122017-10-09 14:07:42 -04002157#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002158
2159#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002160 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2161 SkIRect round;
2162 rect.roundIn(&round);
2163 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2164#StdOut
2165round: 31, 51, 40, 60
2166##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002167##
2168
Cary Clark7fc1d122017-10-09 14:07:42 -04002169#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002170
2171##
2172
Cary Clark7fc1d122017-10-09 14:07:42 -04002173# ------------------------------------------------------------------------------
2174
Cary Clarkbc5697d2017-10-04 14:31:33 -04002175#Method SkIRect round() const
2176
Cary Clark7fc1d122017-10-09 14:07:42 -04002177Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2178members, using
2179#Formula
2180(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2181 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2182##
2183.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002184
Cary Clark7fc1d122017-10-09 14:07:42 -04002185#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002186
2187#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002188 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2189 SkIRect round = rect.round();
2190 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2191#StdOut
2192round: 31, 51, 41, 61
2193##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002194##
2195
Cary Clark7fc1d122017-10-09 14:07:42 -04002196#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002197
2198##
2199
Cary Clark7fc1d122017-10-09 14:07:42 -04002200# ------------------------------------------------------------------------------
2201
Cary Clarkbc5697d2017-10-04 14:31:33 -04002202#Method SkIRect roundOut() const
2203
Cary Clark7fc1d122017-10-09 14:07:42 -04002204Sets IRect by discarding the fractional portion of fLeft and fTop; and
2205rounding up fRight and FBottom, using
2206#Formula
2207(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2208 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2209##
2210.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002211
Cary Clark7fc1d122017-10-09 14:07:42 -04002212#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002213
2214#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002215 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2216 SkIRect round = rect.roundOut();
2217 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2218#StdOut
2219round: 30, 50, 41, 61
2220##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002221##
2222
Cary Clark7fc1d122017-10-09 14:07:42 -04002223#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002224
2225##
2226
Cary Clark7fc1d122017-10-09 14:07:42 -04002227#Topic Round ##
2228
2229# ------------------------------------------------------------------------------
2230
Cary Clarkbc5697d2017-10-04 14:31:33 -04002231#Method void sort()
2232
Cary Clark7fc1d122017-10-09 14:07:42 -04002233Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2234fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2235and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002236
2237#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002238 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2239 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2240 rect.sort();
2241 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2242#StdOut
2243rect: 30.5, 50.5, 20.5, 10.5
2244sorted: 20.5, 10.5, 30.5, 50.5
2245##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002246##
2247
Cary Clark7fc1d122017-10-09 14:07:42 -04002248#SeeAlso makeSorted SkIRect::sort
Cary Clarkbc5697d2017-10-04 14:31:33 -04002249
2250##
2251
Cary Clark7fc1d122017-10-09 14:07:42 -04002252# ------------------------------------------------------------------------------
2253
Cary Clarkbc5697d2017-10-04 14:31:33 -04002254#Method SkRect makeSorted() const
2255
Cary Clark7fc1d122017-10-09 14:07:42 -04002256Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2257with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2258and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002259
Cary Clark7fc1d122017-10-09 14:07:42 -04002260#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002261
2262#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002263 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2264 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2265 SkRect sort = rect.makeSorted();
2266 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
2267#StdOut
2268rect: 30.5, 50.5, 20.5, 10.5
2269sorted: 20.5, 10.5, 30.5, 50.5
2270##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002271##
2272
Cary Clark7fc1d122017-10-09 14:07:42 -04002273#SeeAlso sort SkIRect::makeSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002274
2275##
2276
Cary Clark7fc1d122017-10-09 14:07:42 -04002277# ------------------------------------------------------------------------------
2278
Cary Clarkbc5697d2017-10-04 14:31:33 -04002279#Method const SkScalar* asScalars() const
2280
Cary Clark7fc1d122017-10-09 14:07:42 -04002281Returns pointer to first Scalar in Rect, to treat it as an array with four
2282entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002283
Cary Clark7fc1d122017-10-09 14:07:42 -04002284#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002285
2286#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002287 SkRect rect = {7, 11, 13, 17};
2288SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2289#StdOut
2290rect.asScalars() == &rect.fLeft
2291##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002292##
2293
Cary Clark7fc1d122017-10-09 14:07:42 -04002294#SeeAlso toQuad
2295
Cary Clarkbc5697d2017-10-04 14:31:33 -04002296##
2297
Cary Clark7fc1d122017-10-09 14:07:42 -04002298# ------------------------------------------------------------------------------
2299
Cary Clarkbc5697d2017-10-04 14:31:33 -04002300#Method void dump(bool asHex) const
2301
Cary Clark7fc1d122017-10-09 14:07:42 -04002302Writes text representation of Rect to standard output. Set asHex to true to
2303generate exact binary representations of floating point numbers.
2304
2305#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002306
2307#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002308 SkRect rect = {20, 30, 40, 50};
2309 for (bool dumpAsHex : { false, true } ) {
2310 rect.dump(dumpAsHex);
2311 SkDebugf("\n");
2312 }
2313#StdOut
2314SkRect::MakeLTRB(20, 30, 40, 50);
2315
2316SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2317 SkBits2Float(0x41f00000), /* 30.000000 */
2318 SkBits2Float(0x42200000), /* 40.000000 */
2319 SkBits2Float(0x42480000) /* 50.000000 */);
2320##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002321##
2322
Cary Clark7fc1d122017-10-09 14:07:42 -04002323#SeeAlso dumpHex
2324
Cary Clarkbc5697d2017-10-04 14:31:33 -04002325##
2326
Cary Clark7fc1d122017-10-09 14:07:42 -04002327# ------------------------------------------------------------------------------
2328
Cary Clarkbc5697d2017-10-04 14:31:33 -04002329#Method void dump() const
2330
Cary Clark7fc1d122017-10-09 14:07:42 -04002331Writes text representation of Rect to standard output. The representation may be
2332directly compiled as C++ code. Floating point values are written
2333with limited precision; it may not be possible to reconstruct original Rect
2334from output.
2335
Cary Clarkbc5697d2017-10-04 14:31:33 -04002336#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002337SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2338rect.dump();
2339SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2340SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2341#StdOut
2342SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2343rect is not equal to copy
2344##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002345##
2346
Cary Clark7fc1d122017-10-09 14:07:42 -04002347#SeeAlso dumpHex
2348
Cary Clarkbc5697d2017-10-04 14:31:33 -04002349##
2350
Cary Clark7fc1d122017-10-09 14:07:42 -04002351# ------------------------------------------------------------------------------
2352
Cary Clarkbc5697d2017-10-04 14:31:33 -04002353#Method void dumpHex() const
2354
Cary Clark7fc1d122017-10-09 14:07:42 -04002355Writes text representation of Rect to standard output. The representation may be
2356directly compiled as C++ code. Floating point values are written
2357in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2358original Rect.
2359
2360Use instead of dump() when submitting
2361#A bug reports against Skia # http://bug.skia.org ##
2362.
2363
Cary Clarkbc5697d2017-10-04 14:31:33 -04002364#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002365 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2366rect.dumpHex();
2367SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2368 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2369 SkBits2Float(0x40266666), /* 2.600000 */
2370 SkBits2Float(0x40e00000) /* 7.000000 */);
2371SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2372#StdOut
2373SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2374 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2375 SkBits2Float(0x40266666), /* 2.600000 */
2376 SkBits2Float(0x40e00000) /* 7.000000 */);
2377rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002378##
Cary Clark7fc1d122017-10-09 14:07:42 -04002379##
2380
2381#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002382
2383##
2384
2385#Struct SkRect ##
2386
2387#Topic Rect ##