blob: 57f3ec6b98df7324c9b3f82c8bc8612ccd1061c3 [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
31# description # function ##
32#Legend ##
Cary Clark7fc1d122017-10-09 14:07:42 -040033# friend bool operator!=(const SkRect& a, const SkRect& b) # Returns true if member bits are unequal. ##
34# friend bool operator==(const SkRect& a, const SkRect& b) # Returns true if member bits are equal. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040035#Table ##
36#Subtopic ##
37
38#Subtopic Member_Functions
39#Table
40#Legend
Cary Clark7fc1d122017-10-09 14:07:42 -040041# description # function ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040042#Legend ##
Cary Clark7fc1d122017-10-09 14:07:42 -040043# Intersects # Returns true if areas overlap. ##
44# Make # Constructs from ISize returning (0, 0, width, height). ##
45# MakeEmpty # Constructs from bounds of (0, 0, 0, 0). ##
46# MakeFromIRect # Deprecated. ##
47# MakeIWH # Constructs from int input returning (0, 0, width, height). ##
48# MakeLTRB # Constructs from SkScalar left, top, right, bottom. ##
49# MakeLargest # Constructs (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
50# MakeSize # Constructs from Size returning (0, 0, width, height). ##
51# MakeWH # Constructs from SkScalar input returning (0, 0, width, height). ##
52# MakeXYWH # Constructs from SkScalar input returning (x, y, width, height). ##
53# asScalars # Returns pointer to members as array. ##
54# bottom() # Returns larger bounds in y, if sorted. ##
55# centerX # Returns midpoint in x. ##
56# centerY # Returns midpoint in y. ##
57# contains() # Returns true if points are equal or inside. ##
58# dump() # Sends text representation using floats to standard output. ##
59# dumpHex # Sends text representation using hexadecimal to standard output. ##
60# growToInclude # Sets to union of bounds and one or more Points. ##
61# height # Returns span in y. ##
62# inset() # Moves the sides symmetrically about the center. ##
63# intersect() # Sets to shared area; returns true if not empty. ##
64# intersects() # Returns true if areas overlap. ##
65# isEmpty # Returns true if width or height are zero or negative. ##
66# isFinite # Returns true if no member is infinite or NaN. ##
67# isLargest # Returns equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
68# isSorted # Returns true if width or height are zero or positive. ##
69# iset() # Sets to int input (left, top, right, bottom). ##
70# isetWH # Sets to int input (0, 0, width, height). ##
71# join() # Sets to union of bounds. ##
72# joinNonEmptyArg # Sets to union of bounds, asserting that argument is not empty. ##
73# joinPossiblyEmptyRect # Sets to union of bounds. Skips empty check for both. ##
74# left() # Returns smaller bounds in x, if sorted. ##
75# makeInset # Constructs from sides moved symmetrically about the center. ##
76# makeOffset # Constructs from translated sides. ##
77# makeOutset # Constructs from sides moved symmetrically about the center. ##
78# makeSorted # Constructs, ordering sides from smaller to larger. ##
79# offset() # Translates sides without changing width and height. ##
80# offsetTo # Translates to (x, y) without changing width and height. ##
81# outset() # Moves the sides symmetrically about the center. ##
82# right() # Returns larger bounds in x, if sorted. ##
83# round() # Sets members to nearest integer value. ##
84# roundIn # Sets members to nearest integer value towards opposite. ##
85# roundOut # Sets members to nearest integer value away from opposite. ##
86# set() # Sets to SkScalar input (left, top, right, bottom) and others. ##
87# setBounds # Sets to upper and lower limits of Point array. ##
88# setBoundsCheck # Sets to upper and lower limits of Point array. ##
89# setEmpty # Sets to (0, 0, 0, 0). ##
90# setLTRB # Sets to SkScalar input (left, top, right, bottom). ##
91# setLargest # Sets to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
92# setLargestInverted # Sets to (SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin). ##
93# setWH # Sets to SkScalar input (0, 0, width, height). ##
94# setXYWH # Sets to SkScalar input (x, y, width, height). ##
95# sort() # Orders sides from smaller to larger. ##
96# toQuad # Returns four corners as Point. ##
97# top() # Returns smaller bounds in y, if sorted. ##
98# width() # Returns span in x. ##
99# x() # Returns bounds left. ##
100# y() # Returns bounds top. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400101#Table ##
102#Subtopic ##
103
104#Topic ##
105
106#Member SkScalar fLeft
Cary Clark7fc1d122017-10-09 14:07:42 -0400107May contain any value, including infinities and NaN. The smaller of the
108horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400109##
110
111#Member SkScalar fTop
Cary Clark7fc1d122017-10-09 14:07:42 -0400112May contain any value, including infinities and NaN. The smaller of the
113vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400114##
115
116#Member SkScalar fRight
Cary Clark7fc1d122017-10-09 14:07:42 -0400117May contain any value, including infinities and NaN. The larger of the
118horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400119##
120
121#Member SkScalar fBottom
Cary Clark7fc1d122017-10-09 14:07:42 -0400122May contain any value, including infinities and NaN. The larger of the
123vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400124##
125
126# ------------------------------------------------------------------------------
127
128#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
129
Cary Clark7fc1d122017-10-09 14:07:42 -0400130Returns constructed Rect set to (0, 0, 0, 0).
131Many other rectangles are empty; if left is equal to or greater than right,
132or if top is equal to or greater than bottom. Setting all members to zero
133is a convenience, but does not designate a special empty rectangle.
134
135#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400136
137#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400138 SkRect rect = SkRect::MakeEmpty();
139 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
140 rect.offset(10, 10);
141 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
142 rect.inset(10, 10);
143 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
144 rect.outset(20, 20);
145 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
146#StdOut
147MakeEmpty isEmpty: true
148offset rect isEmpty: true
149inset rect isEmpty: true
150outset rect isEmpty: false
151##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400152##
153
Cary Clark7fc1d122017-10-09 14:07:42 -0400154#SeeAlso isEmpty setEmpty setLargestInverted SkIRect::MakeEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400155
156##
157
158# ------------------------------------------------------------------------------
159
160#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
161
Cary Clark7fc1d122017-10-09 14:07:42 -0400162Returns constructed Rect setting left and top to most negative finite value, and
163setting right and bottom to most positive finite value.
164
165#Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400166
167#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400168 SkRect rect = SkRect::MakeLargest();
169 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
170 SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
171 rect.outset(1e31, 1e31);
172 SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
173 SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
174 rect.outset(1e32, 1e32);
175 SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
176 SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
177#StdOut
178MakeLargest isLargest: true
179MakeLargest isFinite: true
180outset a little isLargest: true
181outset a little isFinite: true
182outset a little more isLargest: false
183outset a little more isFinite: false
184##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400185##
186
Cary Clark7fc1d122017-10-09 14:07:42 -0400187#SeeAlso isLargest setLargest SkIRect::MakeLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400188
189##
190
191# ------------------------------------------------------------------------------
192
193#Method static SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
194
Cary Clark7fc1d122017-10-09 14:07:42 -0400195Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
196validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400197
Cary Clark7fc1d122017-10-09 14:07:42 -0400198Passing integer values may generate a compiler warning since Rect cannot
199represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
200
201#Param w SkScalar width of constructed Rect ##
202#Param h SkScalar height of constructed Rect ##
203
204#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400205
206#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400207 SkRect rect1 = SkRect::MakeWH(25, 35);
208 SkRect rect2 = SkRect::MakeIWH(25, 35);
209 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
210 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
211 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
212 "" : "not ");
213#StdOut
214all equal
215##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400216##
217
Cary Clark7fc1d122017-10-09 14:07:42 -0400218#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400219
220##
221
222# ------------------------------------------------------------------------------
223
224#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
225
Cary Clark7fc1d122017-10-09 14:07:42 -0400226Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
227input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400228
Cary Clark7fc1d122017-10-09 14:07:42 -0400229Use to avoid a compiler warning that input may lose precision when stored.
230Use SkIRect for an exact integer rectangle.
231
232#Param w integer width of constructed Rect ##
233#Param h integer height of constructed Rect ##
234
235#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400236
237#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400238 SkIRect i_rect = SkIRect::MakeWH(25, 35);
239 SkRect f_rect = SkRect::MakeIWH(25, 35);
240 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
241 i_rect = SkIRect::MakeWH(125000111, 0);
242 f_rect = SkRect::MakeIWH(125000111, 0);
243 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
244#StdOut
245i_rect width: 25 f_rect width:25
246i_rect width: 125000111 f_rect width:125000112
247##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400248##
249
Cary Clark7fc1d122017-10-09 14:07:42 -0400250#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400251
252##
253
254# ------------------------------------------------------------------------------
255
256#Method static SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
257
Cary Clark7fc1d122017-10-09 14:07:42 -0400258Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
259validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400260
Cary Clark7fc1d122017-10-09 14:07:42 -0400261#Param size SkScalar values for Rect width and height ##
262
263#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400264
265#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400266 SkSize size = {25.5f, 35.5f};
267 SkRect rect = SkRect::MakeSize(size);
268 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
269 SkISize floor = size.toFloor();
270 rect = SkRect::MakeSize(SkSize::Make(floor));
271 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
272#StdOut
273rect width: 25.5 height: 35.5
274floor width: 25 height: 35
275##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400276##
277
Cary Clark7fc1d122017-10-09 14:07:42 -0400278#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400279
280##
281
282# ------------------------------------------------------------------------------
283
284#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
285 SkScalar b)
286
Cary Clark7fc1d122017-10-09 14:07:42 -0400287Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
288result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400289
Cary Clark7fc1d122017-10-09 14:07:42 -0400290#Param l SkScalar stored in fLeft ##
291#Param t SkScalar stored in fTop ##
292#Param r SkScalar stored in fRight ##
293#Param b SkScalar stored in fBottom ##
294
295#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400296
297#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400298 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
299 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
300 rect.bottom(), rect.isEmpty() ? "true" : "false");
301 rect.sort();
302 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
303 rect.bottom(), rect.isEmpty() ? "true" : "false");
304#StdOut
305rect: 5, 35, 15, 25 isEmpty: true
306rect: 5, 25, 15, 35 isEmpty: false
307##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400308##
309
Cary Clark7fc1d122017-10-09 14:07:42 -0400310#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400311
312##
313
314# ------------------------------------------------------------------------------
315
316#Method static SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
317
Cary Clark7fc1d122017-10-09 14:07:42 -0400318Returns constructed Rect set to
319#Formula
320(x, y, x + w, y + h)
321##
322. Does not validate input;
323w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400324
Cary Clark7fc1d122017-10-09 14:07:42 -0400325#Param x stored in fLeft ##
326#Param y stored in fTop ##
327#Param w added to x and stored in fRight ##
328#Param h added to y and stored in fBottom ##
329
330#Return bounds (x, y, x + w, y + h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400331
332#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400333 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
334 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
335 rect.bottom(), rect.isEmpty() ? "true" : "false");
336 rect.sort();
337 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
338 rect.bottom(), rect.isEmpty() ? "true" : "false");
339#StdOut
340rect: 5, 35, -10, 60 isEmpty: true
341rect: -10, 35, 5, 60 isEmpty: false
342##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400343##
344
Cary Clark7fc1d122017-10-09 14:07:42 -0400345#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400346
347##
348
349# ------------------------------------------------------------------------------
350
351#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
352
Cary Clark7fc1d122017-10-09 14:07:42 -0400353Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400354
Cary Clark7fc1d122017-10-09 14:07:42 -0400355#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400356##
357
Cary Clark7fc1d122017-10-09 14:07:42 -0400358#Param irect integer rect ##
359
360#Return irect as SkRect ##
361
362#NoExample
363##
364
365#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400366
367##
368
369# ------------------------------------------------------------------------------
370
371#Method static SkRect Make(const SkISize& size)
372
Cary Clark7fc1d122017-10-09 14:07:42 -0400373Returns constructed IRect set to (0, 0, size.width(), size.height()).
374Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400375
Cary Clark7fc1d122017-10-09 14:07:42 -0400376#Param size integer values for Rect width and height ##
377
378#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400379
380#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400381 SkRect rect1 = SkRect::MakeSize({2, 35});
382 SkRect rect2 = SkRect::MakeIWH(2, 35);
383 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
384#StdOut
385rect1 == rect2
386##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400387##
388
Cary Clark7fc1d122017-10-09 14:07:42 -0400389#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400390
391##
392
393# ------------------------------------------------------------------------------
394
395#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
396
Cary Clark7fc1d122017-10-09 14:07:42 -0400397Returns constructed IRect set to irect, promoting integers to Scalar.
398Does not validate input; fLeft may be greater than fRight, fTop may be greater
399than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400400
Cary Clark7fc1d122017-10-09 14:07:42 -0400401#Param irect integer unsorted bounds ##
402
403#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400404
405#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400406 SkIRect i_rect1 = {2, 35, 22, 53};
407 SkRect f_rect = SkRect::Make(i_rect1);
408 f_rect.offset(0.49f, 0.49f);
409 SkIRect i_rect2;
410 f_rect.round(&i_rect2);
411 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400412##
413
Cary Clark7fc1d122017-10-09 14:07:42 -0400414#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400415
416##
417
418# ------------------------------------------------------------------------------
419
420#Method bool isEmpty() const
421
Cary Clark7fc1d122017-10-09 14:07:42 -0400422Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
423to or greater than fBottom. Call sort() to reverse rectangles with negative
424width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400425
Cary Clark7fc1d122017-10-09 14:07:42 -0400426#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400427
428#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400429 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
430 for (auto rect : tests) {
431 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
432 rect.bottom(), rect.isEmpty() ? "" : " not");
433 rect.sort();
434 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
435 rect.bottom(), rect.isEmpty() ? "" : " not");
436 }
437#StdOut
438rect: {20, 40, 10, 50} is empty
439sorted: {10, 40, 20, 50} is not empty
440rect: {20, 40, 20, 50} is empty
441sorted: {20, 40, 20, 50} is empty
442##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400443##
444
Cary Clark7fc1d122017-10-09 14:07:42 -0400445#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400446
447##
448
449# ------------------------------------------------------------------------------
450
451#Method bool isSorted() const
452
Cary Clark7fc1d122017-10-09 14:07:42 -0400453Returns true if fLeft is equal to or less than fRight, or if fTop is equal
454to or less than fBottom. Call sort() to reverse rectangles with negative
455width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400456
Cary Clark7fc1d122017-10-09 14:07:42 -0400457#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400458
459#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400460 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
461 for (auto rect : tests) {
462 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
463 rect.bottom(), rect.isSorted() ? "" : " not");
464 rect.sort();
465 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
466 rect.bottom(), rect.isSorted() ? "" : " not");
467 }
468#StdOut
469rect: {20, 40, 10, 50} is not sorted
470sorted: {10, 40, 20, 50} is sorted
471rect: {20, 40, 20, 50} is sorted
472sorted: {20, 40, 20, 50} is sorted
473##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400474##
475
Cary Clark7fc1d122017-10-09 14:07:42 -0400476#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400477
478##
479
480# ------------------------------------------------------------------------------
481
482#Method bool isLargest() const
483
Cary Clark7fc1d122017-10-09 14:07:42 -0400484Returns true if Rect encloses largest possible area.
485
486#Return true if equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400487
488#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400489#Description
490Note that the width cannot be represented as a 32-bit finite value.
491##
492 SkRect large = SkRect::MakeLargest();
493 SkDebugf("large is largest: %s\n" ,large.isLargest() ? "true" : "false");
494 SkDebugf("large width %g\n", large.width());
495 SkDebugf("large is empty: %s\n", large.isEmpty() ? "true" : "false");
496 SkDebugf("large is sorted: %s\n", large.isSorted() ? "true" : "false");
497 SkDebugf("large is finite: %s\n", large.isFinite() ? "true" : "false");
498#StdOut
499large is largest: true
500large width inf
501large is empty: false
502large is sorted: true
503large is finite: true
504##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400505##
506
Cary Clark7fc1d122017-10-09 14:07:42 -0400507#SeeAlso MakeLargest SkIRect::isLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400508
509##
510
511# ------------------------------------------------------------------------------
512
513#Method bool isFinite() const
514
Cary Clark7fc1d122017-10-09 14:07:42 -0400515Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
516and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400517
Cary Clark7fc1d122017-10-09 14:07:42 -0400518#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400519
520#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400521 SkRect largest = SkRect::MakeLargest();
522 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
523 SkDebugf("large width %g\n", largest.width());
524 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
525 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
526#StdOut
527largest is finite: true
528large width inf
529widest is finite: false
530##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400531##
532
Cary Clark7fc1d122017-10-09 14:07:42 -0400533#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400534
535##
536
537# ------------------------------------------------------------------------------
538
539#Method SkScalar x() const
540
Cary Clark7fc1d122017-10-09 14:07:42 -0400541Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
542Call sort() to reverse fLeft and fRight if needed.
543
544#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400545
546#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400547 SkRect unsorted = { 15, 5, 10, 25 };
548 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
549 SkRect sorted = unsorted.makeSorted();
550 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
551#StdOut
552unsorted.fLeft: 15 unsorted.x(): 15
553sorted.fLeft: 10 sorted.x(): 10
554##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400555##
556
Cary Clark7fc1d122017-10-09 14:07:42 -0400557#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400558
559##
560
561# ------------------------------------------------------------------------------
562
563#Method SkScalar y() const
564
Cary Clark7fc1d122017-10-09 14:07:42 -0400565Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
566and sort() to reverse fTop and fBottom if needed.
567
568#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400569
570#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400571 SkRect unsorted = { 15, 25, 10, 5 };
572 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
573 SkRect sorted = unsorted.makeSorted();
574 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
575#StdOut
576unsorted.fTop: 25 unsorted.y(): 25
577sorted.fTop: 5 sorted.y(): 5
578##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400579##
580
Cary Clark7fc1d122017-10-09 14:07:42 -0400581#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400582
583##
584
585# ------------------------------------------------------------------------------
586
587#Method SkScalar left() const
588
Cary Clark7fc1d122017-10-09 14:07:42 -0400589Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
590Call sort() to reverse fLeft and fRight if needed.
591
592#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400593
594#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400595 SkRect unsorted = { 15, 5, 10, 25 };
596 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
597 SkRect sorted = unsorted.makeSorted();
598 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
599#StdOut
600unsorted.fLeft: 15 unsorted.left(): 15
601sorted.fLeft: 10 sorted.left(): 10
602##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400603##
604
Cary Clark7fc1d122017-10-09 14:07:42 -0400605#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400606
607##
608
609# ------------------------------------------------------------------------------
610
611#Method SkScalar top() const
612
Cary Clark7fc1d122017-10-09 14:07:42 -0400613Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
614and sort() to reverse fTop and fBottom if needed.
615
616#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400617
618#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400619 SkRect unsorted = { 15, 25, 10, 5 };
620 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
621 SkRect sorted = unsorted.makeSorted();
622 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
623#StdOut
624unsorted.fTop: 25 unsorted.top(): 25
625sorted.fTop: 5 sorted.top(): 5
626##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400627##
628
Cary Clark7fc1d122017-10-09 14:07:42 -0400629#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400630
631##
632
633# ------------------------------------------------------------------------------
634
635#Method SkScalar right() const
636
Cary Clark7fc1d122017-10-09 14:07:42 -0400637Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
638Call sort() to reverse fLeft and fRight if needed.
639
640#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400641
642#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400643 SkRect unsorted = { 15, 25, 10, 5 };
644 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
645 SkRect sorted = unsorted.makeSorted();
646 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
647#StdOut
648unsorted.fRight: 10 unsorted.right(): 10
649sorted.fRight: 15 sorted.right(): 15
650##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400651##
652
Cary Clark7fc1d122017-10-09 14:07:42 -0400653#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400654
655##
656
657# ------------------------------------------------------------------------------
658
659#Method SkScalar bottom() const
660
Cary Clark7fc1d122017-10-09 14:07:42 -0400661Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
662and sort() to reverse fTop and fBottom if needed.
663
664#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400665
666#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400667 SkRect unsorted = { 15, 25, 10, 5 };
668 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
669 SkRect sorted = unsorted.makeSorted();
670 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
671#StdOut
672unsorted.fBottom: 5 unsorted.bottom(): 5
673sorted.fBottom: 25 sorted.bottom(): 25
674##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400675##
676
Cary Clark7fc1d122017-10-09 14:07:42 -0400677#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400678
679##
680
681# ------------------------------------------------------------------------------
682
683#Method SkScalar width() const
684
Cary Clark7fc1d122017-10-09 14:07:42 -0400685Returns span on the x-axis. This does not check if Rect is sorted, or if
686result fits in 32-bit float; result may be negative or infinity.
687
688#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400689
690#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400691#Description
692Compare with SkIRect::width() example.
693##
694 SkRect unsorted = { 15, 25, 10, 5 };
695 SkDebugf("unsorted width: %g\n", unsorted.width());
696 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
697 SkDebugf("large width: %.0f\n", large.width());
698#StdOut
699unsorted width: -5
700large width: 4294967296
701##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400702##
703
Cary Clark7fc1d122017-10-09 14:07:42 -0400704#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400705
706##
707
708# ------------------------------------------------------------------------------
709
710#Method SkScalar height() const
711
Cary Clark7fc1d122017-10-09 14:07:42 -0400712Returns span on the y-axis. This does not check if IRect is sorted, or if
713result fits in 32-bit float; result may be negative or infinity.
714
715#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400716
717#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400718#Description
719Compare with SkIRect::height() example.
720##
721 SkRect unsorted = { 15, 25, 10, 20 };
722 SkDebugf("unsorted height: %g\n", unsorted.height());
723 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
724 SkDebugf("large height: %.0f\n", large.height());
725#StdOut
726unsorted height: -5
727large height: 4294967296
728##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400729##
730
Cary Clark7fc1d122017-10-09 14:07:42 -0400731#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400732
733##
734
735# ------------------------------------------------------------------------------
736
737#Method SkScalar centerX() const
738
Cary Clark7fc1d122017-10-09 14:07:42 -0400739Returns average of left edge and right edge. Result does not change if Rect
740is sorted. Result may overflow to infinity if Rect is far from the origin.
741
742#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400743
744#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400745 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
746 for (auto rect : tests) {
747 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
748 rect.sort();
749 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
750 }
751#StdOut
752left: 20 right: 41 centerX: 30.5
753left: 20 right: 41 centerX: 30.5
754left: -20 right: -41 centerX: -30.5
755left: -41 right: -20 centerX: -30.5
756##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400757##
758
Cary Clark7fc1d122017-10-09 14:07:42 -0400759#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400760
761##
762
763# ------------------------------------------------------------------------------
764
765#Method SkScalar centerY() const
766
Cary Clark7fc1d122017-10-09 14:07:42 -0400767Returns average of top edge and bottom edge. Result does not change if Rect
768is sorted. Result may overflow to infinity if Rect is far from the origin.
769
770#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400771
772#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400773 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
774 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
775 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
776#StdOut
777left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
778##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400779##
780
Cary Clark7fc1d122017-10-09 14:07:42 -0400781#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400782
783##
784
785# ------------------------------------------------------------------------------
786
787#Method friend bool operator==(const SkRect& a, const SkRect& b)
788
Cary Clark7fc1d122017-10-09 14:07:42 -0400789Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
790equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400791
Cary Clark7fc1d122017-10-09 14:07:42 -0400792a and b are not equal if either contain NaN. a and b are equal if members
793contain zeroes width different signs.
794
795#Param a Rect to compare ##
796#Param b Rect to compare ##
797
798#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400799
800#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400801 auto debugster = [](const SkRect& test) -> void {
802 SkRect negZero = {-0.0f, -0.0f, 2, 2};
803 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
804 test.fLeft, test.fTop, test.fRight, test.fBottom,
805 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
806 test == negZero ? '=' : '!',
807 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
808 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
809 "and are" : "yet are not");
810 };
811 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
812 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
813 for (auto rect : tests) {
814 debugster(rect);
815 }
816#StdOut
817tests are equal
818{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
819{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
820{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
821##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400822##
823
Cary Clark7fc1d122017-10-09 14:07:42 -0400824#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400825
826##
827
828# ------------------------------------------------------------------------------
829
830#Method friend bool operator!=(const SkRect& a, const SkRect& b)
831
Cary Clark7fc1d122017-10-09 14:07:42 -0400832Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
833equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400834
Cary Clark7fc1d122017-10-09 14:07:42 -0400835a and b are not equal if either contain NaN. a and b are equal if members
836contain zeroes width different signs.
837
838#Param a Rect to compare ##
839#Param b Rect to compare ##
840
841#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400842
843#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400844 SkRect test = {0, 0, 2, SK_ScalarNaN};
845 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
846#StdOut
847test with NaN is not equal to itself
848##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400849##
850
Cary Clark7fc1d122017-10-09 14:07:42 -0400851#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400852
853##
854
855# ------------------------------------------------------------------------------
856
857#Method void toQuad(SkPoint quad[4]) const
858
Cary Clark7fc1d122017-10-09 14:07:42 -0400859Returns four points in quad that enclose Rect ordered as: top-left, top-right,
860bottom-right, bottom-left.
861
862#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400863Consider adding param to control whether quad is CW or CCW.
864##
865
Cary Clark7fc1d122017-10-09 14:07:42 -0400866#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400867
868#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400869 SkRect rect = {1, 2, 3, 4};
870 SkPoint corners[4];
871 rect.toQuad(corners);
872 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
873 SkDebugf("corners:");
874 for (auto corner : corners) {
875 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
876 }
877 SkDebugf("\n");
878#StdOut
879rect: {1, 2, 3, 4}
880corners: {1, 2} {3, 2} {3, 4} {1, 4}
881##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400882##
883
Cary Clark7fc1d122017-10-09 14:07:42 -0400884#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400885
886##
887
888# ------------------------------------------------------------------------------
889
890#Method void setEmpty()
891
Cary Clark7fc1d122017-10-09 14:07:42 -0400892Sets Rect to (0, 0, 0, 0).
893
894Many other rectangles are empty; if left is equal to or greater than right,
895or if top is equal to or greater than bottom. Setting all members to zero
896is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400897
898#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400899 SkRect rect = {3, 4, 1, 2};
900 for (int i = 0; i < 2; ++i) {
901 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
902 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
903 rect.setEmpty();
904 }
905#StdOut
906rect: {3, 4, 1, 2} is empty
907rect: {0, 0, 0, 0} is empty
908##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400909##
910
Cary Clark7fc1d122017-10-09 14:07:42 -0400911#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400912
913##
914
915# ------------------------------------------------------------------------------
916
917#Method void set(const SkIRect& src)
918
Cary Clark7fc1d122017-10-09 14:07:42 -0400919Sets Rect to src, promoting src members from integer to Scalar.
920Very large values in src may lose precision.
921
922#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400923
924#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400925 SkIRect i_rect = {3, 4, 1, 2};
926 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
927 SkRect f_rect;
928 f_rect.set(i_rect);
929 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
930#StdOut
931i_rect: {3, 4, 1, 2}
932f_rect: {3, 4, 1, 2}
933##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400934##
935
Cary Clark7fc1d122017-10-09 14:07:42 -0400936#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400937
938##
939
940# ------------------------------------------------------------------------------
941
942#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
943
Cary Clark7fc1d122017-10-09 14:07:42 -0400944Sets Rect to (left, top, right, bottom).
945left and right are not sorted; left is not necessarily less than right.
946top and bottom are not sorted; top is not necessarily less than bottom.
947
948#Param left stored in fLeft ##
949#Param top stored in fTop ##
950#Param right stored in fRight ##
951#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400952
953#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400954 SkRect rect1 = {3, 4, 1, 2};
955 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
956 SkRect rect2;
957 rect2.set(3, 4, 1, 2);
958 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
959#StdOut
960rect1: {3, 4, 1, 2}
961rect2: {3, 4, 1, 2}
962##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400963##
964
Cary Clark7fc1d122017-10-09 14:07:42 -0400965#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400966
967##
968
969# ------------------------------------------------------------------------------
970
971#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
972
Cary Clark7fc1d122017-10-09 14:07:42 -0400973Sets Rect to (left, top, right, bottom).
974left and right are not sorted; left is not necessarily less than right.
975top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400976
Cary Clark7fc1d122017-10-09 14:07:42 -0400977#Param left stored in fLeft ##
978#Param top stored in fTop ##
979#Param right stored in fRight ##
980#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400981
982#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400983 SkRect rect1 = {3, 4, 1, 2};
984 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
985 SkRect rect2;
986 rect2.setLTRB(3, 4, 1, 2);
987 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
988#StdOut
989rect1: {3, 4, 1, 2}
990rect2: {3, 4, 1, 2}
991##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400992##
993
Cary Clark7fc1d122017-10-09 14:07:42 -0400994#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400995
996##
997
998# ------------------------------------------------------------------------------
999
1000#Method void iset(int left, int top, int right, int bottom)
1001
Cary Clark7fc1d122017-10-09 14:07:42 -04001002Sets Rect to (left, top, right, bottom).
1003All parameters are promoted from integer to Scalar.
1004left and right are not sorted; left is not necessarily less than right.
1005top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001006
Cary Clark7fc1d122017-10-09 14:07:42 -04001007#Param left promoted to SkScalar and stored in fLeft ##
1008#Param top promoted to SkScalar and stored in fTop ##
1009#Param right promoted to SkScalar and stored in fRight ##
1010#Param bottom promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001011
1012#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001013 SkRect rect1 = {3, 4, 1, 2};
1014 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1015 SkRect rect2;
1016 rect2.iset(3, 4, 1, 2);
1017 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1018#StdOut
1019rect1: {3, 4, 1, 2}
1020rect2: {3, 4, 1, 2}
1021##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001022##
1023
Cary Clark7fc1d122017-10-09 14:07:42 -04001024#SeeAlso set setLTRB SkIRect::set SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -04001025
1026##
1027
1028# ------------------------------------------------------------------------------
1029
1030#Method void isetWH(int width, int height)
1031
Cary Clark7fc1d122017-10-09 14:07:42 -04001032Sets Rect to (0, 0, width, height).
1033width and height may be zero or negative. width and height are promoted from
1034integer to SkScalar, large values may lose precision.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001035
Cary Clark7fc1d122017-10-09 14:07:42 -04001036#Param width promoted to SkScalar and stored in fRight ##
1037#Param height promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001038
1039#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001040 SkRect rect1 = {0, 0, 1, 2};
1041 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1042 SkRect rect2;
1043 rect2.isetWH(1, 2);
1044 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1045#StdOut
1046rect1: {0, 0, 1, 2}
1047rect2: {0, 0, 1, 2}
1048##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001049##
1050
Cary Clark7fc1d122017-10-09 14:07:42 -04001051#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001052
1053##
1054
1055# ------------------------------------------------------------------------------
1056
1057#Method void set(const SkPoint pts[], int count)
1058
Cary Clark7fc1d122017-10-09 14:07:42 -04001059Sets to bounds of Point array with count entries. If count is zero or smaller,
1060or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001061
Cary Clark7fc1d122017-10-09 14:07:42 -04001062Result is either empty or sorted: fLeft is less than or equal to fRight, and
1063fTop is less than or equal to fBottom.
1064
1065#Param pts Point array ##
1066#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001067
1068#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001069 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1070 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1071 SkRect rect;
1072 rect.set(points, count);
1073 if (count > 0) {
1074 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1075 } else {
1076 SkDebugf("%14s", " ");
1077 }
1078 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1079 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1080 }
1081#StdOut
1082 count: 0 rect: 0, 0, 0, 0
1083added: 3, 4 count: 1 rect: 3, 4, 3, 4
1084added: 1, 2 count: 2 rect: 1, 2, 3, 4
1085added: 5, 6 count: 3 rect: 1, 2, 5, 6
1086added: nan, 8 count: 4 rect: 0, 0, 0, 0
1087##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001088##
1089
Cary Clark7fc1d122017-10-09 14:07:42 -04001090#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001091
1092##
1093
1094# ------------------------------------------------------------------------------
1095
1096#Method void setBounds(const SkPoint pts[], int count)
1097
Cary Clark7fc1d122017-10-09 14:07:42 -04001098Sets to bounds of Point array with count entries. If count is zero or smaller,
1099or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001100
Cary Clark7fc1d122017-10-09 14:07:42 -04001101Result is either empty or sorted: fLeft is less than or equal to fRight, and
1102fTop is less than or equal to fBottom.
1103
1104#Param pts Point array ##
1105#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001106
1107#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001108 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1109 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1110 SkRect rect;
1111 rect.setBounds(points, count);
1112 if (count > 0) {
1113 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1114 } else {
1115 SkDebugf("%14s", " ");
1116 }
1117 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1118 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1119 }
1120#StdOut
1121 count: 0 rect: 0, 0, 0, 0
1122added: 3, 4 count: 1 rect: 3, 4, 3, 4
1123added: 1, 2 count: 2 rect: 1, 2, 3, 4
1124added: 5, 6 count: 3 rect: 1, 2, 5, 6
1125added: nan, 8 count: 4 rect: 0, 0, 0, 0
1126##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001127##
1128
Cary Clark7fc1d122017-10-09 14:07:42 -04001129#SeeAlso set setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001130
1131##
1132
1133# ------------------------------------------------------------------------------
1134
1135#Method bool setBoundsCheck(const SkPoint pts[], int count)
1136
Cary Clark7fc1d122017-10-09 14:07:42 -04001137Sets to bounds of Point array with count entries. Returns false if count is
1138zero or smaller, or if Point array contains an infinity or NaN; in these cases
1139sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001140
Cary Clark7fc1d122017-10-09 14:07:42 -04001141Result is either empty or sorted: fLeft is less than or equal to fRight, and
1142fTop is less than or equal to fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001143
Cary Clark7fc1d122017-10-09 14:07:42 -04001144#Param pts Point array ##
1145#Param count entries in array ##
1146
1147#Return true if all Point values are finite ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001148
1149#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001150 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1151 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1152 SkRect rect;
1153 bool success = rect.setBoundsCheck(points, count);
1154 if (count > 0) {
1155 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1156 } else {
1157 SkDebugf("%14s", " ");
1158 }
1159 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
1160 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
1161 }
1162#StdOut
1163 count: 0 rect: 0, 0, 0, 0 success: true
1164added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
1165added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
1166added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
1167added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
1168##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001169##
1170
Cary Clark7fc1d122017-10-09 14:07:42 -04001171#SeeAlso set setBounds SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001172
1173##
1174
1175# ------------------------------------------------------------------------------
1176
1177#Method void set(const SkPoint& p0, const SkPoint& p1)
1178
Cary Clark7fc1d122017-10-09 14:07:42 -04001179Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1180sorted and may be empty. Does not check to see if values are finite.
1181
1182#Param p0 corner to include ##
1183#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001184
1185#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001186#Description
1187p0 and p1 may be swapped and have the same effect unless one contains NaN.
1188##
1189 SkPoint point1 = {SK_ScalarNaN, 8};
1190 SkPoint point2 = {3, 4};
1191 SkRect rect;
1192 rect.set(point1, point2);
1193 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1194 rect.set(point2, point1);
1195 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001196##
1197
Cary Clark7fc1d122017-10-09 14:07:42 -04001198#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001199
1200##
1201
1202# ------------------------------------------------------------------------------
1203
1204#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1205
Cary Clark7fc1d122017-10-09 14:07:42 -04001206Sets Rect to
1207#Formula
1208(x, y, x + width, y + height)
1209##
1210. Does not validate input;
1211width or height may be negative.
1212
1213#Param x stored in fLeft ##
1214#Param y stored in fTop ##
1215#Param width added to x and stored in fRight ##
1216#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001217
1218#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001219 SkRect rect;
1220 rect.setXYWH(5, 35, -15, 25);
1221 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1222 rect.bottom(), rect.isEmpty() ? "true" : "false");
1223 rect.sort();
1224 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1225 rect.bottom(), rect.isEmpty() ? "true" : "false");
1226#StdOut
1227rect: 5, 35, -10, 60 isEmpty: true
1228rect: -10, 35, 5, 60 isEmpty: false
1229##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001230##
1231
Cary Clark7fc1d122017-10-09 14:07:42 -04001232#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001233
1234##
1235
1236# ------------------------------------------------------------------------------
1237
1238#Method void setWH(SkScalar width, SkScalar height)
1239
Cary Clark7fc1d122017-10-09 14:07:42 -04001240Sets Rect to (0, 0, width, height). Does not validate input;
1241width or height may be negative.
1242
1243#Param width stored in fRight ##
1244#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001245
1246#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001247 SkRect rect;
1248 rect.setWH(-15, 25);
1249 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1250 rect.bottom(), rect.isEmpty() ? "true" : "false");
1251 rect.sort();
1252 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1253 rect.bottom(), rect.isEmpty() ? "true" : "false");
1254#StdOut
1255rect: 0, 0, -15, 25 isEmpty: true
1256rect: -15, 0, 0, 25 isEmpty: false
1257##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001258##
1259
Cary Clark7fc1d122017-10-09 14:07:42 -04001260#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001261
1262##
1263
1264# ------------------------------------------------------------------------------
1265
1266#Method void setLargest()
1267
Cary Clark7fc1d122017-10-09 14:07:42 -04001268Sets rectangle left and top to most negative finite value, and sets
1269right and bottom to most positive finite value.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001270
1271#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001272 SkRect rect;
1273 rect.setLargest();
1274 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
1275 SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
1276 rect.outset(1e31, 1e31);
1277 SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
1278 SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
1279 rect.outset(1e32, 1e32);
1280 SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
1281 SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
1282#StdOut
1283MakeLargest isLargest: true
1284MakeLargest isFinite: true
1285outset a little isLargest: true
1286outset a little isFinite: true
1287outset a little more isLargest: false
1288outset a little more isFinite: false
1289##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001290##
1291
Cary Clark7fc1d122017-10-09 14:07:42 -04001292#SeeAlso MakeLargest isLargest setLargestInverted SK_ScalarMin SK_ScalarMax
Cary Clarkbc5697d2017-10-04 14:31:33 -04001293
1294##
1295
1296# ------------------------------------------------------------------------------
1297
1298#Method void setLargestInverted()
1299
Cary Clark7fc1d122017-10-09 14:07:42 -04001300Sets rectangle left and top to most positive finite value, and sets
1301right and bottom to most negative finite value.
1302
1303Use to initial Rect before one or more calls to growToInclude.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001304
1305#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001306 auto debugster = [](const char* prefix, const SkRect& rect) -> void {
1307 SkDebugf("%s ", prefix);
1308 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1309 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
1310 };
1311 SkRect ptBounds;
1312 ptBounds.setLargestInverted();
1313 debugster("original", ptBounds);
1314 ptBounds.growToInclude( { 42, 24 } );
1315 debugster("grown", ptBounds);
1316#StdOut
1317original rect: 3.40282e+38, 3.40282e+38, -3.40282e+38, -3.40282e+38 isEmpty: true
1318grown rect: 42, 24, 42, 24 isEmpty: true
1319##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001320##
1321
Cary Clark7fc1d122017-10-09 14:07:42 -04001322#SeeAlso growToInclude setEmpty setLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -04001323
1324##
1325
1326# ------------------------------------------------------------------------------
1327
1328#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1329
Cary Clark7fc1d122017-10-09 14:07:42 -04001330Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001331
Cary Clark7fc1d122017-10-09 14:07:42 -04001332If dx is negative, Rect returned is moved to the left.
1333If dx is positive, Rect returned is moved to the right.
1334If dy is negative, Rect returned is moved upward.
1335If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001336
Cary Clark7fc1d122017-10-09 14:07:42 -04001337#Param dx added to fLeft and fRight ##
1338#Param dy added to fTop and fBottom ##
1339
1340#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001341
1342#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001343 SkRect rect = { 10, 50, 20, 60 };
1344 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1345 rect.bottom(), rect.isEmpty() ? "true" : "false");
1346 rect = rect.makeOffset(15, 32);
1347 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1348 rect.bottom(), rect.isEmpty() ? "true" : "false");
1349#StdOut
1350rect: 10, 50, 20, 60 isEmpty: false
1351rect: 25, 82, 35, 92 isEmpty: false
1352##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001353##
1354
Cary Clark7fc1d122017-10-09 14:07:42 -04001355#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001356
1357##
1358
1359# ------------------------------------------------------------------------------
1360
1361#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1362
Cary Clark7fc1d122017-10-09 14:07:42 -04001363Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001364
Cary Clark7fc1d122017-10-09 14:07:42 -04001365If dx is negative, Rect returned is wider.
1366If dx is positive, Rect returned is narrower.
1367If dy is negative, Rect returned is taller.
1368If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
Cary Clark7fc1d122017-10-09 14:07:42 -04001370#Param dx added to fLeft and subtracted from fRight ##
1371#Param dy added to fTop and subtracted from fBottom ##
1372
1373#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001374
1375#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001376 SkRect rect = { 10, 50, 20, 60 };
1377 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1378 rect.bottom(), rect.isEmpty() ? "true" : "false");
1379 rect = rect.makeInset(15, 32);
1380 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1381 rect.bottom(), rect.isEmpty() ? "true" : "false");
1382#StdOut
1383rect: 10, 50, 20, 60 isEmpty: false
1384rect: 25, 82, 5, 28 isEmpty: true
1385##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001386##
1387
Cary Clark7fc1d122017-10-09 14:07:42 -04001388#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001389
1390##
1391
1392# ------------------------------------------------------------------------------
1393
1394#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1395
Cary Clark7fc1d122017-10-09 14:07:42 -04001396Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001397
Cary Clark7fc1d122017-10-09 14:07:42 -04001398If dx is negative, Rect returned is narrower.
1399If dx is positive, Rect returned is wider.
1400If dy is negative, Rect returned is shorter.
1401If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001402
Cary Clark7fc1d122017-10-09 14:07:42 -04001403#Param dx subtracted to fLeft and added from fRight ##
1404#Param dy subtracted to fTop and added from fBottom ##
1405
1406#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001407
1408#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001409 SkRect rect = { 10, 50, 20, 60 };
1410 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1411 rect.bottom(), rect.isEmpty() ? "true" : "false");
1412 rect = rect.makeOutset(15, 32);
1413 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1414 rect.bottom(), rect.isEmpty() ? "true" : "false");
1415#StdOut
1416rect: 10, 50, 20, 60 isEmpty: false
1417rect: -5, 18, 35, 92 isEmpty: false
1418##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001419##
1420
Cary Clark7fc1d122017-10-09 14:07:42 -04001421#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001422
1423##
1424
1425# ------------------------------------------------------------------------------
1426
1427#Method void offset(SkScalar dx, SkScalar dy)
1428
Cary Clark7fc1d122017-10-09 14:07:42 -04001429Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001430
Cary Clark7fc1d122017-10-09 14:07:42 -04001431If dx is negative, moves Rect to the left.
1432If dx is positive, moves Rect to the right.
1433If dy is negative, moves Rect upward.
1434If dy is positive, moves Rect downward.
1435
1436#Param dx offset added to fLeft and fRight ##
1437#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001438
1439#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001440 SkRect rect = { 10, 14, 50, 73 };
1441 rect.offset(5, 13);
1442 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1443#StdOut
1444rect: 15, 27, 55, 86
1445##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001446##
1447
Cary Clark7fc1d122017-10-09 14:07:42 -04001448#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001449
1450##
1451
1452# ------------------------------------------------------------------------------
1453
1454#Method void offset(const SkPoint& delta)
1455
Cary Clark7fc1d122017-10-09 14:07:42 -04001456Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1457fTop, fBottom.
1458
1459If delta.fX is negative, moves Rect to the left.
1460If delta.fX is positive, moves Rect to the right.
1461If delta.fY is negative, moves Rect upward.
1462If delta.fY is positive, moves Rect downward.
1463
1464#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001465
1466#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001467 SkRect rect = { 10, 14, 50, 73 };
1468 rect.offset({5, 13});
1469 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1470#StdOut
1471rect: 15, 27, 55, 86
1472##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001473##
1474
Cary Clark7fc1d122017-10-09 14:07:42 -04001475#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001476
1477##
1478
1479# ------------------------------------------------------------------------------
1480
1481#Method void offsetTo(SkScalar newX, SkScalar newY)
1482
Cary Clark7fc1d122017-10-09 14:07:42 -04001483Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1484are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001485
Cary Clark7fc1d122017-10-09 14:07:42 -04001486#Param newX stored in fLeft, preserving width() ##
1487#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488
1489#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001490 SkRect rect = { 10, 14, 50, 73 };
1491 rect.offsetTo(15, 27);
1492 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1493#StdOut
1494rect: 15, 27, 55, 86
1495##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001496##
1497
Cary Clark7fc1d122017-10-09 14:07:42 -04001498#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001499
1500##
1501
1502# ------------------------------------------------------------------------------
1503
1504#Method void inset(SkScalar dx, SkScalar dy)
1505
Cary Clark7fc1d122017-10-09 14:07:42 -04001506Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001507
Cary Clark7fc1d122017-10-09 14:07:42 -04001508If dx is positive, makes Rect narrower.
1509If dx is negative, makes Rect wider.
1510If dy is positive, makes Rect shorter.
1511If dy is negative, makes Rect taller.
1512
1513#Param dx added to fLeft and subtracted from fRight ##
1514#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001515
1516#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001517 SkRect rect = { 10, 14, 50, 73 };
1518 rect.inset(5, 13);
1519 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1520#StdOut
1521rect: 15, 27, 45, 60
1522##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001523##
1524
Cary Clark7fc1d122017-10-09 14:07:42 -04001525#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001526
1527##
1528
1529# ------------------------------------------------------------------------------
1530
1531#Method void outset(SkScalar dx, SkScalar dy)
1532
Cary Clark7fc1d122017-10-09 14:07:42 -04001533Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001534
Cary Clark7fc1d122017-10-09 14:07:42 -04001535If dx is positive, makes Rect wider.
1536If dx is negative, makes Rect narrower.
1537If dy is positive, makes Rect taller.
1538If dy is negative, makes Rect shorter.
1539
1540#Param dx subtracted to fLeft and added from fRight ##
1541#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001542
1543#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001544 SkRect rect = { 10, 14, 50, 73 };
1545 rect.outset(5, 13);
1546 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1547#StdOut
1548rect: 5, 1, 55, 86
1549##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001550##
1551
Cary Clark7fc1d122017-10-09 14:07:42 -04001552#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001553
1554##
1555
Cary Clark7fc1d122017-10-09 14:07:42 -04001556#Topic Intersection
1557
1558Rects intersect when they enclose a common area. To intersect, each of the pair
1559must describe area; fLeft is less than fRight, and fTop is less than fBottom;
1560empty() returns false. The intersection of Rect a and Rect b can be described by:
1561#Formula
1562(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1563 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1564##
1565The intersection is only meaningful if the resulting Rect is not empty and
1566describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1567
Cary Clarkbc5697d2017-10-04 14:31:33 -04001568# ------------------------------------------------------------------------------
1569
1570#Method bool intersect(const SkRect& r)
1571
Cary Clark7fc1d122017-10-09 14:07:42 -04001572Returns true if Rect intersects r, and sets Rect to intersection.
1573Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001574
Cary Clark7fc1d122017-10-09 14:07:42 -04001575Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001576
Cary Clark7fc1d122017-10-09 14:07:42 -04001577#Param r limit of result ##
1578
1579#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001580
1581#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001582#Description
1583Two SkDebugf calls are required. If the calls are combined, their arguments
1584may not be evaluated in left to right order: the printed intersection may
1585be before or after the call to intersect.
1586##
1587 SkRect leftRect = { 10, 40, 50, 80 };
1588 SkRect rightRect = { 30, 60, 70, 90 };
1589 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1590 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
1591 leftRect.right(), leftRect.bottom());
1592#StdOut
1593 intersection: 30, 60, 50, 80
1594##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001595##
1596
Cary Clark7fc1d122017-10-09 14:07:42 -04001597#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001598
1599##
1600
1601# ------------------------------------------------------------------------------
1602
1603#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1604
Cary Clark7fc1d122017-10-09 14:07:42 -04001605Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1606construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001607
Cary Clark7fc1d122017-10-09 14:07:42 -04001608Returns true if Rect intersects construction, and sets Rect to intersection.
1609Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001610
Cary Clark7fc1d122017-10-09 14:07:42 -04001611Returns false if either construction or Rect is empty, leaving Rect unchanged.
1612
1613#Param left x minimum of constructed Rect ##
1614#Param top y minimum of constructed Rect ##
1615#Param right x maximum of constructed Rect ##
1616#Param bottom y maximum of constructed Rect ##
1617
1618#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001619
1620#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001621#Description
1622Two SkDebugf calls are required. If the calls are combined, their arguments
1623may not be evaluated in left to right order: the printed intersection may
1624be before or after the call to intersect.
1625##
1626 SkRect leftRect = { 10, 40, 50, 80 };
1627 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1628 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
1629 leftRect.right(), leftRect.bottom());
1630#StdOut
1631 intersection: 30, 60, 50, 80
1632##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001633##
1634
Cary Clark7fc1d122017-10-09 14:07:42 -04001635#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001636
1637##
1638
1639# ------------------------------------------------------------------------------
1640
1641#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1642
Cary Clark7fc1d122017-10-09 14:07:42 -04001643Returns true if a intersects b, and sets Rect to intersection.
1644Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001645
Cary Clark7fc1d122017-10-09 14:07:42 -04001646Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001647
Cary Clark7fc1d122017-10-09 14:07:42 -04001648#Param a Rect to intersect ##
1649#Param b Rect to intersect ##
1650
1651#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001652
1653#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001654 SkRect result;
1655 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1656 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1657 result.left(), result.top(), result.right(), result.bottom());
1658#StdOut
1659 intersection: 30, 60, 50, 80
1660##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001661##
1662
Cary Clark7fc1d122017-10-09 14:07:42 -04001663#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001664
1665##
1666
Cary Clark7fc1d122017-10-09 14:07:42 -04001667# ------------------------------------------------------------------------------
1668
Cary Clarkbc5697d2017-10-04 14:31:33 -04001669#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1670
Cary Clark7fc1d122017-10-09 14:07:42 -04001671Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1672construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001673
Cary Clark7fc1d122017-10-09 14:07:42 -04001674Returns true if Rect intersects construction.
1675Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001676
Cary Clark7fc1d122017-10-09 14:07:42 -04001677#Param left x minimum of constructed Rect ##
1678#Param top y minimum of constructed Rect ##
1679#Param right x maximum of constructed Rect ##
1680#Param bottom y maximum of constructed Rect ##
1681
1682#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001683
1684#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001685 SkRect rect = { 10, 40, 50, 80 };
1686 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
1687#StdOut
1688 intersection
1689##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001690##
1691
Cary Clark7fc1d122017-10-09 14:07:42 -04001692#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001693
1694##
1695
Cary Clark7fc1d122017-10-09 14:07:42 -04001696# ------------------------------------------------------------------------------
1697
Cary Clarkbc5697d2017-10-04 14:31:33 -04001698#Method bool intersects(const SkRect& r) const
1699
Cary Clark7fc1d122017-10-09 14:07:42 -04001700Returns true if Rect intersects r.
1701Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001702
Cary Clark7fc1d122017-10-09 14:07:42 -04001703#Param r Rect to intersect ##
1704
1705#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001706
1707#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001708 SkRect rect = { 10, 40, 50, 80 };
1709 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
1710#StdOut
1711 intersection
1712##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001713##
1714
Cary Clark7fc1d122017-10-09 14:07:42 -04001715#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001716
1717##
1718
Cary Clark7fc1d122017-10-09 14:07:42 -04001719# ------------------------------------------------------------------------------
1720
Cary Clarkbc5697d2017-10-04 14:31:33 -04001721#Method static bool Intersects(const SkRect& a, const SkRect& b)
1722
Cary Clark7fc1d122017-10-09 14:07:42 -04001723Returns true if a intersects b.
1724Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001725
Cary Clark7fc1d122017-10-09 14:07:42 -04001726#Param a Rect to intersect ##
1727#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001728
Cary Clark7fc1d122017-10-09 14:07:42 -04001729#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001730
1731#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001732 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
1733#StdOut
1734 intersection
1735##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001736##
1737
Cary Clark7fc1d122017-10-09 14:07:42 -04001738#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001739
1740##
1741
Cary Clark7fc1d122017-10-09 14:07:42 -04001742#Topic Intersection ##
1743
1744
1745# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746
1747#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1748
Cary Clark7fc1d122017-10-09 14:07:42 -04001749Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1750construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001751
Cary Clark7fc1d122017-10-09 14:07:42 -04001752Sets Rect to the union of itself and the construction.
1753
1754Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1755Rect to construction.
1756
1757#Param left x minimum of constructed Rect ##
1758#Param top y minimum of constructed Rect ##
1759#Param right x maximum of constructed Rect ##
1760#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001761
1762#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001763 SkRect rect = { 10, 20, 15, 25};
1764 rect.join(50, 60, 55, 65);
1765 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1766#StdOut
1767 join: 10, 20, 55, 65
1768##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769##
1770
Cary Clark7fc1d122017-10-09 14:07:42 -04001771#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001772
1773##
1774
Cary Clark7fc1d122017-10-09 14:07:42 -04001775# ------------------------------------------------------------------------------
1776
Cary Clarkbc5697d2017-10-04 14:31:33 -04001777#Method void join(const SkRect& r)
1778
Cary Clark7fc1d122017-10-09 14:07:42 -04001779Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001780
Cary Clark7fc1d122017-10-09 14:07:42 -04001781Has no effect if r is empty. Otherwise, if Rect is empty, sets
1782Rect to r.
1783
1784#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001785
1786#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001787 SkRect rect = { 10, 20, 15, 25};
1788 rect.join({50, 60, 55, 65});
1789 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1790#StdOut
1791 join: 10, 20, 55, 65
1792##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793##
1794
Cary Clark7fc1d122017-10-09 14:07:42 -04001795#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::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 joinNonEmptyArg(const SkRect& r)
1802
Cary Clark7fc1d122017-10-09 14:07:42 -04001803Sets Rect to the union of itself and r.
1804
1805Asserts if r is empty and SK_DEBUG is defined.
1806If Rect is empty, sets Rect to r.
1807
1808May produce incorrect results if r is empty.
1809
1810#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001811
1812#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001813#Description
1814Since Rect is not sorted, first result is copy of toJoin.
1815##
1816 SkRect rect = { 10, 100, 15, 0};
1817 SkRect sorted = rect.makeSorted();
1818 SkRect toJoin = { 50, 60, 55, 65 };
1819 rect.joinNonEmptyArg(toJoin);
1820 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1821 sorted.joinNonEmptyArg(toJoin);
1822 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1823#StdOut
1824rect: 50, 60, 55, 65
1825sorted: 10, 0, 55, 100
1826##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001827##
1828
Cary Clark7fc1d122017-10-09 14:07:42 -04001829#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001830
1831##
1832
Cary Clark7fc1d122017-10-09 14:07:42 -04001833# ------------------------------------------------------------------------------
1834
Cary Clarkbc5697d2017-10-04 14:31:33 -04001835#Method void joinPossiblyEmptyRect(const SkRect& r)
1836
Cary Clark7fc1d122017-10-09 14:07:42 -04001837Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001838
Cary Clark7fc1d122017-10-09 14:07:42 -04001839May produce incorrect results if Rect or r is empty.
1840
1841#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001842
1843#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001844#Description
1845Since Rect is not sorted, first result is not useful.
1846##
1847 SkRect rect = { 10, 100, 15, 0};
1848 SkRect sorted = rect.makeSorted();
1849 SkRect toJoin = { 50, 60, 55, 65 };
1850 rect.joinPossiblyEmptyRect(toJoin);
1851 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1852 sorted.joinPossiblyEmptyRect(toJoin);
1853 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1854#StdOut
1855rect: 10, 60, 55, 65
1856sorted: 10, 0, 55, 100
1857##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001858##
1859
Cary Clark7fc1d122017-10-09 14:07:42 -04001860#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001861
1862##
1863
Cary Clark7fc1d122017-10-09 14:07:42 -04001864# ------------------------------------------------------------------------------
1865
Cary Clarkbc5697d2017-10-04 14:31:33 -04001866#Method void growToInclude(SkPoint pt)
1867
Cary Clark7fc1d122017-10-09 14:07:42 -04001868Grows Rect to include (pt.fX, pt.fY), modifying it so that:
1869#Formula
1870fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1871##
1872.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001873
Cary Clark7fc1d122017-10-09 14:07:42 -04001874If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1875Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001876
Cary Clark7fc1d122017-10-09 14:07:42 -04001877#Param pt Point to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001878
1879#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001880 SkRect rect;
1881 rect.setLargestInverted();
1882 rect.growToInclude( { 42, 24 } );
1883 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1884 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
1885#StdOut
1886rect: 42, 24, 42, 24 isEmpty: true
1887##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001888##
1889
Cary Clark7fc1d122017-10-09 14:07:42 -04001890#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001891
1892##
1893
Cary Clark7fc1d122017-10-09 14:07:42 -04001894# ------------------------------------------------------------------------------
1895
Cary Clarkbc5697d2017-10-04 14:31:33 -04001896#Method void growToInclude(const SkPoint pts[], int count)
1897
Cary Clark7fc1d122017-10-09 14:07:42 -04001898For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1899it so that:
1900#Formula
1901fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1902##
1903.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001904
Cary Clark7fc1d122017-10-09 14:07:42 -04001905If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1906Points after one or more calls. In this case, Rect is empty after first call.
1907
1908#Param pts Point array ##
1909#Param count number of points in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001910
1911#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001912 SkPoint pts[] = { { 30, 50 }, { 40, 50 }, { 30, 60 } };
1913 SkRect rect = { pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY };
1914 rect.growToInclude( pts[1] );
1915 rect.growToInclude( pts[2] );
1916 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1917#StdOut
1918rect: 30, 50, 40, 60
1919##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001920##
1921
Cary Clark7fc1d122017-10-09 14:07:42 -04001922#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001923
1924##
1925
Cary Clark7fc1d122017-10-09 14:07:42 -04001926# ------------------------------------------------------------------------------
1927
Cary Clarkbc5697d2017-10-04 14:31:33 -04001928#Method void growToInclude(const SkPoint pts[], size_t stride, int count)
1929
Cary Clark7fc1d122017-10-09 14:07:42 -04001930For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1931it so that:
1932#Formula
1933fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1934##
1935. Point may be followed with other data in each array element. stride is number
1936 of bytes in element; the interval to skip to advance from one Point to
1937the next.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001938
Cary Clark7fc1d122017-10-09 14:07:42 -04001939If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1940Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001941
Cary Clark7fc1d122017-10-09 14:07:42 -04001942#Param pts array of elements beginning with Point ##
1943#Param stride size of pts elements in 32-bit words; zero or greater ##
1944#Param count number of elements in array ##
1945
1946#Bug 7142 ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001947#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001948 SkPoint3 pts[] = { { 30, 50, -1 }, { 40, 50, -1 }, { 30, 60, -1 } };
1949 SkRect rect;
1950 rect.setLargestInverted();
1951 rect.growToInclude((SkPoint* ) &pts[0].fX, sizeof(SkPoint3), SK_ARRAY_COUNT(pts));
1952 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1953#StdOut
1954#Volatile
1955rect: 30, 50, 40, 60
1956##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001957##
1958
Cary Clark7fc1d122017-10-09 14:07:42 -04001959#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001960
1961##
1962
Cary Clark7fc1d122017-10-09 14:07:42 -04001963# ------------------------------------------------------------------------------
1964
Cary Clarkbc5697d2017-10-04 14:31:33 -04001965#Method bool contains(const SkRect& r) const {
1966
Cary Clark7fc1d122017-10-09 14:07:42 -04001967Returns true if Rect contains r.
1968Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001969
Cary Clark7fc1d122017-10-09 14:07:42 -04001970Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001971
Cary Clark7fc1d122017-10-09 14:07:42 -04001972#Param r Rect contained ##
1973
1974#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001975
1976#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001977 SkRect rect = { 30, 50, 40, 60 };
1978 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1979 for (auto contained : tests) {
1980 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1981 rect.left(), rect.top(), rect.right(), rect.bottom(),
1982 rect.contains(contained) ? "contains" : "does not contain",
1983 contained.left(), contained.top(), contained.right(), contained.bottom());
1984 }
1985#StdOut
1986rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1987rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1988rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1989##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001990##
1991
Cary Clark7fc1d122017-10-09 14:07:42 -04001992#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04001993
1994##
1995
Cary Clark7fc1d122017-10-09 14:07:42 -04001996# ------------------------------------------------------------------------------
1997
Cary Clarkbc5697d2017-10-04 14:31:33 -04001998#Method bool contains(const SkIRect& r) const
1999
Cary Clark7fc1d122017-10-09 14:07:42 -04002000Returns true if Rect contains r.
2001Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002002
Cary Clark7fc1d122017-10-09 14:07:42 -04002003Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002004
Cary Clark7fc1d122017-10-09 14:07:42 -04002005#Param r IRect contained ##
2006
2007#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002008
2009#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002010 SkRect rect = { 30, 50, 40, 60 };
2011 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
2012 for (auto contained : tests) {
2013 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
2014 rect.left(), rect.top(), rect.right(), rect.bottom(),
2015 rect.contains(contained) ? "contains" : "does not contain",
2016 contained.left(), contained.top(), contained.right(), contained.bottom());
2017 }
2018#StdOut
2019rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
2020rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
2021rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
2022##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002023##
2024
Cary Clark7fc1d122017-10-09 14:07:42 -04002025#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04002026
2027##
2028
Cary Clark7fc1d122017-10-09 14:07:42 -04002029#Topic Round
2030
2031# ------------------------------------------------------------------------------
2032
Cary Clarkbc5697d2017-10-04 14:31:33 -04002033#Method void round(SkIRect* dst) const
2034
Cary Clark7fc1d122017-10-09 14:07:42 -04002035Sets IRect by adding 0.5 and discarding the fractional portion of Rect
2036members, using
2037#Formula
2038(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2039 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2040##
2041.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002042
Cary Clark7fc1d122017-10-09 14:07:42 -04002043#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002044
2045#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002046 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2047 SkIRect round;
2048 rect.round(&round);
2049 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2050#StdOut
2051round: 31, 51, 41, 61
2052##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002053##
2054
Cary Clark7fc1d122017-10-09 14:07:42 -04002055#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002056
2057##
2058
Cary Clark7fc1d122017-10-09 14:07:42 -04002059# ------------------------------------------------------------------------------
2060
Cary Clarkbc5697d2017-10-04 14:31:33 -04002061#Method void roundOut(SkIRect* dst) const
2062
Cary Clark7fc1d122017-10-09 14:07:42 -04002063Sets IRect by discarding the fractional portion of fLeft and fTop; and
2064rounding up fRight and FBottom, using
2065#Formula
2066(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2067 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2068##
2069.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002070
Cary Clark7fc1d122017-10-09 14:07:42 -04002071#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002072
2073#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002074 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2075 SkIRect round;
2076 rect.roundOut(&round);
2077 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2078#StdOut
2079round: 30, 50, 41, 61
2080##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002081##
2082
Cary Clark7fc1d122017-10-09 14:07:42 -04002083#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002084
2085##
2086
Cary Clark7fc1d122017-10-09 14:07:42 -04002087# ------------------------------------------------------------------------------
2088
Cary Clarkbc5697d2017-10-04 14:31:33 -04002089#Method void roundOut(SkRect* dst) const
2090
Cary Clark7fc1d122017-10-09 14:07:42 -04002091Sets Rect by discarding the fractional portion of fLeft and fTop; and
2092rounding up fRight and FBottom, using
2093#Formula
2094(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2095 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2096##
2097.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002098
Cary Clark7fc1d122017-10-09 14:07:42 -04002099#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002100
2101#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002102 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2103 SkRect round;
2104 rect.roundOut(&round);
2105 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2106#StdOut
2107round: 30, 50, 41, 61
2108##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002109##
2110
Cary Clark7fc1d122017-10-09 14:07:42 -04002111#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002112
2113##
2114
Cary Clark7fc1d122017-10-09 14:07:42 -04002115# ------------------------------------------------------------------------------
2116
Cary Clarkbc5697d2017-10-04 14:31:33 -04002117#Method void roundIn(SkIRect* dst) const
2118
Cary Clark7fc1d122017-10-09 14:07:42 -04002119Sets Rect by rounding up fLeft and fTop; and
2120discarding the fractional portion of fRight and FBottom, using
2121#Formula
2122(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2123 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2124##
2125.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002126
Cary Clark7fc1d122017-10-09 14:07:42 -04002127#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002128
2129#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002130 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2131 SkIRect round;
2132 rect.roundIn(&round);
2133 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2134#StdOut
2135round: 31, 51, 40, 60
2136##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002137##
2138
Cary Clark7fc1d122017-10-09 14:07:42 -04002139#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002140
2141##
2142
Cary Clark7fc1d122017-10-09 14:07:42 -04002143# ------------------------------------------------------------------------------
2144
Cary Clarkbc5697d2017-10-04 14:31:33 -04002145#Method SkIRect round() const
2146
Cary Clark7fc1d122017-10-09 14:07:42 -04002147Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2148members, using
2149#Formula
2150(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2151 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2152##
2153.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002154
Cary Clark7fc1d122017-10-09 14:07:42 -04002155#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002156
2157#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002158 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2159 SkIRect round = rect.round();
2160 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2161#StdOut
2162round: 31, 51, 41, 61
2163##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002164##
2165
Cary Clark7fc1d122017-10-09 14:07:42 -04002166#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002167
2168##
2169
Cary Clark7fc1d122017-10-09 14:07:42 -04002170# ------------------------------------------------------------------------------
2171
Cary Clarkbc5697d2017-10-04 14:31:33 -04002172#Method SkIRect roundOut() const
2173
Cary Clark7fc1d122017-10-09 14:07:42 -04002174Sets IRect by discarding the fractional portion of fLeft and fTop; and
2175rounding up fRight and FBottom, using
2176#Formula
2177(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2178 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2179##
2180.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002181
Cary Clark7fc1d122017-10-09 14:07:42 -04002182#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002183
2184#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002185 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2186 SkIRect round = rect.roundOut();
2187 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
2188#StdOut
2189round: 30, 50, 41, 61
2190##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002191##
2192
Cary Clark7fc1d122017-10-09 14:07:42 -04002193#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002194
2195##
2196
Cary Clark7fc1d122017-10-09 14:07:42 -04002197#Topic Round ##
2198
2199# ------------------------------------------------------------------------------
2200
Cary Clarkbc5697d2017-10-04 14:31:33 -04002201#Method void sort()
2202
Cary Clark7fc1d122017-10-09 14:07:42 -04002203Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2204fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2205and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002206
2207#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002208 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2209 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2210 rect.sort();
2211 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2212#StdOut
2213rect: 30.5, 50.5, 20.5, 10.5
2214sorted: 20.5, 10.5, 30.5, 50.5
2215##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002216##
2217
Cary Clark7fc1d122017-10-09 14:07:42 -04002218#SeeAlso makeSorted SkIRect::sort
Cary Clarkbc5697d2017-10-04 14:31:33 -04002219
2220##
2221
Cary Clark7fc1d122017-10-09 14:07:42 -04002222# ------------------------------------------------------------------------------
2223
Cary Clarkbc5697d2017-10-04 14:31:33 -04002224#Method SkRect makeSorted() const
2225
Cary Clark7fc1d122017-10-09 14:07:42 -04002226Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2227with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2228and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002229
Cary Clark7fc1d122017-10-09 14:07:42 -04002230#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002231
2232#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002233 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2234 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2235 SkRect sort = rect.makeSorted();
2236 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
2237#StdOut
2238rect: 30.5, 50.5, 20.5, 10.5
2239sorted: 20.5, 10.5, 30.5, 50.5
2240##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002241##
2242
Cary Clark7fc1d122017-10-09 14:07:42 -04002243#SeeAlso sort SkIRect::makeSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002244
2245##
2246
Cary Clark7fc1d122017-10-09 14:07:42 -04002247# ------------------------------------------------------------------------------
2248
Cary Clarkbc5697d2017-10-04 14:31:33 -04002249#Method const SkScalar* asScalars() const
2250
Cary Clark7fc1d122017-10-09 14:07:42 -04002251Returns pointer to first Scalar in Rect, to treat it as an array with four
2252entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002253
Cary Clark7fc1d122017-10-09 14:07:42 -04002254#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002255
2256#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002257 SkRect rect = {7, 11, 13, 17};
2258SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2259#StdOut
2260rect.asScalars() == &rect.fLeft
2261##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002262##
2263
Cary Clark7fc1d122017-10-09 14:07:42 -04002264#SeeAlso toQuad
2265
Cary Clarkbc5697d2017-10-04 14:31:33 -04002266##
2267
Cary Clark7fc1d122017-10-09 14:07:42 -04002268# ------------------------------------------------------------------------------
2269
Cary Clarkbc5697d2017-10-04 14:31:33 -04002270#Method void dump(bool asHex) const
2271
Cary Clark7fc1d122017-10-09 14:07:42 -04002272Writes text representation of Rect to standard output. Set asHex to true to
2273generate exact binary representations of floating point numbers.
2274
2275#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002276
2277#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002278 SkRect rect = {20, 30, 40, 50};
2279 for (bool dumpAsHex : { false, true } ) {
2280 rect.dump(dumpAsHex);
2281 SkDebugf("\n");
2282 }
2283#StdOut
2284SkRect::MakeLTRB(20, 30, 40, 50);
2285
2286SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2287 SkBits2Float(0x41f00000), /* 30.000000 */
2288 SkBits2Float(0x42200000), /* 40.000000 */
2289 SkBits2Float(0x42480000) /* 50.000000 */);
2290##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002291##
2292
Cary Clark7fc1d122017-10-09 14:07:42 -04002293#SeeAlso dumpHex
2294
Cary Clarkbc5697d2017-10-04 14:31:33 -04002295##
2296
Cary Clark7fc1d122017-10-09 14:07:42 -04002297# ------------------------------------------------------------------------------
2298
Cary Clarkbc5697d2017-10-04 14:31:33 -04002299#Method void dump() const
2300
Cary Clark7fc1d122017-10-09 14:07:42 -04002301Writes text representation of Rect to standard output. The representation may be
2302directly compiled as C++ code. Floating point values are written
2303with limited precision; it may not be possible to reconstruct original Rect
2304from output.
2305
Cary Clarkbc5697d2017-10-04 14:31:33 -04002306#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002307SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2308rect.dump();
2309SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2310SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2311#StdOut
2312SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2313rect is not equal to copy
2314##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002315##
2316
Cary Clark7fc1d122017-10-09 14:07:42 -04002317#SeeAlso dumpHex
2318
Cary Clarkbc5697d2017-10-04 14:31:33 -04002319##
2320
Cary Clark7fc1d122017-10-09 14:07:42 -04002321# ------------------------------------------------------------------------------
2322
Cary Clarkbc5697d2017-10-04 14:31:33 -04002323#Method void dumpHex() const
2324
Cary Clark7fc1d122017-10-09 14:07:42 -04002325Writes text representation of Rect to standard output. The representation may be
2326directly compiled as C++ code. Floating point values are written
2327in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2328original Rect.
2329
2330Use instead of dump() when submitting
2331#A bug reports against Skia # http://bug.skia.org ##
2332.
2333
Cary Clarkbc5697d2017-10-04 14:31:33 -04002334#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002335 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2336rect.dumpHex();
2337SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2338 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2339 SkBits2Float(0x40266666), /* 2.600000 */
2340 SkBits2Float(0x40e00000) /* 7.000000 */);
2341SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2342#StdOut
2343SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2344 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2345 SkBits2Float(0x40266666), /* 2.600000 */
2346 SkBits2Float(0x40e00000) /* 7.000000 */);
2347rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002348##
Cary Clark7fc1d122017-10-09 14:07:42 -04002349##
2350
2351#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002352
2353##
2354
2355#Struct SkRect ##
2356
2357#Topic Rect ##