blob: 120191957aea13ac761356b78b2d57927caafbb0 [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 Clarka560c472017-11-27 10:44:06 -050033# bool operator!=(const SkRect& a, const SkRect& b) # Returns true if members are unequal. ##
34# bool operator==(const SkRect& a, const SkRect& b) # Returns true if members 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. ##
Cary Clark7fc1d122017-10-09 14:07:42 -040049# MakeSize # Constructs from Size returning (0, 0, width, height). ##
50# MakeWH # Constructs from SkScalar input returning (0, 0, width, height). ##
51# MakeXYWH # Constructs from SkScalar input returning (x, y, width, height). ##
52# asScalars # Returns pointer to members as array. ##
53# bottom() # Returns larger bounds in y, if sorted. ##
54# centerX # Returns midpoint in x. ##
55# centerY # Returns midpoint in y. ##
56# contains() # Returns true if points are equal or inside. ##
57# dump() # Sends text representation using floats to standard output. ##
58# dumpHex # Sends text representation using hexadecimal to standard output. ##
59# growToInclude # Sets to union of bounds and one or more Points. ##
60# height # Returns span in y. ##
61# inset() # Moves the sides symmetrically about the center. ##
62# intersect() # Sets to shared area; returns true if not empty. ##
63# intersects() # Returns true if areas overlap. ##
64# isEmpty # Returns true if width or height are zero or negative. ##
65# isFinite # Returns true if no member is infinite or NaN. ##
Cary Clark7fc1d122017-10-09 14:07:42 -040066# isSorted # Returns true if width or height are zero or positive. ##
67# iset() # Sets to int input (left, top, right, bottom). ##
68# isetWH # Sets to int input (0, 0, width, height). ##
69# join() # Sets to union of bounds. ##
70# joinNonEmptyArg # Sets to union of bounds, asserting that argument is not empty. ##
71# joinPossiblyEmptyRect # Sets to union of bounds. Skips empty check for both. ##
72# left() # Returns smaller bounds in x, if sorted. ##
73# makeInset # Constructs from sides moved symmetrically about the center. ##
74# makeOffset # Constructs from translated sides. ##
75# makeOutset # Constructs from sides moved symmetrically about the center. ##
76# makeSorted # Constructs, ordering sides from smaller to larger. ##
77# offset() # Translates sides without changing width and height. ##
78# offsetTo # Translates to (x, y) without changing width and height. ##
79# outset() # Moves the sides symmetrically about the center. ##
80# right() # Returns larger bounds in x, if sorted. ##
81# round() # Sets members to nearest integer value. ##
82# roundIn # Sets members to nearest integer value towards opposite. ##
83# roundOut # Sets members to nearest integer value away from opposite. ##
84# set() # Sets to SkScalar input (left, top, right, bottom) and others. ##
85# setBounds # Sets to upper and lower limits of Point array. ##
86# setBoundsCheck # Sets to upper and lower limits of Point array. ##
87# setEmpty # Sets to (0, 0, 0, 0). ##
88# setLTRB # Sets to SkScalar input (left, top, right, bottom). ##
Cary Clark7fc1d122017-10-09 14:07:42 -040089# setWH # Sets to SkScalar input (0, 0, width, height). ##
90# setXYWH # Sets to SkScalar input (x, y, width, height). ##
91# sort() # Orders sides from smaller to larger. ##
92# toQuad # Returns four corners as Point. ##
93# top() # Returns smaller bounds in y, if sorted. ##
94# width() # Returns span in x. ##
95# x() # Returns bounds left. ##
96# y() # Returns bounds top. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040097#Table ##
98#Subtopic ##
99
100#Topic ##
101
102#Member SkScalar fLeft
Cary Clark7fc1d122017-10-09 14:07:42 -0400103May contain any value, including infinities and NaN. The smaller of the
104horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400105##
106
107#Member SkScalar fTop
Cary Clark7fc1d122017-10-09 14:07:42 -0400108May contain any value, including infinities and NaN. The smaller of the
109vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400110##
111
112#Member SkScalar fRight
Cary Clark7fc1d122017-10-09 14:07:42 -0400113May contain any value, including infinities and NaN. The larger of the
114horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400115##
116
117#Member SkScalar fBottom
Cary Clark7fc1d122017-10-09 14:07:42 -0400118May contain any value, including infinities and NaN. The larger of the
119vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400120##
121
122# ------------------------------------------------------------------------------
123
124#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
125
Cary Clark7fc1d122017-10-09 14:07:42 -0400126Returns constructed Rect set to (0, 0, 0, 0).
127Many other rectangles are empty; if left is equal to or greater than right,
128or if top is equal to or greater than bottom. Setting all members to zero
129is a convenience, but does not designate a special empty rectangle.
130
131#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400132
133#Example
Cary Clark154beea2017-10-26 07:58:48 -0400134 SkRect rect = SkRect::MakeEmpty();
135 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
136 rect.offset(10, 10);
137 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
138 rect.inset(10, 10);
139 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
140 rect.outset(20, 20);
141 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
142#StdOut
143MakeEmpty isEmpty: true
144offset rect isEmpty: true
145inset rect isEmpty: true
146outset rect isEmpty: false
147##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400148##
149
Mike Reed274218e2018-01-08 15:05:02 -0500150#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -0400151
152##
153
154# ------------------------------------------------------------------------------
155
156#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400157
Cary Clark7fc1d122017-10-09 14:07:42 -0400158Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
159validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400160
Cary Clark7fc1d122017-10-09 14:07:42 -0400161Passing integer values may generate a compiler warning since Rect cannot
162represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
163
164#Param w SkScalar width of constructed Rect ##
165#Param h SkScalar height of constructed Rect ##
166
167#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400168
169#Example
Cary Clark154beea2017-10-26 07:58:48 -0400170 SkRect rect1 = SkRect::MakeWH(25, 35);
171 SkRect rect2 = SkRect::MakeIWH(25, 35);
172 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
173 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
174 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400175 "" : "not ");
176#StdOut
177all equal
178##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400179##
180
Cary Clark7fc1d122017-10-09 14:07:42 -0400181#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400182
183##
184
185# ------------------------------------------------------------------------------
186
187#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
188
Cary Clark7fc1d122017-10-09 14:07:42 -0400189Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
190input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400191
Cary Clark7fc1d122017-10-09 14:07:42 -0400192Use to avoid a compiler warning that input may lose precision when stored.
193Use SkIRect for an exact integer rectangle.
194
195#Param w integer width of constructed Rect ##
196#Param h integer height of constructed Rect ##
197
198#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400199
200#Example
Cary Clark154beea2017-10-26 07:58:48 -0400201 SkIRect i_rect = SkIRect::MakeWH(25, 35);
202 SkRect f_rect = SkRect::MakeIWH(25, 35);
203 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
204 i_rect = SkIRect::MakeWH(125000111, 0);
205 f_rect = SkRect::MakeIWH(125000111, 0);
206 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400207#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400208i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400209i_rect width: 125000111 f_rect width:125000112
210##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400211##
212
Cary Clark7fc1d122017-10-09 14:07:42 -0400213#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400214
215##
216
217# ------------------------------------------------------------------------------
218
Cary Clark884dd7d2017-10-11 10:37:52 -0400219#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400220
Cary Clark7fc1d122017-10-09 14:07:42 -0400221Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
222validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400223
Cary Clark7fc1d122017-10-09 14:07:42 -0400224#Param size SkScalar values for Rect width and height ##
225
226#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400227
228#Example
Cary Clark154beea2017-10-26 07:58:48 -0400229 SkSize size = {25.5f, 35.5f};
230 SkRect rect = SkRect::MakeSize(size);
231 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
232 SkISize floor = size.toFloor();
233 rect = SkRect::MakeSize(SkSize::Make(floor));
234 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400235#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400236rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400237floor width: 25 height: 35
238##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400239##
240
Cary Clark7fc1d122017-10-09 14:07:42 -0400241#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400242
243##
244
245# ------------------------------------------------------------------------------
246
247#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
248 SkScalar b)
249
Cary Clark7fc1d122017-10-09 14:07:42 -0400250Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
251result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400252
Cary Clark7fc1d122017-10-09 14:07:42 -0400253#Param l SkScalar stored in fLeft ##
254#Param t SkScalar stored in fTop ##
255#Param r SkScalar stored in fRight ##
256#Param b SkScalar stored in fBottom ##
257
258#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400259
260#Example
Cary Clark154beea2017-10-26 07:58:48 -0400261 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
262 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
263 rect.bottom(), rect.isEmpty() ? "true" : "false");
264 rect.sort();
265 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
266 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400267#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400268rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400269rect: 5, 25, 15, 35 isEmpty: false
270##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400271##
272
Cary Clark7fc1d122017-10-09 14:07:42 -0400273#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400274
275##
276
277# ------------------------------------------------------------------------------
278
Cary Clark884dd7d2017-10-11 10:37:52 -0400279#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400280
Cary Clark7fc1d122017-10-09 14:07:42 -0400281Returns constructed Rect set to
282#Formula
283(x, y, x + w, y + h)
284##
285. Does not validate input;
286w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400287
Cary Clark7fc1d122017-10-09 14:07:42 -0400288#Param x stored in fLeft ##
289#Param y stored in fTop ##
290#Param w added to x and stored in fRight ##
291#Param h added to y and stored in fBottom ##
292
Cary Clark884dd7d2017-10-11 10:37:52 -0400293#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
295#Example
Cary Clark154beea2017-10-26 07:58:48 -0400296 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
297 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
298 rect.bottom(), rect.isEmpty() ? "true" : "false");
299 rect.sort();
300 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
301 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400302#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400303rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400304rect: -10, 35, 5, 60 isEmpty: false
305##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400306##
307
Cary Clark7fc1d122017-10-09 14:07:42 -0400308#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309
310##
311
312# ------------------------------------------------------------------------------
313
314#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
315
Cary Clark7fc1d122017-10-09 14:07:42 -0400316Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400317
Cary Clark7fc1d122017-10-09 14:07:42 -0400318#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400319##
320
Cary Clark7fc1d122017-10-09 14:07:42 -0400321#Param irect integer rect ##
322
323#Return irect as SkRect ##
324
325#NoExample
326##
327
328#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400329
330##
331
332# ------------------------------------------------------------------------------
333
334#Method static SkRect Make(const SkISize& size)
335
Cary Clark7fc1d122017-10-09 14:07:42 -0400336Returns constructed IRect set to (0, 0, size.width(), size.height()).
337Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400338
Cary Clark7fc1d122017-10-09 14:07:42 -0400339#Param size integer values for Rect width and height ##
340
341#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400342
343#Example
Cary Clark154beea2017-10-26 07:58:48 -0400344 SkRect rect1 = SkRect::MakeSize({2, 35});
345 SkRect rect2 = SkRect::MakeIWH(2, 35);
346 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400347#StdOut
348rect1 == rect2
349##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400350##
351
Cary Clark7fc1d122017-10-09 14:07:42 -0400352#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400353
354##
355
356# ------------------------------------------------------------------------------
357
358#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
359
Cary Clark7fc1d122017-10-09 14:07:42 -0400360Returns constructed IRect set to irect, promoting integers to Scalar.
361Does not validate input; fLeft may be greater than fRight, fTop may be greater
362than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400363
Cary Clark7fc1d122017-10-09 14:07:42 -0400364#Param irect integer unsorted bounds ##
365
366#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400367
368#Example
Cary Clark154beea2017-10-26 07:58:48 -0400369 SkIRect i_rect1 = {2, 35, 22, 53};
370 SkRect f_rect = SkRect::Make(i_rect1);
371 f_rect.offset(0.49f, 0.49f);
372 SkIRect i_rect2;
373 f_rect.round(&i_rect2);
374 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400375##
376
Cary Clark7fc1d122017-10-09 14:07:42 -0400377#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400378
379##
380
381# ------------------------------------------------------------------------------
382
383#Method bool isEmpty() const
384
Cary Clark7fc1d122017-10-09 14:07:42 -0400385Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
386to or greater than fBottom. Call sort() to reverse rectangles with negative
387width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400388
Cary Clark7fc1d122017-10-09 14:07:42 -0400389#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400390
391#Example
Cary Clark154beea2017-10-26 07:58:48 -0400392 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
393 for (auto rect : tests) {
394 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
395 rect.bottom(), rect.isEmpty() ? "" : " not");
396 rect.sort();
397 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
398 rect.bottom(), rect.isEmpty() ? "" : " not");
399 }
400#StdOut
401rect: {20, 40, 10, 50} is empty
402sorted: {10, 40, 20, 50} is not empty
403rect: {20, 40, 20, 50} is empty
404sorted: {20, 40, 20, 50} is empty
405##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400406##
407
Cary Clark7fc1d122017-10-09 14:07:42 -0400408#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400409
410##
411
412# ------------------------------------------------------------------------------
413
414#Method bool isSorted() const
415
Cary Clark7fc1d122017-10-09 14:07:42 -0400416Returns true if fLeft is equal to or less than fRight, or if fTop is equal
417to or less than fBottom. Call sort() to reverse rectangles with negative
418width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400419
Cary Clark7fc1d122017-10-09 14:07:42 -0400420#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400421
422#Example
Cary Clark154beea2017-10-26 07:58:48 -0400423 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
424 for (auto rect : tests) {
425 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
426 rect.bottom(), rect.isSorted() ? "" : " not");
427 rect.sort();
428 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
429 rect.bottom(), rect.isSorted() ? "" : " not");
430 }
431#StdOut
432rect: {20, 40, 10, 50} is not sorted
433sorted: {10, 40, 20, 50} is sorted
434rect: {20, 40, 20, 50} is sorted
435sorted: {20, 40, 20, 50} is sorted
436##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400437##
438
Cary Clark7fc1d122017-10-09 14:07:42 -0400439#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400440
441##
442
443# ------------------------------------------------------------------------------
444
Cary Clarkbc5697d2017-10-04 14:31:33 -0400445#Method bool isFinite() const
446
Cary Clark7fc1d122017-10-09 14:07:42 -0400447Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
448and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400449
Cary Clark7fc1d122017-10-09 14:07:42 -0400450#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400451
452#Example
Mike Reed274218e2018-01-08 15:05:02 -0500453SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400454 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
455 SkDebugf("large width %g\n", largest.width());
456 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
457 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
458#StdOut
459largest is finite: true
460large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400461widest is finite: false
462##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400463##
464
Cary Clark7fc1d122017-10-09 14:07:42 -0400465#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400466
467##
468
469# ------------------------------------------------------------------------------
470
471#Method SkScalar x() const
472
Cary Clark7fc1d122017-10-09 14:07:42 -0400473Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
474Call sort() to reverse fLeft and fRight if needed.
475
476#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400477
478#Example
Cary Clark154beea2017-10-26 07:58:48 -0400479 SkRect unsorted = { 15, 5, 10, 25 };
480 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
481 SkRect sorted = unsorted.makeSorted();
482 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400483#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400484unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400485sorted.fLeft: 10 sorted.x(): 10
486##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400487##
488
Cary Clark7fc1d122017-10-09 14:07:42 -0400489#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400490
491##
492
493# ------------------------------------------------------------------------------
494
495#Method SkScalar y() const
496
Cary Clark7fc1d122017-10-09 14:07:42 -0400497Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
498and sort() to reverse fTop and fBottom if needed.
499
500#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400501
502#Example
Cary Clark154beea2017-10-26 07:58:48 -0400503 SkRect unsorted = { 15, 25, 10, 5 };
504 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
505 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400506 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
507#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400508unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400509sorted.fTop: 5 sorted.y(): 5
510##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400511##
512
Cary Clark7fc1d122017-10-09 14:07:42 -0400513#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400514
515##
516
517# ------------------------------------------------------------------------------
518
519#Method SkScalar left() const
520
Cary Clark7fc1d122017-10-09 14:07:42 -0400521Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
522Call sort() to reverse fLeft and fRight if needed.
523
524#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400525
526#Example
Cary Clark154beea2017-10-26 07:58:48 -0400527 SkRect unsorted = { 15, 5, 10, 25 };
528 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
529 SkRect sorted = unsorted.makeSorted();
530 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400531#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400532unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400533sorted.fLeft: 10 sorted.left(): 10
534##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400535##
536
Cary Clark7fc1d122017-10-09 14:07:42 -0400537#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400538
539##
540
541# ------------------------------------------------------------------------------
542
543#Method SkScalar top() const
544
Cary Clark7fc1d122017-10-09 14:07:42 -0400545Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
546and sort() to reverse fTop and fBottom if needed.
547
548#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400549
550#Example
Cary Clark154beea2017-10-26 07:58:48 -0400551 SkRect unsorted = { 15, 25, 10, 5 };
552 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
553 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400554 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
555#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400556unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400557sorted.fTop: 5 sorted.top(): 5
558##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400559##
560
Cary Clark7fc1d122017-10-09 14:07:42 -0400561#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400562
563##
564
565# ------------------------------------------------------------------------------
566
567#Method SkScalar right() const
568
Cary Clark7fc1d122017-10-09 14:07:42 -0400569Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
570Call sort() to reverse fLeft and fRight if needed.
571
572#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400573
574#Example
Cary Clark154beea2017-10-26 07:58:48 -0400575 SkRect unsorted = { 15, 25, 10, 5 };
576 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
577 SkRect sorted = unsorted.makeSorted();
578 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400579#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400580unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400581sorted.fRight: 15 sorted.right(): 15
582##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400583##
584
Cary Clark7fc1d122017-10-09 14:07:42 -0400585#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400586
587##
588
589# ------------------------------------------------------------------------------
590
591#Method SkScalar bottom() const
592
Cary Clark7fc1d122017-10-09 14:07:42 -0400593Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
594and sort() to reverse fTop and fBottom if needed.
595
596#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400597
598#Example
Cary Clark154beea2017-10-26 07:58:48 -0400599 SkRect unsorted = { 15, 25, 10, 5 };
600 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
601 SkRect sorted = unsorted.makeSorted();
602 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400603#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400604unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400605sorted.fBottom: 25 sorted.bottom(): 25
606##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400607##
608
Cary Clark7fc1d122017-10-09 14:07:42 -0400609#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400610
611##
612
613# ------------------------------------------------------------------------------
614
615#Method SkScalar width() const
616
Cary Clark7fc1d122017-10-09 14:07:42 -0400617Returns span on the x-axis. This does not check if Rect is sorted, or if
618result fits in 32-bit float; result may be negative or infinity.
619
620#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400621
622#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400623#Description
624Compare with SkIRect::width() example.
625##
Cary Clark154beea2017-10-26 07:58:48 -0400626 SkRect unsorted = { 15, 25, 10, 5 };
627 SkDebugf("unsorted width: %g\n", unsorted.width());
628 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
629 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400630#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400631unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400632large width: 4294967296
633##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400634##
635
Cary Clark7fc1d122017-10-09 14:07:42 -0400636#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400637
638##
639
640# ------------------------------------------------------------------------------
641
642#Method SkScalar height() const
643
Cary Clark7fc1d122017-10-09 14:07:42 -0400644Returns span on the y-axis. This does not check if IRect is sorted, or if
645result fits in 32-bit float; result may be negative or infinity.
646
647#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400648
649#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400650#Description
651Compare with SkIRect::height() example.
652##
Cary Clark154beea2017-10-26 07:58:48 -0400653 SkRect unsorted = { 15, 25, 10, 20 };
654 SkDebugf("unsorted height: %g\n", unsorted.height());
655 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
656 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400657#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400658unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400659large height: 4294967296
660##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400661##
662
Cary Clark7fc1d122017-10-09 14:07:42 -0400663#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400664
665##
666
667# ------------------------------------------------------------------------------
668
669#Method SkScalar centerX() const
670
Cary Clark7fc1d122017-10-09 14:07:42 -0400671Returns average of left edge and right edge. Result does not change if Rect
672is sorted. Result may overflow to infinity if Rect is far from the origin.
673
674#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400675
676#Example
Cary Clark154beea2017-10-26 07:58:48 -0400677 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
678 for (auto rect : tests) {
679 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
680 rect.sort();
681 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
682 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400683#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400684left: 20 right: 41 centerX: 30.5
685left: 20 right: 41 centerX: 30.5
686left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400687left: -41 right: -20 centerX: -30.5
688##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400689##
690
Cary Clark7fc1d122017-10-09 14:07:42 -0400691#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400692
693##
694
695# ------------------------------------------------------------------------------
696
697#Method SkScalar centerY() const
698
Cary Clark7fc1d122017-10-09 14:07:42 -0400699Returns average of top edge and bottom edge. Result does not change if Rect
700is sorted. Result may overflow to infinity if Rect is far from the origin.
701
702#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400703
704#Example
Cary Clark154beea2017-10-26 07:58:48 -0400705 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
706 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
707 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400708#StdOut
709left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
710##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400711##
712
Cary Clark7fc1d122017-10-09 14:07:42 -0400713#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400714
715##
716
717# ------------------------------------------------------------------------------
718
Cary Clark884dd7d2017-10-11 10:37:52 -0400719#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400720
Cary Clark7fc1d122017-10-09 14:07:42 -0400721Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
722equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400723
Cary Clark7fc1d122017-10-09 14:07:42 -0400724a and b are not equal if either contain NaN. a and b are equal if members
725contain zeroes width different signs.
726
727#Param a Rect to compare ##
728#Param b Rect to compare ##
729
730#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400731
732#Example
Cary Clark154beea2017-10-26 07:58:48 -0400733 auto debugster = [](const SkRect& test) -> void {
734 SkRect negZero = {-0.0f, -0.0f, 2, 2};
735 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
736 test.fLeft, test.fTop, test.fRight, test.fBottom,
737 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
738 test == negZero ? '=' : '!',
739 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
740 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
741 "and are" : "yet are not");
742 };
743 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
744 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
745 for (auto rect : tests) {
746 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400747 }
Cary Clark154beea2017-10-26 07:58:48 -0400748#StdOut
749tests are equal
750{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
751{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400752{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
753##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400754##
755
Cary Clark7fc1d122017-10-09 14:07:42 -0400756#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400757
758##
759
760# ------------------------------------------------------------------------------
761
Cary Clark884dd7d2017-10-11 10:37:52 -0400762#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400763
Cary Clark7fc1d122017-10-09 14:07:42 -0400764Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
765equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400766
Cary Clark7fc1d122017-10-09 14:07:42 -0400767a and b are not equal if either contain NaN. a and b are equal if members
768contain zeroes width different signs.
769
770#Param a Rect to compare ##
771#Param b Rect to compare ##
772
773#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400774
775#Example
Cary Clark154beea2017-10-26 07:58:48 -0400776 SkRect test = {0, 0, 2, SK_ScalarNaN};
777 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
778#StdOut
Cary Clark7fc1d122017-10-09 14:07:42 -0400779test with NaN is not equal to itself
780##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400781##
782
Cary Clark7fc1d122017-10-09 14:07:42 -0400783#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400784
785##
786
787# ------------------------------------------------------------------------------
788
789#Method void toQuad(SkPoint quad[4]) const
790
Cary Clark7fc1d122017-10-09 14:07:42 -0400791Returns four points in quad that enclose Rect ordered as: top-left, top-right,
792bottom-right, bottom-left.
793
794#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400795Consider adding param to control whether quad is CW or CCW.
796##
797
Cary Clark7fc1d122017-10-09 14:07:42 -0400798#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400799
800#Example
Cary Clark154beea2017-10-26 07:58:48 -0400801 SkRect rect = {1, 2, 3, 4};
802 SkPoint corners[4];
803 rect.toQuad(corners);
804 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
805 SkDebugf("corners:");
806 for (auto corner : corners) {
807 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
808 }
809 SkDebugf("\n");
810#StdOut
811rect: {1, 2, 3, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400812corners: {1, 2} {3, 2} {3, 4} {1, 4}
813##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400814##
815
Cary Clark7fc1d122017-10-09 14:07:42 -0400816#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400817
818##
819
820# ------------------------------------------------------------------------------
821
822#Method void setEmpty()
823
Cary Clark7fc1d122017-10-09 14:07:42 -0400824Sets Rect to (0, 0, 0, 0).
825
826Many other rectangles are empty; if left is equal to or greater than right,
827or if top is equal to or greater than bottom. Setting all members to zero
828is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400829
830#Example
Cary Clark154beea2017-10-26 07:58:48 -0400831 SkRect rect = {3, 4, 1, 2};
832 for (int i = 0; i < 2; ++i) {
833 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
834 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
835 rect.setEmpty();
836 }
837#StdOut
838rect: {3, 4, 1, 2} is empty
839rect: {0, 0, 0, 0} is empty
840##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400841##
842
Cary Clark7fc1d122017-10-09 14:07:42 -0400843#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400844
845##
846
847# ------------------------------------------------------------------------------
848
849#Method void set(const SkIRect& src)
850
Cary Clark7fc1d122017-10-09 14:07:42 -0400851Sets Rect to src, promoting src members from integer to Scalar.
852Very large values in src may lose precision.
853
854#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400855
856#Example
Cary Clark154beea2017-10-26 07:58:48 -0400857 SkIRect i_rect = {3, 4, 1, 2};
858 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
859 SkRect f_rect;
860 f_rect.set(i_rect);
861 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
862#StdOut
863i_rect: {3, 4, 1, 2}
864f_rect: {3, 4, 1, 2}
865##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400866##
867
Cary Clark7fc1d122017-10-09 14:07:42 -0400868#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400869
870##
871
872# ------------------------------------------------------------------------------
873
874#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
875
Cary Clark7fc1d122017-10-09 14:07:42 -0400876Sets Rect to (left, top, right, bottom).
877left and right are not sorted; left is not necessarily less than right.
878top and bottom are not sorted; top is not necessarily less than bottom.
879
880#Param left stored in fLeft ##
881#Param top stored in fTop ##
882#Param right stored in fRight ##
883#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400884
885#Example
Cary Clark154beea2017-10-26 07:58:48 -0400886 SkRect rect1 = {3, 4, 1, 2};
887 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
888 SkRect rect2;
889 rect2.set(3, 4, 1, 2);
890 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
891#StdOut
892rect1: {3, 4, 1, 2}
893rect2: {3, 4, 1, 2}
894##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400895##
896
Cary Clark7fc1d122017-10-09 14:07:42 -0400897#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400898
899##
900
901# ------------------------------------------------------------------------------
902
903#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
904
Cary Clark7fc1d122017-10-09 14:07:42 -0400905Sets Rect to (left, top, right, bottom).
906left and right are not sorted; left is not necessarily less than right.
907top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400908
Cary Clark7fc1d122017-10-09 14:07:42 -0400909#Param left stored in fLeft ##
910#Param top stored in fTop ##
911#Param right stored in fRight ##
912#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400913
914#Example
Cary Clark154beea2017-10-26 07:58:48 -0400915 SkRect rect1 = {3, 4, 1, 2};
916 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
917 SkRect rect2;
918 rect2.setLTRB(3, 4, 1, 2);
919 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
920#StdOut
921rect1: {3, 4, 1, 2}
922rect2: {3, 4, 1, 2}
923##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400924##
925
Cary Clark7fc1d122017-10-09 14:07:42 -0400926#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400927
928##
929
930# ------------------------------------------------------------------------------
931
932#Method void iset(int left, int top, int right, int bottom)
933
Cary Clark7fc1d122017-10-09 14:07:42 -0400934Sets Rect to (left, top, right, bottom).
935All parameters are promoted from integer to Scalar.
936left and right are not sorted; left is not necessarily less than right.
937top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400938
Cary Clark7fc1d122017-10-09 14:07:42 -0400939#Param left promoted to SkScalar and stored in fLeft ##
940#Param top promoted to SkScalar and stored in fTop ##
941#Param right promoted to SkScalar and stored in fRight ##
942#Param bottom promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400943
944#Example
Cary Clark154beea2017-10-26 07:58:48 -0400945 SkRect rect1 = {3, 4, 1, 2};
946 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
947 SkRect rect2;
948 rect2.iset(3, 4, 1, 2);
949 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
950#StdOut
951rect1: {3, 4, 1, 2}
952rect2: {3, 4, 1, 2}
953##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400954##
955
Cary Clark7fc1d122017-10-09 14:07:42 -0400956#SeeAlso set setLTRB SkIRect::set SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400957
958##
959
960# ------------------------------------------------------------------------------
961
962#Method void isetWH(int width, int height)
963
Cary Clark7fc1d122017-10-09 14:07:42 -0400964Sets Rect to (0, 0, width, height).
965width and height may be zero or negative. width and height are promoted from
966integer to SkScalar, large values may lose precision.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400967
Cary Clark7fc1d122017-10-09 14:07:42 -0400968#Param width promoted to SkScalar and stored in fRight ##
969#Param height promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400970
971#Example
Cary Clark154beea2017-10-26 07:58:48 -0400972 SkRect rect1 = {0, 0, 1, 2};
973 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
974 SkRect rect2;
975 rect2.isetWH(1, 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400976 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
Cary Clark154beea2017-10-26 07:58:48 -0400977#StdOut
978rect1: {0, 0, 1, 2}
979rect2: {0, 0, 1, 2}
980##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400981##
982
Cary Clark7fc1d122017-10-09 14:07:42 -0400983#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400984
985##
986
987# ------------------------------------------------------------------------------
988
989#Method void set(const SkPoint pts[], int count)
990
Cary Clark7fc1d122017-10-09 14:07:42 -0400991Sets to bounds of Point array with count entries. If count is zero or smaller,
992or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -0400993
Cary Clark7fc1d122017-10-09 14:07:42 -0400994Result is either empty or sorted: fLeft is less than or equal to fRight, and
995fTop is less than or equal to fBottom.
996
997#Param pts Point array ##
998#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400999
1000#Example
Cary Clark154beea2017-10-26 07:58:48 -04001001 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1002 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1003 SkRect rect;
1004 rect.set(points, count);
1005 if (count > 0) {
1006 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1007 } else {
1008 SkDebugf("%14s", " ");
1009 }
1010 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1011 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1012 }
1013#StdOut
1014 count: 0 rect: 0, 0, 0, 0
1015added: 3, 4 count: 1 rect: 3, 4, 3, 4
1016added: 1, 2 count: 2 rect: 1, 2, 3, 4
1017added: 5, 6 count: 3 rect: 1, 2, 5, 6
1018added: nan, 8 count: 4 rect: 0, 0, 0, 0
1019##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001020##
1021
Cary Clark7fc1d122017-10-09 14:07:42 -04001022#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001023
1024##
1025
1026# ------------------------------------------------------------------------------
1027
1028#Method void setBounds(const SkPoint pts[], int count)
1029
Cary Clark7fc1d122017-10-09 14:07:42 -04001030Sets to bounds of Point array with count entries. If count is zero or smaller,
1031or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001032
Cary Clark7fc1d122017-10-09 14:07:42 -04001033Result is either empty or sorted: fLeft is less than or equal to fRight, and
1034fTop is less than or equal to fBottom.
1035
1036#Param pts Point array ##
1037#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001038
1039#Example
Cary Clark154beea2017-10-26 07:58:48 -04001040 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1041 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1042 SkRect rect;
1043 rect.setBounds(points, count);
1044 if (count > 0) {
1045 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1046 } else {
1047 SkDebugf("%14s", " ");
1048 }
1049 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1050 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1051 }
1052#StdOut
1053 count: 0 rect: 0, 0, 0, 0
1054added: 3, 4 count: 1 rect: 3, 4, 3, 4
1055added: 1, 2 count: 2 rect: 1, 2, 3, 4
1056added: 5, 6 count: 3 rect: 1, 2, 5, 6
1057added: nan, 8 count: 4 rect: 0, 0, 0, 0
1058##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001059##
1060
Cary Clark7fc1d122017-10-09 14:07:42 -04001061#SeeAlso set setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001062
1063##
1064
1065# ------------------------------------------------------------------------------
1066
1067#Method bool setBoundsCheck(const SkPoint pts[], int count)
1068
Cary Clark7fc1d122017-10-09 14:07:42 -04001069Sets to bounds of Point array with count entries. Returns false if count is
1070zero or smaller, or if Point array contains an infinity or NaN; in these cases
1071sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001072
Cary Clark7fc1d122017-10-09 14:07:42 -04001073Result is either empty or sorted: fLeft is less than or equal to fRight, and
1074fTop is less than or equal to fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001075
Cary Clark7fc1d122017-10-09 14:07:42 -04001076#Param pts Point array ##
1077#Param count entries in array ##
1078
1079#Return true if all Point values are finite ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001080
1081#Example
Cary Clark154beea2017-10-26 07:58:48 -04001082 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1083 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1084 SkRect rect;
1085 bool success = rect.setBoundsCheck(points, count);
1086 if (count > 0) {
1087 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1088 } else {
1089 SkDebugf("%14s", " ");
1090 }
1091 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
1092 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
1093 }
1094#StdOut
1095 count: 0 rect: 0, 0, 0, 0 success: true
1096added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
1097added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
1098added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
1099added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
1100##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001101##
1102
Cary Clark7fc1d122017-10-09 14:07:42 -04001103#SeeAlso set setBounds SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001104
1105##
1106
1107# ------------------------------------------------------------------------------
1108
1109#Method void set(const SkPoint& p0, const SkPoint& p1)
1110
Cary Clark7fc1d122017-10-09 14:07:42 -04001111Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1112sorted and may be empty. Does not check to see if values are finite.
1113
1114#Param p0 corner to include ##
1115#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001116
1117#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001118#Description
1119p0 and p1 may be swapped and have the same effect unless one contains NaN.
1120##
Cary Clark154beea2017-10-26 07:58:48 -04001121 SkPoint point1 = {SK_ScalarNaN, 8};
1122 SkPoint point2 = {3, 4};
1123 SkRect rect;
1124 rect.set(point1, point2);
1125 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1126 rect.set(point2, point1);
1127 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001128##
1129
Cary Clark7fc1d122017-10-09 14:07:42 -04001130#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001131
1132##
1133
1134# ------------------------------------------------------------------------------
1135
1136#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1137
Cary Clark7fc1d122017-10-09 14:07:42 -04001138Sets Rect to
1139#Formula
1140(x, y, x + width, y + height)
1141##
1142. Does not validate input;
1143width or height may be negative.
1144
1145#Param x stored in fLeft ##
1146#Param y stored in fTop ##
1147#Param width added to x and stored in fRight ##
1148#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001149
1150#Example
Cary Clark154beea2017-10-26 07:58:48 -04001151 SkRect rect;
1152 rect.setXYWH(5, 35, -15, 25);
1153 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1154 rect.bottom(), rect.isEmpty() ? "true" : "false");
1155 rect.sort();
1156 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1157 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001158#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001159rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001160rect: -10, 35, 5, 60 isEmpty: false
1161##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001162##
1163
Cary Clark7fc1d122017-10-09 14:07:42 -04001164#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001165
1166##
1167
1168# ------------------------------------------------------------------------------
1169
1170#Method void setWH(SkScalar width, SkScalar height)
1171
Cary Clark7fc1d122017-10-09 14:07:42 -04001172Sets Rect to (0, 0, width, height). Does not validate input;
1173width or height may be negative.
1174
1175#Param width stored in fRight ##
1176#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001177
1178#Example
Cary Clark154beea2017-10-26 07:58:48 -04001179 SkRect rect;
1180 rect.setWH(-15, 25);
1181 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1182 rect.bottom(), rect.isEmpty() ? "true" : "false");
1183 rect.sort();
1184 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1185 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001186#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001187rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001188rect: -15, 0, 0, 25 isEmpty: false
1189##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001190##
1191
Cary Clark7fc1d122017-10-09 14:07:42 -04001192#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001193
1194##
1195
1196# ------------------------------------------------------------------------------
1197
Cary Clarkbc5697d2017-10-04 14:31:33 -04001198#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1199
Cary Clark7fc1d122017-10-09 14:07:42 -04001200Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001201
Cary Clark7fc1d122017-10-09 14:07:42 -04001202If dx is negative, Rect returned is moved to the left.
1203If dx is positive, Rect returned is moved to the right.
1204If dy is negative, Rect returned is moved upward.
1205If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001206
Cary Clark7fc1d122017-10-09 14:07:42 -04001207#Param dx added to fLeft and fRight ##
1208#Param dy added to fTop and fBottom ##
1209
1210#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001211
1212#Example
Cary Clark154beea2017-10-26 07:58:48 -04001213 SkRect rect = { 10, 50, 20, 60 };
1214 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1215 rect.bottom(), rect.isEmpty() ? "true" : "false");
1216 rect = rect.makeOffset(15, 32);
1217 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1218 rect.bottom(), rect.isEmpty() ? "true" : "false");
1219#StdOut
1220rect: 10, 50, 20, 60 isEmpty: false
1221rect: 25, 82, 35, 92 isEmpty: false
1222##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001223##
1224
Cary Clark7fc1d122017-10-09 14:07:42 -04001225#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001226
1227##
1228
1229# ------------------------------------------------------------------------------
1230
1231#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1232
Cary Clark7fc1d122017-10-09 14:07:42 -04001233Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001234
Cary Clark7fc1d122017-10-09 14:07:42 -04001235If dx is negative, Rect returned is wider.
1236If dx is positive, Rect returned is narrower.
1237If dy is negative, Rect returned is taller.
1238If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001239
Cary Clark7fc1d122017-10-09 14:07:42 -04001240#Param dx added to fLeft and subtracted from fRight ##
1241#Param dy added to fTop and subtracted from fBottom ##
1242
1243#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001244
1245#Example
Cary Clark154beea2017-10-26 07:58:48 -04001246 SkRect rect = { 10, 50, 20, 60 };
1247 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1248 rect.bottom(), rect.isEmpty() ? "true" : "false");
1249 rect = rect.makeInset(15, 32);
1250 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1251 rect.bottom(), rect.isEmpty() ? "true" : "false");
1252#StdOut
1253rect: 10, 50, 20, 60 isEmpty: false
1254rect: 25, 82, 5, 28 isEmpty: true
1255##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001256##
1257
Cary Clark7fc1d122017-10-09 14:07:42 -04001258#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001259
1260##
1261
1262# ------------------------------------------------------------------------------
1263
1264#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1265
Cary Clark7fc1d122017-10-09 14:07:42 -04001266Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001267
Cary Clark7fc1d122017-10-09 14:07:42 -04001268If dx is negative, Rect returned is narrower.
1269If dx is positive, Rect returned is wider.
1270If dy is negative, Rect returned is shorter.
1271If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001272
Cary Clark7fc1d122017-10-09 14:07:42 -04001273#Param dx subtracted to fLeft and added from fRight ##
1274#Param dy subtracted to fTop and added from fBottom ##
1275
1276#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001277
1278#Example
Cary Clark154beea2017-10-26 07:58:48 -04001279 SkRect rect = { 10, 50, 20, 60 };
1280 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1281 rect.bottom(), rect.isEmpty() ? "true" : "false");
1282 rect = rect.makeOutset(15, 32);
1283 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1284 rect.bottom(), rect.isEmpty() ? "true" : "false");
1285#StdOut
1286rect: 10, 50, 20, 60 isEmpty: false
1287rect: -5, 18, 35, 92 isEmpty: false
1288##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001289##
1290
Cary Clark7fc1d122017-10-09 14:07:42 -04001291#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001292
1293##
1294
1295# ------------------------------------------------------------------------------
1296
1297#Method void offset(SkScalar dx, SkScalar dy)
1298
Cary Clark7fc1d122017-10-09 14:07:42 -04001299Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001300
Cary Clark7fc1d122017-10-09 14:07:42 -04001301If dx is negative, moves Rect to the left.
1302If dx is positive, moves Rect to the right.
1303If dy is negative, moves Rect upward.
1304If dy is positive, moves Rect downward.
1305
1306#Param dx offset added to fLeft and fRight ##
1307#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001308
1309#Example
Cary Clark154beea2017-10-26 07:58:48 -04001310 SkRect rect = { 10, 14, 50, 73 };
1311 rect.offset(5, 13);
1312 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1313#StdOut
1314rect: 15, 27, 55, 86
1315##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001316##
1317
Cary Clark7fc1d122017-10-09 14:07:42 -04001318#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001319
1320##
1321
1322# ------------------------------------------------------------------------------
1323
1324#Method void offset(const SkPoint& delta)
1325
Cary Clark7fc1d122017-10-09 14:07:42 -04001326Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1327fTop, fBottom.
1328
1329If delta.fX is negative, moves Rect to the left.
1330If delta.fX is positive, moves Rect to the right.
1331If delta.fY is negative, moves Rect upward.
1332If delta.fY is positive, moves Rect downward.
1333
1334#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001335
1336#Example
Cary Clark154beea2017-10-26 07:58:48 -04001337 SkRect rect = { 10, 14, 50, 73 };
1338 rect.offset({5, 13});
1339 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1340#StdOut
1341rect: 15, 27, 55, 86
1342##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001343##
1344
Cary Clark7fc1d122017-10-09 14:07:42 -04001345#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001346
1347##
1348
1349# ------------------------------------------------------------------------------
1350
1351#Method void offsetTo(SkScalar newX, SkScalar newY)
1352
Cary Clark7fc1d122017-10-09 14:07:42 -04001353Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1354are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001355
Cary Clark7fc1d122017-10-09 14:07:42 -04001356#Param newX stored in fLeft, preserving width() ##
1357#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358
1359#Example
Cary Clark154beea2017-10-26 07:58:48 -04001360 SkRect rect = { 10, 14, 50, 73 };
1361 rect.offsetTo(15, 27);
1362 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1363#StdOut
1364rect: 15, 27, 55, 86
1365##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001366##
1367
Cary Clark7fc1d122017-10-09 14:07:42 -04001368#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
1370##
1371
1372# ------------------------------------------------------------------------------
1373
1374#Method void inset(SkScalar dx, SkScalar dy)
1375
Cary Clark7fc1d122017-10-09 14:07:42 -04001376Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001377
Cary Clark7fc1d122017-10-09 14:07:42 -04001378If dx is positive, makes Rect narrower.
1379If dx is negative, makes Rect wider.
1380If dy is positive, makes Rect shorter.
1381If dy is negative, makes Rect taller.
1382
1383#Param dx added to fLeft and subtracted from fRight ##
1384#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001385
1386#Example
Cary Clark154beea2017-10-26 07:58:48 -04001387 SkRect rect = { 10, 14, 50, 73 };
1388 rect.inset(5, 13);
1389 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1390#StdOut
1391rect: 15, 27, 45, 60
1392##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001393##
1394
Cary Clark7fc1d122017-10-09 14:07:42 -04001395#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001396
1397##
1398
1399# ------------------------------------------------------------------------------
1400
1401#Method void outset(SkScalar dx, SkScalar dy)
1402
Cary Clark7fc1d122017-10-09 14:07:42 -04001403Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001404
Cary Clark7fc1d122017-10-09 14:07:42 -04001405If dx is positive, makes Rect wider.
1406If dx is negative, makes Rect narrower.
1407If dy is positive, makes Rect taller.
1408If dy is negative, makes Rect shorter.
1409
1410#Param dx subtracted to fLeft and added from fRight ##
1411#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001412
1413#Example
Cary Clark154beea2017-10-26 07:58:48 -04001414 SkRect rect = { 10, 14, 50, 73 };
1415 rect.outset(5, 13);
1416 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1417#StdOut
1418rect: 5, 1, 55, 86
1419##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001420##
1421
Cary Clark7fc1d122017-10-09 14:07:42 -04001422#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001423
1424##
1425
Cary Clark7fc1d122017-10-09 14:07:42 -04001426#Topic Intersection
1427
1428Rects intersect when they enclose a common area. To intersect, each of the pair
1429must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001430empty() returns false. The intersection of Rect pair can be described by:
1431
Cary Clark7fc1d122017-10-09 14:07:42 -04001432#Formula
1433(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1434 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1435##
Cary Clark154beea2017-10-26 07:58:48 -04001436.
1437
Cary Clark7fc1d122017-10-09 14:07:42 -04001438The intersection is only meaningful if the resulting Rect is not empty and
1439describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1440
Cary Clarkbc5697d2017-10-04 14:31:33 -04001441# ------------------------------------------------------------------------------
1442
1443#Method bool intersect(const SkRect& r)
1444
Cary Clark7fc1d122017-10-09 14:07:42 -04001445Returns true if Rect intersects r, and sets Rect to intersection.
1446Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001447
Cary Clark7fc1d122017-10-09 14:07:42 -04001448Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001449
Cary Clark7fc1d122017-10-09 14:07:42 -04001450#Param r limit of result ##
1451
1452#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001453
1454#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001455#Description
1456Two SkDebugf calls are required. If the calls are combined, their arguments
1457may not be evaluated in left to right order: the printed intersection may
1458be before or after the call to intersect.
1459##
Cary Clark154beea2017-10-26 07:58:48 -04001460 SkRect leftRect = { 10, 40, 50, 80 };
1461 SkRect rightRect = { 30, 60, 70, 90 };
1462 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1463 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001464 leftRect.right(), leftRect.bottom());
1465#StdOut
1466 intersection: 30, 60, 50, 80
1467##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001468##
1469
Cary Clark7fc1d122017-10-09 14:07:42 -04001470#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001471
1472##
1473
1474# ------------------------------------------------------------------------------
1475
1476#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1477
Cary Clark7fc1d122017-10-09 14:07:42 -04001478Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1479construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001480
Cary Clark7fc1d122017-10-09 14:07:42 -04001481Returns true if Rect intersects construction, and sets Rect to intersection.
1482Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001483
Cary Clark7fc1d122017-10-09 14:07:42 -04001484Returns false if either construction or Rect is empty, leaving Rect unchanged.
1485
1486#Param left x minimum of constructed Rect ##
1487#Param top y minimum of constructed Rect ##
1488#Param right x maximum of constructed Rect ##
1489#Param bottom y maximum of constructed Rect ##
1490
1491#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001492
1493#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001494#Description
1495Two SkDebugf calls are required. If the calls are combined, their arguments
1496may not be evaluated in left to right order: the printed intersection may
1497be before or after the call to intersect.
1498##
Cary Clark154beea2017-10-26 07:58:48 -04001499 SkRect leftRect = { 10, 40, 50, 80 };
1500 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1501 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001502 leftRect.right(), leftRect.bottom());
1503#StdOut
1504 intersection: 30, 60, 50, 80
1505##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001506##
1507
Cary Clark7fc1d122017-10-09 14:07:42 -04001508#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001509
1510##
1511
1512# ------------------------------------------------------------------------------
1513
1514#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1515
Cary Clark7fc1d122017-10-09 14:07:42 -04001516Returns true if a intersects b, and sets Rect to intersection.
1517Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001518
Cary Clark7fc1d122017-10-09 14:07:42 -04001519Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001520
Cary Clark7fc1d122017-10-09 14:07:42 -04001521#Param a Rect to intersect ##
1522#Param b Rect to intersect ##
1523
1524#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001525
1526#Example
Cary Clark154beea2017-10-26 07:58:48 -04001527 SkRect result;
1528 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1529 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1530 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001531#StdOut
1532 intersection: 30, 60, 50, 80
1533##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001534##
1535
Cary Clark7fc1d122017-10-09 14:07:42 -04001536#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001537
1538##
1539
Cary Clark7fc1d122017-10-09 14:07:42 -04001540# ------------------------------------------------------------------------------
1541
Cary Clarkbc5697d2017-10-04 14:31:33 -04001542#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1543
Cary Clark7fc1d122017-10-09 14:07:42 -04001544Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1545construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001546
Cary Clark7fc1d122017-10-09 14:07:42 -04001547Returns true if Rect intersects construction.
1548Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001549
Cary Clark7fc1d122017-10-09 14:07:42 -04001550#Param left x minimum of constructed Rect ##
1551#Param top y minimum of constructed Rect ##
1552#Param right x maximum of constructed Rect ##
1553#Param bottom y maximum of constructed Rect ##
1554
1555#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001556
1557#Example
Cary Clark154beea2017-10-26 07:58:48 -04001558 SkRect rect = { 10, 40, 50, 80 };
1559 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001560#StdOut
1561 intersection
1562##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001563##
1564
Cary Clark7fc1d122017-10-09 14:07:42 -04001565#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001566
1567##
1568
Cary Clark7fc1d122017-10-09 14:07:42 -04001569# ------------------------------------------------------------------------------
1570
Cary Clarkbc5697d2017-10-04 14:31:33 -04001571#Method bool intersects(const SkRect& r) const
1572
Cary Clark7fc1d122017-10-09 14:07:42 -04001573Returns true if Rect intersects r.
1574Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001575
Cary Clark7fc1d122017-10-09 14:07:42 -04001576#Param r Rect to intersect ##
1577
1578#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001579
1580#Example
Cary Clark154beea2017-10-26 07:58:48 -04001581 SkRect rect = { 10, 40, 50, 80 };
1582 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001583#StdOut
1584 intersection
1585##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001586##
1587
Cary Clark7fc1d122017-10-09 14:07:42 -04001588#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001589
1590##
1591
Cary Clark7fc1d122017-10-09 14:07:42 -04001592# ------------------------------------------------------------------------------
1593
Cary Clarkbc5697d2017-10-04 14:31:33 -04001594#Method static bool Intersects(const SkRect& a, const SkRect& b)
1595
Cary Clark7fc1d122017-10-09 14:07:42 -04001596Returns true if a intersects b.
1597Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001598
Cary Clark7fc1d122017-10-09 14:07:42 -04001599#Param a Rect to intersect ##
1600#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001601
Cary Clark7fc1d122017-10-09 14:07:42 -04001602#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001603
1604#Example
Cary Clark154beea2017-10-26 07:58:48 -04001605 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001606#StdOut
1607 intersection
1608##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001609##
1610
Cary Clark7fc1d122017-10-09 14:07:42 -04001611#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001612
1613##
1614
Cary Clark7fc1d122017-10-09 14:07:42 -04001615#Topic Intersection ##
1616
1617
1618# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001619
1620#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1621
Cary Clark7fc1d122017-10-09 14:07:42 -04001622Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1623construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001624
Cary Clark7fc1d122017-10-09 14:07:42 -04001625Sets Rect to the union of itself and the construction.
1626
1627Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1628Rect to construction.
1629
1630#Param left x minimum of constructed Rect ##
1631#Param top y minimum of constructed Rect ##
1632#Param right x maximum of constructed Rect ##
1633#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001634
1635#Example
Cary Clark154beea2017-10-26 07:58:48 -04001636 SkRect rect = { 10, 20, 15, 25};
1637 rect.join(50, 60, 55, 65);
1638 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001639#StdOut
1640 join: 10, 20, 55, 65
1641##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001642##
1643
Cary Clark7fc1d122017-10-09 14:07:42 -04001644#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001645
1646##
1647
Cary Clark7fc1d122017-10-09 14:07:42 -04001648# ------------------------------------------------------------------------------
1649
Cary Clarkbc5697d2017-10-04 14:31:33 -04001650#Method void join(const SkRect& r)
1651
Cary Clark7fc1d122017-10-09 14:07:42 -04001652Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001653
Cary Clark7fc1d122017-10-09 14:07:42 -04001654Has no effect if r is empty. Otherwise, if Rect is empty, sets
1655Rect to r.
1656
1657#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001658
1659#Example
Cary Clark154beea2017-10-26 07:58:48 -04001660 SkRect rect = { 10, 20, 15, 25};
1661 rect.join({50, 60, 55, 65});
1662 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001663#StdOut
1664 join: 10, 20, 55, 65
1665##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001666##
1667
Cary Clark7fc1d122017-10-09 14:07:42 -04001668#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001669
1670##
1671
Cary Clark7fc1d122017-10-09 14:07:42 -04001672# ------------------------------------------------------------------------------
1673
Cary Clarkbc5697d2017-10-04 14:31:33 -04001674#Method void joinNonEmptyArg(const SkRect& r)
1675
Cary Clark7fc1d122017-10-09 14:07:42 -04001676Sets Rect to the union of itself and r.
1677
1678Asserts if r is empty and SK_DEBUG is defined.
1679If Rect is empty, sets Rect to r.
1680
1681May produce incorrect results if r is empty.
1682
1683#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001684
1685#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001686#Description
1687Since Rect is not sorted, first result is copy of toJoin.
1688##
Cary Clark154beea2017-10-26 07:58:48 -04001689 SkRect rect = { 10, 100, 15, 0};
1690 SkRect sorted = rect.makeSorted();
1691 SkRect toJoin = { 50, 60, 55, 65 };
1692 rect.joinNonEmptyArg(toJoin);
1693 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1694 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001695 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1696#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001697rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001698sorted: 10, 0, 55, 100
1699##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001700##
1701
Cary Clark7fc1d122017-10-09 14:07:42 -04001702#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001703
1704##
1705
Cary Clark7fc1d122017-10-09 14:07:42 -04001706# ------------------------------------------------------------------------------
1707
Cary Clarkbc5697d2017-10-04 14:31:33 -04001708#Method void joinPossiblyEmptyRect(const SkRect& r)
1709
Cary Clark7fc1d122017-10-09 14:07:42 -04001710Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001711
Cary Clark7fc1d122017-10-09 14:07:42 -04001712May produce incorrect results if Rect or r is empty.
1713
1714#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001715
1716#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001717#Description
1718Since Rect is not sorted, first result is not useful.
1719##
Cary Clark154beea2017-10-26 07:58:48 -04001720 SkRect rect = { 10, 100, 15, 0};
1721 SkRect sorted = rect.makeSorted();
1722 SkRect toJoin = { 50, 60, 55, 65 };
1723 rect.joinPossiblyEmptyRect(toJoin);
1724 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1725 sorted.joinPossiblyEmptyRect(toJoin);
1726 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001727#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001728rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001729sorted: 10, 0, 55, 100
1730##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001731##
1732
Cary Clark7fc1d122017-10-09 14:07:42 -04001733#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001734
1735##
1736
Cary Clark7fc1d122017-10-09 14:07:42 -04001737# ------------------------------------------------------------------------------
1738
Cary Clarkbc5697d2017-10-04 14:31:33 -04001739#Method void growToInclude(SkPoint pt)
1740
Cary Clark7fc1d122017-10-09 14:07:42 -04001741Grows Rect to include (pt.fX, pt.fY), modifying it so that:
Cary Clark154beea2017-10-26 07:58:48 -04001742
Cary Clark7fc1d122017-10-09 14:07:42 -04001743#Formula
1744fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1745##
1746.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001747
Mike Reed274218e2018-01-08 15:05:02 -05001748If Rect is inverted, then Rect will contain bounds of
Cary Clark7fc1d122017-10-09 14:07:42 -04001749Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001750
Cary Clark7fc1d122017-10-09 14:07:42 -04001751#Param pt Point to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001752
1753#Example
Mike Reed274218e2018-01-08 15:05:02 -05001754 SkRect rect = { 1, 1, 0, 0 };
Cary Clark154beea2017-10-26 07:58:48 -04001755 rect.growToInclude( { 42, 24 } );
1756 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1757 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001758#StdOut
1759rect: 42, 24, 42, 24 isEmpty: true
1760##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001761##
1762
Mike Reed274218e2018-01-08 15:05:02 -05001763#SeeAlso join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001764
1765##
1766
Cary Clark7fc1d122017-10-09 14:07:42 -04001767# ------------------------------------------------------------------------------
1768
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769#Method void growToInclude(const SkPoint pts[], int count)
1770
Cary Clark7fc1d122017-10-09 14:07:42 -04001771For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1772it so that:
1773#Formula
1774fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1775##
1776.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001777
Mike Reed274218e2018-01-08 15:05:02 -05001778If Rect is inverted, then Rect will contain bounds of
Cary Clark7fc1d122017-10-09 14:07:42 -04001779Points after one or more calls. In this case, Rect is empty after first call.
1780
1781#Param pts Point array ##
1782#Param count number of points in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001783
1784#Example
Cary Clark154beea2017-10-26 07:58:48 -04001785 SkPoint pts[] = { { 30, 50 }, { 40, 50 }, { 30, 60 } };
1786 SkRect rect = { pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY };
1787 rect.growToInclude( pts[1] );
1788 rect.growToInclude( pts[2] );
1789 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001790#StdOut
1791rect: 30, 50, 40, 60
1792##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793##
1794
Mike Reed274218e2018-01-08 15:05:02 -05001795#SeeAlso join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001796
1797##
1798
Cary Clark7fc1d122017-10-09 14:07:42 -04001799# ------------------------------------------------------------------------------
1800
Cary Clarkbc5697d2017-10-04 14:31:33 -04001801#Method void growToInclude(const SkPoint pts[], size_t stride, int count)
1802
Cary Clark7fc1d122017-10-09 14:07:42 -04001803For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1804it so that:
1805#Formula
1806fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1807##
Cary Clark154beea2017-10-26 07:58:48 -04001808.
1809
1810Point may be followed with other data in each array element. stride is number
1811of bytes in element; the interval to skip to advance from one Point to
Cary Clark7fc1d122017-10-09 14:07:42 -04001812the next.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001813
Mike Reed274218e2018-01-08 15:05:02 -05001814If Rect is inverted, then Rect will contain bounds of
Cary Clark7fc1d122017-10-09 14:07:42 -04001815Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001816
Cary Clark7fc1d122017-10-09 14:07:42 -04001817#Param pts array of elements beginning with Point ##
1818#Param stride size of pts elements in 32-bit words; zero or greater ##
1819#Param count number of elements in array ##
1820
1821#Bug 7142 ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001822#Example
Cary Clark154beea2017-10-26 07:58:48 -04001823 SkPoint3 pts[] = { { 30, 50, -1 }, { 40, 50, -1 }, { 30, 60, -1 } };
Mike Reed274218e2018-01-08 15:05:02 -05001824 SkRect rect = { 1, 1, 0, 0 };
Cary Clark154beea2017-10-26 07:58:48 -04001825 rect.growToInclude((SkPoint* ) &pts[0].fX, sizeof(SkPoint3), SK_ARRAY_COUNT(pts));
1826 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001827#StdOut
1828#Volatile
1829rect: 30, 50, 40, 60
1830##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001831##
1832
Mike Reed274218e2018-01-08 15:05:02 -05001833#SeeAlso join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001834
1835##
1836
Cary Clark7fc1d122017-10-09 14:07:42 -04001837# ------------------------------------------------------------------------------
1838
Cary Clark884dd7d2017-10-11 10:37:52 -04001839#Method bool contains(const SkRect& r) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001840
Cary Clark7fc1d122017-10-09 14:07:42 -04001841Returns true if Rect contains r.
1842Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001843
Cary Clark7fc1d122017-10-09 14:07:42 -04001844Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001845
Cary Clark7fc1d122017-10-09 14:07:42 -04001846#Param r Rect contained ##
1847
1848#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001849
1850#Example
Cary Clark154beea2017-10-26 07:58:48 -04001851 SkRect rect = { 30, 50, 40, 60 };
1852 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1853 for (auto contained : tests) {
1854 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1855 rect.left(), rect.top(), rect.right(), rect.bottom(),
1856 rect.contains(contained) ? "contains" : "does not contain",
1857 contained.left(), contained.top(), contained.right(), contained.bottom());
1858 }
1859#StdOut
1860rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1861rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1862rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1863##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001864##
1865
Cary Clark7fc1d122017-10-09 14:07:42 -04001866#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001867
1868##
1869
Cary Clark7fc1d122017-10-09 14:07:42 -04001870# ------------------------------------------------------------------------------
1871
Cary Clarkbc5697d2017-10-04 14:31:33 -04001872#Method bool contains(const SkIRect& r) const
1873
Cary Clark7fc1d122017-10-09 14:07:42 -04001874Returns true if Rect contains r.
1875Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001876
Cary Clark7fc1d122017-10-09 14:07:42 -04001877Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001878
Cary Clark7fc1d122017-10-09 14:07:42 -04001879#Param r IRect contained ##
1880
1881#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001882
1883#Example
Cary Clark154beea2017-10-26 07:58:48 -04001884 SkRect rect = { 30, 50, 40, 60 };
1885 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1886 for (auto contained : tests) {
1887 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1888 rect.left(), rect.top(), rect.right(), rect.bottom(),
1889 rect.contains(contained) ? "contains" : "does not contain",
1890 contained.left(), contained.top(), contained.right(), contained.bottom());
1891 }
1892#StdOut
1893rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1894rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1895rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1896##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001897##
1898
Cary Clark7fc1d122017-10-09 14:07:42 -04001899#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001900
1901##
1902
Cary Clark7fc1d122017-10-09 14:07:42 -04001903#Topic Round
1904
1905# ------------------------------------------------------------------------------
1906
Cary Clarkbc5697d2017-10-04 14:31:33 -04001907#Method void round(SkIRect* dst) const
1908
Cary Clark7fc1d122017-10-09 14:07:42 -04001909Sets IRect by adding 0.5 and discarding the fractional portion of Rect
1910members, using
1911#Formula
1912(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1913 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
1914##
1915.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001916
Cary Clark7fc1d122017-10-09 14:07:42 -04001917#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918
1919#Example
Cary Clark154beea2017-10-26 07:58:48 -04001920 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1921 SkIRect round;
1922 rect.round(&round);
1923 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001924#StdOut
1925round: 31, 51, 41, 61
1926##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001927##
1928
Cary Clark7fc1d122017-10-09 14:07:42 -04001929#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001930
1931##
1932
Cary Clark7fc1d122017-10-09 14:07:42 -04001933# ------------------------------------------------------------------------------
1934
Cary Clarkbc5697d2017-10-04 14:31:33 -04001935#Method void roundOut(SkIRect* dst) const
1936
Cary Clark7fc1d122017-10-09 14:07:42 -04001937Sets IRect by discarding the fractional portion of fLeft and fTop; and
1938rounding up fRight and FBottom, using
1939#Formula
1940(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1941 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1942##
1943.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001944
Cary Clark7fc1d122017-10-09 14:07:42 -04001945#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001946
1947#Example
Cary Clark154beea2017-10-26 07:58:48 -04001948 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1949 SkIRect round;
1950 rect.roundOut(&round);
1951 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001952#StdOut
1953round: 30, 50, 41, 61
1954##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001955##
1956
Cary Clark7fc1d122017-10-09 14:07:42 -04001957#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001958
1959##
1960
Cary Clark7fc1d122017-10-09 14:07:42 -04001961# ------------------------------------------------------------------------------
1962
Cary Clarkbc5697d2017-10-04 14:31:33 -04001963#Method void roundOut(SkRect* dst) const
1964
Cary Clark7fc1d122017-10-09 14:07:42 -04001965Sets Rect by discarding the fractional portion of fLeft and fTop; and
1966rounding up fRight and FBottom, using
1967#Formula
1968(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1969 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1970##
1971.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001972
Cary Clark7fc1d122017-10-09 14:07:42 -04001973#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001974
1975#Example
Cary Clark154beea2017-10-26 07:58:48 -04001976 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1977 SkRect round;
1978 rect.roundOut(&round);
1979 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001980#StdOut
1981round: 30, 50, 41, 61
1982##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001983##
1984
Cary Clark7fc1d122017-10-09 14:07:42 -04001985#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001986
1987##
1988
Cary Clark7fc1d122017-10-09 14:07:42 -04001989# ------------------------------------------------------------------------------
1990
Cary Clarkbc5697d2017-10-04 14:31:33 -04001991#Method void roundIn(SkIRect* dst) const
1992
Cary Clark7fc1d122017-10-09 14:07:42 -04001993Sets Rect by rounding up fLeft and fTop; and
1994discarding the fractional portion of fRight and FBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04001995
Cary Clark7fc1d122017-10-09 14:07:42 -04001996#Formula
1997(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1998 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
1999##
2000.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002001
Cary Clark7fc1d122017-10-09 14:07:42 -04002002#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002003
2004#Example
Cary Clark154beea2017-10-26 07:58:48 -04002005 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2006 SkIRect round;
2007 rect.roundIn(&round);
2008 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002009#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002010round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002011##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002012##
2013
Cary Clark7fc1d122017-10-09 14:07:42 -04002014#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002015
2016##
2017
Cary Clark7fc1d122017-10-09 14:07:42 -04002018# ------------------------------------------------------------------------------
2019
Cary Clarkbc5697d2017-10-04 14:31:33 -04002020#Method SkIRect round() const
2021
Cary Clark7fc1d122017-10-09 14:07:42 -04002022Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2023members, using
2024#Formula
2025(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2026 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2027##
2028.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002029
Cary Clark7fc1d122017-10-09 14:07:42 -04002030#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002031
2032#Example
Cary Clark154beea2017-10-26 07:58:48 -04002033 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2034 SkIRect round = rect.round();
2035 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002036#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002037round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002038##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002039##
2040
Cary Clark7fc1d122017-10-09 14:07:42 -04002041#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002042
2043##
2044
Cary Clark7fc1d122017-10-09 14:07:42 -04002045# ------------------------------------------------------------------------------
2046
Cary Clarkbc5697d2017-10-04 14:31:33 -04002047#Method SkIRect roundOut() const
2048
Cary Clark7fc1d122017-10-09 14:07:42 -04002049Sets IRect by discarding the fractional portion of fLeft and fTop; and
2050rounding up fRight and FBottom, using
2051#Formula
2052(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2053 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2054##
2055.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002056
Cary Clark7fc1d122017-10-09 14:07:42 -04002057#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002058
2059#Example
Cary Clark154beea2017-10-26 07:58:48 -04002060 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2061 SkIRect round = rect.roundOut();
2062 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002063#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002064round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002065##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002066##
2067
Cary Clark7fc1d122017-10-09 14:07:42 -04002068#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002069
2070##
2071
Cary Clark7fc1d122017-10-09 14:07:42 -04002072#Topic Round ##
2073
2074# ------------------------------------------------------------------------------
2075
Cary Clarkbc5697d2017-10-04 14:31:33 -04002076#Method void sort()
2077
Cary Clark7fc1d122017-10-09 14:07:42 -04002078Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2079fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2080and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002081
2082#Example
Cary Clark154beea2017-10-26 07:58:48 -04002083 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2084 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2085 rect.sort();
2086 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002087#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002088rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002089sorted: 20.5, 10.5, 30.5, 50.5
2090##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002091##
2092
Cary Clark7fc1d122017-10-09 14:07:42 -04002093#SeeAlso makeSorted SkIRect::sort
Cary Clarkbc5697d2017-10-04 14:31:33 -04002094
2095##
2096
Cary Clark7fc1d122017-10-09 14:07:42 -04002097# ------------------------------------------------------------------------------
2098
Cary Clarkbc5697d2017-10-04 14:31:33 -04002099#Method SkRect makeSorted() const
2100
Cary Clark7fc1d122017-10-09 14:07:42 -04002101Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2102with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2103and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104
Cary Clark7fc1d122017-10-09 14:07:42 -04002105#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002106
2107#Example
Cary Clark154beea2017-10-26 07:58:48 -04002108 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2109 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2110 SkRect sort = rect.makeSorted();
2111 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002112#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002113rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002114sorted: 20.5, 10.5, 30.5, 50.5
2115##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002116##
2117
Cary Clark7fc1d122017-10-09 14:07:42 -04002118#SeeAlso sort SkIRect::makeSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119
2120##
2121
Cary Clark7fc1d122017-10-09 14:07:42 -04002122# ------------------------------------------------------------------------------
2123
Cary Clarkbc5697d2017-10-04 14:31:33 -04002124#Method const SkScalar* asScalars() const
2125
Cary Clark7fc1d122017-10-09 14:07:42 -04002126Returns pointer to first Scalar in Rect, to treat it as an array with four
2127entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002128
Cary Clark7fc1d122017-10-09 14:07:42 -04002129#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002130
2131#Example
Cary Clark154beea2017-10-26 07:58:48 -04002132 SkRect rect = {7, 11, 13, 17};
2133SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2134#StdOut
2135rect.asScalars() == &rect.fLeft
2136##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002137##
2138
Cary Clark7fc1d122017-10-09 14:07:42 -04002139#SeeAlso toQuad
2140
Cary Clarkbc5697d2017-10-04 14:31:33 -04002141##
2142
Cary Clark7fc1d122017-10-09 14:07:42 -04002143# ------------------------------------------------------------------------------
2144
Cary Clarkbc5697d2017-10-04 14:31:33 -04002145#Method void dump(bool asHex) const
2146
Cary Clark7fc1d122017-10-09 14:07:42 -04002147Writes text representation of Rect to standard output. Set asHex to true to
2148generate exact binary representations of floating point numbers.
2149
2150#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002151
2152#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002153 SkRect rect = {20, 30, 40, 50};
2154 for (bool dumpAsHex : { false, true } ) {
2155 rect.dump(dumpAsHex);
2156 SkDebugf("\n");
2157 }
2158#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002159SkRect::MakeLTRB(20, 30, 40, 50);
2160
2161SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2162 SkBits2Float(0x41f00000), /* 30.000000 */
2163 SkBits2Float(0x42200000), /* 40.000000 */
2164 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002165##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002166##
2167
Cary Clark7fc1d122017-10-09 14:07:42 -04002168#SeeAlso dumpHex
2169
Cary Clarkbc5697d2017-10-04 14:31:33 -04002170##
2171
Cary Clark7fc1d122017-10-09 14:07:42 -04002172# ------------------------------------------------------------------------------
2173
Cary Clarkbc5697d2017-10-04 14:31:33 -04002174#Method void dump() const
2175
Cary Clark7fc1d122017-10-09 14:07:42 -04002176Writes text representation of Rect to standard output. The representation may be
2177directly compiled as C++ code. Floating point values are written
2178with limited precision; it may not be possible to reconstruct original Rect
2179from output.
2180
Cary Clarkbc5697d2017-10-04 14:31:33 -04002181#Example
Cary Clark154beea2017-10-26 07:58:48 -04002182SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2183rect.dump();
2184SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2185SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002186#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002187SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002188rect is not equal to copy
2189##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002190##
2191
Cary Clark7fc1d122017-10-09 14:07:42 -04002192#SeeAlso dumpHex
2193
Cary Clarkbc5697d2017-10-04 14:31:33 -04002194##
2195
Cary Clark7fc1d122017-10-09 14:07:42 -04002196# ------------------------------------------------------------------------------
2197
Cary Clarkbc5697d2017-10-04 14:31:33 -04002198#Method void dumpHex() const
2199
Cary Clark7fc1d122017-10-09 14:07:42 -04002200Writes text representation of Rect to standard output. The representation may be
2201directly compiled as C++ code. Floating point values are written
2202in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2203original Rect.
2204
2205Use instead of dump() when submitting
2206#A bug reports against Skia # http://bug.skia.org ##
2207.
2208
Cary Clarkbc5697d2017-10-04 14:31:33 -04002209#Example
Cary Clark154beea2017-10-26 07:58:48 -04002210 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2211rect.dumpHex();
2212SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2213 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2214 SkBits2Float(0x40266666), /* 2.600000 */
2215 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002216SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2217#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002218SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2219 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2220 SkBits2Float(0x40266666), /* 2.600000 */
2221 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002222rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002223##
Cary Clark7fc1d122017-10-09 14:07:42 -04002224##
2225
2226#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002227
2228##
2229
2230#Struct SkRect ##
2231
2232#Topic Rect ##