blob: 7f1bdd8b1928315096d8a4de396a9ac0a9872fc1 [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Rect
2#Alias Rects
3#Alias Rect_Reference
4
Cary Clark08895c42018-02-01 09:37:32 -05005#Subtopic Overview
6 #Subtopic Subtopics
7 #Populate
8 ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05009##
10
Cary Clarkbc5697d2017-10-04 14:31:33 -040011#Struct SkRect
12
Cary Clark7fc1d122017-10-09 14:07:42 -040013SkRect holds four SkScalar coordinates describing the upper and
14lower bounds of a rectangle. SkRect may be created from outer bounds or
15from position, width, and height. SkRect describes an area; if its right
16is less than or equal to its left, or if its bottom is less than or equal to
17its top, it is considered empty.
18
19# move to topic about MakeIWH and friends
20SkRect can be constructed from int values to avoid compiler warnings that
21integer input cannot convert to SkScalar without loss of precision.
22
Cary Clark2dc84ad2018-01-26 12:56:22 -050023#Subtopic Related_Functions
Cary Clark08895c42018-02-01 09:37:32 -050024#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040025#Subtopic ##
26
27#Subtopic Member_Functions
Cary Clark08895c42018-02-01 09:37:32 -050028#Populate
29##
Cary Clarkbc5697d2017-10-04 14:31:33 -040030
Cary Clark2dc84ad2018-01-26 12:56:22 -050031#Subtopic Members
Cary Clark08895c42018-02-01 09:37:32 -050032#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040033
34#Member SkScalar fLeft
Cary Clark08895c42018-02-01 09:37:32 -050035#Line # smaller x-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040036May contain any value, including infinities and NaN. The smaller of the
37horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040038##
39
40#Member SkScalar fTop
Cary Clark08895c42018-02-01 09:37:32 -050041#Line # smaller y-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040042May contain any value, including infinities and NaN. The smaller of the
43vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040044##
45
46#Member SkScalar fRight
Cary Clark08895c42018-02-01 09:37:32 -050047#Line # larger x-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040048May contain any value, including infinities and NaN. The larger of the
49horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040050##
51
52#Member SkScalar fBottom
Cary Clark08895c42018-02-01 09:37:32 -050053#Line # larger y-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040054May contain any value, including infinities and NaN. The larger of the
55vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040056##
57
Cary Clark2dc84ad2018-01-26 12:56:22 -050058#Subtopic Members ##
59
60#Subtopic Constructors
61#Table
62#Legend
63# name # description ##
64#Legend ##
65# Make # constructs from ISize returning (0, 0, width, height) ##
66# MakeEmpty # constructs from bounds of (0, 0, 0, 0) ##
67# MakeFromIRect # deprecated ##
68# MakeIWH # constructs from int input returning (0, 0, width, height) ##
69# MakeLTRB # constructs from SkScalar left, top, right, bottom ##
70# MakeLargest # deprecated ##
71# MakeSize # constructs from Size returning (0, 0, width, height) ##
72# MakeWH # constructs from SkScalar input returning (0, 0, width, height) ##
73# MakeXYWH # constructs from SkScalar input returning (x, y, width, height) ##
74# makeInset # constructs from sides moved symmetrically about the center ##
75# makeOffset # constructs from translated sides ##
76# makeOutset # constructs from sides moved symmetrically about the center ##
77# makeSorted # constructs, ordering sides from smaller to larger ##
78#Table ##
79
Cary Clarkbc5697d2017-10-04 14:31:33 -040080# ------------------------------------------------------------------------------
81
82#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
83
Cary Clarkab2621d2018-01-30 10:08:57 -050084#In Constructors
85#Line # constructs from bounds of (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040086Returns constructed Rect set to (0, 0, 0, 0).
87Many other rectangles are empty; if left is equal to or greater than right,
88or if top is equal to or greater than bottom. Setting all members to zero
89is a convenience, but does not designate a special empty rectangle.
90
91#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040092
93#Example
Cary Clark154beea2017-10-26 07:58:48 -040094 SkRect rect = SkRect::MakeEmpty();
95 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
96 rect.offset(10, 10);
97 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
98 rect.inset(10, 10);
99 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
100 rect.outset(20, 20);
101 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
102#StdOut
103MakeEmpty isEmpty: true
104offset rect isEmpty: true
105inset rect isEmpty: true
106outset rect isEmpty: false
107##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400108##
109
Mike Reed274218e2018-01-08 15:05:02 -0500110#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -0400111
112##
113
114# ------------------------------------------------------------------------------
115
116#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400117
Cary Clarkab2621d2018-01-30 10:08:57 -0500118#In Constructors
119#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400120Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
121validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400122
Cary Clark7fc1d122017-10-09 14:07:42 -0400123Passing integer values may generate a compiler warning since Rect cannot
124represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
125
126#Param w SkScalar width of constructed Rect ##
127#Param h SkScalar height of constructed Rect ##
128
129#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400130
131#Example
Cary Clark154beea2017-10-26 07:58:48 -0400132 SkRect rect1 = SkRect::MakeWH(25, 35);
133 SkRect rect2 = SkRect::MakeIWH(25, 35);
134 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
135 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
136 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400137 "" : "not ");
138#StdOut
139all equal
140##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400141##
142
Cary Clark7fc1d122017-10-09 14:07:42 -0400143#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400144
145##
146
147# ------------------------------------------------------------------------------
148
149#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
150
Cary Clarkab2621d2018-01-30 10:08:57 -0500151#In Constructors
152#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400153Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
154input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400155
Cary Clark7fc1d122017-10-09 14:07:42 -0400156Use to avoid a compiler warning that input may lose precision when stored.
157Use SkIRect for an exact integer rectangle.
158
159#Param w integer width of constructed Rect ##
160#Param h integer height of constructed Rect ##
161
162#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400163
164#Example
Cary Clark154beea2017-10-26 07:58:48 -0400165 SkIRect i_rect = SkIRect::MakeWH(25, 35);
166 SkRect f_rect = SkRect::MakeIWH(25, 35);
167 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
168 i_rect = SkIRect::MakeWH(125000111, 0);
169 f_rect = SkRect::MakeIWH(125000111, 0);
170 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400171#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400172i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400173i_rect width: 125000111 f_rect width:125000112
174##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400175##
176
Cary Clark7fc1d122017-10-09 14:07:42 -0400177#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400178
179##
180
181# ------------------------------------------------------------------------------
182
Cary Clark884dd7d2017-10-11 10:37:52 -0400183#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400184
Cary Clarkab2621d2018-01-30 10:08:57 -0500185#In Constructors
186#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400187Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
188validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400189
Cary Clark7fc1d122017-10-09 14:07:42 -0400190#Param size SkScalar values for Rect width and height ##
191
192#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400193
194#Example
Cary Clark154beea2017-10-26 07:58:48 -0400195 SkSize size = {25.5f, 35.5f};
196 SkRect rect = SkRect::MakeSize(size);
197 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
198 SkISize floor = size.toFloor();
199 rect = SkRect::MakeSize(SkSize::Make(floor));
200 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400201#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400202rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400203floor width: 25 height: 35
204##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400205##
206
Cary Clark7fc1d122017-10-09 14:07:42 -0400207#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400208
209##
210
211# ------------------------------------------------------------------------------
212
213#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
214 SkScalar b)
Cary Clarkab2621d2018-01-30 10:08:57 -0500215#In Constructors
216#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400217
Cary Clark7fc1d122017-10-09 14:07:42 -0400218Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
219result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400220
Cary Clark7fc1d122017-10-09 14:07:42 -0400221#Param l SkScalar stored in fLeft ##
222#Param t SkScalar stored in fTop ##
223#Param r SkScalar stored in fRight ##
224#Param b SkScalar stored in fBottom ##
225
226#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400227
228#Example
Cary Clark154beea2017-10-26 07:58:48 -0400229 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
230 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
231 rect.bottom(), rect.isEmpty() ? "true" : "false");
232 rect.sort();
233 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
234 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400235#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400236rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400237rect: 5, 25, 15, 35 isEmpty: false
238##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400239##
240
Cary Clark7fc1d122017-10-09 14:07:42 -0400241#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400242
243##
244
245# ------------------------------------------------------------------------------
246
Cary Clark884dd7d2017-10-11 10:37:52 -0400247#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400248
Cary Clarkab2621d2018-01-30 10:08:57 -0500249#In Constructors
250#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400251Returns constructed Rect set to
252#Formula
253(x, y, x + w, y + h)
254##
255. Does not validate input;
256w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400257
Cary Clark7fc1d122017-10-09 14:07:42 -0400258#Param x stored in fLeft ##
259#Param y stored in fTop ##
260#Param w added to x and stored in fRight ##
261#Param h added to y and stored in fBottom ##
262
Cary Clark884dd7d2017-10-11 10:37:52 -0400263#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400264
265#Example
Cary Clark154beea2017-10-26 07:58:48 -0400266 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
267 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
268 rect.bottom(), rect.isEmpty() ? "true" : "false");
269 rect.sort();
270 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
271 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400272#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400273rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400274rect: -10, 35, 5, 60 isEmpty: false
275##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400276##
277
Cary Clark7fc1d122017-10-09 14:07:42 -0400278#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400279
280##
281
282# ------------------------------------------------------------------------------
283
284#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
285
Cary Clarkab2621d2018-01-30 10:08:57 -0500286#In Constructors
287#Line # deprecated ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400288Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400289
Cary Clark7fc1d122017-10-09 14:07:42 -0400290#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400291##
292
Cary Clark7fc1d122017-10-09 14:07:42 -0400293#Param irect integer rect ##
294
295#Return irect as SkRect ##
296
297#NoExample
298##
299
300#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400301
302##
303
304# ------------------------------------------------------------------------------
305
306#Method static SkRect Make(const SkISize& size)
307
Cary Clarkab2621d2018-01-30 10:08:57 -0500308#In Constructors
309#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400310Returns constructed IRect set to (0, 0, size.width(), size.height()).
311Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400312
Cary Clark7fc1d122017-10-09 14:07:42 -0400313#Param size integer values for Rect width and height ##
314
315#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400316
317#Example
Cary Clark154beea2017-10-26 07:58:48 -0400318 SkRect rect1 = SkRect::MakeSize({2, 35});
319 SkRect rect2 = SkRect::MakeIWH(2, 35);
320 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400321#StdOut
322rect1 == rect2
323##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400324##
325
Cary Clark7fc1d122017-10-09 14:07:42 -0400326#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400327
328##
329
330# ------------------------------------------------------------------------------
331
332#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
333
Cary Clarkab2621d2018-01-30 10:08:57 -0500334#In Constructors
Cary Clark7fc1d122017-10-09 14:07:42 -0400335Returns constructed IRect set to irect, promoting integers to Scalar.
336Does not validate input; fLeft may be greater than fRight, fTop may be greater
337than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400338
Cary Clark7fc1d122017-10-09 14:07:42 -0400339#Param irect integer unsorted bounds ##
340
341#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400342
343#Example
Cary Clark154beea2017-10-26 07:58:48 -0400344 SkIRect i_rect1 = {2, 35, 22, 53};
345 SkRect f_rect = SkRect::Make(i_rect1);
346 f_rect.offset(0.49f, 0.49f);
347 SkIRect i_rect2;
348 f_rect.round(&i_rect2);
349 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400350##
351
Cary Clark7fc1d122017-10-09 14:07:42 -0400352#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400353
354##
355
Cary Clark2dc84ad2018-01-26 12:56:22 -0500356#Subtopic Constructors ##
357
358#Subtopic Properties
Cary Clark08895c42018-02-01 09:37:32 -0500359#Line # side values, center, validity ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500360
361#Table
362#Legend
363# name # description ##
364#Legend ##
365# bottom() # returns larger bounds in y, if sorted ##
366# centerX # returns midpoint in x ##
367# centerY # returns midpoint in y ##
368# height() # returns span in y ##
369# isEmpty # returns true if width or height are zero or negative ##
370# isFinite # returns true if no member is infinite or NaN ##
371# isSorted # returns true if width or height are zero or positive ##
372# left() # returns smaller bounds in x, if sorted ##
373# right() # returns larger bounds in x, if sorted ##
374# top() # returns smaller bounds in y, if sorted ##
375# width() # returns span in x ##
376# x() # returns bounds left ##
377# y() # returns bounds top ##
378#Table ##
379
Cary Clarkbc5697d2017-10-04 14:31:33 -0400380# ------------------------------------------------------------------------------
381
382#Method bool isEmpty() const
383
Cary Clarkab2621d2018-01-30 10:08:57 -0500384#In Properties
385#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400386Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
387to or greater than fBottom. Call sort() to reverse rectangles with negative
388width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400389
Cary Clark7fc1d122017-10-09 14:07:42 -0400390#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400391
392#Example
Cary Clark154beea2017-10-26 07:58:48 -0400393 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
394 for (auto rect : tests) {
395 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
396 rect.bottom(), rect.isEmpty() ? "" : " not");
397 rect.sort();
398 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
399 rect.bottom(), rect.isEmpty() ? "" : " not");
400 }
401#StdOut
402rect: {20, 40, 10, 50} is empty
403sorted: {10, 40, 20, 50} is not empty
404rect: {20, 40, 20, 50} is empty
405sorted: {20, 40, 20, 50} is empty
406##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400407##
408
Cary Clark7fc1d122017-10-09 14:07:42 -0400409#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400410
411##
412
413# ------------------------------------------------------------------------------
414
415#Method bool isSorted() const
416
Cary Clarkab2621d2018-01-30 10:08:57 -0500417#In Properties
418#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400419Returns true if fLeft is equal to or less than fRight, or if fTop is equal
420to or less than fBottom. Call sort() to reverse rectangles with negative
421width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400422
Cary Clark7fc1d122017-10-09 14:07:42 -0400423#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400424
425#Example
Cary Clark154beea2017-10-26 07:58:48 -0400426 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
427 for (auto rect : tests) {
428 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
429 rect.bottom(), rect.isSorted() ? "" : " not");
430 rect.sort();
431 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
432 rect.bottom(), rect.isSorted() ? "" : " not");
433 }
434#StdOut
435rect: {20, 40, 10, 50} is not sorted
436sorted: {10, 40, 20, 50} is sorted
437rect: {20, 40, 20, 50} is sorted
438sorted: {20, 40, 20, 50} is sorted
439##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400440##
441
Cary Clark7fc1d122017-10-09 14:07:42 -0400442#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400443
444##
445
446# ------------------------------------------------------------------------------
447
Cary Clarkbc5697d2017-10-04 14:31:33 -0400448#Method bool isFinite() const
449
Cary Clarkab2621d2018-01-30 10:08:57 -0500450#In Properties
451#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400452Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
453and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400454
Cary Clark7fc1d122017-10-09 14:07:42 -0400455#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400456
457#Example
Mike Reed274218e2018-01-08 15:05:02 -0500458SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400459 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
460 SkDebugf("large width %g\n", largest.width());
461 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
462 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
463#StdOut
464largest is finite: true
465large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400466widest is finite: false
467##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400468##
469
Cary Clark7fc1d122017-10-09 14:07:42 -0400470#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400471
472##
473
474# ------------------------------------------------------------------------------
475
476#Method SkScalar x() const
477
Cary Clarkab2621d2018-01-30 10:08:57 -0500478#In Properties
479#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400480Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
481Call sort() to reverse fLeft and fRight if needed.
482
483#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400484
485#Example
Cary Clark154beea2017-10-26 07:58:48 -0400486 SkRect unsorted = { 15, 5, 10, 25 };
487 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
488 SkRect sorted = unsorted.makeSorted();
489 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400490#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400491unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400492sorted.fLeft: 10 sorted.x(): 10
493##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400494##
495
Cary Clark7fc1d122017-10-09 14:07:42 -0400496#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400497
498##
499
500# ------------------------------------------------------------------------------
501
502#Method SkScalar y() const
503
Cary Clarkab2621d2018-01-30 10:08:57 -0500504#In Properties
505#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400506Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
507and sort() to reverse fTop and fBottom if needed.
508
509#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400510
511#Example
Cary Clark154beea2017-10-26 07:58:48 -0400512 SkRect unsorted = { 15, 25, 10, 5 };
513 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
514 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400515 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
516#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400517unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400518sorted.fTop: 5 sorted.y(): 5
519##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400520##
521
Cary Clark7fc1d122017-10-09 14:07:42 -0400522#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400523
524##
525
526# ------------------------------------------------------------------------------
527
528#Method SkScalar left() const
529
Cary Clarkab2621d2018-01-30 10:08:57 -0500530#In Properties
531#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400532Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
533Call sort() to reverse fLeft and fRight if needed.
534
535#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400536
537#Example
Cary Clark154beea2017-10-26 07:58:48 -0400538 SkRect unsorted = { 15, 5, 10, 25 };
539 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
540 SkRect sorted = unsorted.makeSorted();
541 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400542#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400543unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400544sorted.fLeft: 10 sorted.left(): 10
545##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400546##
547
Cary Clark7fc1d122017-10-09 14:07:42 -0400548#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400549
550##
551
552# ------------------------------------------------------------------------------
553
554#Method SkScalar top() const
555
Cary Clarkab2621d2018-01-30 10:08:57 -0500556#In Properties
557#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400558Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
559and sort() to reverse fTop and fBottom if needed.
560
561#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400562
563#Example
Cary Clark154beea2017-10-26 07:58:48 -0400564 SkRect unsorted = { 15, 25, 10, 5 };
565 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
566 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400567 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
568#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400569unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400570sorted.fTop: 5 sorted.top(): 5
571##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400572##
573
Cary Clark7fc1d122017-10-09 14:07:42 -0400574#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400575
576##
577
578# ------------------------------------------------------------------------------
579
580#Method SkScalar right() const
581
Cary Clarkab2621d2018-01-30 10:08:57 -0500582#In Properties
583#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400584Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
585Call sort() to reverse fLeft and fRight if needed.
586
587#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400588
589#Example
Cary Clark154beea2017-10-26 07:58:48 -0400590 SkRect unsorted = { 15, 25, 10, 5 };
591 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
592 SkRect sorted = unsorted.makeSorted();
593 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400594#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400595unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400596sorted.fRight: 15 sorted.right(): 15
597##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400598##
599
Cary Clark7fc1d122017-10-09 14:07:42 -0400600#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400601
602##
603
604# ------------------------------------------------------------------------------
605
606#Method SkScalar bottom() const
607
Cary Clarkab2621d2018-01-30 10:08:57 -0500608#In Properties
609#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400610Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
611and sort() to reverse fTop and fBottom if needed.
612
613#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400614
615#Example
Cary Clark154beea2017-10-26 07:58:48 -0400616 SkRect unsorted = { 15, 25, 10, 5 };
617 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
618 SkRect sorted = unsorted.makeSorted();
619 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400620#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400621unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400622sorted.fBottom: 25 sorted.bottom(): 25
623##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400624##
625
Cary Clark7fc1d122017-10-09 14:07:42 -0400626#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400627
628##
629
630# ------------------------------------------------------------------------------
631
632#Method SkScalar width() const
633
Cary Clarkab2621d2018-01-30 10:08:57 -0500634#In Properties
635#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400636Returns span on the x-axis. This does not check if Rect is sorted, or if
637result fits in 32-bit float; result may be negative or infinity.
638
639#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400640
641#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400642#Description
643Compare with SkIRect::width() example.
644##
Cary Clark154beea2017-10-26 07:58:48 -0400645 SkRect unsorted = { 15, 25, 10, 5 };
646 SkDebugf("unsorted width: %g\n", unsorted.width());
647 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
648 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400649#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400650unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400651large width: 4294967296
652##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400653##
654
Cary Clark7fc1d122017-10-09 14:07:42 -0400655#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400656
657##
658
659# ------------------------------------------------------------------------------
660
661#Method SkScalar height() const
662
Cary Clarkab2621d2018-01-30 10:08:57 -0500663#In Properties
664#Line # returns span in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400665Returns span on the y-axis. This does not check if IRect is sorted, or if
666result fits in 32-bit float; result may be negative or infinity.
667
668#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400669
670#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400671#Description
672Compare with SkIRect::height() example.
673##
Cary Clark154beea2017-10-26 07:58:48 -0400674 SkRect unsorted = { 15, 25, 10, 20 };
675 SkDebugf("unsorted height: %g\n", unsorted.height());
676 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
677 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400678#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400679unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400680large height: 4294967296
681##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400682##
683
Cary Clark7fc1d122017-10-09 14:07:42 -0400684#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400685
686##
687
688# ------------------------------------------------------------------------------
689
690#Method SkScalar centerX() const
691
Cary Clarkab2621d2018-01-30 10:08:57 -0500692#In Properties
693#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400694Returns average of left edge and right edge. Result does not change if Rect
695is sorted. Result may overflow to infinity if Rect is far from the origin.
696
697#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400698
699#Example
Cary Clark154beea2017-10-26 07:58:48 -0400700 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
701 for (auto rect : tests) {
702 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
703 rect.sort();
704 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
705 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400706#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400707left: 20 right: 41 centerX: 30.5
708left: 20 right: 41 centerX: 30.5
709left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400710left: -41 right: -20 centerX: -30.5
711##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400712##
713
Cary Clark7fc1d122017-10-09 14:07:42 -0400714#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400715
716##
717
718# ------------------------------------------------------------------------------
719
720#Method SkScalar centerY() const
721
Cary Clarkab2621d2018-01-30 10:08:57 -0500722#In Properties
723#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400724Returns average of top edge and bottom edge. Result does not change if Rect
725is sorted. Result may overflow to infinity if Rect is far from the origin.
726
727#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400728
729#Example
Cary Clark154beea2017-10-26 07:58:48 -0400730 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
731 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
732 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400733#StdOut
734left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
735##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400736##
737
Cary Clark7fc1d122017-10-09 14:07:42 -0400738#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400739
740##
741
Cary Clark2dc84ad2018-01-26 12:56:22 -0500742#Subtopic Properties ##
743
744#Subtopic Operators
745
746#Table
747#Legend
Cary Clarkab2621d2018-01-30 10:08:57 -0500748# name # description ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500749#Legend ##
Cary Clarkab2621d2018-01-30 10:08:57 -0500750# operator!=(const SkRect& a, const SkRect& b) # returns true if members are unequal ##
751# operator==(const SkRect& a, const SkRect& b) # returns true if members are equal ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500752#Table ##
753
Cary Clarkbc5697d2017-10-04 14:31:33 -0400754# ------------------------------------------------------------------------------
755
Cary Clark884dd7d2017-10-11 10:37:52 -0400756#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400757
Cary Clarkab2621d2018-01-30 10:08:57 -0500758#In Operators
759#Line # returns true if members are equal ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400760Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
761equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400762
Cary Clark7fc1d122017-10-09 14:07:42 -0400763a and b are not equal if either contain NaN. a and b are equal if members
764contain zeroes width different signs.
765
766#Param a Rect to compare ##
767#Param b Rect to compare ##
768
769#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400770
771#Example
Cary Clark154beea2017-10-26 07:58:48 -0400772 auto debugster = [](const SkRect& test) -> void {
773 SkRect negZero = {-0.0f, -0.0f, 2, 2};
774 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
775 test.fLeft, test.fTop, test.fRight, test.fBottom,
776 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
777 test == negZero ? '=' : '!',
778 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
779 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
780 "and are" : "yet are not");
781 };
782 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
783 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
784 for (auto rect : tests) {
785 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400786 }
Cary Clark154beea2017-10-26 07:58:48 -0400787#StdOut
788tests are equal
789{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
790{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400791{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
792##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400793##
794
Cary Clark7fc1d122017-10-09 14:07:42 -0400795#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400796
797##
798
799# ------------------------------------------------------------------------------
800
Cary Clark884dd7d2017-10-11 10:37:52 -0400801#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400802
Cary Clarkab2621d2018-01-30 10:08:57 -0500803#In Operators
804#Line # returns true if members are unequal ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400805Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
806equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400807
Cary Clark7fc1d122017-10-09 14:07:42 -0400808a and b are not equal if either contain NaN. a and b are equal if members
809contain zeroes width different signs.
810
811#Param a Rect to compare ##
812#Param b Rect to compare ##
813
814#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400815
816#Example
Cary Clark154beea2017-10-26 07:58:48 -0400817 SkRect test = {0, 0, 2, SK_ScalarNaN};
818 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
819#StdOut
Cary Clark7fc1d122017-10-09 14:07:42 -0400820test with NaN is not equal to itself
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
Cary Clark2dc84ad2018-01-26 12:56:22 -0500828#Subtopic Operators ##
829
830#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500831#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500832
833#Table
834#Legend
835# name # description ##
836#Legend ##
837# setBounds # sets to upper and lower limits of Point array ##
838# setBoundsCheck # sets to upper and lower limits of Point array ##
839# toQuad # returns four corners as Point ##
840#Table ##
841
Cary Clarkbc5697d2017-10-04 14:31:33 -0400842# ------------------------------------------------------------------------------
843
844#Method void toQuad(SkPoint quad[4]) const
845
Cary Clarkab2621d2018-01-30 10:08:57 -0500846#In As_Points
847#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400848Returns four points in quad that enclose Rect ordered as: top-left, top-right,
849bottom-right, bottom-left.
850
851#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400852Consider adding param to control whether quad is CW or CCW.
853##
854
Cary Clark7fc1d122017-10-09 14:07:42 -0400855#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400856
857#Example
Cary Clark154beea2017-10-26 07:58:48 -0400858 SkRect rect = {1, 2, 3, 4};
859 SkPoint corners[4];
860 rect.toQuad(corners);
861 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
862 SkDebugf("corners:");
863 for (auto corner : corners) {
864 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
865 }
866 SkDebugf("\n");
867#StdOut
868rect: {1, 2, 3, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400869corners: {1, 2} {3, 2} {3, 4} {1, 4}
870##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400871##
872
Cary Clark7fc1d122017-10-09 14:07:42 -0400873#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400874
875##
876
877# ------------------------------------------------------------------------------
878
Cary Clark2dc84ad2018-01-26 12:56:22 -0500879#Method void setBounds(const SkPoint pts[], int count)
880
Cary Clarkab2621d2018-01-30 10:08:57 -0500881#In As_Points
882#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500883Sets to bounds of Point array with count entries. If count is zero or smaller,
884or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
885
886Result is either empty or sorted: fLeft is less than or equal to fRight, and
887fTop is less than or equal to fBottom.
888
889#Param pts Point array ##
890#Param count entries in array ##
891
892#Example
893 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
894 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
895 SkRect rect;
896 rect.setBounds(points, count);
897 if (count > 0) {
898 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
899 } else {
900 SkDebugf("%14s", " ");
901 }
902 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
903 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
904 }
905#StdOut
906 count: 0 rect: 0, 0, 0, 0
907added: 3, 4 count: 1 rect: 3, 4, 3, 4
908added: 1, 2 count: 2 rect: 1, 2, 3, 4
909added: 5, 6 count: 3 rect: 1, 2, 5, 6
910added: nan, 8 count: 4 rect: 0, 0, 0, 0
911##
912##
913
914#SeeAlso set setBoundsCheck SkPath::addPoly
915
916##
917
918# ------------------------------------------------------------------------------
919
920#Method bool setBoundsCheck(const SkPoint pts[], int count)
921
Cary Clarkab2621d2018-01-30 10:08:57 -0500922#In As_Points
923#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500924Sets to bounds of Point array with count entries. Returns false if count is
925zero or smaller, or if Point array contains an infinity or NaN; in these cases
926sets Rect to (0, 0, 0, 0).
927
928Result is either empty or sorted: fLeft is less than or equal to fRight, and
929fTop is less than or equal to fBottom.
930
931#Param pts Point array ##
932#Param count entries in array ##
933
934#Return true if all Point values are finite ##
935
936#Example
937 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
938 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
939 SkRect rect;
940 bool success = rect.setBoundsCheck(points, count);
941 if (count > 0) {
942 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
943 } else {
944 SkDebugf("%14s", " ");
945 }
946 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
947 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
948 }
949#StdOut
950 count: 0 rect: 0, 0, 0, 0 success: true
951added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
952added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
953added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
954added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
955##
956##
957
958#SeeAlso set setBounds SkPath::addPoly
959
960##
961
962#Subtopic As_Points ##
963
964#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500965#Line # replaces all values ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500966
967#Table
968#Legend
969# name # description ##
970#Legend ##
971# iset() # sets to int input (left, top, right, bottom) ##
972# isetWH # sets to int input (0, 0, width, height) ##
973# set() # sets to SkScalar input (left, top, right, bottom) and others ##
974# # void set(const SkIRect& src) ##
975# # void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
976# # void set(const SkPoint pts[], int count) ##
977# # void set(const SkPoint& p0, const SkPoint& p1) ##
978# setEmpty # sets to (0, 0, 0, 0) ##
979# setLTRB # sets to SkScalar input (left, top, right, bottom) ##
980# setWH # sets to SkScalar input (0, 0, width, height) ##
981# setXYWH # sets to SkScalar input (x, y, width, height) ##
982#Table ##
983
984# ------------------------------------------------------------------------------
985
Cary Clarkbc5697d2017-10-04 14:31:33 -0400986#Method void setEmpty()
987
Cary Clarkab2621d2018-01-30 10:08:57 -0500988#In Set
989#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400990Sets Rect to (0, 0, 0, 0).
991
992Many other rectangles are empty; if left is equal to or greater than right,
993or if top is equal to or greater than bottom. Setting all members to zero
994is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400995
996#Example
Cary Clark154beea2017-10-26 07:58:48 -0400997 SkRect rect = {3, 4, 1, 2};
998 for (int i = 0; i < 2; ++i) {
999 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
1000 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
1001 rect.setEmpty();
1002 }
1003#StdOut
1004rect: {3, 4, 1, 2} is empty
1005rect: {0, 0, 0, 0} is empty
1006##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001007##
1008
Cary Clark7fc1d122017-10-09 14:07:42 -04001009#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -04001010
1011##
1012
1013# ------------------------------------------------------------------------------
1014
1015#Method void set(const SkIRect& src)
1016
Cary Clarkab2621d2018-01-30 10:08:57 -05001017#In Set
1018#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001019Sets Rect to src, promoting src members from integer to Scalar.
1020Very large values in src may lose precision.
1021
1022#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001023
1024#Example
Cary Clark154beea2017-10-26 07:58:48 -04001025 SkIRect i_rect = {3, 4, 1, 2};
1026 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
1027 SkRect f_rect;
1028 f_rect.set(i_rect);
1029 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
1030#StdOut
1031i_rect: {3, 4, 1, 2}
1032f_rect: {3, 4, 1, 2}
1033##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001034##
1035
Cary Clark7fc1d122017-10-09 14:07:42 -04001036#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -04001037
1038##
1039
1040# ------------------------------------------------------------------------------
1041
1042#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1043
Cary Clarkab2621d2018-01-30 10:08:57 -05001044#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001045Sets Rect to (left, top, right, bottom).
1046left and right are not sorted; left is not necessarily less than right.
1047top and bottom are not sorted; top is not necessarily less than bottom.
1048
1049#Param left stored in fLeft ##
1050#Param top stored in fTop ##
1051#Param right stored in fRight ##
1052#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001053
1054#Example
Cary Clark154beea2017-10-26 07:58:48 -04001055 SkRect rect1 = {3, 4, 1, 2};
1056 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1057 SkRect rect2;
1058 rect2.set(3, 4, 1, 2);
1059 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1060#StdOut
1061rect1: {3, 4, 1, 2}
1062rect2: {3, 4, 1, 2}
1063##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001064##
1065
Cary Clark7fc1d122017-10-09 14:07:42 -04001066#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001067
1068##
1069
1070# ------------------------------------------------------------------------------
1071
1072#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1073
Cary Clarkab2621d2018-01-30 10:08:57 -05001074#In Set
1075#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001076Sets Rect to (left, top, right, bottom).
1077left and right are not sorted; left is not necessarily less than right.
1078top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001079
Cary Clark7fc1d122017-10-09 14:07:42 -04001080#Param left stored in fLeft ##
1081#Param top stored in fTop ##
1082#Param right stored in fRight ##
1083#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001084
1085#Example
Cary Clark154beea2017-10-26 07:58:48 -04001086 SkRect rect1 = {3, 4, 1, 2};
1087 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1088 SkRect rect2;
1089 rect2.setLTRB(3, 4, 1, 2);
1090 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1091#StdOut
1092rect1: {3, 4, 1, 2}
1093rect2: {3, 4, 1, 2}
1094##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001095##
1096
Cary Clark7fc1d122017-10-09 14:07:42 -04001097#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001098
1099##
1100
1101# ------------------------------------------------------------------------------
1102
Cary Clarkbc5697d2017-10-04 14:31:33 -04001103#Method void set(const SkPoint pts[], int count)
1104
Cary Clarkab2621d2018-01-30 10:08:57 -05001105#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001106Sets to bounds of Point array with count entries. If count is zero or smaller,
1107or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001108
Cary Clark7fc1d122017-10-09 14:07:42 -04001109Result is either empty or sorted: fLeft is less than or equal to fRight, and
1110fTop is less than or equal to fBottom.
1111
1112#Param pts Point array ##
1113#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001114
1115#Example
Cary Clark154beea2017-10-26 07:58:48 -04001116 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1117 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1118 SkRect rect;
1119 rect.set(points, count);
1120 if (count > 0) {
1121 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1122 } else {
1123 SkDebugf("%14s", " ");
1124 }
1125 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1126 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1127 }
1128#StdOut
1129 count: 0 rect: 0, 0, 0, 0
1130added: 3, 4 count: 1 rect: 3, 4, 3, 4
1131added: 1, 2 count: 2 rect: 1, 2, 3, 4
1132added: 5, 6 count: 3 rect: 1, 2, 5, 6
1133added: nan, 8 count: 4 rect: 0, 0, 0, 0
1134##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001135##
1136
Cary Clark7fc1d122017-10-09 14:07:42 -04001137#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001138
1139##
1140
1141# ------------------------------------------------------------------------------
1142
Cary Clarkbc5697d2017-10-04 14:31:33 -04001143#Method void set(const SkPoint& p0, const SkPoint& p1)
1144
Cary Clarkab2621d2018-01-30 10:08:57 -05001145#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001146Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1147sorted and may be empty. Does not check to see if values are finite.
1148
1149#Param p0 corner to include ##
1150#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001151
1152#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001153#Description
1154p0 and p1 may be swapped and have the same effect unless one contains NaN.
1155##
Cary Clark154beea2017-10-26 07:58:48 -04001156 SkPoint point1 = {SK_ScalarNaN, 8};
1157 SkPoint point2 = {3, 4};
1158 SkRect rect;
1159 rect.set(point1, point2);
1160 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1161 rect.set(point2, point1);
1162 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001163##
1164
Cary Clark7fc1d122017-10-09 14:07:42 -04001165#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001166
1167##
1168
1169# ------------------------------------------------------------------------------
1170
1171#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1172
Cary Clarkab2621d2018-01-30 10:08:57 -05001173#In Set
1174#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001175Sets Rect to
1176#Formula
1177(x, y, x + width, y + height)
1178##
1179. Does not validate input;
1180width or height may be negative.
1181
1182#Param x stored in fLeft ##
1183#Param y stored in fTop ##
1184#Param width added to x and stored in fRight ##
1185#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001186
1187#Example
Cary Clark154beea2017-10-26 07:58:48 -04001188 SkRect rect;
1189 rect.setXYWH(5, 35, -15, 25);
1190 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1191 rect.bottom(), rect.isEmpty() ? "true" : "false");
1192 rect.sort();
1193 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1194 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001195#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001196rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001197rect: -10, 35, 5, 60 isEmpty: false
1198##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001199##
1200
Cary Clark7fc1d122017-10-09 14:07:42 -04001201#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001202
1203##
1204
1205# ------------------------------------------------------------------------------
1206
1207#Method void setWH(SkScalar width, SkScalar height)
1208
Cary Clarkab2621d2018-01-30 10:08:57 -05001209#In Set
1210#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001211Sets Rect to (0, 0, width, height). Does not validate input;
1212width or height may be negative.
1213
1214#Param width stored in fRight ##
1215#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001216
1217#Example
Cary Clark154beea2017-10-26 07:58:48 -04001218 SkRect rect;
1219 rect.setWH(-15, 25);
1220 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1221 rect.bottom(), rect.isEmpty() ? "true" : "false");
1222 rect.sort();
1223 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1224 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001225#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001226rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001227rect: -15, 0, 0, 25 isEmpty: false
1228##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001229##
1230
Cary Clark7fc1d122017-10-09 14:07:42 -04001231#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001232
1233##
1234
Cary Clark2dc84ad2018-01-26 12:56:22 -05001235#Subtopic Set ##
1236
1237#Subtopic From_Integers
Cary Clark08895c42018-02-01 09:37:32 -05001238#Line # set Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001239
1240#Table
1241#Legend
1242# name # description ##
1243#Legend ##
1244# iset() # sets to int input (left, top, right, bottom) ##
1245# isetWH # sets to int input (0, 0, width, height) ##
1246#Table ##
1247
1248# ------------------------------------------------------------------------------
1249
1250#Method void iset(int left, int top, int right, int bottom)
1251
Cary Clarkab2621d2018-01-30 10:08:57 -05001252#In From_Integers
1253#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001254Sets Rect to (left, top, right, bottom).
1255All parameters are promoted from integer to Scalar.
1256left and right are not sorted; left is not necessarily less than right.
1257top and bottom are not sorted; top is not necessarily less than bottom.
1258
1259#Param left promoted to SkScalar and stored in fLeft ##
1260#Param top promoted to SkScalar and stored in fTop ##
1261#Param right promoted to SkScalar and stored in fRight ##
1262#Param bottom promoted to SkScalar and stored in fBottom ##
1263
1264#Example
1265 SkRect rect1 = {3, 4, 1, 2};
1266 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1267 SkRect rect2;
1268 rect2.iset(3, 4, 1, 2);
1269 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1270#StdOut
1271rect1: {3, 4, 1, 2}
1272rect2: {3, 4, 1, 2}
1273##
1274##
1275
1276#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1277
1278##
1279
1280# ------------------------------------------------------------------------------
1281
1282#Method void isetWH(int width, int height)
1283
Cary Clarkab2621d2018-01-30 10:08:57 -05001284#In From_Integers
1285#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001286Sets Rect to (0, 0, width, height).
1287width and height may be zero or negative. width and height are promoted from
1288integer to SkScalar, large values may lose precision.
1289
1290#Param width promoted to SkScalar and stored in fRight ##
1291#Param height promoted to SkScalar and stored in fBottom ##
1292
1293#Example
1294 SkRect rect1 = {0, 0, 1, 2};
1295 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1296 SkRect rect2;
1297 rect2.isetWH(1, 2);
1298 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1299#StdOut
1300rect1: {0, 0, 1, 2}
1301rect2: {0, 0, 1, 2}
1302##
1303##
1304
1305#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1306
1307##
1308
1309#Subtopic From_Integers ##
1310
1311#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001312#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001313
1314#Table
1315#Legend
1316# name # description ##
1317#Legend ##
1318# inset() # moves the sides symmetrically about the center ##
1319# makeInset # constructs from sides moved symmetrically about the center ##
1320# makeOffset # constructs from translated sides ##
1321# makeOutset # constructs from sides moved symmetrically about the center ##
1322# offset() # translates sides without changing width and height ##
1323# # void offset(SkScalar dx, SkScalar dy) ##
1324# # void offset(const SkPoint& delta) ##
1325# offsetTo # translates to (x, y) without changing width and height ##
1326# outset() # moves the sides symmetrically about the center ##
1327#Table ##
1328
Cary Clarkbc5697d2017-10-04 14:31:33 -04001329# ------------------------------------------------------------------------------
1330
Cary Clarkbc5697d2017-10-04 14:31:33 -04001331#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1332
Cary Clarkab2621d2018-01-30 10:08:57 -05001333#In Inset_Outset_Offset
1334#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001335Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001336
Cary Clark7fc1d122017-10-09 14:07:42 -04001337If dx is negative, Rect returned is moved to the left.
1338If dx is positive, Rect returned is moved to the right.
1339If dy is negative, Rect returned is moved upward.
1340If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001341
Cary Clark7fc1d122017-10-09 14:07:42 -04001342#Param dx added to fLeft and fRight ##
1343#Param dy added to fTop and fBottom ##
1344
1345#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001346
1347#Example
Cary Clark154beea2017-10-26 07:58:48 -04001348 SkRect rect = { 10, 50, 20, 60 };
1349 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1350 rect.bottom(), rect.isEmpty() ? "true" : "false");
1351 rect = rect.makeOffset(15, 32);
1352 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1353 rect.bottom(), rect.isEmpty() ? "true" : "false");
1354#StdOut
1355rect: 10, 50, 20, 60 isEmpty: false
1356rect: 25, 82, 35, 92 isEmpty: false
1357##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358##
1359
Cary Clark7fc1d122017-10-09 14:07:42 -04001360#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001361
1362##
1363
1364# ------------------------------------------------------------------------------
1365
1366#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1367
Cary Clarkab2621d2018-01-30 10:08:57 -05001368#In Inset_Outset_Offset
1369#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001370Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001371
Cary Clark7fc1d122017-10-09 14:07:42 -04001372If dx is negative, Rect returned is wider.
1373If dx is positive, Rect returned is narrower.
1374If dy is negative, Rect returned is taller.
1375If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001376
Cary Clark7fc1d122017-10-09 14:07:42 -04001377#Param dx added to fLeft and subtracted from fRight ##
1378#Param dy added to fTop and subtracted from fBottom ##
1379
1380#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001381
1382#Example
Cary Clark154beea2017-10-26 07:58:48 -04001383 SkRect rect = { 10, 50, 20, 60 };
1384 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1385 rect.bottom(), rect.isEmpty() ? "true" : "false");
1386 rect = rect.makeInset(15, 32);
1387 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1388 rect.bottom(), rect.isEmpty() ? "true" : "false");
1389#StdOut
1390rect: 10, 50, 20, 60 isEmpty: false
1391rect: 25, 82, 5, 28 isEmpty: true
1392##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001393##
1394
Cary Clark7fc1d122017-10-09 14:07:42 -04001395#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001396
1397##
1398
1399# ------------------------------------------------------------------------------
1400
1401#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1402
Cary Clarkab2621d2018-01-30 10:08:57 -05001403#In Inset_Outset_Offset
1404#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001405Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001406
Cary Clark7fc1d122017-10-09 14:07:42 -04001407If dx is negative, Rect returned is narrower.
1408If dx is positive, Rect returned is wider.
1409If dy is negative, Rect returned is shorter.
1410If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001411
Cary Clark7fc1d122017-10-09 14:07:42 -04001412#Param dx subtracted to fLeft and added from fRight ##
1413#Param dy subtracted to fTop and added from fBottom ##
1414
1415#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001416
1417#Example
Cary Clark154beea2017-10-26 07:58:48 -04001418 SkRect rect = { 10, 50, 20, 60 };
1419 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1420 rect.bottom(), rect.isEmpty() ? "true" : "false");
1421 rect = rect.makeOutset(15, 32);
1422 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1423 rect.bottom(), rect.isEmpty() ? "true" : "false");
1424#StdOut
1425rect: 10, 50, 20, 60 isEmpty: false
1426rect: -5, 18, 35, 92 isEmpty: false
1427##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001428##
1429
Cary Clark7fc1d122017-10-09 14:07:42 -04001430#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001431
1432##
1433
1434# ------------------------------------------------------------------------------
1435
1436#Method void offset(SkScalar dx, SkScalar dy)
1437
Cary Clarkab2621d2018-01-30 10:08:57 -05001438#In Inset_Outset_Offset
1439#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001440Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001441
Cary Clark7fc1d122017-10-09 14:07:42 -04001442If dx is negative, moves Rect to the left.
1443If dx is positive, moves Rect to the right.
1444If dy is negative, moves Rect upward.
1445If dy is positive, moves Rect downward.
1446
1447#Param dx offset added to fLeft and fRight ##
1448#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001449
1450#Example
Cary Clark154beea2017-10-26 07:58:48 -04001451 SkRect rect = { 10, 14, 50, 73 };
1452 rect.offset(5, 13);
1453 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1454#StdOut
1455rect: 15, 27, 55, 86
1456##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001457##
1458
Cary Clark7fc1d122017-10-09 14:07:42 -04001459#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001460
1461##
1462
1463# ------------------------------------------------------------------------------
1464
1465#Method void offset(const SkPoint& delta)
1466
Cary Clarkab2621d2018-01-30 10:08:57 -05001467#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001468Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1469fTop, fBottom.
1470
1471If delta.fX is negative, moves Rect to the left.
1472If delta.fX is positive, moves Rect to the right.
1473If delta.fY is negative, moves Rect upward.
1474If delta.fY is positive, moves Rect downward.
1475
1476#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001477
1478#Example
Cary Clark154beea2017-10-26 07:58:48 -04001479 SkRect rect = { 10, 14, 50, 73 };
1480 rect.offset({5, 13});
1481 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1482#StdOut
1483rect: 15, 27, 55, 86
1484##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001485##
1486
Cary Clark7fc1d122017-10-09 14:07:42 -04001487#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488
1489##
1490
1491# ------------------------------------------------------------------------------
1492
1493#Method void offsetTo(SkScalar newX, SkScalar newY)
1494
Cary Clarkab2621d2018-01-30 10:08:57 -05001495#In Inset_Outset_Offset
1496#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001497Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1498are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001499
Cary Clark7fc1d122017-10-09 14:07:42 -04001500#Param newX stored in fLeft, preserving width() ##
1501#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001502
1503#Example
Cary Clark154beea2017-10-26 07:58:48 -04001504 SkRect rect = { 10, 14, 50, 73 };
1505 rect.offsetTo(15, 27);
1506 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1507#StdOut
1508rect: 15, 27, 55, 86
1509##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001510##
1511
Cary Clark7fc1d122017-10-09 14:07:42 -04001512#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001513
1514##
1515
1516# ------------------------------------------------------------------------------
1517
1518#Method void inset(SkScalar dx, SkScalar dy)
1519
Cary Clarkab2621d2018-01-30 10:08:57 -05001520#In Inset_Outset_Offset
1521#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001522Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001523
Cary Clark7fc1d122017-10-09 14:07:42 -04001524If dx is positive, makes Rect narrower.
1525If dx is negative, makes Rect wider.
1526If dy is positive, makes Rect shorter.
1527If dy is negative, makes Rect taller.
1528
1529#Param dx added to fLeft and subtracted from fRight ##
1530#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001531
1532#Example
Cary Clark154beea2017-10-26 07:58:48 -04001533 SkRect rect = { 10, 14, 50, 73 };
1534 rect.inset(5, 13);
1535 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1536#StdOut
1537rect: 15, 27, 45, 60
1538##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001539##
1540
Cary Clark7fc1d122017-10-09 14:07:42 -04001541#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001542
1543##
1544
1545# ------------------------------------------------------------------------------
1546
1547#Method void outset(SkScalar dx, SkScalar dy)
1548
Cary Clarkab2621d2018-01-30 10:08:57 -05001549#In Inset_Outset_Offset
1550#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001551Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001552
Cary Clark7fc1d122017-10-09 14:07:42 -04001553If dx is positive, makes Rect wider.
1554If dx is negative, makes Rect narrower.
1555If dy is positive, makes Rect taller.
1556If dy is negative, makes Rect shorter.
1557
1558#Param dx subtracted to fLeft and added from fRight ##
1559#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001560
1561#Example
Cary Clark154beea2017-10-26 07:58:48 -04001562 SkRect rect = { 10, 14, 50, 73 };
1563 rect.outset(5, 13);
1564 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1565#StdOut
1566rect: 5, 1, 55, 86
1567##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001568##
1569
Cary Clark7fc1d122017-10-09 14:07:42 -04001570#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001571
1572##
1573
Cary Clark2dc84ad2018-01-26 12:56:22 -05001574#Subtopic Inset_Outset_Offset ##
1575
1576#Subtopic Intersection
Cary Clark08895c42018-02-01 09:37:32 -05001577#Line # set to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001578
1579Rects intersect when they enclose a common area. To intersect, each of the pair
1580must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001581empty() returns false. The intersection of Rect pair can be described by:
1582
Cary Clark7fc1d122017-10-09 14:07:42 -04001583#Formula
1584(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1585 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1586##
Cary Clark154beea2017-10-26 07:58:48 -04001587.
1588
Cary Clark7fc1d122017-10-09 14:07:42 -04001589The intersection is only meaningful if the resulting Rect is not empty and
1590describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1591
Cary Clark2dc84ad2018-01-26 12:56:22 -05001592#Table
1593#Legend
1594# name # description ##
1595#Legend ##
1596# Intersects # returns true if areas overlap ##
1597# contains() # returns true if points are equal or inside ##
1598# # bool contains(const SkRect& r) const ##
1599# # bool contains(const SkIRect& r) const ##
1600# intersect() # sets to shared area; returns true if not empty ##
1601# # bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1602# # bool intersect(const SkRect& r) ##
1603# # bool intersect(const SkRect& a, const SkRect& b) ##
1604# intersects() # returns true if areas overlap ##
1605# # bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const ##
1606# # bool intersects(const SkRect& r) const ##
1607#Table ##
1608
1609# ------------------------------------------------------------------------------
1610
1611#Method bool contains(const SkRect& r) const
1612
Cary Clarkab2621d2018-01-30 10:08:57 -05001613#In Intersection
1614#Line # returns true if points are equal or inside ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001615Returns true if Rect contains r.
1616Returns false if Rect is empty or r is empty.
1617
1618Rect contains r when Rect area completely includes r area.
1619
1620#Param r Rect contained ##
1621
1622#Return true if all sides of Rect are outside r ##
1623
1624#Example
1625 SkRect rect = { 30, 50, 40, 60 };
1626 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1627 for (auto contained : tests) {
1628 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1629 rect.left(), rect.top(), rect.right(), rect.bottom(),
1630 rect.contains(contained) ? "contains" : "does not contain",
1631 contained.left(), contained.top(), contained.right(), contained.bottom());
1632 }
1633#StdOut
1634rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1635rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1636rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1637##
1638##
1639
1640#SeeAlso SkIRect::contains
1641
1642##
1643
1644# ------------------------------------------------------------------------------
1645
1646#Method bool contains(const SkIRect& r) const
1647
Cary Clarkab2621d2018-01-30 10:08:57 -05001648#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001649Returns true if Rect contains r.
1650Returns false if Rect is empty or r is empty.
1651
1652Rect contains r when Rect area completely includes r area.
1653
1654#Param r IRect contained ##
1655
1656#Return true if all sides of Rect are outside r ##
1657
1658#Example
1659 SkRect rect = { 30, 50, 40, 60 };
1660 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1661 for (auto contained : tests) {
1662 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1663 rect.left(), rect.top(), rect.right(), rect.bottom(),
1664 rect.contains(contained) ? "contains" : "does not contain",
1665 contained.left(), contained.top(), contained.right(), contained.bottom());
1666 }
1667#StdOut
1668rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1669rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1670rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1671##
1672##
1673
1674#SeeAlso SkIRect::contains
1675
1676##
1677
Cary Clarkbc5697d2017-10-04 14:31:33 -04001678# ------------------------------------------------------------------------------
1679
1680#Method bool intersect(const SkRect& r)
1681
Cary Clarkab2621d2018-01-30 10:08:57 -05001682#In Intersection
1683#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001684Returns true if Rect intersects r, and sets Rect to intersection.
1685Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001686
Cary Clark7fc1d122017-10-09 14:07:42 -04001687Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001688
Cary Clark7fc1d122017-10-09 14:07:42 -04001689#Param r limit of result ##
1690
1691#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001692
1693#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001694#Description
1695Two SkDebugf calls are required. If the calls are combined, their arguments
1696may not be evaluated in left to right order: the printed intersection may
1697be before or after the call to intersect.
1698##
Cary Clark154beea2017-10-26 07:58:48 -04001699 SkRect leftRect = { 10, 40, 50, 80 };
1700 SkRect rightRect = { 30, 60, 70, 90 };
1701 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1702 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001703 leftRect.right(), leftRect.bottom());
1704#StdOut
1705 intersection: 30, 60, 50, 80
1706##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001707##
1708
Cary Clark7fc1d122017-10-09 14:07:42 -04001709#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001710
1711##
1712
1713# ------------------------------------------------------------------------------
1714
1715#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1716
Cary Clarkab2621d2018-01-30 10:08:57 -05001717#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001718Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1719construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001720
Cary Clark7fc1d122017-10-09 14:07:42 -04001721Returns true if Rect intersects construction, and sets Rect to intersection.
1722Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723
Cary Clark7fc1d122017-10-09 14:07:42 -04001724Returns false if either construction or Rect is empty, leaving Rect unchanged.
1725
1726#Param left x minimum of constructed Rect ##
1727#Param top y minimum of constructed Rect ##
1728#Param right x maximum of constructed Rect ##
1729#Param bottom y maximum of constructed Rect ##
1730
1731#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001732
1733#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001734#Description
1735Two SkDebugf calls are required. If the calls are combined, their arguments
1736may not be evaluated in left to right order: the printed intersection may
1737be before or after the call to intersect.
1738##
Cary Clark154beea2017-10-26 07:58:48 -04001739 SkRect leftRect = { 10, 40, 50, 80 };
1740 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1741 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001742 leftRect.right(), leftRect.bottom());
1743#StdOut
1744 intersection: 30, 60, 50, 80
1745##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746##
1747
Cary Clark7fc1d122017-10-09 14:07:42 -04001748#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001749
1750##
1751
1752# ------------------------------------------------------------------------------
1753
1754#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1755
Cary Clarkab2621d2018-01-30 10:08:57 -05001756#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001757Returns true if a intersects b, and sets Rect to intersection.
1758Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001759
Cary Clark7fc1d122017-10-09 14:07:42 -04001760Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001761
Cary Clark7fc1d122017-10-09 14:07:42 -04001762#Param a Rect to intersect ##
1763#Param b Rect to intersect ##
1764
1765#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001766
1767#Example
Cary Clark154beea2017-10-26 07:58:48 -04001768 SkRect result;
1769 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1770 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1771 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001772#StdOut
1773 intersection: 30, 60, 50, 80
1774##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001775##
1776
Cary Clark7fc1d122017-10-09 14:07:42 -04001777#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001778
1779##
1780
Cary Clark7fc1d122017-10-09 14:07:42 -04001781# ------------------------------------------------------------------------------
1782
Cary Clarkbc5697d2017-10-04 14:31:33 -04001783#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1784
Cary Clarkab2621d2018-01-30 10:08:57 -05001785#In Intersection
1786#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001787Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1788construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001789
Cary Clark7fc1d122017-10-09 14:07:42 -04001790Returns true if Rect intersects construction.
1791Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001792
Cary Clark7fc1d122017-10-09 14:07:42 -04001793#Param left x minimum of constructed Rect ##
1794#Param top y minimum of constructed Rect ##
1795#Param right x maximum of constructed Rect ##
1796#Param bottom y maximum of constructed Rect ##
1797
1798#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001799
1800#Example
Cary Clark154beea2017-10-26 07:58:48 -04001801 SkRect rect = { 10, 40, 50, 80 };
1802 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001803#StdOut
1804 intersection
1805##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001806##
1807
Cary Clark7fc1d122017-10-09 14:07:42 -04001808#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001809
1810##
1811
Cary Clark7fc1d122017-10-09 14:07:42 -04001812# ------------------------------------------------------------------------------
1813
Cary Clarkbc5697d2017-10-04 14:31:33 -04001814#Method bool intersects(const SkRect& r) const
1815
Cary Clarkab2621d2018-01-30 10:08:57 -05001816#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001817Returns true if Rect intersects r.
1818Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001819
Cary Clark7fc1d122017-10-09 14:07:42 -04001820#Param r Rect to intersect ##
1821
1822#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001823
1824#Example
Cary Clark154beea2017-10-26 07:58:48 -04001825 SkRect rect = { 10, 40, 50, 80 };
1826 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001827#StdOut
1828 intersection
1829##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001830##
1831
Cary Clark7fc1d122017-10-09 14:07:42 -04001832#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001833
1834##
1835
Cary Clark7fc1d122017-10-09 14:07:42 -04001836# ------------------------------------------------------------------------------
1837
Cary Clarkbc5697d2017-10-04 14:31:33 -04001838#Method static bool Intersects(const SkRect& a, const SkRect& b)
1839
Cary Clarkab2621d2018-01-30 10:08:57 -05001840#In Intersection
1841#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001842Returns true if a intersects b.
1843Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001844
Cary Clark7fc1d122017-10-09 14:07:42 -04001845#Param a Rect to intersect ##
1846#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001847
Cary Clark7fc1d122017-10-09 14:07:42 -04001848#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001849
1850#Example
Cary Clark154beea2017-10-26 07:58:48 -04001851 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001852#StdOut
1853 intersection
1854##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001855##
1856
Cary Clark7fc1d122017-10-09 14:07:42 -04001857#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001858
1859##
1860
Cary Clark2dc84ad2018-01-26 12:56:22 -05001861#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001862
Cary Clark2dc84ad2018-01-26 12:56:22 -05001863#Subtopic Join
Cary Clark08895c42018-02-01 09:37:32 -05001864#Line # set to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001865
1866#Table
1867#Legend
1868# name # description ##
1869#Legend ##
1870# join() # sets to union of bounds ##
1871# # void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1872# # void join(const SkRect& r) ##
1873# joinNonEmptyArg # sets to union of bounds, asserting that argument is not empty ##
1874# joinPossiblyEmptyRect # sets to union of bounds. Skips empty check for both ##
1875#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001876
1877# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001878
1879#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1880
Cary Clarkab2621d2018-01-30 10:08:57 -05001881#In Join
1882#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001883Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1884construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885
Cary Clark7fc1d122017-10-09 14:07:42 -04001886Sets Rect to the union of itself and the construction.
1887
1888Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1889Rect to construction.
1890
1891#Param left x minimum of constructed Rect ##
1892#Param top y minimum of constructed Rect ##
1893#Param right x maximum of constructed Rect ##
1894#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001895
1896#Example
Cary Clark154beea2017-10-26 07:58:48 -04001897 SkRect rect = { 10, 20, 15, 25};
1898 rect.join(50, 60, 55, 65);
1899 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001900#StdOut
1901 join: 10, 20, 55, 65
1902##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001903##
1904
Cary Clark7fc1d122017-10-09 14:07:42 -04001905#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001906
1907##
1908
Cary Clark7fc1d122017-10-09 14:07:42 -04001909# ------------------------------------------------------------------------------
1910
Cary Clarkbc5697d2017-10-04 14:31:33 -04001911#Method void join(const SkRect& r)
1912
Cary Clarkab2621d2018-01-30 10:08:57 -05001913#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001914Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001915
Cary Clark7fc1d122017-10-09 14:07:42 -04001916Has no effect if r is empty. Otherwise, if Rect is empty, sets
1917Rect to r.
1918
1919#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001920
1921#Example
Cary Clark154beea2017-10-26 07:58:48 -04001922 SkRect rect = { 10, 20, 15, 25};
1923 rect.join({50, 60, 55, 65});
1924 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001925#StdOut
1926 join: 10, 20, 55, 65
1927##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001928##
1929
Cary Clark7fc1d122017-10-09 14:07:42 -04001930#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001931
1932##
1933
Cary Clark7fc1d122017-10-09 14:07:42 -04001934# ------------------------------------------------------------------------------
1935
Cary Clarkbc5697d2017-10-04 14:31:33 -04001936#Method void joinNonEmptyArg(const SkRect& r)
1937
Cary Clarkab2621d2018-01-30 10:08:57 -05001938#In Join
1939#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001940Sets Rect to the union of itself and r.
1941
1942Asserts if r is empty and SK_DEBUG is defined.
1943If Rect is empty, sets Rect to r.
1944
1945May produce incorrect results if r is empty.
1946
1947#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001948
1949#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001950#Description
1951Since Rect is not sorted, first result is copy of toJoin.
1952##
Cary Clark154beea2017-10-26 07:58:48 -04001953 SkRect rect = { 10, 100, 15, 0};
1954 SkRect sorted = rect.makeSorted();
1955 SkRect toJoin = { 50, 60, 55, 65 };
1956 rect.joinNonEmptyArg(toJoin);
1957 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1958 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001959 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1960#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001961rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001962sorted: 10, 0, 55, 100
1963##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001964##
1965
Cary Clark7fc1d122017-10-09 14:07:42 -04001966#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001967
1968##
1969
Cary Clark7fc1d122017-10-09 14:07:42 -04001970# ------------------------------------------------------------------------------
1971
Cary Clarkbc5697d2017-10-04 14:31:33 -04001972#Method void joinPossiblyEmptyRect(const SkRect& r)
1973
Cary Clarkab2621d2018-01-30 10:08:57 -05001974#In Join
1975#Line # sets to union of bounds. Skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001976Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977
Cary Clark7fc1d122017-10-09 14:07:42 -04001978May produce incorrect results if Rect or r is empty.
1979
1980#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001981
1982#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001983#Description
1984Since Rect is not sorted, first result is not useful.
1985##
Cary Clark154beea2017-10-26 07:58:48 -04001986 SkRect rect = { 10, 100, 15, 0};
1987 SkRect sorted = rect.makeSorted();
1988 SkRect toJoin = { 50, 60, 55, 65 };
1989 rect.joinPossiblyEmptyRect(toJoin);
1990 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1991 sorted.joinPossiblyEmptyRect(toJoin);
1992 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001993#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001994rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001995sorted: 10, 0, 55, 100
1996##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001997##
1998
Cary Clark7fc1d122017-10-09 14:07:42 -04001999#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04002000
2001##
2002
Cary Clark2dc84ad2018-01-26 12:56:22 -05002003#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002004
Cary Clark2dc84ad2018-01-26 12:56:22 -05002005#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05002006#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002007
Cary Clark2dc84ad2018-01-26 12:56:22 -05002008#Table
2009#Legend
2010# name # description ##
2011#Legend ##
2012# round() # sets members to nearest integer value ##
2013# # void round(SkIRect* dst) const ##
2014# # SkIRect round() const ##
2015# roundIn # sets members to nearest integer value towards opposite ##
2016# roundOut # sets members to nearest integer value away from opposite ##
2017# # void roundOut(SkIRect* dst) const ##
2018# # void roundOut(SkRect* dst) const ##
2019# # SkIRect roundOut() const ##
2020#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002021
Cary Clarkbc5697d2017-10-04 14:31:33 -04002022#Method void round(SkIRect* dst) const
2023
Cary Clarkab2621d2018-01-30 10:08:57 -05002024#In Rounding
2025#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002026Sets IRect by adding 0.5 and discarding the fractional portion of Rect
2027members, using
2028#Formula
2029(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2030 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2031##
2032.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002033
Cary Clark7fc1d122017-10-09 14:07:42 -04002034#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002035
2036#Example
Cary Clark154beea2017-10-26 07:58:48 -04002037 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2038 SkIRect round;
2039 rect.round(&round);
2040 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002041#StdOut
2042round: 31, 51, 41, 61
2043##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002044##
2045
Cary Clark7fc1d122017-10-09 14:07:42 -04002046#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002047
2048##
2049
Cary Clark7fc1d122017-10-09 14:07:42 -04002050# ------------------------------------------------------------------------------
2051
Cary Clarkbc5697d2017-10-04 14:31:33 -04002052#Method void roundOut(SkIRect* dst) const
2053
Cary Clarkab2621d2018-01-30 10:08:57 -05002054#In Rounding
2055#Line # sets members to nearest integer value away from opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002056Sets IRect by discarding the fractional portion of fLeft and fTop; and
2057rounding up fRight and FBottom, using
2058#Formula
2059(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2060 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2061##
2062.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002063
Cary Clark7fc1d122017-10-09 14:07:42 -04002064#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002065
2066#Example
Cary Clark154beea2017-10-26 07:58:48 -04002067 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2068 SkIRect round;
2069 rect.roundOut(&round);
2070 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002071#StdOut
2072round: 30, 50, 41, 61
2073##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002074##
2075
Cary Clark7fc1d122017-10-09 14:07:42 -04002076#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002077
2078##
2079
Cary Clark7fc1d122017-10-09 14:07:42 -04002080# ------------------------------------------------------------------------------
2081
Cary Clarkbc5697d2017-10-04 14:31:33 -04002082#Method void roundOut(SkRect* dst) const
2083
Cary Clarkab2621d2018-01-30 10:08:57 -05002084#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002085Sets Rect by discarding the fractional portion of fLeft and fTop; and
2086rounding up fRight and FBottom, using
2087#Formula
2088(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2089 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2090##
2091.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002092
Cary Clark7fc1d122017-10-09 14:07:42 -04002093#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002094
2095#Example
Cary Clark154beea2017-10-26 07:58:48 -04002096 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2097 SkRect round;
2098 rect.roundOut(&round);
2099 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002100#StdOut
2101round: 30, 50, 41, 61
2102##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002103##
2104
Cary Clark7fc1d122017-10-09 14:07:42 -04002105#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002106
2107##
2108
Cary Clark7fc1d122017-10-09 14:07:42 -04002109# ------------------------------------------------------------------------------
2110
Cary Clarkbc5697d2017-10-04 14:31:33 -04002111#Method void roundIn(SkIRect* dst) const
2112
Cary Clarkab2621d2018-01-30 10:08:57 -05002113#In Rounding
2114#Line # sets members to nearest integer value towards opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002115Sets Rect by rounding up fLeft and fTop; and
2116discarding the fractional portion of fRight and FBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002117
Cary Clark7fc1d122017-10-09 14:07:42 -04002118#Formula
2119(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2120 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2121##
2122.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002123
Cary Clark7fc1d122017-10-09 14:07:42 -04002124#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002125
2126#Example
Cary Clark154beea2017-10-26 07:58:48 -04002127 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2128 SkIRect round;
2129 rect.roundIn(&round);
2130 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002131#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002132round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002133##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002134##
2135
Cary Clark7fc1d122017-10-09 14:07:42 -04002136#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002137
2138##
2139
Cary Clark7fc1d122017-10-09 14:07:42 -04002140# ------------------------------------------------------------------------------
2141
Cary Clarkbc5697d2017-10-04 14:31:33 -04002142#Method SkIRect round() const
2143
Cary Clarkab2621d2018-01-30 10:08:57 -05002144#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002145Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2146members, using
2147#Formula
2148(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2149 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2150##
2151.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002152
Cary Clark7fc1d122017-10-09 14:07:42 -04002153#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002154
2155#Example
Cary Clark154beea2017-10-26 07:58:48 -04002156 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2157 SkIRect round = rect.round();
2158 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002159#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002160round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002161##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002162##
2163
Cary Clark7fc1d122017-10-09 14:07:42 -04002164#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002165
2166##
2167
Cary Clark7fc1d122017-10-09 14:07:42 -04002168# ------------------------------------------------------------------------------
2169
Cary Clarkbc5697d2017-10-04 14:31:33 -04002170#Method SkIRect roundOut() const
2171
Cary Clarkab2621d2018-01-30 10:08:57 -05002172#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002173Sets IRect by discarding the fractional portion of fLeft and fTop; and
2174rounding up fRight and FBottom, using
2175#Formula
2176(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2177 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2178##
2179.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002180
Cary Clark7fc1d122017-10-09 14:07:42 -04002181#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002182
2183#Example
Cary Clark154beea2017-10-26 07:58:48 -04002184 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2185 SkIRect round = rect.roundOut();
2186 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002187#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002188round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002189##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002190##
2191
Cary Clark7fc1d122017-10-09 14:07:42 -04002192#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002193
2194##
2195
Cary Clark2dc84ad2018-01-26 12:56:22 -05002196#Subtopic Rounding ##
2197
2198#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002199#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002200
2201#Table
2202#Legend
2203# name # description ##
2204#Legend ##
2205# makeSorted # constructs, ordering sides from smaller to larger ##
2206# sort() # orders sides from smaller to larger ##
2207#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002208
2209# ------------------------------------------------------------------------------
2210
Cary Clarkbc5697d2017-10-04 14:31:33 -04002211#Method void sort()
2212
Cary Clarkab2621d2018-01-30 10:08:57 -05002213#In Sorting
2214#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002215Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2216fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2217and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002218
2219#Example
Cary Clark154beea2017-10-26 07:58:48 -04002220 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2221 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2222 rect.sort();
2223 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002224#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002225rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002226sorted: 20.5, 10.5, 30.5, 50.5
2227##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002228##
2229
Cary Clark2dc84ad2018-01-26 12:56:22 -05002230#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002231
2232##
2233
Cary Clark7fc1d122017-10-09 14:07:42 -04002234# ------------------------------------------------------------------------------
2235
Cary Clarkbc5697d2017-10-04 14:31:33 -04002236#Method SkRect makeSorted() const
2237
Cary Clarkab2621d2018-01-30 10:08:57 -05002238#In Sorting
2239#Line # constructs, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002240Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2241with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2242and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002243
Cary Clark7fc1d122017-10-09 14:07:42 -04002244#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002245
2246#Example
Cary Clark154beea2017-10-26 07:58:48 -04002247 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2248 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2249 SkRect sort = rect.makeSorted();
2250 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002251#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002252rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002253sorted: 20.5, 10.5, 30.5, 50.5
2254##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002255##
2256
Cary Clark2dc84ad2018-01-26 12:56:22 -05002257#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002258
2259##
2260
Cary Clark2dc84ad2018-01-26 12:56:22 -05002261#Subtopic Sorting ##
2262
Cary Clark7fc1d122017-10-09 14:07:42 -04002263# ------------------------------------------------------------------------------
2264
Cary Clarkbc5697d2017-10-04 14:31:33 -04002265#Method const SkScalar* asScalars() const
2266
Cary Clarkab2621d2018-01-30 10:08:57 -05002267#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002268Returns pointer to first Scalar in Rect, to treat it as an array with four
2269entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002270
Cary Clark7fc1d122017-10-09 14:07:42 -04002271#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002272
2273#Example
Cary Clark154beea2017-10-26 07:58:48 -04002274 SkRect rect = {7, 11, 13, 17};
2275SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2276#StdOut
2277rect.asScalars() == &rect.fLeft
2278##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002279##
2280
Cary Clark7fc1d122017-10-09 14:07:42 -04002281#SeeAlso toQuad
2282
Cary Clarkbc5697d2017-10-04 14:31:33 -04002283##
2284
Cary Clark7fc1d122017-10-09 14:07:42 -04002285# ------------------------------------------------------------------------------
2286
Cary Clarkbc5697d2017-10-04 14:31:33 -04002287#Method void dump(bool asHex) const
2288
Cary Clarkab2621d2018-01-30 10:08:57 -05002289#Line # sends text representation to standard output using floats ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002290Writes text representation of Rect to standard output. Set asHex to true to
2291generate exact binary representations of floating point numbers.
2292
2293#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002294
2295#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002296 SkRect rect = {20, 30, 40, 50};
2297 for (bool dumpAsHex : { false, true } ) {
2298 rect.dump(dumpAsHex);
2299 SkDebugf("\n");
2300 }
2301#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002302SkRect::MakeLTRB(20, 30, 40, 50);
2303
2304SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2305 SkBits2Float(0x41f00000), /* 30.000000 */
2306 SkBits2Float(0x42200000), /* 40.000000 */
2307 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002308##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002309##
2310
Cary Clark7fc1d122017-10-09 14:07:42 -04002311#SeeAlso dumpHex
2312
Cary Clarkbc5697d2017-10-04 14:31:33 -04002313##
2314
Cary Clark7fc1d122017-10-09 14:07:42 -04002315# ------------------------------------------------------------------------------
2316
Cary Clarkbc5697d2017-10-04 14:31:33 -04002317#Method void dump() const
2318
Cary Clark7fc1d122017-10-09 14:07:42 -04002319Writes text representation of Rect to standard output. The representation may be
2320directly compiled as C++ code. Floating point values are written
2321with limited precision; it may not be possible to reconstruct original Rect
2322from output.
2323
Cary Clarkbc5697d2017-10-04 14:31:33 -04002324#Example
Cary Clark154beea2017-10-26 07:58:48 -04002325SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2326rect.dump();
2327SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2328SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002329#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002330SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002331rect is not equal to copy
2332##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002333##
2334
Cary Clark7fc1d122017-10-09 14:07:42 -04002335#SeeAlso dumpHex
2336
Cary Clarkbc5697d2017-10-04 14:31:33 -04002337##
2338
Cary Clark7fc1d122017-10-09 14:07:42 -04002339# ------------------------------------------------------------------------------
2340
Cary Clarkbc5697d2017-10-04 14:31:33 -04002341#Method void dumpHex() const
2342
Cary Clarkab2621d2018-01-30 10:08:57 -05002343#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002344Writes text representation of Rect to standard output. The representation may be
2345directly compiled as C++ code. Floating point values are written
2346in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2347original Rect.
2348
2349Use instead of dump() when submitting
2350#A bug reports against Skia # http://bug.skia.org ##
2351.
2352
Cary Clarkbc5697d2017-10-04 14:31:33 -04002353#Example
Cary Clark154beea2017-10-26 07:58:48 -04002354 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2355rect.dumpHex();
2356SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2357 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2358 SkBits2Float(0x40266666), /* 2.600000 */
2359 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002360SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2361#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002362SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2363 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2364 SkBits2Float(0x40266666), /* 2.600000 */
2365 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002366rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002367##
Cary Clark7fc1d122017-10-09 14:07:42 -04002368##
2369
2370#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002371
2372##
2373
Cary Clark0c95aab2018-01-08 16:20:59 -05002374#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
2375
Cary Clarkab2621d2018-01-30 10:08:57 -05002376#Line # deprecated ##
Cary Clark0c95aab2018-01-08 16:20:59 -05002377#Deprecated
2378##
2379
Cary Clarkac47b882018-01-11 10:35:44 -05002380Returns constructed SkRect setting left and top to most negative finite value, and
2381setting right and bottom to most positive finite value.
2382
2383#Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
2384
Cary Clark0c95aab2018-01-08 16:20:59 -05002385##
2386
Cary Clarkbc5697d2017-10-04 14:31:33 -04002387#Struct SkRect ##
2388
2389#Topic Rect ##