blob: 5807f0a28105640fd3b7429679b02f0fc3a53927 [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
Cary Clark4855f782018-02-06 09:41:53 -05006 #Subtopic Subtopic
Cary Clark08895c42018-02-01 09:37:32 -05007 #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 Clark4855f782018-02-06 09:41:53 -050023#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050024#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040025#Subtopic ##
26
Cary Clark4855f782018-02-06 09:41:53 -050027#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -050028#Populate
29##
Cary Clarkbc5697d2017-10-04 14:31:33 -040030
Cary Clark4855f782018-02-06 09:41:53 -050031#Subtopic Member
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 Clark4855f782018-02-06 09:41:53 -050058#Subtopic Member ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050059
Cary Clark4855f782018-02-06 09:41:53 -050060#Subtopic Constructor
61#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -050062
Cary Clarkbc5697d2017-10-04 14:31:33 -040063# ------------------------------------------------------------------------------
64
65#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
66
Cary Clark4855f782018-02-06 09:41:53 -050067#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -050068#Line # constructs from bounds of (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040069Returns constructed Rect set to (0, 0, 0, 0).
70Many other rectangles are empty; if left is equal to or greater than right,
71or if top is equal to or greater than bottom. Setting all members to zero
72is a convenience, but does not designate a special empty rectangle.
73
74#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040075
76#Example
Cary Clark154beea2017-10-26 07:58:48 -040077 SkRect rect = SkRect::MakeEmpty();
78 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
79 rect.offset(10, 10);
80 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
81 rect.inset(10, 10);
82 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
83 rect.outset(20, 20);
84 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
85#StdOut
86MakeEmpty isEmpty: true
87offset rect isEmpty: true
88inset rect isEmpty: true
89outset rect isEmpty: false
90##
Cary Clarkbc5697d2017-10-04 14:31:33 -040091##
92
Mike Reed274218e2018-01-08 15:05:02 -050093#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -040094
95##
96
97# ------------------------------------------------------------------------------
98
99#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400100
Cary Clark4855f782018-02-06 09:41:53 -0500101#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500102#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400103Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
104validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400105
Cary Clark7fc1d122017-10-09 14:07:42 -0400106Passing integer values may generate a compiler warning since Rect cannot
107represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
108
109#Param w SkScalar width of constructed Rect ##
110#Param h SkScalar height of constructed Rect ##
111
112#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400113
114#Example
Cary Clark154beea2017-10-26 07:58:48 -0400115 SkRect rect1 = SkRect::MakeWH(25, 35);
116 SkRect rect2 = SkRect::MakeIWH(25, 35);
117 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
118 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
119 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400120 "" : "not ");
121#StdOut
122all equal
123##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400124##
125
Cary Clark7fc1d122017-10-09 14:07:42 -0400126#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400127
128##
129
130# ------------------------------------------------------------------------------
131
132#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
133
Cary Clark4855f782018-02-06 09:41:53 -0500134#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500135#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400136Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
137input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400138
Cary Clark7fc1d122017-10-09 14:07:42 -0400139Use to avoid a compiler warning that input may lose precision when stored.
140Use SkIRect for an exact integer rectangle.
141
142#Param w integer width of constructed Rect ##
143#Param h integer height of constructed Rect ##
144
145#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400146
147#Example
Cary Clark154beea2017-10-26 07:58:48 -0400148 SkIRect i_rect = SkIRect::MakeWH(25, 35);
149 SkRect f_rect = SkRect::MakeIWH(25, 35);
150 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
151 i_rect = SkIRect::MakeWH(125000111, 0);
152 f_rect = SkRect::MakeIWH(125000111, 0);
153 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400154#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400155i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400156i_rect width: 125000111 f_rect width:125000112
157##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400158##
159
Cary Clark7fc1d122017-10-09 14:07:42 -0400160#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400161
162##
163
164# ------------------------------------------------------------------------------
165
Cary Clark884dd7d2017-10-11 10:37:52 -0400166#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400167
Cary Clark4855f782018-02-06 09:41:53 -0500168#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500169#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400170Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
171validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400172
Cary Clark7fc1d122017-10-09 14:07:42 -0400173#Param size SkScalar values for Rect width and height ##
174
175#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400176
177#Example
Cary Clark154beea2017-10-26 07:58:48 -0400178 SkSize size = {25.5f, 35.5f};
179 SkRect rect = SkRect::MakeSize(size);
180 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
181 SkISize floor = size.toFloor();
182 rect = SkRect::MakeSize(SkSize::Make(floor));
183 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400184#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400185rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400186floor width: 25 height: 35
187##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400188##
189
Cary Clark7fc1d122017-10-09 14:07:42 -0400190#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400191
192##
193
194# ------------------------------------------------------------------------------
195
196#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
197 SkScalar b)
Cary Clark4855f782018-02-06 09:41:53 -0500198#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500199#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400200
Cary Clark7fc1d122017-10-09 14:07:42 -0400201Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
202result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400203
Cary Clark7fc1d122017-10-09 14:07:42 -0400204#Param l SkScalar stored in fLeft ##
205#Param t SkScalar stored in fTop ##
206#Param r SkScalar stored in fRight ##
207#Param b SkScalar stored in fBottom ##
208
209#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400210
211#Example
Cary Clark154beea2017-10-26 07:58:48 -0400212 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
213 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
214 rect.bottom(), rect.isEmpty() ? "true" : "false");
215 rect.sort();
216 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
217 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400218#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400219rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400220rect: 5, 25, 15, 35 isEmpty: false
221##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400222##
223
Cary Clark7fc1d122017-10-09 14:07:42 -0400224#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400225
226##
227
228# ------------------------------------------------------------------------------
229
Cary Clark884dd7d2017-10-11 10:37:52 -0400230#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400231
Cary Clark4855f782018-02-06 09:41:53 -0500232#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500233#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400234Returns constructed Rect set to
235#Formula
236(x, y, x + w, y + h)
237##
238. Does not validate input;
239w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400240
Cary Clark7fc1d122017-10-09 14:07:42 -0400241#Param x stored in fLeft ##
242#Param y stored in fTop ##
243#Param w added to x and stored in fRight ##
244#Param h added to y and stored in fBottom ##
245
Cary Clark884dd7d2017-10-11 10:37:52 -0400246#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400247
248#Example
Cary Clark154beea2017-10-26 07:58:48 -0400249 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
250 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
251 rect.bottom(), rect.isEmpty() ? "true" : "false");
252 rect.sort();
253 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
254 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400255#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400256rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400257rect: -10, 35, 5, 60 isEmpty: false
258##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400259##
260
Cary Clark7fc1d122017-10-09 14:07:42 -0400261#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400262
263##
264
265# ------------------------------------------------------------------------------
266
267#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
Cary Clark7fc1d122017-10-09 14:07:42 -0400268#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400269##
270
Cary Clarkbc5697d2017-10-04 14:31:33 -0400271# ------------------------------------------------------------------------------
272
273#Method static SkRect Make(const SkISize& size)
274
Cary Clark4855f782018-02-06 09:41:53 -0500275#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500276#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400277Returns constructed IRect set to (0, 0, size.width(), size.height()).
278Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400279
Cary Clark7fc1d122017-10-09 14:07:42 -0400280#Param size integer values for Rect width and height ##
281
282#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400283
284#Example
Cary Clark154beea2017-10-26 07:58:48 -0400285 SkRect rect1 = SkRect::MakeSize({2, 35});
286 SkRect rect2 = SkRect::MakeIWH(2, 35);
287 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400288#StdOut
289rect1 == rect2
290##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400291##
292
Cary Clark7fc1d122017-10-09 14:07:42 -0400293#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
295##
296
297# ------------------------------------------------------------------------------
298
299#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
300
Cary Clark4855f782018-02-06 09:41:53 -0500301#In Constructor
Cary Clark7fc1d122017-10-09 14:07:42 -0400302Returns constructed IRect set to irect, promoting integers to Scalar.
303Does not validate input; fLeft may be greater than fRight, fTop may be greater
304than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400305
Cary Clark7fc1d122017-10-09 14:07:42 -0400306#Param irect integer unsorted bounds ##
307
308#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309
310#Example
Cary Clark154beea2017-10-26 07:58:48 -0400311 SkIRect i_rect1 = {2, 35, 22, 53};
312 SkRect f_rect = SkRect::Make(i_rect1);
313 f_rect.offset(0.49f, 0.49f);
314 SkIRect i_rect2;
315 f_rect.round(&i_rect2);
316 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400317##
318
Cary Clark7fc1d122017-10-09 14:07:42 -0400319#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400320
321##
322
Cary Clark4855f782018-02-06 09:41:53 -0500323#Subtopic Constructor ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500324
Cary Clark4855f782018-02-06 09:41:53 -0500325#Subtopic Property
326#Line # member values, center, validity ##
327#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500328
Cary Clarkbc5697d2017-10-04 14:31:33 -0400329# ------------------------------------------------------------------------------
330
331#Method bool isEmpty() const
332
Cary Clark4855f782018-02-06 09:41:53 -0500333#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500334#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400335Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
336to or greater than fBottom. Call sort() to reverse rectangles with negative
337width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400338
Cary Clark7fc1d122017-10-09 14:07:42 -0400339#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400340
341#Example
Cary Clark154beea2017-10-26 07:58:48 -0400342 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
343 for (auto rect : tests) {
344 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
345 rect.bottom(), rect.isEmpty() ? "" : " not");
346 rect.sort();
347 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
348 rect.bottom(), rect.isEmpty() ? "" : " not");
349 }
350#StdOut
351rect: {20, 40, 10, 50} is empty
352sorted: {10, 40, 20, 50} is not empty
353rect: {20, 40, 20, 50} is empty
354sorted: {20, 40, 20, 50} is empty
355##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400356##
357
Cary Clark7fc1d122017-10-09 14:07:42 -0400358#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400359
360##
361
362# ------------------------------------------------------------------------------
363
364#Method bool isSorted() const
365
Cary Clark4855f782018-02-06 09:41:53 -0500366#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500367#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400368Returns true if fLeft is equal to or less than fRight, or if fTop is equal
369to or less than fBottom. Call sort() to reverse rectangles with negative
370width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400371
Cary Clark7fc1d122017-10-09 14:07:42 -0400372#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400373
374#Example
Cary Clark154beea2017-10-26 07:58:48 -0400375 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
376 for (auto rect : tests) {
377 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
378 rect.bottom(), rect.isSorted() ? "" : " not");
379 rect.sort();
380 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
381 rect.bottom(), rect.isSorted() ? "" : " not");
382 }
383#StdOut
384rect: {20, 40, 10, 50} is not sorted
385sorted: {10, 40, 20, 50} is sorted
386rect: {20, 40, 20, 50} is sorted
387sorted: {20, 40, 20, 50} is sorted
388##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400389##
390
Cary Clark7fc1d122017-10-09 14:07:42 -0400391#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400392
393##
394
395# ------------------------------------------------------------------------------
396
Cary Clarkbc5697d2017-10-04 14:31:33 -0400397#Method bool isFinite() const
398
Cary Clark4855f782018-02-06 09:41:53 -0500399#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500400#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400401Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
402and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400403
Cary Clark7fc1d122017-10-09 14:07:42 -0400404#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400405
406#Example
Mike Reed274218e2018-01-08 15:05:02 -0500407SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400408 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
409 SkDebugf("large width %g\n", largest.width());
410 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
411 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
412#StdOut
413largest is finite: true
414large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400415widest is finite: false
416##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400417##
418
Cary Clark7fc1d122017-10-09 14:07:42 -0400419#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400420
421##
422
423# ------------------------------------------------------------------------------
424
425#Method SkScalar x() const
426
Cary Clark4855f782018-02-06 09:41:53 -0500427#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500428#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400429Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
430Call sort() to reverse fLeft and fRight if needed.
431
432#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400433
434#Example
Cary Clark154beea2017-10-26 07:58:48 -0400435 SkRect unsorted = { 15, 5, 10, 25 };
436 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
437 SkRect sorted = unsorted.makeSorted();
438 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400439#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400440unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400441sorted.fLeft: 10 sorted.x(): 10
442##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400443##
444
Cary Clark7fc1d122017-10-09 14:07:42 -0400445#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400446
447##
448
449# ------------------------------------------------------------------------------
450
451#Method SkScalar y() const
452
Cary Clark4855f782018-02-06 09:41:53 -0500453#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500454#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400455Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
456and sort() to reverse fTop and fBottom if needed.
457
458#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400459
460#Example
Cary Clark154beea2017-10-26 07:58:48 -0400461 SkRect unsorted = { 15, 25, 10, 5 };
462 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
463 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400464 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
465#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400466unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400467sorted.fTop: 5 sorted.y(): 5
468##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400469##
470
Cary Clark7fc1d122017-10-09 14:07:42 -0400471#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400472
473##
474
475# ------------------------------------------------------------------------------
476
477#Method SkScalar left() const
478
Cary Clark4855f782018-02-06 09:41:53 -0500479#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500480#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400481Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
482Call sort() to reverse fLeft and fRight if needed.
483
484#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400485
486#Example
Cary Clark154beea2017-10-26 07:58:48 -0400487 SkRect unsorted = { 15, 5, 10, 25 };
488 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
489 SkRect sorted = unsorted.makeSorted();
490 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400491#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400492unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400493sorted.fLeft: 10 sorted.left(): 10
494##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400495##
496
Cary Clark7fc1d122017-10-09 14:07:42 -0400497#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400498
499##
500
501# ------------------------------------------------------------------------------
502
503#Method SkScalar top() const
504
Cary Clark4855f782018-02-06 09:41:53 -0500505#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500506#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400507Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
508and sort() to reverse fTop and fBottom if needed.
509
510#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400511
512#Example
Cary Clark154beea2017-10-26 07:58:48 -0400513 SkRect unsorted = { 15, 25, 10, 5 };
514 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
515 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400516 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
517#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400518unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400519sorted.fTop: 5 sorted.top(): 5
520##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400521##
522
Cary Clark7fc1d122017-10-09 14:07:42 -0400523#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400524
525##
526
527# ------------------------------------------------------------------------------
528
529#Method SkScalar right() const
530
Cary Clark4855f782018-02-06 09:41:53 -0500531#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500532#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400533Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
534Call sort() to reverse fLeft and fRight if needed.
535
536#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400537
538#Example
Cary Clark154beea2017-10-26 07:58:48 -0400539 SkRect unsorted = { 15, 25, 10, 5 };
540 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
541 SkRect sorted = unsorted.makeSorted();
542 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400543#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400544unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400545sorted.fRight: 15 sorted.right(): 15
546##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400547##
548
Cary Clark7fc1d122017-10-09 14:07:42 -0400549#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400550
551##
552
553# ------------------------------------------------------------------------------
554
555#Method SkScalar bottom() const
556
Cary Clark4855f782018-02-06 09:41:53 -0500557#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500558#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400559Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
560and sort() to reverse fTop and fBottom if needed.
561
562#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400563
564#Example
Cary Clark154beea2017-10-26 07:58:48 -0400565 SkRect unsorted = { 15, 25, 10, 5 };
566 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
567 SkRect sorted = unsorted.makeSorted();
568 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400569#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400570unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400571sorted.fBottom: 25 sorted.bottom(): 25
572##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400573##
574
Cary Clark7fc1d122017-10-09 14:07:42 -0400575#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400576
577##
578
579# ------------------------------------------------------------------------------
580
581#Method SkScalar width() const
582
Cary Clark4855f782018-02-06 09:41:53 -0500583#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500584#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400585Returns span on the x-axis. This does not check if Rect is sorted, or if
586result fits in 32-bit float; result may be negative or infinity.
587
588#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400589
590#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400591#Description
592Compare with SkIRect::width() example.
593##
Cary Clark154beea2017-10-26 07:58:48 -0400594 SkRect unsorted = { 15, 25, 10, 5 };
595 SkDebugf("unsorted width: %g\n", unsorted.width());
596 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
597 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400598#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400599unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400600large width: 4294967296
601##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400602##
603
Cary Clark7fc1d122017-10-09 14:07:42 -0400604#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400605
606##
607
608# ------------------------------------------------------------------------------
609
610#Method SkScalar height() const
611
Cary Clark4855f782018-02-06 09:41:53 -0500612#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500613#Line # returns span in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400614Returns span on the y-axis. This does not check if IRect is sorted, or if
615result fits in 32-bit float; result may be negative or infinity.
616
617#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400618
619#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400620#Description
621Compare with SkIRect::height() example.
622##
Cary Clark154beea2017-10-26 07:58:48 -0400623 SkRect unsorted = { 15, 25, 10, 20 };
624 SkDebugf("unsorted height: %g\n", unsorted.height());
625 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
626 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400627#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400628unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400629large height: 4294967296
630##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400631##
632
Cary Clark7fc1d122017-10-09 14:07:42 -0400633#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400634
635##
636
637# ------------------------------------------------------------------------------
638
639#Method SkScalar centerX() const
640
Cary Clark4855f782018-02-06 09:41:53 -0500641#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500642#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400643Returns average of left edge and right edge. Result does not change if Rect
644is sorted. Result may overflow to infinity if Rect is far from the origin.
645
646#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400647
648#Example
Cary Clark154beea2017-10-26 07:58:48 -0400649 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
650 for (auto rect : tests) {
651 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
652 rect.sort();
653 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
654 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400655#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400656left: 20 right: 41 centerX: 30.5
657left: 20 right: 41 centerX: 30.5
658left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400659left: -41 right: -20 centerX: -30.5
660##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400661##
662
Cary Clark7fc1d122017-10-09 14:07:42 -0400663#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400664
665##
666
667# ------------------------------------------------------------------------------
668
669#Method SkScalar centerY() const
670
Cary Clark4855f782018-02-06 09:41:53 -0500671#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500672#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400673Returns average of top edge and bottom edge. Result does not change if Rect
674is sorted. Result may overflow to infinity if Rect is far from the origin.
675
676#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400677
678#Example
Cary Clark154beea2017-10-26 07:58:48 -0400679 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
680 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
681 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400682#StdOut
683left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
684##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400685##
686
Cary Clark7fc1d122017-10-09 14:07:42 -0400687#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400688
689##
690
Cary Clark4855f782018-02-06 09:41:53 -0500691#Subtopic Property ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500692
Cary Clark4855f782018-02-06 09:41:53 -0500693#Subtopic Operator
Cary Clark2dc84ad2018-01-26 12:56:22 -0500694
Cary Clark4855f782018-02-06 09:41:53 -0500695#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500696
Cary Clarkbc5697d2017-10-04 14:31:33 -0400697# ------------------------------------------------------------------------------
698
Cary Clark884dd7d2017-10-11 10:37:52 -0400699#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400700
Cary Clark4855f782018-02-06 09:41:53 -0500701#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500702#Line # returns true if members are equal ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400703Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
704equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400705
Cary Clark7fc1d122017-10-09 14:07:42 -0400706a and b are not equal if either contain NaN. a and b are equal if members
707contain zeroes width different signs.
708
709#Param a Rect to compare ##
710#Param b Rect to compare ##
711
712#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400713
714#Example
Cary Clark154beea2017-10-26 07:58:48 -0400715 auto debugster = [](const SkRect& test) -> void {
716 SkRect negZero = {-0.0f, -0.0f, 2, 2};
717 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
718 test.fLeft, test.fTop, test.fRight, test.fBottom,
719 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
720 test == negZero ? '=' : '!',
721 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
722 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
723 "and are" : "yet are not");
724 };
725 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
726 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
727 for (auto rect : tests) {
728 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400729 }
Cary Clark154beea2017-10-26 07:58:48 -0400730#StdOut
731tests are equal
732{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
733{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400734{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
735##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400736##
737
Cary Clark7fc1d122017-10-09 14:07:42 -0400738#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400739
740##
741
742# ------------------------------------------------------------------------------
743
Cary Clark884dd7d2017-10-11 10:37:52 -0400744#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400745
Cary Clark4855f782018-02-06 09:41:53 -0500746#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500747#Line # returns true if members are unequal ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400748Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
749equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400750
Cary Clark7fc1d122017-10-09 14:07:42 -0400751a and b are not equal if either contain NaN. a and b are equal if members
752contain zeroes width different signs.
753
754#Param a Rect to compare ##
755#Param b Rect to compare ##
756
757#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400758
759#Example
Cary Clark154beea2017-10-26 07:58:48 -0400760 SkRect test = {0, 0, 2, SK_ScalarNaN};
761 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
762#StdOut
Cary Clark7fc1d122017-10-09 14:07:42 -0400763test with NaN is not equal to itself
764##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400765##
766
Cary Clark7fc1d122017-10-09 14:07:42 -0400767#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400768
769##
770
Cary Clark4855f782018-02-06 09:41:53 -0500771#Subtopic Operator ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500772
773#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500774#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500775
Cary Clark4855f782018-02-06 09:41:53 -0500776#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500777
Cary Clarkbc5697d2017-10-04 14:31:33 -0400778# ------------------------------------------------------------------------------
779
780#Method void toQuad(SkPoint quad[4]) const
781
Cary Clarkab2621d2018-01-30 10:08:57 -0500782#In As_Points
783#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400784Returns four points in quad that enclose Rect ordered as: top-left, top-right,
785bottom-right, bottom-left.
786
787#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400788Consider adding param to control whether quad is CW or CCW.
789##
790
Cary Clark7fc1d122017-10-09 14:07:42 -0400791#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400792
793#Example
Cary Clark154beea2017-10-26 07:58:48 -0400794 SkRect rect = {1, 2, 3, 4};
795 SkPoint corners[4];
796 rect.toQuad(corners);
797 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
798 SkDebugf("corners:");
799 for (auto corner : corners) {
800 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
801 }
802 SkDebugf("\n");
803#StdOut
804rect: {1, 2, 3, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400805corners: {1, 2} {3, 2} {3, 4} {1, 4}
806##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400807##
808
Cary Clark7fc1d122017-10-09 14:07:42 -0400809#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400810
811##
812
813# ------------------------------------------------------------------------------
814
Cary Clark2dc84ad2018-01-26 12:56:22 -0500815#Method void setBounds(const SkPoint pts[], int count)
816
Cary Clarkab2621d2018-01-30 10:08:57 -0500817#In As_Points
818#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500819Sets to bounds of Point array with count entries. If count is zero or smaller,
820or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
821
822Result is either empty or sorted: fLeft is less than or equal to fRight, and
823fTop is less than or equal to fBottom.
824
825#Param pts Point array ##
826#Param count entries in array ##
827
828#Example
829 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
830 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
831 SkRect rect;
832 rect.setBounds(points, count);
833 if (count > 0) {
834 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
835 } else {
836 SkDebugf("%14s", " ");
837 }
838 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
839 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
840 }
841#StdOut
842 count: 0 rect: 0, 0, 0, 0
843added: 3, 4 count: 1 rect: 3, 4, 3, 4
844added: 1, 2 count: 2 rect: 1, 2, 3, 4
845added: 5, 6 count: 3 rect: 1, 2, 5, 6
846added: nan, 8 count: 4 rect: 0, 0, 0, 0
847##
848##
849
850#SeeAlso set setBoundsCheck SkPath::addPoly
851
852##
853
854# ------------------------------------------------------------------------------
855
856#Method bool setBoundsCheck(const SkPoint pts[], int count)
857
Cary Clarkab2621d2018-01-30 10:08:57 -0500858#In As_Points
859#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500860Sets to bounds of Point array with count entries. Returns false if count is
861zero or smaller, or if Point array contains an infinity or NaN; in these cases
862sets Rect to (0, 0, 0, 0).
863
864Result is either empty or sorted: fLeft is less than or equal to fRight, and
865fTop is less than or equal to fBottom.
866
867#Param pts Point array ##
868#Param count entries in array ##
869
870#Return true if all Point values are finite ##
871
872#Example
873 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
874 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
875 SkRect rect;
876 bool success = rect.setBoundsCheck(points, count);
877 if (count > 0) {
878 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
879 } else {
880 SkDebugf("%14s", " ");
881 }
882 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
883 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
884 }
885#StdOut
886 count: 0 rect: 0, 0, 0, 0 success: true
887added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
888added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
889added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
890added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
891##
892##
893
894#SeeAlso set setBounds SkPath::addPoly
895
896##
897
898#Subtopic As_Points ##
899
900#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500901#Line # replaces all values ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500902
Cary Clark4855f782018-02-06 09:41:53 -0500903#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500904
905# ------------------------------------------------------------------------------
906
Cary Clarkbc5697d2017-10-04 14:31:33 -0400907#Method void setEmpty()
908
Cary Clarkab2621d2018-01-30 10:08:57 -0500909#In Set
910#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400911Sets Rect to (0, 0, 0, 0).
912
913Many other rectangles are empty; if left is equal to or greater than right,
914or if top is equal to or greater than bottom. Setting all members to zero
915is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400916
917#Example
Cary Clark154beea2017-10-26 07:58:48 -0400918 SkRect rect = {3, 4, 1, 2};
919 for (int i = 0; i < 2; ++i) {
920 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
921 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
922 rect.setEmpty();
923 }
924#StdOut
925rect: {3, 4, 1, 2} is empty
926rect: {0, 0, 0, 0} is empty
927##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400928##
929
Cary Clark7fc1d122017-10-09 14:07:42 -0400930#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400931
932##
933
934# ------------------------------------------------------------------------------
935
936#Method void set(const SkIRect& src)
937
Cary Clarkab2621d2018-01-30 10:08:57 -0500938#In Set
939#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400940Sets Rect to src, promoting src members from integer to Scalar.
941Very large values in src may lose precision.
942
943#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400944
945#Example
Cary Clark154beea2017-10-26 07:58:48 -0400946 SkIRect i_rect = {3, 4, 1, 2};
947 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
948 SkRect f_rect;
949 f_rect.set(i_rect);
950 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
951#StdOut
952i_rect: {3, 4, 1, 2}
953f_rect: {3, 4, 1, 2}
954##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400955##
956
Cary Clark7fc1d122017-10-09 14:07:42 -0400957#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400958
959##
960
961# ------------------------------------------------------------------------------
962
963#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
964
Cary Clarkab2621d2018-01-30 10:08:57 -0500965#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400966Sets Rect to (left, top, right, bottom).
967left and right are not sorted; left is not necessarily less than right.
968top and bottom are not sorted; top is not necessarily less than bottom.
969
970#Param left stored in fLeft ##
971#Param top stored in fTop ##
972#Param right stored in fRight ##
973#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400974
975#Example
Cary Clark154beea2017-10-26 07:58:48 -0400976 SkRect rect1 = {3, 4, 1, 2};
977 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
978 SkRect rect2;
979 rect2.set(3, 4, 1, 2);
980 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
981#StdOut
982rect1: {3, 4, 1, 2}
983rect2: {3, 4, 1, 2}
984##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400985##
986
Cary Clark7fc1d122017-10-09 14:07:42 -0400987#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400988
989##
990
991# ------------------------------------------------------------------------------
992
993#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
994
Cary Clarkab2621d2018-01-30 10:08:57 -0500995#In Set
996#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400997Sets Rect to (left, top, right, bottom).
998left and right are not sorted; left is not necessarily less than right.
999top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001000
Cary Clark7fc1d122017-10-09 14:07:42 -04001001#Param left stored in fLeft ##
1002#Param top stored in fTop ##
1003#Param right stored in fRight ##
1004#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001005
1006#Example
Cary Clark154beea2017-10-26 07:58:48 -04001007 SkRect rect1 = {3, 4, 1, 2};
1008 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1009 SkRect rect2;
1010 rect2.setLTRB(3, 4, 1, 2);
1011 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1012#StdOut
1013rect1: {3, 4, 1, 2}
1014rect2: {3, 4, 1, 2}
1015##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001016##
1017
Cary Clark7fc1d122017-10-09 14:07:42 -04001018#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001019
1020##
1021
1022# ------------------------------------------------------------------------------
1023
Cary Clarkbc5697d2017-10-04 14:31:33 -04001024#Method void set(const SkPoint pts[], int count)
1025
Cary Clarkab2621d2018-01-30 10:08:57 -05001026#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001027Sets to bounds of Point array with count entries. If count is zero or smaller,
1028or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001029
Cary Clark7fc1d122017-10-09 14:07:42 -04001030Result is either empty or sorted: fLeft is less than or equal to fRight, and
1031fTop is less than or equal to fBottom.
1032
1033#Param pts Point array ##
1034#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001035
1036#Example
Cary Clark154beea2017-10-26 07:58:48 -04001037 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1038 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1039 SkRect rect;
1040 rect.set(points, count);
1041 if (count > 0) {
1042 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1043 } else {
1044 SkDebugf("%14s", " ");
1045 }
1046 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1047 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1048 }
1049#StdOut
1050 count: 0 rect: 0, 0, 0, 0
1051added: 3, 4 count: 1 rect: 3, 4, 3, 4
1052added: 1, 2 count: 2 rect: 1, 2, 3, 4
1053added: 5, 6 count: 3 rect: 1, 2, 5, 6
1054added: nan, 8 count: 4 rect: 0, 0, 0, 0
1055##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001056##
1057
Cary Clark7fc1d122017-10-09 14:07:42 -04001058#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001059
1060##
1061
1062# ------------------------------------------------------------------------------
1063
Cary Clarkbc5697d2017-10-04 14:31:33 -04001064#Method void set(const SkPoint& p0, const SkPoint& p1)
1065
Cary Clarkab2621d2018-01-30 10:08:57 -05001066#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001067Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1068sorted and may be empty. Does not check to see if values are finite.
1069
1070#Param p0 corner to include ##
1071#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001072
1073#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001074#Description
1075p0 and p1 may be swapped and have the same effect unless one contains NaN.
1076##
Cary Clark154beea2017-10-26 07:58:48 -04001077 SkPoint point1 = {SK_ScalarNaN, 8};
1078 SkPoint point2 = {3, 4};
1079 SkRect rect;
1080 rect.set(point1, point2);
1081 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1082 rect.set(point2, point1);
1083 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001084##
1085
Cary Clark7fc1d122017-10-09 14:07:42 -04001086#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001087
1088##
1089
1090# ------------------------------------------------------------------------------
1091
1092#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1093
Cary Clarkab2621d2018-01-30 10:08:57 -05001094#In Set
1095#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001096Sets Rect to
1097#Formula
1098(x, y, x + width, y + height)
1099##
1100. Does not validate input;
1101width or height may be negative.
1102
1103#Param x stored in fLeft ##
1104#Param y stored in fTop ##
1105#Param width added to x and stored in fRight ##
1106#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001107
1108#Example
Cary Clark154beea2017-10-26 07:58:48 -04001109 SkRect rect;
1110 rect.setXYWH(5, 35, -15, 25);
1111 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1112 rect.bottom(), rect.isEmpty() ? "true" : "false");
1113 rect.sort();
1114 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1115 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001116#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001117rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001118rect: -10, 35, 5, 60 isEmpty: false
1119##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001120##
1121
Cary Clark7fc1d122017-10-09 14:07:42 -04001122#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001123
1124##
1125
1126# ------------------------------------------------------------------------------
1127
1128#Method void setWH(SkScalar width, SkScalar height)
1129
Cary Clarkab2621d2018-01-30 10:08:57 -05001130#In Set
1131#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001132Sets Rect to (0, 0, width, height). Does not validate input;
1133width or height may be negative.
1134
1135#Param width stored in fRight ##
1136#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001137
1138#Example
Cary Clark154beea2017-10-26 07:58:48 -04001139 SkRect rect;
1140 rect.setWH(-15, 25);
1141 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1142 rect.bottom(), rect.isEmpty() ? "true" : "false");
1143 rect.sort();
1144 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1145 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001146#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001147rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001148rect: -15, 0, 0, 25 isEmpty: false
1149##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001150##
1151
Cary Clark7fc1d122017-10-09 14:07:42 -04001152#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001153
1154##
1155
Cary Clark2dc84ad2018-01-26 12:56:22 -05001156#Subtopic Set ##
1157
1158#Subtopic From_Integers
Cary Clark08895c42018-02-01 09:37:32 -05001159#Line # set Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001160
Cary Clark4855f782018-02-06 09:41:53 -05001161#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001162
1163# ------------------------------------------------------------------------------
1164
1165#Method void iset(int left, int top, int right, int bottom)
1166
Cary Clarkab2621d2018-01-30 10:08:57 -05001167#In From_Integers
1168#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001169Sets Rect to (left, top, right, bottom).
1170All parameters are promoted from integer to Scalar.
1171left and right are not sorted; left is not necessarily less than right.
1172top and bottom are not sorted; top is not necessarily less than bottom.
1173
1174#Param left promoted to SkScalar and stored in fLeft ##
1175#Param top promoted to SkScalar and stored in fTop ##
1176#Param right promoted to SkScalar and stored in fRight ##
1177#Param bottom promoted to SkScalar and stored in fBottom ##
1178
1179#Example
1180 SkRect rect1 = {3, 4, 1, 2};
1181 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1182 SkRect rect2;
1183 rect2.iset(3, 4, 1, 2);
1184 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1185#StdOut
1186rect1: {3, 4, 1, 2}
1187rect2: {3, 4, 1, 2}
1188##
1189##
1190
1191#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1192
1193##
1194
1195# ------------------------------------------------------------------------------
1196
1197#Method void isetWH(int width, int height)
1198
Cary Clarkab2621d2018-01-30 10:08:57 -05001199#In From_Integers
1200#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001201Sets Rect to (0, 0, width, height).
1202width and height may be zero or negative. width and height are promoted from
1203integer to SkScalar, large values may lose precision.
1204
1205#Param width promoted to SkScalar and stored in fRight ##
1206#Param height promoted to SkScalar and stored in fBottom ##
1207
1208#Example
1209 SkRect rect1 = {0, 0, 1, 2};
1210 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1211 SkRect rect2;
1212 rect2.isetWH(1, 2);
1213 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1214#StdOut
1215rect1: {0, 0, 1, 2}
1216rect2: {0, 0, 1, 2}
1217##
1218##
1219
1220#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1221
1222##
1223
1224#Subtopic From_Integers ##
1225
1226#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001227#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001228
Cary Clark4855f782018-02-06 09:41:53 -05001229#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001230
Cary Clarkbc5697d2017-10-04 14:31:33 -04001231# ------------------------------------------------------------------------------
1232
Cary Clarkbc5697d2017-10-04 14:31:33 -04001233#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1234
Cary Clarkab2621d2018-01-30 10:08:57 -05001235#In Inset_Outset_Offset
1236#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001237Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001238
Cary Clark7fc1d122017-10-09 14:07:42 -04001239If dx is negative, Rect returned is moved to the left.
1240If dx is positive, Rect returned is moved to the right.
1241If dy is negative, Rect returned is moved upward.
1242If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001243
Cary Clark7fc1d122017-10-09 14:07:42 -04001244#Param dx added to fLeft and fRight ##
1245#Param dy added to fTop and fBottom ##
1246
1247#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001248
1249#Example
Cary Clark154beea2017-10-26 07:58:48 -04001250 SkRect rect = { 10, 50, 20, 60 };
1251 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1252 rect.bottom(), rect.isEmpty() ? "true" : "false");
1253 rect = rect.makeOffset(15, 32);
1254 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1255 rect.bottom(), rect.isEmpty() ? "true" : "false");
1256#StdOut
1257rect: 10, 50, 20, 60 isEmpty: false
1258rect: 25, 82, 35, 92 isEmpty: false
1259##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001260##
1261
Cary Clark7fc1d122017-10-09 14:07:42 -04001262#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001263
1264##
1265
1266# ------------------------------------------------------------------------------
1267
1268#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1269
Cary Clarkab2621d2018-01-30 10:08:57 -05001270#In Inset_Outset_Offset
1271#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001272Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001273
Cary Clark7fc1d122017-10-09 14:07:42 -04001274If dx is negative, Rect returned is wider.
1275If dx is positive, Rect returned is narrower.
1276If dy is negative, Rect returned is taller.
1277If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001278
Cary Clark7fc1d122017-10-09 14:07:42 -04001279#Param dx added to fLeft and subtracted from fRight ##
1280#Param dy added to fTop and subtracted from fBottom ##
1281
1282#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001283
1284#Example
Cary Clark154beea2017-10-26 07:58:48 -04001285 SkRect rect = { 10, 50, 20, 60 };
1286 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1287 rect.bottom(), rect.isEmpty() ? "true" : "false");
1288 rect = rect.makeInset(15, 32);
1289 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1290 rect.bottom(), rect.isEmpty() ? "true" : "false");
1291#StdOut
1292rect: 10, 50, 20, 60 isEmpty: false
1293rect: 25, 82, 5, 28 isEmpty: true
1294##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001295##
1296
Cary Clark7fc1d122017-10-09 14:07:42 -04001297#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001298
1299##
1300
1301# ------------------------------------------------------------------------------
1302
1303#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1304
Cary Clarkab2621d2018-01-30 10:08:57 -05001305#In Inset_Outset_Offset
1306#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001307Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001308
Cary Clark7fc1d122017-10-09 14:07:42 -04001309If dx is negative, Rect returned is narrower.
1310If dx is positive, Rect returned is wider.
1311If dy is negative, Rect returned is shorter.
1312If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001313
Cary Clark7fc1d122017-10-09 14:07:42 -04001314#Param dx subtracted to fLeft and added from fRight ##
1315#Param dy subtracted to fTop and added from fBottom ##
1316
1317#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001318
1319#Example
Cary Clark154beea2017-10-26 07:58:48 -04001320 SkRect rect = { 10, 50, 20, 60 };
1321 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1322 rect.bottom(), rect.isEmpty() ? "true" : "false");
1323 rect = rect.makeOutset(15, 32);
1324 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1325 rect.bottom(), rect.isEmpty() ? "true" : "false");
1326#StdOut
1327rect: 10, 50, 20, 60 isEmpty: false
1328rect: -5, 18, 35, 92 isEmpty: false
1329##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001330##
1331
Cary Clark7fc1d122017-10-09 14:07:42 -04001332#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001333
1334##
1335
1336# ------------------------------------------------------------------------------
1337
1338#Method void offset(SkScalar dx, SkScalar dy)
1339
Cary Clarkab2621d2018-01-30 10:08:57 -05001340#In Inset_Outset_Offset
1341#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001342Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001343
Cary Clark7fc1d122017-10-09 14:07:42 -04001344If dx is negative, moves Rect to the left.
1345If dx is positive, moves Rect to the right.
1346If dy is negative, moves Rect upward.
1347If dy is positive, moves Rect downward.
1348
1349#Param dx offset added to fLeft and fRight ##
1350#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001351
1352#Example
Cary Clark154beea2017-10-26 07:58:48 -04001353 SkRect rect = { 10, 14, 50, 73 };
1354 rect.offset(5, 13);
1355 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1356#StdOut
1357rect: 15, 27, 55, 86
1358##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001359##
1360
Cary Clark7fc1d122017-10-09 14:07:42 -04001361#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001362
1363##
1364
1365# ------------------------------------------------------------------------------
1366
1367#Method void offset(const SkPoint& delta)
1368
Cary Clarkab2621d2018-01-30 10:08:57 -05001369#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001370Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1371fTop, fBottom.
1372
1373If delta.fX is negative, moves Rect to the left.
1374If delta.fX is positive, moves Rect to the right.
1375If delta.fY is negative, moves Rect upward.
1376If delta.fY is positive, moves Rect downward.
1377
1378#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001379
1380#Example
Cary Clark154beea2017-10-26 07:58:48 -04001381 SkRect rect = { 10, 14, 50, 73 };
1382 rect.offset({5, 13});
1383 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1384#StdOut
1385rect: 15, 27, 55, 86
1386##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001387##
1388
Cary Clark7fc1d122017-10-09 14:07:42 -04001389#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001390
1391##
1392
1393# ------------------------------------------------------------------------------
1394
1395#Method void offsetTo(SkScalar newX, SkScalar newY)
1396
Cary Clarkab2621d2018-01-30 10:08:57 -05001397#In Inset_Outset_Offset
1398#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001399Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1400are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001401
Cary Clark7fc1d122017-10-09 14:07:42 -04001402#Param newX stored in fLeft, preserving width() ##
1403#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001404
1405#Example
Cary Clark154beea2017-10-26 07:58:48 -04001406 SkRect rect = { 10, 14, 50, 73 };
1407 rect.offsetTo(15, 27);
1408 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1409#StdOut
1410rect: 15, 27, 55, 86
1411##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001412##
1413
Cary Clark7fc1d122017-10-09 14:07:42 -04001414#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001415
1416##
1417
1418# ------------------------------------------------------------------------------
1419
1420#Method void inset(SkScalar dx, SkScalar dy)
1421
Cary Clarkab2621d2018-01-30 10:08:57 -05001422#In Inset_Outset_Offset
1423#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001424Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001425
Cary Clark7fc1d122017-10-09 14:07:42 -04001426If dx is positive, makes Rect narrower.
1427If dx is negative, makes Rect wider.
1428If dy is positive, makes Rect shorter.
1429If dy is negative, makes Rect taller.
1430
1431#Param dx added to fLeft and subtracted from fRight ##
1432#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001433
1434#Example
Cary Clark154beea2017-10-26 07:58:48 -04001435 SkRect rect = { 10, 14, 50, 73 };
1436 rect.inset(5, 13);
1437 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1438#StdOut
1439rect: 15, 27, 45, 60
1440##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001441##
1442
Cary Clark7fc1d122017-10-09 14:07:42 -04001443#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001444
1445##
1446
1447# ------------------------------------------------------------------------------
1448
1449#Method void outset(SkScalar dx, SkScalar dy)
1450
Cary Clarkab2621d2018-01-30 10:08:57 -05001451#In Inset_Outset_Offset
1452#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001453Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001454
Cary Clark7fc1d122017-10-09 14:07:42 -04001455If dx is positive, makes Rect wider.
1456If dx is negative, makes Rect narrower.
1457If dy is positive, makes Rect taller.
1458If dy is negative, makes Rect shorter.
1459
1460#Param dx subtracted to fLeft and added from fRight ##
1461#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001462
1463#Example
Cary Clark154beea2017-10-26 07:58:48 -04001464 SkRect rect = { 10, 14, 50, 73 };
1465 rect.outset(5, 13);
1466 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1467#StdOut
1468rect: 5, 1, 55, 86
1469##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001470##
1471
Cary Clark7fc1d122017-10-09 14:07:42 -04001472#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001473
1474##
1475
Cary Clark2dc84ad2018-01-26 12:56:22 -05001476#Subtopic Inset_Outset_Offset ##
1477
1478#Subtopic Intersection
Cary Clark08895c42018-02-01 09:37:32 -05001479#Line # set to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001480
1481Rects intersect when they enclose a common area. To intersect, each of the pair
1482must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001483empty() returns false. The intersection of Rect pair can be described by:
1484
Cary Clark7fc1d122017-10-09 14:07:42 -04001485#Formula
1486(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1487 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1488##
Cary Clark154beea2017-10-26 07:58:48 -04001489.
1490
Cary Clark7fc1d122017-10-09 14:07:42 -04001491The intersection is only meaningful if the resulting Rect is not empty and
1492describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1493
Cary Clark4855f782018-02-06 09:41:53 -05001494#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001495
1496# ------------------------------------------------------------------------------
1497
1498#Method bool contains(const SkRect& r) const
1499
Cary Clarkab2621d2018-01-30 10:08:57 -05001500#In Intersection
1501#Line # returns true if points are equal or inside ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001502Returns true if Rect contains r.
1503Returns false if Rect is empty or r is empty.
1504
1505Rect contains r when Rect area completely includes r area.
1506
1507#Param r Rect contained ##
1508
1509#Return true if all sides of Rect are outside r ##
1510
1511#Example
1512 SkRect rect = { 30, 50, 40, 60 };
1513 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1514 for (auto contained : tests) {
1515 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1516 rect.left(), rect.top(), rect.right(), rect.bottom(),
1517 rect.contains(contained) ? "contains" : "does not contain",
1518 contained.left(), contained.top(), contained.right(), contained.bottom());
1519 }
1520#StdOut
1521rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1522rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1523rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1524##
1525##
1526
1527#SeeAlso SkIRect::contains
1528
1529##
1530
1531# ------------------------------------------------------------------------------
1532
1533#Method bool contains(const SkIRect& r) const
1534
Cary Clarkab2621d2018-01-30 10:08:57 -05001535#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001536Returns true if Rect contains r.
1537Returns false if Rect is empty or r is empty.
1538
1539Rect contains r when Rect area completely includes r area.
1540
1541#Param r IRect contained ##
1542
1543#Return true if all sides of Rect are outside r ##
1544
1545#Example
1546 SkRect rect = { 30, 50, 40, 60 };
1547 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1548 for (auto contained : tests) {
1549 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1550 rect.left(), rect.top(), rect.right(), rect.bottom(),
1551 rect.contains(contained) ? "contains" : "does not contain",
1552 contained.left(), contained.top(), contained.right(), contained.bottom());
1553 }
1554#StdOut
1555rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1556rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1557rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1558##
1559##
1560
1561#SeeAlso SkIRect::contains
1562
1563##
1564
Cary Clarkbc5697d2017-10-04 14:31:33 -04001565# ------------------------------------------------------------------------------
1566
1567#Method bool intersect(const SkRect& r)
1568
Cary Clarkab2621d2018-01-30 10:08:57 -05001569#In Intersection
1570#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001571Returns true if Rect intersects r, and sets Rect to intersection.
1572Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001573
Cary Clark7fc1d122017-10-09 14:07:42 -04001574Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001575
Cary Clark7fc1d122017-10-09 14:07:42 -04001576#Param r limit of result ##
1577
1578#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001579
1580#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001581#Description
1582Two SkDebugf calls are required. If the calls are combined, their arguments
1583may not be evaluated in left to right order: the printed intersection may
1584be before or after the call to intersect.
1585##
Cary Clark154beea2017-10-26 07:58:48 -04001586 SkRect leftRect = { 10, 40, 50, 80 };
1587 SkRect rightRect = { 30, 60, 70, 90 };
1588 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1589 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001590 leftRect.right(), leftRect.bottom());
1591#StdOut
1592 intersection: 30, 60, 50, 80
1593##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001594##
1595
Cary Clark7fc1d122017-10-09 14:07:42 -04001596#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001597
1598##
1599
1600# ------------------------------------------------------------------------------
1601
1602#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1603
Cary Clarkab2621d2018-01-30 10:08:57 -05001604#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001605Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1606construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001607
Cary Clark7fc1d122017-10-09 14:07:42 -04001608Returns true if Rect intersects construction, and sets Rect to intersection.
1609Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001610
Cary Clark7fc1d122017-10-09 14:07:42 -04001611Returns false if either construction or Rect is empty, leaving Rect unchanged.
1612
1613#Param left x minimum of constructed Rect ##
1614#Param top y minimum of constructed Rect ##
1615#Param right x maximum of constructed Rect ##
1616#Param bottom y maximum of constructed Rect ##
1617
1618#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001619
1620#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001621#Description
1622Two SkDebugf calls are required. If the calls are combined, their arguments
1623may not be evaluated in left to right order: the printed intersection may
1624be before or after the call to intersect.
1625##
Cary Clark154beea2017-10-26 07:58:48 -04001626 SkRect leftRect = { 10, 40, 50, 80 };
1627 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1628 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001629 leftRect.right(), leftRect.bottom());
1630#StdOut
1631 intersection: 30, 60, 50, 80
1632##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001633##
1634
Cary Clark7fc1d122017-10-09 14:07:42 -04001635#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001636
1637##
1638
1639# ------------------------------------------------------------------------------
1640
1641#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1642
Cary Clarkab2621d2018-01-30 10:08:57 -05001643#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001644Returns true if a intersects b, and sets Rect to intersection.
1645Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001646
Cary Clark7fc1d122017-10-09 14:07:42 -04001647Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001648
Cary Clark7fc1d122017-10-09 14:07:42 -04001649#Param a Rect to intersect ##
1650#Param b Rect to intersect ##
1651
1652#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001653
1654#Example
Cary Clark154beea2017-10-26 07:58:48 -04001655 SkRect result;
1656 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1657 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1658 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001659#StdOut
1660 intersection: 30, 60, 50, 80
1661##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001662##
1663
Cary Clark7fc1d122017-10-09 14:07:42 -04001664#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001665
1666##
1667
Cary Clark7fc1d122017-10-09 14:07:42 -04001668# ------------------------------------------------------------------------------
1669
Cary Clarkbc5697d2017-10-04 14:31:33 -04001670#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1671
Cary Clarkab2621d2018-01-30 10:08:57 -05001672#In Intersection
1673#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001674Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1675construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001676
Cary Clark7fc1d122017-10-09 14:07:42 -04001677Returns true if Rect intersects construction.
1678Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001679
Cary Clark7fc1d122017-10-09 14:07:42 -04001680#Param left x minimum of constructed Rect ##
1681#Param top y minimum of constructed Rect ##
1682#Param right x maximum of constructed Rect ##
1683#Param bottom y maximum of constructed Rect ##
1684
1685#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001686
1687#Example
Cary Clark154beea2017-10-26 07:58:48 -04001688 SkRect rect = { 10, 40, 50, 80 };
1689 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001690#StdOut
1691 intersection
1692##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001693##
1694
Cary Clark7fc1d122017-10-09 14:07:42 -04001695#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001696
1697##
1698
Cary Clark7fc1d122017-10-09 14:07:42 -04001699# ------------------------------------------------------------------------------
1700
Cary Clarkbc5697d2017-10-04 14:31:33 -04001701#Method bool intersects(const SkRect& r) const
1702
Cary Clarkab2621d2018-01-30 10:08:57 -05001703#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001704Returns true if Rect intersects r.
1705Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001706
Cary Clark7fc1d122017-10-09 14:07:42 -04001707#Param r Rect to intersect ##
1708
1709#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001710
1711#Example
Cary Clark154beea2017-10-26 07:58:48 -04001712 SkRect rect = { 10, 40, 50, 80 };
1713 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001714#StdOut
1715 intersection
1716##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001717##
1718
Cary Clark7fc1d122017-10-09 14:07:42 -04001719#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001720
1721##
1722
Cary Clark7fc1d122017-10-09 14:07:42 -04001723# ------------------------------------------------------------------------------
1724
Cary Clarkbc5697d2017-10-04 14:31:33 -04001725#Method static bool Intersects(const SkRect& a, const SkRect& b)
1726
Cary Clarkab2621d2018-01-30 10:08:57 -05001727#In Intersection
1728#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001729Returns true if a intersects b.
1730Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001731
Cary Clark7fc1d122017-10-09 14:07:42 -04001732#Param a Rect to intersect ##
1733#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001734
Cary Clark7fc1d122017-10-09 14:07:42 -04001735#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001736
1737#Example
Cary Clark154beea2017-10-26 07:58:48 -04001738 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001739#StdOut
1740 intersection
1741##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001742##
1743
Cary Clark7fc1d122017-10-09 14:07:42 -04001744#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001745
1746##
1747
Cary Clark2dc84ad2018-01-26 12:56:22 -05001748#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001749
Cary Clark2dc84ad2018-01-26 12:56:22 -05001750#Subtopic Join
Cary Clark08895c42018-02-01 09:37:32 -05001751#Line # set to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001752
Cary Clark4855f782018-02-06 09:41:53 -05001753#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001754
1755# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001756
1757#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1758
Cary Clarkab2621d2018-01-30 10:08:57 -05001759#In Join
1760#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001761Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1762construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001763
Cary Clark7fc1d122017-10-09 14:07:42 -04001764Sets Rect to the union of itself and the construction.
1765
1766Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1767Rect to construction.
1768
1769#Param left x minimum of constructed Rect ##
1770#Param top y minimum of constructed Rect ##
1771#Param right x maximum of constructed Rect ##
1772#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001773
1774#Example
Cary Clark154beea2017-10-26 07:58:48 -04001775 SkRect rect = { 10, 20, 15, 25};
1776 rect.join(50, 60, 55, 65);
1777 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001778#StdOut
1779 join: 10, 20, 55, 65
1780##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001781##
1782
Cary Clark7fc1d122017-10-09 14:07:42 -04001783#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001784
1785##
1786
Cary Clark7fc1d122017-10-09 14:07:42 -04001787# ------------------------------------------------------------------------------
1788
Cary Clarkbc5697d2017-10-04 14:31:33 -04001789#Method void join(const SkRect& r)
1790
Cary Clarkab2621d2018-01-30 10:08:57 -05001791#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001792Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793
Cary Clark7fc1d122017-10-09 14:07:42 -04001794Has no effect if r is empty. Otherwise, if Rect is empty, sets
1795Rect to r.
1796
1797#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001798
1799#Example
Cary Clark154beea2017-10-26 07:58:48 -04001800 SkRect rect = { 10, 20, 15, 25};
1801 rect.join({50, 60, 55, 65});
1802 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001803#StdOut
1804 join: 10, 20, 55, 65
1805##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001806##
1807
Cary Clark7fc1d122017-10-09 14:07:42 -04001808#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
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 void joinNonEmptyArg(const SkRect& r)
1815
Cary Clarkab2621d2018-01-30 10:08:57 -05001816#In Join
1817#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001818Sets Rect to the union of itself and r.
1819
1820Asserts if r is empty and SK_DEBUG is defined.
1821If Rect is empty, sets Rect to r.
1822
1823May produce incorrect results if r is empty.
1824
1825#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001826
1827#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001828#Description
1829Since Rect is not sorted, first result is copy of toJoin.
1830##
Cary Clark154beea2017-10-26 07:58:48 -04001831 SkRect rect = { 10, 100, 15, 0};
1832 SkRect sorted = rect.makeSorted();
1833 SkRect toJoin = { 50, 60, 55, 65 };
1834 rect.joinNonEmptyArg(toJoin);
1835 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1836 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001837 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1838#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001839rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001840sorted: 10, 0, 55, 100
1841##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001842##
1843
Cary Clark7fc1d122017-10-09 14:07:42 -04001844#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001845
1846##
1847
Cary Clark7fc1d122017-10-09 14:07:42 -04001848# ------------------------------------------------------------------------------
1849
Cary Clarkbc5697d2017-10-04 14:31:33 -04001850#Method void joinPossiblyEmptyRect(const SkRect& r)
1851
Cary Clarkab2621d2018-01-30 10:08:57 -05001852#In Join
1853#Line # sets to union of bounds. Skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001854Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001855
Cary Clark7fc1d122017-10-09 14:07:42 -04001856May produce incorrect results if Rect or r is empty.
1857
1858#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001859
1860#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001861#Description
1862Since Rect is not sorted, first result is not useful.
1863##
Cary Clark154beea2017-10-26 07:58:48 -04001864 SkRect rect = { 10, 100, 15, 0};
1865 SkRect sorted = rect.makeSorted();
1866 SkRect toJoin = { 50, 60, 55, 65 };
1867 rect.joinPossiblyEmptyRect(toJoin);
1868 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1869 sorted.joinPossiblyEmptyRect(toJoin);
1870 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001871#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001872rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001873sorted: 10, 0, 55, 100
1874##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001875##
1876
Cary Clark7fc1d122017-10-09 14:07:42 -04001877#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001878
1879##
1880
Cary Clark2dc84ad2018-01-26 12:56:22 -05001881#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001882
Cary Clark2dc84ad2018-01-26 12:56:22 -05001883#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001884#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885
Cary Clark4855f782018-02-06 09:41:53 -05001886#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001887
Cary Clarkbc5697d2017-10-04 14:31:33 -04001888#Method void round(SkIRect* dst) const
1889
Cary Clarkab2621d2018-01-30 10:08:57 -05001890#In Rounding
1891#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001892Sets IRect by adding 0.5 and discarding the fractional portion of Rect
1893members, using
1894#Formula
1895(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1896 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
1897##
1898.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001899
Cary Clark7fc1d122017-10-09 14:07:42 -04001900#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001901
1902#Example
Cary Clark154beea2017-10-26 07:58:48 -04001903 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1904 SkIRect round;
1905 rect.round(&round);
1906 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001907#StdOut
1908round: 31, 51, 41, 61
1909##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001910##
1911
Cary Clark7fc1d122017-10-09 14:07:42 -04001912#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001913
1914##
1915
Cary Clark7fc1d122017-10-09 14:07:42 -04001916# ------------------------------------------------------------------------------
1917
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918#Method void roundOut(SkIRect* dst) const
1919
Cary Clarkab2621d2018-01-30 10:08:57 -05001920#In Rounding
1921#Line # sets members to nearest integer value away from opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001922Sets IRect by discarding the fractional portion of fLeft and fTop; and
1923rounding up fRight and FBottom, using
1924#Formula
1925(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1926 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1927##
1928.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001929
Cary Clark7fc1d122017-10-09 14:07:42 -04001930#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001931
1932#Example
Cary Clark154beea2017-10-26 07:58:48 -04001933 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1934 SkIRect round;
1935 rect.roundOut(&round);
1936 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001937#StdOut
1938round: 30, 50, 41, 61
1939##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001940##
1941
Cary Clark7fc1d122017-10-09 14:07:42 -04001942#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001943
1944##
1945
Cary Clark7fc1d122017-10-09 14:07:42 -04001946# ------------------------------------------------------------------------------
1947
Cary Clarkbc5697d2017-10-04 14:31:33 -04001948#Method void roundOut(SkRect* dst) const
1949
Cary Clarkab2621d2018-01-30 10:08:57 -05001950#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04001951Sets Rect by discarding the fractional portion of fLeft and fTop; and
1952rounding up fRight and FBottom, using
1953#Formula
1954(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1955 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1956##
1957.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001958
Cary Clark7fc1d122017-10-09 14:07:42 -04001959#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001960
1961#Example
Cary Clark154beea2017-10-26 07:58:48 -04001962 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1963 SkRect round;
1964 rect.roundOut(&round);
1965 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001966#StdOut
1967round: 30, 50, 41, 61
1968##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001969##
1970
Cary Clark7fc1d122017-10-09 14:07:42 -04001971#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001972
1973##
1974
Cary Clark7fc1d122017-10-09 14:07:42 -04001975# ------------------------------------------------------------------------------
1976
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977#Method void roundIn(SkIRect* dst) const
1978
Cary Clarkab2621d2018-01-30 10:08:57 -05001979#In Rounding
1980#Line # sets members to nearest integer value towards opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001981Sets Rect by rounding up fLeft and fTop; and
1982discarding the fractional portion of fRight and FBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04001983
Cary Clark7fc1d122017-10-09 14:07:42 -04001984#Formula
1985(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1986 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
1987##
1988.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001989
Cary Clark7fc1d122017-10-09 14:07:42 -04001990#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001991
1992#Example
Cary Clark154beea2017-10-26 07:58:48 -04001993 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1994 SkIRect round;
1995 rect.roundIn(&round);
1996 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001997#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001998round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04001999##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002000##
2001
Cary Clark7fc1d122017-10-09 14:07:42 -04002002#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002003
2004##
2005
Cary Clark7fc1d122017-10-09 14:07:42 -04002006# ------------------------------------------------------------------------------
2007
Cary Clarkbc5697d2017-10-04 14:31:33 -04002008#Method SkIRect round() const
2009
Cary Clarkab2621d2018-01-30 10:08:57 -05002010#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002011Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2012members, using
2013#Formula
2014(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2015 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2016##
2017.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002018
Cary Clark7fc1d122017-10-09 14:07:42 -04002019#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002020
2021#Example
Cary Clark154beea2017-10-26 07:58:48 -04002022 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2023 SkIRect round = rect.round();
2024 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002025#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002026round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002027##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002028##
2029
Cary Clark7fc1d122017-10-09 14:07:42 -04002030#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002031
2032##
2033
Cary Clark7fc1d122017-10-09 14:07:42 -04002034# ------------------------------------------------------------------------------
2035
Cary Clarkbc5697d2017-10-04 14:31:33 -04002036#Method SkIRect roundOut() const
2037
Cary Clarkab2621d2018-01-30 10:08:57 -05002038#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002039Sets IRect by discarding the fractional portion of fLeft and fTop; and
2040rounding up fRight and FBottom, using
2041#Formula
2042(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2043 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2044##
2045.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002046
Cary Clark7fc1d122017-10-09 14:07:42 -04002047#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002048
2049#Example
Cary Clark154beea2017-10-26 07:58:48 -04002050 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2051 SkIRect round = rect.roundOut();
2052 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002053#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002054round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002055##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002056##
2057
Cary Clark7fc1d122017-10-09 14:07:42 -04002058#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002059
2060##
2061
Cary Clark2dc84ad2018-01-26 12:56:22 -05002062#Subtopic Rounding ##
2063
2064#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002065#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002066
Cary Clark4855f782018-02-06 09:41:53 -05002067#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04002068
2069# ------------------------------------------------------------------------------
2070
Cary Clarkbc5697d2017-10-04 14:31:33 -04002071#Method void sort()
2072
Cary Clarkab2621d2018-01-30 10:08:57 -05002073#In Sorting
2074#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002075Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2076fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2077and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002078
2079#Example
Cary Clark154beea2017-10-26 07:58:48 -04002080 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2081 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2082 rect.sort();
2083 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002084#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002085rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002086sorted: 20.5, 10.5, 30.5, 50.5
2087##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002088##
2089
Cary Clark2dc84ad2018-01-26 12:56:22 -05002090#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002091
2092##
2093
Cary Clark7fc1d122017-10-09 14:07:42 -04002094# ------------------------------------------------------------------------------
2095
Cary Clarkbc5697d2017-10-04 14:31:33 -04002096#Method SkRect makeSorted() const
2097
Cary Clarkab2621d2018-01-30 10:08:57 -05002098#In Sorting
Cary Clark4855f782018-02-06 09:41:53 -05002099#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -05002100#Line # constructs, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002101Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2102with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2103and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104
Cary Clark7fc1d122017-10-09 14:07:42 -04002105#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002106
2107#Example
Cary Clark154beea2017-10-26 07:58:48 -04002108 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2109 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2110 SkRect sort = rect.makeSorted();
2111 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002112#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002113rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002114sorted: 20.5, 10.5, 30.5, 50.5
2115##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002116##
2117
Cary Clark2dc84ad2018-01-26 12:56:22 -05002118#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119
2120##
2121
Cary Clark2dc84ad2018-01-26 12:56:22 -05002122#Subtopic Sorting ##
2123
Cary Clark7fc1d122017-10-09 14:07:42 -04002124# ------------------------------------------------------------------------------
2125
Cary Clarkbc5697d2017-10-04 14:31:33 -04002126#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002127#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002128#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002129Returns pointer to first Scalar in Rect, to treat it as an array with four
2130entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002131
Cary Clark7fc1d122017-10-09 14:07:42 -04002132#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002133
2134#Example
Cary Clark154beea2017-10-26 07:58:48 -04002135 SkRect rect = {7, 11, 13, 17};
2136SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2137#StdOut
2138rect.asScalars() == &rect.fLeft
2139##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002140##
2141
Cary Clark7fc1d122017-10-09 14:07:42 -04002142#SeeAlso toQuad
2143
Cary Clarkbc5697d2017-10-04 14:31:33 -04002144##
2145
Cary Clark7fc1d122017-10-09 14:07:42 -04002146# ------------------------------------------------------------------------------
2147
Cary Clarkbc5697d2017-10-04 14:31:33 -04002148#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002149#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002150#Line # sends text representation to standard output using floats ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002151Writes text representation of Rect to standard output. Set asHex to true to
2152generate exact binary representations of floating point numbers.
2153
2154#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002155
2156#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002157 SkRect rect = {20, 30, 40, 50};
2158 for (bool dumpAsHex : { false, true } ) {
2159 rect.dump(dumpAsHex);
2160 SkDebugf("\n");
2161 }
2162#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002163SkRect::MakeLTRB(20, 30, 40, 50);
2164
2165SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2166 SkBits2Float(0x41f00000), /* 30.000000 */
2167 SkBits2Float(0x42200000), /* 40.000000 */
2168 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002169##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002170##
2171
Cary Clark7fc1d122017-10-09 14:07:42 -04002172#SeeAlso dumpHex
2173
Cary Clarkbc5697d2017-10-04 14:31:33 -04002174##
2175
Cary Clark7fc1d122017-10-09 14:07:42 -04002176# ------------------------------------------------------------------------------
2177
Cary Clarkbc5697d2017-10-04 14:31:33 -04002178#Method void dump() const
2179
Cary Clark7fc1d122017-10-09 14:07:42 -04002180Writes text representation of Rect to standard output. The representation may be
2181directly compiled as C++ code. Floating point values are written
2182with limited precision; it may not be possible to reconstruct original Rect
2183from output.
2184
Cary Clarkbc5697d2017-10-04 14:31:33 -04002185#Example
Cary Clark154beea2017-10-26 07:58:48 -04002186SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2187rect.dump();
2188SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2189SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002190#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002191SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002192rect is not equal to copy
2193##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002194##
2195
Cary Clark7fc1d122017-10-09 14:07:42 -04002196#SeeAlso dumpHex
2197
Cary Clarkbc5697d2017-10-04 14:31:33 -04002198##
2199
Cary Clark7fc1d122017-10-09 14:07:42 -04002200# ------------------------------------------------------------------------------
2201
Cary Clarkbc5697d2017-10-04 14:31:33 -04002202#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002203#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002204#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002205Writes text representation of Rect to standard output. The representation may be
2206directly compiled as C++ code. Floating point values are written
2207in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2208original Rect.
2209
2210Use instead of dump() when submitting
2211#A bug reports against Skia # http://bug.skia.org ##
2212.
2213
Cary Clarkbc5697d2017-10-04 14:31:33 -04002214#Example
Cary Clark154beea2017-10-26 07:58:48 -04002215 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2216rect.dumpHex();
2217SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2218 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2219 SkBits2Float(0x40266666), /* 2.600000 */
2220 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002221SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2222#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002223SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2224 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2225 SkBits2Float(0x40266666), /* 2.600000 */
2226 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002227rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002228##
Cary Clark7fc1d122017-10-09 14:07:42 -04002229##
2230
2231#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002232
2233##
2234
Cary Clark0c95aab2018-01-08 16:20:59 -05002235#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05002236#Deprecated
2237##
2238
Cary Clarkbc5697d2017-10-04 14:31:33 -04002239#Struct SkRect ##
2240
2241#Topic Rect ##