blob: 73225fcc88f00fc324f56fbca90e6a08bc7f767c [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Rect
2#Alias Rects
3#Alias Rect_Reference
4
5#Struct SkRect
6
Cary Clark7fc1d122017-10-09 14:07:42 -04007SkRect holds four SkScalar coordinates describing the upper and
Cary Clark682c58d2018-05-16 07:07:07 -04008lower bounds of a rectangle. SkRect may be created from outer bounds or
Cary Clark7fc1d122017-10-09 14:07:42 -04009from position, width, and height. SkRect describes an area; if its right
10is less than or equal to its left, or if its bottom is less than or equal to
11its top, it is considered empty.
12
13# move to topic about MakeIWH and friends
14SkRect can be constructed from int values to avoid compiler warnings that
15integer input cannot convert to SkScalar without loss of precision.
16
Cary Clark682c58d2018-05-16 07:07:07 -040017#Subtopic Overview
18#Populate
19##
20
Cary Clark4855f782018-02-06 09:41:53 -050021#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050022#Populate
Cary Clark682c58d2018-05-16 07:07:07 -040023##
Cary Clarkbc5697d2017-10-04 14:31:33 -040024
Cary Clark4855f782018-02-06 09:41:53 -050025#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -050026#Populate
27##
Cary Clarkbc5697d2017-10-04 14:31:33 -040028
Cary Clark4855f782018-02-06 09:41:53 -050029#Subtopic Member
Cary Clark08895c42018-02-01 09:37:32 -050030#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040031
32#Member SkScalar fLeft
Cary Clark08895c42018-02-01 09:37:32 -050033#Line # smaller x-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040034May contain any value, including infinities and NaN. The smaller of the
35horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040036##
37
38#Member SkScalar fTop
Cary Clark08895c42018-02-01 09:37:32 -050039#Line # smaller y-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040040May contain any value, including infinities and NaN. The smaller of the
41vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040042##
43
44#Member SkScalar fRight
Cary Clark08895c42018-02-01 09:37:32 -050045#Line # larger x-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040046May contain any value, including infinities and NaN. The larger of the
47horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040048##
49
50#Member SkScalar fBottom
Cary Clark08895c42018-02-01 09:37:32 -050051#Line # larger y-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040052May contain any value, including infinities and NaN. The larger of the
53vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040054##
55
Cary Clark4855f782018-02-06 09:41:53 -050056#Subtopic Member ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050057
Cary Clark4855f782018-02-06 09:41:53 -050058#Subtopic Constructor
59#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -050060
Cary Clarkbc5697d2017-10-04 14:31:33 -040061# ------------------------------------------------------------------------------
62
63#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
64
Cary Clark4855f782018-02-06 09:41:53 -050065#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -050066#Line # constructs from bounds of (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040067Returns constructed Rect set to (0, 0, 0, 0).
68Many other rectangles are empty; if left is equal to or greater than right,
69or if top is equal to or greater than bottom. Setting all members to zero
70is a convenience, but does not designate a special empty rectangle.
Cary Clark682c58d2018-05-16 07:07:07 -040071
Cary Clark7fc1d122017-10-09 14:07:42 -040072#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040073
74#Example
Cary Clark154beea2017-10-26 07:58:48 -040075 SkRect rect = SkRect::MakeEmpty();
76 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
77 rect.offset(10, 10);
78 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
79 rect.inset(10, 10);
80 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
81 rect.outset(20, 20);
82 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
83#StdOut
84MakeEmpty isEmpty: true
85offset rect isEmpty: true
86inset rect isEmpty: true
87outset rect isEmpty: false
88##
Cary Clarkbc5697d2017-10-04 14:31:33 -040089##
90
Mike Reed274218e2018-01-08 15:05:02 -050091#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -040092
93##
94
95# ------------------------------------------------------------------------------
96
97#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -040098
Cary Clark4855f782018-02-06 09:41:53 -050099#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500100#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400101Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
102validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400103
Cary Clark7fc1d122017-10-09 14:07:42 -0400104Passing integer values may generate a compiler warning since Rect cannot
105represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
106
107#Param w SkScalar width of constructed Rect ##
108#Param h SkScalar height of constructed Rect ##
109
110#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400111
112#Example
Cary Clark154beea2017-10-26 07:58:48 -0400113 SkRect rect1 = SkRect::MakeWH(25, 35);
114 SkRect rect2 = SkRect::MakeIWH(25, 35);
115 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
116 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
117 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400118 "" : "not ");
119#StdOut
120all equal
121##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400122##
123
Cary Clark7fc1d122017-10-09 14:07:42 -0400124#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400125
126##
127
128# ------------------------------------------------------------------------------
129
130#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
131
Cary Clark4855f782018-02-06 09:41:53 -0500132#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500133#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400134Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
135input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400136
Cary Clark7fc1d122017-10-09 14:07:42 -0400137Use to avoid a compiler warning that input may lose precision when stored.
138Use SkIRect for an exact integer rectangle.
139
140#Param w integer width of constructed Rect ##
141#Param h integer height of constructed Rect ##
142
143#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400144
145#Example
Cary Clark154beea2017-10-26 07:58:48 -0400146 SkIRect i_rect = SkIRect::MakeWH(25, 35);
147 SkRect f_rect = SkRect::MakeIWH(25, 35);
148 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
149 i_rect = SkIRect::MakeWH(125000111, 0);
150 f_rect = SkRect::MakeIWH(125000111, 0);
151 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400152#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400153i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400154i_rect width: 125000111 f_rect width:125000112
155##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400156##
157
Cary Clark7fc1d122017-10-09 14:07:42 -0400158#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400159
160##
161
162# ------------------------------------------------------------------------------
163
Cary Clark884dd7d2017-10-11 10:37:52 -0400164#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400165
Cary Clark4855f782018-02-06 09:41:53 -0500166#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500167#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400168Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
169validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400170
Cary Clark7fc1d122017-10-09 14:07:42 -0400171#Param size SkScalar values for Rect width and height ##
172
173#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400174
175#Example
Cary Clark154beea2017-10-26 07:58:48 -0400176 SkSize size = {25.5f, 35.5f};
177 SkRect rect = SkRect::MakeSize(size);
178 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
179 SkISize floor = size.toFloor();
180 rect = SkRect::MakeSize(SkSize::Make(floor));
181 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400182#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400183rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400184floor width: 25 height: 35
185##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400186##
187
Cary Clark7fc1d122017-10-09 14:07:42 -0400188#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400189
190##
191
192# ------------------------------------------------------------------------------
193
194#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
195 SkScalar b)
Cary Clark4855f782018-02-06 09:41:53 -0500196#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500197#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400198
Cary Clark7fc1d122017-10-09 14:07:42 -0400199Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
200result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400201
Cary Clark7fc1d122017-10-09 14:07:42 -0400202#Param l SkScalar stored in fLeft ##
203#Param t SkScalar stored in fTop ##
204#Param r SkScalar stored in fRight ##
205#Param b SkScalar stored in fBottom ##
206
207#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400208
209#Example
Cary Clark154beea2017-10-26 07:58:48 -0400210 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
211 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
212 rect.bottom(), rect.isEmpty() ? "true" : "false");
213 rect.sort();
214 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
215 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400216#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400217rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400218rect: 5, 25, 15, 35 isEmpty: false
219##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400220##
221
Cary Clark7fc1d122017-10-09 14:07:42 -0400222#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400223
224##
225
226# ------------------------------------------------------------------------------
227
Cary Clark884dd7d2017-10-11 10:37:52 -0400228#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400229
Cary Clark4855f782018-02-06 09:41:53 -0500230#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500231#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400232Returns constructed Rect set to
233#Formula
234(x, y, x + w, y + h)
235##
236. Does not validate input;
237w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400238
Cary Clark7fc1d122017-10-09 14:07:42 -0400239#Param x stored in fLeft ##
240#Param y stored in fTop ##
241#Param w added to x and stored in fRight ##
242#Param h added to y and stored in fBottom ##
243
Cary Clark884dd7d2017-10-11 10:37:52 -0400244#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400245
246#Example
Cary Clark154beea2017-10-26 07:58:48 -0400247 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
248 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
249 rect.bottom(), rect.isEmpty() ? "true" : "false");
250 rect.sort();
251 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
252 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400253#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400254rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400255rect: -10, 35, 5, 60 isEmpty: false
256##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400257##
258
Cary Clark7fc1d122017-10-09 14:07:42 -0400259#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400260
261##
262
263# ------------------------------------------------------------------------------
264
265#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
Cary Clark7fc1d122017-10-09 14:07:42 -0400266#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400267##
268
Cary Clarkbc5697d2017-10-04 14:31:33 -0400269# ------------------------------------------------------------------------------
270
271#Method static SkRect Make(const SkISize& size)
272
Cary Clark4855f782018-02-06 09:41:53 -0500273#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500274#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark682c58d2018-05-16 07:07:07 -0400275Returns constructed IRect set to (0, 0, size.width(), size.height()).
Cary Clark7fc1d122017-10-09 14:07:42 -0400276Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400277
Cary Clark7fc1d122017-10-09 14:07:42 -0400278#Param size integer values for Rect width and height ##
279
280#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400281
282#Example
Cary Clark154beea2017-10-26 07:58:48 -0400283 SkRect rect1 = SkRect::MakeSize({2, 35});
284 SkRect rect2 = SkRect::MakeIWH(2, 35);
285 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400286#StdOut
287rect1 == rect2
288##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400289##
290
Cary Clark7fc1d122017-10-09 14:07:42 -0400291#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400292
293##
294
295# ------------------------------------------------------------------------------
296
297#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
298
Cary Clark4855f782018-02-06 09:41:53 -0500299#In Constructor
Cary Clark7fc1d122017-10-09 14:07:42 -0400300Returns constructed IRect set to irect, promoting integers to Scalar.
301Does not validate input; fLeft may be greater than fRight, fTop may be greater
302than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400303
Cary Clark7fc1d122017-10-09 14:07:42 -0400304#Param irect integer unsorted bounds ##
305
306#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400307
308#Example
Cary Clark154beea2017-10-26 07:58:48 -0400309 SkIRect i_rect1 = {2, 35, 22, 53};
310 SkRect f_rect = SkRect::Make(i_rect1);
311 f_rect.offset(0.49f, 0.49f);
312 SkIRect i_rect2;
313 f_rect.round(&i_rect2);
314 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400315##
316
Cary Clark7fc1d122017-10-09 14:07:42 -0400317#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400318
319##
320
Cary Clark4855f782018-02-06 09:41:53 -0500321#Subtopic Constructor ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500322
Cary Clark4855f782018-02-06 09:41:53 -0500323#Subtopic Property
324#Line # member values, center, validity ##
325#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500326
Cary Clarkbc5697d2017-10-04 14:31:33 -0400327# ------------------------------------------------------------------------------
328
329#Method bool isEmpty() const
330
Cary Clark4855f782018-02-06 09:41:53 -0500331#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500332#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400333Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
334to or greater than fBottom. Call sort() to reverse rectangles with negative
335width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400336
Cary Clark7fc1d122017-10-09 14:07:42 -0400337#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400338
339#Example
Cary Clark154beea2017-10-26 07:58:48 -0400340 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
341 for (auto rect : tests) {
342 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
343 rect.bottom(), rect.isEmpty() ? "" : " not");
344 rect.sort();
345 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
346 rect.bottom(), rect.isEmpty() ? "" : " not");
347 }
348#StdOut
349rect: {20, 40, 10, 50} is empty
350sorted: {10, 40, 20, 50} is not empty
351rect: {20, 40, 20, 50} is empty
352sorted: {20, 40, 20, 50} is empty
353##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400354##
355
Cary Clark7fc1d122017-10-09 14:07:42 -0400356#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400357
358##
359
360# ------------------------------------------------------------------------------
361
362#Method bool isSorted() const
363
Cary Clark4855f782018-02-06 09:41:53 -0500364#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500365#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400366Returns true if fLeft is equal to or less than fRight, or if fTop is equal
367to or less than fBottom. Call sort() to reverse rectangles with negative
368width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400369
Cary Clark7fc1d122017-10-09 14:07:42 -0400370#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400371
372#Example
Cary Clark154beea2017-10-26 07:58:48 -0400373 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
374 for (auto rect : tests) {
375 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
376 rect.bottom(), rect.isSorted() ? "" : " not");
377 rect.sort();
378 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
379 rect.bottom(), rect.isSorted() ? "" : " not");
380 }
381#StdOut
382rect: {20, 40, 10, 50} is not sorted
383sorted: {10, 40, 20, 50} is sorted
384rect: {20, 40, 20, 50} is sorted
385sorted: {20, 40, 20, 50} is sorted
386##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400387##
388
Cary Clark7fc1d122017-10-09 14:07:42 -0400389#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400390
391##
392
393# ------------------------------------------------------------------------------
394
Cary Clarkbc5697d2017-10-04 14:31:33 -0400395#Method bool isFinite() const
396
Cary Clark4855f782018-02-06 09:41:53 -0500397#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500398#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400399Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
Cary Clark682c58d2018-05-16 07:07:07 -0400400and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400401
Cary Clark7fc1d122017-10-09 14:07:42 -0400402#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400403
404#Example
Mike Reed274218e2018-01-08 15:05:02 -0500405SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400406 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
407 SkDebugf("large width %g\n", largest.width());
408 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
409 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
410#StdOut
411largest is finite: true
412large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400413widest is finite: false
414##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400415##
416
Cary Clark7fc1d122017-10-09 14:07:42 -0400417#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400418
419##
420
421# ------------------------------------------------------------------------------
422
423#Method SkScalar x() const
424
Cary Clark4855f782018-02-06 09:41:53 -0500425#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500426#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400427Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
428Call sort() to reverse fLeft and fRight if needed.
429
430#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400431
432#Example
Cary Clark154beea2017-10-26 07:58:48 -0400433 SkRect unsorted = { 15, 5, 10, 25 };
434 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
435 SkRect sorted = unsorted.makeSorted();
436 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400437#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400438unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400439sorted.fLeft: 10 sorted.x(): 10
440##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400441##
442
Cary Clark7fc1d122017-10-09 14:07:42 -0400443#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400444
445##
446
447# ------------------------------------------------------------------------------
448
449#Method SkScalar y() const
450
Cary Clark4855f782018-02-06 09:41:53 -0500451#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500452#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400453Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
454and sort() to reverse fTop and fBottom if needed.
455
456#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400457
458#Example
Cary Clark154beea2017-10-26 07:58:48 -0400459 SkRect unsorted = { 15, 25, 10, 5 };
460 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
461 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400462 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
463#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400464unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400465sorted.fTop: 5 sorted.y(): 5
466##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400467##
468
Cary Clark7fc1d122017-10-09 14:07:42 -0400469#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400470
471##
472
473# ------------------------------------------------------------------------------
474
475#Method SkScalar left() const
476
Cary Clark4855f782018-02-06 09:41:53 -0500477#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500478#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400479Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
480Call sort() to reverse fLeft and fRight if needed.
481
482#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400483
484#Example
Cary Clark154beea2017-10-26 07:58:48 -0400485 SkRect unsorted = { 15, 5, 10, 25 };
486 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
487 SkRect sorted = unsorted.makeSorted();
488 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400489#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400490unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400491sorted.fLeft: 10 sorted.left(): 10
492##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400493##
494
Cary Clark7fc1d122017-10-09 14:07:42 -0400495#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400496
497##
498
499# ------------------------------------------------------------------------------
500
501#Method SkScalar top() const
502
Cary Clark4855f782018-02-06 09:41:53 -0500503#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500504#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400505Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
506and sort() to reverse fTop and fBottom if needed.
507
508#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400509
510#Example
Cary Clark154beea2017-10-26 07:58:48 -0400511 SkRect unsorted = { 15, 25, 10, 5 };
512 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
513 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400514 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
515#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400516unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400517sorted.fTop: 5 sorted.top(): 5
518##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400519##
520
Cary Clark7fc1d122017-10-09 14:07:42 -0400521#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400522
523##
524
525# ------------------------------------------------------------------------------
526
527#Method SkScalar right() const
528
Cary Clark4855f782018-02-06 09:41:53 -0500529#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500530#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400531Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
532Call sort() to reverse fLeft and fRight if needed.
533
534#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400535
536#Example
Cary Clark154beea2017-10-26 07:58:48 -0400537 SkRect unsorted = { 15, 25, 10, 5 };
538 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
539 SkRect sorted = unsorted.makeSorted();
540 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400541#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400542unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400543sorted.fRight: 15 sorted.right(): 15
544##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400545##
546
Cary Clark7fc1d122017-10-09 14:07:42 -0400547#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400548
549##
550
551# ------------------------------------------------------------------------------
552
553#Method SkScalar bottom() const
554
Cary Clark4855f782018-02-06 09:41:53 -0500555#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500556#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400557Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
558and sort() to reverse fTop and fBottom if needed.
559
560#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400561
562#Example
Cary Clark154beea2017-10-26 07:58:48 -0400563 SkRect unsorted = { 15, 25, 10, 5 };
564 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
565 SkRect sorted = unsorted.makeSorted();
566 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400567#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400568unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400569sorted.fBottom: 25 sorted.bottom(): 25
570##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400571##
572
Cary Clark7fc1d122017-10-09 14:07:42 -0400573#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400574
575##
576
577# ------------------------------------------------------------------------------
578
579#Method SkScalar width() const
580
Cary Clark4855f782018-02-06 09:41:53 -0500581#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500582#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400583Returns span on the x-axis. This does not check if Rect is sorted, or if
584result fits in 32-bit float; result may be negative or infinity.
585
586#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400587
588#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400589#Description
590Compare with SkIRect::width() example.
591##
Cary Clark154beea2017-10-26 07:58:48 -0400592 SkRect unsorted = { 15, 25, 10, 5 };
593 SkDebugf("unsorted width: %g\n", unsorted.width());
594 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
595 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400596#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400597unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400598large width: 4294967296
599##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400600##
601
Cary Clark7fc1d122017-10-09 14:07:42 -0400602#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400603
604##
605
606# ------------------------------------------------------------------------------
607
608#Method SkScalar height() const
609
Cary Clark4855f782018-02-06 09:41:53 -0500610#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500611#Line # returns span in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400612Returns span on the y-axis. This does not check if IRect is sorted, or if
613result fits in 32-bit float; result may be negative or infinity.
614
615#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400616
617#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400618#Description
619Compare with SkIRect::height() example.
620##
Cary Clark154beea2017-10-26 07:58:48 -0400621 SkRect unsorted = { 15, 25, 10, 20 };
622 SkDebugf("unsorted height: %g\n", unsorted.height());
623 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
624 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400625#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400626unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400627large height: 4294967296
628##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400629##
630
Cary Clark7fc1d122017-10-09 14:07:42 -0400631#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400632
633##
634
635# ------------------------------------------------------------------------------
636
637#Method SkScalar centerX() const
638
Cary Clark4855f782018-02-06 09:41:53 -0500639#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500640#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400641Returns average of left edge and right edge. Result does not change if Rect
642is sorted. Result may overflow to infinity if Rect is far from the origin.
643
644#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400645
646#Example
Cary Clark154beea2017-10-26 07:58:48 -0400647 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
648 for (auto rect : tests) {
649 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
650 rect.sort();
651 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
652 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400653#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400654left: 20 right: 41 centerX: 30.5
655left: 20 right: 41 centerX: 30.5
656left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400657left: -41 right: -20 centerX: -30.5
658##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400659##
660
Cary Clark47d7dae2018-04-11 16:54:35 -0400661#SeeAlso centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400662
663##
664
665# ------------------------------------------------------------------------------
666
667#Method SkScalar centerY() const
668
Cary Clark4855f782018-02-06 09:41:53 -0500669#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500670#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400671Returns average of top edge and bottom edge. Result does not change if Rect
672is sorted. Result may overflow to infinity if Rect is far from the origin.
673
674#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400675
676#Example
Cary Clark154beea2017-10-26 07:58:48 -0400677 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
678 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
679 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400680#StdOut
681left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
682##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400683##
684
Cary Clark47d7dae2018-04-11 16:54:35 -0400685#SeeAlso centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400686
687##
688
Cary Clark4855f782018-02-06 09:41:53 -0500689#Subtopic Property ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500690
Cary Clark4855f782018-02-06 09:41:53 -0500691#Subtopic Operator
Cary Clark2dc84ad2018-01-26 12:56:22 -0500692
Cary Clark4855f782018-02-06 09:41:53 -0500693#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500694
Cary Clarkbc5697d2017-10-04 14:31:33 -0400695# ------------------------------------------------------------------------------
696
Cary Clark884dd7d2017-10-11 10:37:52 -0400697#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400698
Cary Clark4855f782018-02-06 09:41:53 -0500699#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500700#Line # returns true if members are equal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400701Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
Cary Clark7fc1d122017-10-09 14:07:42 -0400702equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400703
Cary Clark7fc1d122017-10-09 14:07:42 -0400704a and b are not equal if either contain NaN. a and b are equal if members
705contain zeroes width different signs.
706
707#Param a Rect to compare ##
708#Param b Rect to compare ##
709
710#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400711
712#Example
Cary Clark154beea2017-10-26 07:58:48 -0400713 auto debugster = [](const SkRect& test) -> void {
714 SkRect negZero = {-0.0f, -0.0f, 2, 2};
715 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
716 test.fLeft, test.fTop, test.fRight, test.fBottom,
717 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
718 test == negZero ? '=' : '!',
719 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
720 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
721 "and are" : "yet are not");
722 };
723 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
724 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
725 for (auto rect : tests) {
726 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400727 }
Cary Clark154beea2017-10-26 07:58:48 -0400728#StdOut
729tests are equal
730{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
731{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark682c58d2018-05-16 07:07:07 -0400732{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400733##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400734##
735
Cary Clark7fc1d122017-10-09 14:07:42 -0400736#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400737
738##
739
740# ------------------------------------------------------------------------------
741
Cary Clark884dd7d2017-10-11 10:37:52 -0400742#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400743
Cary Clark4855f782018-02-06 09:41:53 -0500744#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500745#Line # returns true if members are unequal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400746Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
Cary Clark7fc1d122017-10-09 14:07:42 -0400747equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400748
Cary Clark7fc1d122017-10-09 14:07:42 -0400749a and b are not equal if either contain NaN. a and b are equal if members
750contain zeroes width different signs.
751
752#Param a Rect to compare ##
753#Param b Rect to compare ##
754
755#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400756
757#Example
Cary Clark154beea2017-10-26 07:58:48 -0400758 SkRect test = {0, 0, 2, SK_ScalarNaN};
759 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
760#StdOut
Cary Clark682c58d2018-05-16 07:07:07 -0400761test with NaN is not equal to itself
Cary Clark7fc1d122017-10-09 14:07:42 -0400762##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400763##
764
Cary Clark7fc1d122017-10-09 14:07:42 -0400765#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400766
767##
768
Cary Clark4855f782018-02-06 09:41:53 -0500769#Subtopic Operator ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500770
771#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500772#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500773
Cary Clark4855f782018-02-06 09:41:53 -0500774#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500775
Cary Clarkbc5697d2017-10-04 14:31:33 -0400776# ------------------------------------------------------------------------------
777
778#Method void toQuad(SkPoint quad[4]) const
779
Cary Clarkab2621d2018-01-30 10:08:57 -0500780#In As_Points
781#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400782Returns four points in quad that enclose Rect ordered as: top-left, top-right,
Cary Clark682c58d2018-05-16 07:07:07 -0400783bottom-right, bottom-left.
Cary Clark7fc1d122017-10-09 14:07:42 -0400784
785#Private
Cary Clark682c58d2018-05-16 07:07:07 -0400786Consider adding param to control whether quad is clockwise or counterclockwise.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400787##
788
Cary Clark7fc1d122017-10-09 14:07:42 -0400789#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400790
791#Example
Cary Clark154beea2017-10-26 07:58:48 -0400792 SkRect rect = {1, 2, 3, 4};
793 SkPoint corners[4];
794 rect.toQuad(corners);
795 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
796 SkDebugf("corners:");
797 for (auto corner : corners) {
798 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
799 }
800 SkDebugf("\n");
801#StdOut
802rect: {1, 2, 3, 4}
Cary Clark682c58d2018-05-16 07:07:07 -0400803corners: {1, 2} {3, 2} {3, 4} {1, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400804##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400805##
806
Cary Clark7fc1d122017-10-09 14:07:42 -0400807#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400808
809##
810
811# ------------------------------------------------------------------------------
812
Cary Clark2dc84ad2018-01-26 12:56:22 -0500813#Method void setBounds(const SkPoint pts[], int count)
814
Cary Clarkab2621d2018-01-30 10:08:57 -0500815#In As_Points
816#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500817Sets to bounds of Point array with count entries. If count is zero or smaller,
818or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
819
820Result is either empty or sorted: fLeft is less than or equal to fRight, and
821fTop is less than or equal to fBottom.
822
823#Param pts Point array ##
824#Param count entries in array ##
825
826#Example
827 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
828 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
829 SkRect rect;
830 rect.setBounds(points, count);
831 if (count > 0) {
832 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
833 } else {
834 SkDebugf("%14s", " ");
835 }
836 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
837 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
838 }
839#StdOut
840 count: 0 rect: 0, 0, 0, 0
841added: 3, 4 count: 1 rect: 3, 4, 3, 4
842added: 1, 2 count: 2 rect: 1, 2, 3, 4
843added: 5, 6 count: 3 rect: 1, 2, 5, 6
844added: nan, 8 count: 4 rect: 0, 0, 0, 0
845##
846##
847
848#SeeAlso set setBoundsCheck SkPath::addPoly
849
850##
851
852# ------------------------------------------------------------------------------
853
854#Method bool setBoundsCheck(const SkPoint pts[], int count)
855
Cary Clarkab2621d2018-01-30 10:08:57 -0500856#In As_Points
857#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500858Sets to bounds of Point array with count entries. Returns false if count is
859zero or smaller, or if Point array contains an infinity or NaN; in these cases
860sets Rect to (0, 0, 0, 0).
861
862Result is either empty or sorted: fLeft is less than or equal to fRight, and
863fTop is less than or equal to fBottom.
864
865#Param pts Point array ##
866#Param count entries in array ##
867
868#Return true if all Point values are finite ##
869
870#Example
871 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
872 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
873 SkRect rect;
874 bool success = rect.setBoundsCheck(points, count);
875 if (count > 0) {
876 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
877 } else {
878 SkDebugf("%14s", " ");
879 }
880 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
881 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
882 }
883#StdOut
884 count: 0 rect: 0, 0, 0, 0 success: true
885added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
886added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
887added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
888added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
889##
890##
891
892#SeeAlso set setBounds SkPath::addPoly
893
894##
895
896#Subtopic As_Points ##
897
898#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500899#Line # replaces all values ##
Cary Clark4855f782018-02-06 09:41:53 -0500900#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500901
902# ------------------------------------------------------------------------------
903
Cary Clarkbc5697d2017-10-04 14:31:33 -0400904#Method void setEmpty()
905
Cary Clarkab2621d2018-01-30 10:08:57 -0500906#In Set
907#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400908Sets Rect to (0, 0, 0, 0).
909
910Many other rectangles are empty; if left is equal to or greater than right,
911or if top is equal to or greater than bottom. Setting all members to zero
912is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400913
914#Example
Cary Clark154beea2017-10-26 07:58:48 -0400915 SkRect rect = {3, 4, 1, 2};
916 for (int i = 0; i < 2; ++i) {
917 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
918 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
919 rect.setEmpty();
920 }
921#StdOut
922rect: {3, 4, 1, 2} is empty
923rect: {0, 0, 0, 0} is empty
924##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400925##
926
Cary Clark7fc1d122017-10-09 14:07:42 -0400927#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400928
929##
930
931# ------------------------------------------------------------------------------
932
933#Method void set(const SkIRect& src)
934
Cary Clarkab2621d2018-01-30 10:08:57 -0500935#In Set
936#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400937Sets Rect to src, promoting src members from integer to Scalar.
Cary Clark682c58d2018-05-16 07:07:07 -0400938Very large values in src may lose precision.
Cary Clark7fc1d122017-10-09 14:07:42 -0400939
940#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400941
942#Example
Cary Clark154beea2017-10-26 07:58:48 -0400943 SkIRect i_rect = {3, 4, 1, 2};
944 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
945 SkRect f_rect;
946 f_rect.set(i_rect);
947 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
948#StdOut
949i_rect: {3, 4, 1, 2}
950f_rect: {3, 4, 1, 2}
951##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400952##
953
Cary Clark7fc1d122017-10-09 14:07:42 -0400954#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400955
956##
957
958# ------------------------------------------------------------------------------
959
960#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
961
Cary Clarkab2621d2018-01-30 10:08:57 -0500962#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400963Sets Rect to (left, top, right, bottom).
964left and right are not sorted; left is not necessarily less than right.
965top and bottom are not sorted; top is not necessarily less than bottom.
966
967#Param left stored in fLeft ##
968#Param top stored in fTop ##
969#Param right stored in fRight ##
970#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400971
972#Example
Cary Clark154beea2017-10-26 07:58:48 -0400973 SkRect rect1 = {3, 4, 1, 2};
974 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
975 SkRect rect2;
976 rect2.set(3, 4, 1, 2);
977 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
978#StdOut
979rect1: {3, 4, 1, 2}
980rect2: {3, 4, 1, 2}
981##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400982##
983
Cary Clark7fc1d122017-10-09 14:07:42 -0400984#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400985
986##
987
988# ------------------------------------------------------------------------------
989
990#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
991
Cary Clarkab2621d2018-01-30 10:08:57 -0500992#In Set
993#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400994Sets Rect to (left, top, right, bottom).
995left and right are not sorted; left is not necessarily less than right.
996top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400997
Cary Clark7fc1d122017-10-09 14:07:42 -0400998#Param left stored in fLeft ##
999#Param top stored in fTop ##
1000#Param right stored in fRight ##
1001#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001002
1003#Example
Cary Clark154beea2017-10-26 07:58:48 -04001004 SkRect rect1 = {3, 4, 1, 2};
1005 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1006 SkRect rect2;
1007 rect2.setLTRB(3, 4, 1, 2);
1008 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1009#StdOut
1010rect1: {3, 4, 1, 2}
1011rect2: {3, 4, 1, 2}
1012##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001013##
1014
Cary Clark7fc1d122017-10-09 14:07:42 -04001015#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001016
1017##
1018
1019# ------------------------------------------------------------------------------
1020
Cary Clarkbc5697d2017-10-04 14:31:33 -04001021#Method void set(const SkPoint pts[], int count)
1022
Cary Clarkab2621d2018-01-30 10:08:57 -05001023#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001024Sets to bounds of Point array with count entries. If count is zero or smaller,
1025or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001026
Cary Clark7fc1d122017-10-09 14:07:42 -04001027Result is either empty or sorted: fLeft is less than or equal to fRight, and
1028fTop is less than or equal to fBottom.
1029
1030#Param pts Point array ##
1031#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001032
1033#Example
Cary Clark154beea2017-10-26 07:58:48 -04001034 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1035 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1036 SkRect rect;
1037 rect.set(points, count);
1038 if (count > 0) {
1039 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1040 } else {
1041 SkDebugf("%14s", " ");
1042 }
1043 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1044 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1045 }
1046#StdOut
1047 count: 0 rect: 0, 0, 0, 0
1048added: 3, 4 count: 1 rect: 3, 4, 3, 4
1049added: 1, 2 count: 2 rect: 1, 2, 3, 4
1050added: 5, 6 count: 3 rect: 1, 2, 5, 6
1051added: nan, 8 count: 4 rect: 0, 0, 0, 0
1052##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001053##
1054
Cary Clark7fc1d122017-10-09 14:07:42 -04001055#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001056
1057##
1058
1059# ------------------------------------------------------------------------------
1060
Cary Clarkbc5697d2017-10-04 14:31:33 -04001061#Method void set(const SkPoint& p0, const SkPoint& p1)
1062
Cary Clarkab2621d2018-01-30 10:08:57 -05001063#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001064Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1065sorted and may be empty. Does not check to see if values are finite.
1066
1067#Param p0 corner to include ##
1068#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001069
1070#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001071#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001072p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -04001073##
Cary Clark154beea2017-10-26 07:58:48 -04001074 SkPoint point1 = {SK_ScalarNaN, 8};
1075 SkPoint point2 = {3, 4};
1076 SkRect rect;
1077 rect.set(point1, point2);
1078 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1079 rect.set(point2, point1);
1080 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001081##
1082
Cary Clark7fc1d122017-10-09 14:07:42 -04001083#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001084
1085##
1086
1087# ------------------------------------------------------------------------------
1088
1089#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1090
Cary Clarkab2621d2018-01-30 10:08:57 -05001091#In Set
1092#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark682c58d2018-05-16 07:07:07 -04001093Sets Rect to
Cary Clark7fc1d122017-10-09 14:07:42 -04001094#Formula
1095(x, y, x + width, y + height)
1096##
1097. Does not validate input;
1098width or height may be negative.
1099
1100#Param x stored in fLeft ##
1101#Param y stored in fTop ##
1102#Param width added to x and stored in fRight ##
1103#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001104
1105#Example
Cary Clark154beea2017-10-26 07:58:48 -04001106 SkRect rect;
1107 rect.setXYWH(5, 35, -15, 25);
1108 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1109 rect.bottom(), rect.isEmpty() ? "true" : "false");
1110 rect.sort();
1111 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1112 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001113#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001114rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001115rect: -10, 35, 5, 60 isEmpty: false
1116##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001117##
1118
Cary Clark7fc1d122017-10-09 14:07:42 -04001119#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001120
1121##
1122
1123# ------------------------------------------------------------------------------
1124
1125#Method void setWH(SkScalar width, SkScalar height)
1126
Cary Clarkab2621d2018-01-30 10:08:57 -05001127#In Set
1128#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001129Sets Rect to (0, 0, width, height). Does not validate input;
1130width or height may be negative.
1131
1132#Param width stored in fRight ##
1133#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001134
1135#Example
Cary Clark154beea2017-10-26 07:58:48 -04001136 SkRect rect;
1137 rect.setWH(-15, 25);
1138 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1139 rect.bottom(), rect.isEmpty() ? "true" : "false");
1140 rect.sort();
1141 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1142 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001143#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001144rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001145rect: -15, 0, 0, 25 isEmpty: false
1146##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001147##
1148
Cary Clark7fc1d122017-10-09 14:07:42 -04001149#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001150
1151##
1152
Cary Clark2dc84ad2018-01-26 12:56:22 -05001153#Subtopic Set ##
1154
1155#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -04001156#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001157
Cary Clark4855f782018-02-06 09:41:53 -05001158#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001159
1160# ------------------------------------------------------------------------------
1161
1162#Method void iset(int left, int top, int right, int bottom)
1163
Cary Clarkab2621d2018-01-30 10:08:57 -05001164#In From_Integers
1165#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001166Sets Rect to (left, top, right, bottom).
1167All parameters are promoted from integer to Scalar.
1168left and right are not sorted; left is not necessarily less than right.
1169top and bottom are not sorted; top is not necessarily less than bottom.
1170
1171#Param left promoted to SkScalar and stored in fLeft ##
1172#Param top promoted to SkScalar and stored in fTop ##
1173#Param right promoted to SkScalar and stored in fRight ##
1174#Param bottom promoted to SkScalar and stored in fBottom ##
1175
1176#Example
1177 SkRect rect1 = {3, 4, 1, 2};
1178 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1179 SkRect rect2;
1180 rect2.iset(3, 4, 1, 2);
1181 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1182#StdOut
1183rect1: {3, 4, 1, 2}
1184rect2: {3, 4, 1, 2}
1185##
1186##
1187
1188#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1189
1190##
1191
1192# ------------------------------------------------------------------------------
1193
1194#Method void isetWH(int width, int height)
1195
Cary Clarkab2621d2018-01-30 10:08:57 -05001196#In From_Integers
1197#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001198Sets Rect to (0, 0, width, height).
1199width and height may be zero or negative. width and height are promoted from
1200integer to SkScalar, large values may lose precision.
1201
1202#Param width promoted to SkScalar and stored in fRight ##
1203#Param height promoted to SkScalar and stored in fBottom ##
1204
1205#Example
1206 SkRect rect1 = {0, 0, 1, 2};
1207 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1208 SkRect rect2;
1209 rect2.isetWH(1, 2);
1210 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1211#StdOut
1212rect1: {0, 0, 1, 2}
1213rect2: {0, 0, 1, 2}
1214##
1215##
1216
1217#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1218
1219##
1220
1221#Subtopic From_Integers ##
1222
1223#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001224#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001225
Cary Clark4855f782018-02-06 09:41:53 -05001226#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001227
Cary Clarkbc5697d2017-10-04 14:31:33 -04001228# ------------------------------------------------------------------------------
1229
Cary Clarkbc5697d2017-10-04 14:31:33 -04001230#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1231
Cary Clarkab2621d2018-01-30 10:08:57 -05001232#In Inset_Outset_Offset
1233#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001234Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001235
Cary Clark7fc1d122017-10-09 14:07:42 -04001236If dx is negative, Rect returned is moved to the left.
1237If dx is positive, Rect returned is moved to the right.
1238If dy is negative, Rect returned is moved upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001239If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001240
Cary Clark7fc1d122017-10-09 14:07:42 -04001241#Param dx added to fLeft and fRight ##
1242#Param dy added to fTop and fBottom ##
1243
1244#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001245
1246#Example
Cary Clark154beea2017-10-26 07:58:48 -04001247 SkRect rect = { 10, 50, 20, 60 };
1248 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1249 rect.bottom(), rect.isEmpty() ? "true" : "false");
1250 rect = rect.makeOffset(15, 32);
1251 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1252 rect.bottom(), rect.isEmpty() ? "true" : "false");
1253#StdOut
1254rect: 10, 50, 20, 60 isEmpty: false
1255rect: 25, 82, 35, 92 isEmpty: false
1256##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001257##
1258
Cary Clark7fc1d122017-10-09 14:07:42 -04001259#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001260
1261##
1262
1263# ------------------------------------------------------------------------------
1264
1265#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1266
Cary Clarkab2621d2018-01-30 10:08:57 -05001267#In Inset_Outset_Offset
1268#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001269Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001270
Cary Clark7fc1d122017-10-09 14:07:42 -04001271If dx is negative, Rect returned is wider.
1272If dx is positive, Rect returned is narrower.
1273If dy is negative, Rect returned is taller.
Cary Clark682c58d2018-05-16 07:07:07 -04001274If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001275
Cary Clark7fc1d122017-10-09 14:07:42 -04001276#Param dx added to fLeft and subtracted from fRight ##
1277#Param dy added to fTop and subtracted from fBottom ##
1278
1279#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001280
1281#Example
Cary Clark154beea2017-10-26 07:58:48 -04001282 SkRect rect = { 10, 50, 20, 60 };
1283 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1284 rect.bottom(), rect.isEmpty() ? "true" : "false");
1285 rect = rect.makeInset(15, 32);
1286 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1287 rect.bottom(), rect.isEmpty() ? "true" : "false");
1288#StdOut
1289rect: 10, 50, 20, 60 isEmpty: false
1290rect: 25, 82, 5, 28 isEmpty: true
1291##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001292##
1293
Cary Clark7fc1d122017-10-09 14:07:42 -04001294#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001295
1296##
1297
1298# ------------------------------------------------------------------------------
1299
1300#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1301
Cary Clarkab2621d2018-01-30 10:08:57 -05001302#In Inset_Outset_Offset
1303#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001304Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001305
Cary Clark7fc1d122017-10-09 14:07:42 -04001306If dx is negative, Rect returned is narrower.
1307If dx is positive, Rect returned is wider.
1308If dy is negative, Rect returned is shorter.
Cary Clark682c58d2018-05-16 07:07:07 -04001309If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001310
Cary Clark7fc1d122017-10-09 14:07:42 -04001311#Param dx subtracted to fLeft and added from fRight ##
1312#Param dy subtracted to fTop and added from fBottom ##
1313
1314#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001315
1316#Example
Cary Clark154beea2017-10-26 07:58:48 -04001317 SkRect rect = { 10, 50, 20, 60 };
1318 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1319 rect.bottom(), rect.isEmpty() ? "true" : "false");
1320 rect = rect.makeOutset(15, 32);
1321 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1322 rect.bottom(), rect.isEmpty() ? "true" : "false");
1323#StdOut
1324rect: 10, 50, 20, 60 isEmpty: false
1325rect: -5, 18, 35, 92 isEmpty: false
1326##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001327##
1328
Cary Clark7fc1d122017-10-09 14:07:42 -04001329#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001330
1331##
1332
1333# ------------------------------------------------------------------------------
1334
1335#Method void offset(SkScalar dx, SkScalar dy)
1336
Cary Clarkab2621d2018-01-30 10:08:57 -05001337#In Inset_Outset_Offset
1338#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001339Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001340
Cary Clark7fc1d122017-10-09 14:07:42 -04001341If dx is negative, moves Rect to the left.
1342If dx is positive, moves Rect to the right.
1343If dy is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001344If dy is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001345
1346#Param dx offset added to fLeft and fRight ##
1347#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001348
1349#Example
Cary Clark154beea2017-10-26 07:58:48 -04001350 SkRect rect = { 10, 14, 50, 73 };
1351 rect.offset(5, 13);
1352 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1353#StdOut
1354rect: 15, 27, 55, 86
1355##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001356##
1357
Cary Clark7fc1d122017-10-09 14:07:42 -04001358#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001359
1360##
1361
1362# ------------------------------------------------------------------------------
1363
1364#Method void offset(const SkPoint& delta)
1365
Cary Clarkab2621d2018-01-30 10:08:57 -05001366#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001367Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1368fTop, fBottom.
1369
1370If delta.fX is negative, moves Rect to the left.
1371If delta.fX is positive, moves Rect to the right.
1372If delta.fY is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001373If delta.fY is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001374
1375#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001376
1377#Example
Cary Clark154beea2017-10-26 07:58:48 -04001378 SkRect rect = { 10, 14, 50, 73 };
1379 rect.offset({5, 13});
1380 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1381#StdOut
1382rect: 15, 27, 55, 86
1383##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001384##
1385
Cary Clark7fc1d122017-10-09 14:07:42 -04001386#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001387
1388##
1389
1390# ------------------------------------------------------------------------------
1391
1392#Method void offsetTo(SkScalar newX, SkScalar newY)
1393
Cary Clarkab2621d2018-01-30 10:08:57 -05001394#In Inset_Outset_Offset
1395#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001396Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1397are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001398
Cary Clark7fc1d122017-10-09 14:07:42 -04001399#Param newX stored in fLeft, preserving width() ##
1400#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001401
1402#Example
Cary Clark154beea2017-10-26 07:58:48 -04001403 SkRect rect = { 10, 14, 50, 73 };
1404 rect.offsetTo(15, 27);
1405 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1406#StdOut
1407rect: 15, 27, 55, 86
1408##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001409##
1410
Cary Clark7fc1d122017-10-09 14:07:42 -04001411#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001412
1413##
1414
1415# ------------------------------------------------------------------------------
1416
1417#Method void inset(SkScalar dx, SkScalar dy)
1418
Cary Clarkab2621d2018-01-30 10:08:57 -05001419#In Inset_Outset_Offset
1420#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001421Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001422
Cary Clark7fc1d122017-10-09 14:07:42 -04001423If dx is positive, makes Rect narrower.
1424If dx is negative, makes Rect wider.
1425If dy is positive, makes Rect shorter.
1426If dy is negative, makes Rect taller.
1427
1428#Param dx added to fLeft and subtracted from fRight ##
1429#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001430
1431#Example
Cary Clark154beea2017-10-26 07:58:48 -04001432 SkRect rect = { 10, 14, 50, 73 };
1433 rect.inset(5, 13);
1434 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1435#StdOut
1436rect: 15, 27, 45, 60
1437##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001438##
1439
Cary Clark7fc1d122017-10-09 14:07:42 -04001440#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001441
1442##
1443
1444# ------------------------------------------------------------------------------
1445
1446#Method void outset(SkScalar dx, SkScalar dy)
1447
Cary Clarkab2621d2018-01-30 10:08:57 -05001448#In Inset_Outset_Offset
1449#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001450Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001451
Cary Clark7fc1d122017-10-09 14:07:42 -04001452If dx is positive, makes Rect wider.
1453If dx is negative, makes Rect narrower.
1454If dy is positive, makes Rect taller.
1455If dy is negative, makes Rect shorter.
1456
1457#Param dx subtracted to fLeft and added from fRight ##
1458#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001459
1460#Example
Cary Clark154beea2017-10-26 07:58:48 -04001461 SkRect rect = { 10, 14, 50, 73 };
1462 rect.outset(5, 13);
1463 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1464#StdOut
1465rect: 5, 1, 55, 86
1466##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001467##
1468
Cary Clark7fc1d122017-10-09 14:07:42 -04001469#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001470
1471##
1472
Cary Clark2dc84ad2018-01-26 12:56:22 -05001473#Subtopic Inset_Outset_Offset ##
1474
1475#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001476#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001477
Cary Clark682c58d2018-05-16 07:07:07 -04001478Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001479must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001480empty() returns false. The intersection of Rect pair can be described by:
1481
Cary Clark7fc1d122017-10-09 14:07:42 -04001482#Formula
1483(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1484 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1485##
Cary Clark154beea2017-10-26 07:58:48 -04001486.
1487
Cary Clark7fc1d122017-10-09 14:07:42 -04001488The intersection is only meaningful if the resulting Rect is not empty and
1489describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1490
Cary Clark4855f782018-02-06 09:41:53 -05001491#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001492
1493# ------------------------------------------------------------------------------
1494
Florin Malitaeb420452018-02-20 11:44:43 -05001495#Method bool contains(SkScalar x, SkScalar y) const
1496
1497#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001498#Line # returns true if points are equal or inside ##
Florin Malitaeb420452018-02-20 11:44:43 -05001499Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
1500Returns false if SkRect is empty.
1501
1502#Param x test SkPoint x-coordinate ##
1503#Param y test SkPoint y-coordinate ##
1504
1505#Return true if (x, y) is inside SkRect ##
1506
1507#Example
1508 SkRect rect = { 30, 50, 40, 60 };
1509 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1510 for (auto contained : tests) {
1511 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1512 rect.left(), rect.top(), rect.right(), rect.bottom(),
1513 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1514 contained.x(), contained.y());
1515 }
1516#StdOut
1517rect: (30, 50, 40, 60) contains (30, 50)
1518rect: (30, 50, 40, 60) does not contain (39, 49)
1519rect: (30, 50, 40, 60) does not contain (29, 59)
1520##
1521##
1522
1523#SeeAlso SkIRect::contains
1524
1525##
1526
1527# ------------------------------------------------------------------------------
1528
Cary Clark2dc84ad2018-01-26 12:56:22 -05001529#Method bool contains(const SkRect& r) const
1530
Cary Clarkab2621d2018-01-30 10:08:57 -05001531#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001532Returns true if Rect contains r.
1533Returns false if Rect is empty or r is empty.
1534
1535Rect contains r when Rect area completely includes r area.
1536
1537#Param r Rect contained ##
1538
1539#Return true if all sides of Rect are outside r ##
1540
1541#Example
1542 SkRect rect = { 30, 50, 40, 60 };
1543 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1544 for (auto contained : tests) {
1545 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1546 rect.left(), rect.top(), rect.right(), rect.bottom(),
1547 rect.contains(contained) ? "contains" : "does not contain",
1548 contained.left(), contained.top(), contained.right(), contained.bottom());
1549 }
1550#StdOut
1551rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1552rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1553rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1554##
1555##
1556
1557#SeeAlso SkIRect::contains
1558
1559##
1560
1561# ------------------------------------------------------------------------------
1562
1563#Method bool contains(const SkIRect& r) const
1564
Cary Clarkab2621d2018-01-30 10:08:57 -05001565#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001566Returns true if Rect contains r.
1567Returns false if Rect is empty or r is empty.
1568
1569Rect contains r when Rect area completely includes r area.
1570
1571#Param r IRect contained ##
1572
1573#Return true if all sides of Rect are outside r ##
1574
1575#Example
1576 SkRect rect = { 30, 50, 40, 60 };
1577 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1578 for (auto contained : tests) {
1579 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1580 rect.left(), rect.top(), rect.right(), rect.bottom(),
1581 rect.contains(contained) ? "contains" : "does not contain",
1582 contained.left(), contained.top(), contained.right(), contained.bottom());
1583 }
1584#StdOut
1585rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1586rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1587rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1588##
1589##
1590
1591#SeeAlso SkIRect::contains
1592
1593##
1594
Cary Clarkbc5697d2017-10-04 14:31:33 -04001595# ------------------------------------------------------------------------------
1596
1597#Method bool intersect(const SkRect& r)
1598
Cary Clarkab2621d2018-01-30 10:08:57 -05001599#In Intersection
1600#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001601Returns true if Rect intersects r, and sets Rect to intersection.
1602Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001603
Cary Clark7fc1d122017-10-09 14:07:42 -04001604Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001605
Cary Clark7fc1d122017-10-09 14:07:42 -04001606#Param r limit of result ##
1607
1608#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001609
1610#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001611#Description
1612Two SkDebugf calls are required. If the calls are combined, their arguments
1613may not be evaluated in left to right order: the printed intersection may
1614be before or after the call to intersect.
1615##
Cary Clark154beea2017-10-26 07:58:48 -04001616 SkRect leftRect = { 10, 40, 50, 80 };
1617 SkRect rightRect = { 30, 60, 70, 90 };
1618 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001619 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001620 leftRect.right(), leftRect.bottom());
1621#StdOut
1622 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001623##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001624##
1625
Cary Clark7fc1d122017-10-09 14:07:42 -04001626#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001627
1628##
1629
1630# ------------------------------------------------------------------------------
1631
1632#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1633
Cary Clarkab2621d2018-01-30 10:08:57 -05001634#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001635Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1636construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001637
Cary Clark7fc1d122017-10-09 14:07:42 -04001638Returns true if Rect intersects construction, and sets Rect to intersection.
1639Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001640
Cary Clark7fc1d122017-10-09 14:07:42 -04001641Returns false if either construction or Rect is empty, leaving Rect unchanged.
1642
1643#Param left x minimum of constructed Rect ##
1644#Param top y minimum of constructed Rect ##
1645#Param right x maximum of constructed Rect ##
1646#Param bottom y maximum of constructed Rect ##
1647
1648#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001649
1650#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001651#Description
1652Two SkDebugf calls are required. If the calls are combined, their arguments
1653may not be evaluated in left to right order: the printed intersection may
1654be before or after the call to intersect.
1655##
Cary Clark154beea2017-10-26 07:58:48 -04001656 SkRect leftRect = { 10, 40, 50, 80 };
1657 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001658 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001659 leftRect.right(), leftRect.bottom());
1660#StdOut
1661 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001662##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001663##
1664
Cary Clark7fc1d122017-10-09 14:07:42 -04001665#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001666
1667##
1668
1669# ------------------------------------------------------------------------------
1670
1671#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1672
Cary Clarkab2621d2018-01-30 10:08:57 -05001673#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001674Returns true if a intersects b, and sets Rect to intersection.
1675Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001676
Cary Clark7fc1d122017-10-09 14:07:42 -04001677Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001678
Cary Clark7fc1d122017-10-09 14:07:42 -04001679#Param a Rect to intersect ##
1680#Param b Rect to intersect ##
1681
1682#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001683
1684#Example
Cary Clark154beea2017-10-26 07:58:48 -04001685 SkRect result;
1686 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1687 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1688 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001689#StdOut
1690 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001691##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001692##
1693
Cary Clark7fc1d122017-10-09 14:07:42 -04001694#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001695
1696##
1697
Cary Clark7fc1d122017-10-09 14:07:42 -04001698# ------------------------------------------------------------------------------
1699
Cary Clarkbc5697d2017-10-04 14:31:33 -04001700#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1701
Cary Clarkab2621d2018-01-30 10:08:57 -05001702#In Intersection
1703#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001704Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1705construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001706
Cary Clark7fc1d122017-10-09 14:07:42 -04001707Returns true if Rect intersects construction.
1708Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001709
Cary Clark7fc1d122017-10-09 14:07:42 -04001710#Param left x minimum of constructed Rect ##
1711#Param top y minimum of constructed Rect ##
1712#Param right x maximum of constructed Rect ##
1713#Param bottom y maximum of constructed Rect ##
1714
1715#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001716
1717#Example
Cary Clark154beea2017-10-26 07:58:48 -04001718 SkRect rect = { 10, 40, 50, 80 };
1719 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001720#StdOut
1721 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001722##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723##
1724
Cary Clark7fc1d122017-10-09 14:07:42 -04001725#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001726
1727##
1728
Cary Clark7fc1d122017-10-09 14:07:42 -04001729# ------------------------------------------------------------------------------
1730
Cary Clarkbc5697d2017-10-04 14:31:33 -04001731#Method bool intersects(const SkRect& r) const
1732
Cary Clarkab2621d2018-01-30 10:08:57 -05001733#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001734Returns true if Rect intersects r.
1735Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001736
Cary Clark7fc1d122017-10-09 14:07:42 -04001737#Param r Rect to intersect ##
1738
1739#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001740
1741#Example
Cary Clark154beea2017-10-26 07:58:48 -04001742 SkRect rect = { 10, 40, 50, 80 };
1743 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001744#StdOut
1745 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001746##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001747##
1748
Cary Clark7fc1d122017-10-09 14:07:42 -04001749#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001750
1751##
1752
Cary Clark7fc1d122017-10-09 14:07:42 -04001753# ------------------------------------------------------------------------------
1754
Cary Clarkbc5697d2017-10-04 14:31:33 -04001755#Method static bool Intersects(const SkRect& a, const SkRect& b)
1756
Cary Clarkab2621d2018-01-30 10:08:57 -05001757#In Intersection
1758#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001759Returns true if a intersects b.
1760Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001761
Cary Clark7fc1d122017-10-09 14:07:42 -04001762#Param a Rect to intersect ##
1763#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001764
Cary Clark7fc1d122017-10-09 14:07:42 -04001765#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001766
1767#Example
Cary Clark154beea2017-10-26 07:58:48 -04001768 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001769#StdOut
1770 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001771##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001772##
1773
Cary Clark7fc1d122017-10-09 14:07:42 -04001774#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001775
1776##
1777
Cary Clark2dc84ad2018-01-26 12:56:22 -05001778#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001779
Cary Clark2dc84ad2018-01-26 12:56:22 -05001780#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001781#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001782
Cary Clark4855f782018-02-06 09:41:53 -05001783#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001784
1785# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001786
1787#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1788
Cary Clarkab2621d2018-01-30 10:08:57 -05001789#In Join
1790#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001791Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1792construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793
Cary Clark7fc1d122017-10-09 14:07:42 -04001794Sets Rect to the union of itself and the construction.
1795
1796Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1797Rect to construction.
1798
1799#Param left x minimum of constructed Rect ##
1800#Param top y minimum of constructed Rect ##
1801#Param right x maximum of constructed Rect ##
1802#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001803
1804#Example
Cary Clark154beea2017-10-26 07:58:48 -04001805 SkRect rect = { 10, 20, 15, 25};
1806 rect.join(50, 60, 55, 65);
1807 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001808#StdOut
1809 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001810##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001811##
1812
Cary Clark7fc1d122017-10-09 14:07:42 -04001813#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001814
1815##
1816
Cary Clark7fc1d122017-10-09 14:07:42 -04001817# ------------------------------------------------------------------------------
1818
Cary Clarkbc5697d2017-10-04 14:31:33 -04001819#Method void join(const SkRect& r)
1820
Cary Clarkab2621d2018-01-30 10:08:57 -05001821#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001822Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001823
Cary Clark7fc1d122017-10-09 14:07:42 -04001824Has no effect if r is empty. Otherwise, if Rect is empty, sets
1825Rect to r.
1826
1827#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001828
1829#Example
Cary Clark154beea2017-10-26 07:58:48 -04001830 SkRect rect = { 10, 20, 15, 25};
1831 rect.join({50, 60, 55, 65});
1832 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001833#StdOut
1834 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001835##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001836##
1837
Cary Clark7fc1d122017-10-09 14:07:42 -04001838#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001839
1840##
1841
Cary Clark7fc1d122017-10-09 14:07:42 -04001842# ------------------------------------------------------------------------------
1843
Cary Clarkbc5697d2017-10-04 14:31:33 -04001844#Method void joinNonEmptyArg(const SkRect& r)
1845
Cary Clarkab2621d2018-01-30 10:08:57 -05001846#In Join
1847#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001848Sets Rect to the union of itself and r.
1849
1850Asserts if r is empty and SK_DEBUG is defined.
1851If Rect is empty, sets Rect to r.
1852
1853May produce incorrect results if r is empty.
1854
1855#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001856
1857#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001858#Description
1859Since Rect is not sorted, first result is copy of toJoin.
1860##
Cary Clark154beea2017-10-26 07:58:48 -04001861 SkRect rect = { 10, 100, 15, 0};
1862 SkRect sorted = rect.makeSorted();
1863 SkRect toJoin = { 50, 60, 55, 65 };
1864 rect.joinNonEmptyArg(toJoin);
1865 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1866 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001867 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1868#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001869rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001870sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001871##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001872##
1873
Cary Clark7fc1d122017-10-09 14:07:42 -04001874#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001875
1876##
1877
Cary Clark7fc1d122017-10-09 14:07:42 -04001878# ------------------------------------------------------------------------------
1879
Cary Clarkbc5697d2017-10-04 14:31:33 -04001880#Method void joinPossiblyEmptyRect(const SkRect& r)
1881
Cary Clarkab2621d2018-01-30 10:08:57 -05001882#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001883#Line # sets to union of bounds; skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001884Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885
Cary Clark7fc1d122017-10-09 14:07:42 -04001886May produce incorrect results if Rect or r is empty.
1887
1888#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001889
1890#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001891#Description
1892Since Rect is not sorted, first result is not useful.
1893##
Cary Clark154beea2017-10-26 07:58:48 -04001894 SkRect rect = { 10, 100, 15, 0};
1895 SkRect sorted = rect.makeSorted();
1896 SkRect toJoin = { 50, 60, 55, 65 };
1897 rect.joinPossiblyEmptyRect(toJoin);
1898 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1899 sorted.joinPossiblyEmptyRect(toJoin);
1900 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001901#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001902rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001903sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001904##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001905##
1906
Cary Clark7fc1d122017-10-09 14:07:42 -04001907#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001908
1909##
1910
Cary Clark2dc84ad2018-01-26 12:56:22 -05001911#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001912
Cary Clark2dc84ad2018-01-26 12:56:22 -05001913#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001914#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001915
Cary Clark4855f782018-02-06 09:41:53 -05001916#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001917
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918#Method void round(SkIRect* dst) const
1919
Cary Clarkab2621d2018-01-30 10:08:57 -05001920#In Rounding
1921#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001922Sets IRect by adding 0.5 and discarding the fractional portion of Rect
1923members, using
1924#Formula
1925(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1926 SkScalarRoundToInt(fRight), SkScalarRoundToInt(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.round(&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: 31, 51, 41, 61
1939##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001940##
1941
Cary Clark7fc1d122017-10-09 14:07:42 -04001942#SeeAlso roundIn roundOut 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(SkIRect* dst) const
1949
Cary Clarkab2621d2018-01-30 10:08:57 -05001950#In Rounding
1951#Line # sets members to nearest integer value away from opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001952Sets IRect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05001953rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04001954#Formula
1955(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1956 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1957##
1958.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001959
Cary Clark7fc1d122017-10-09 14:07:42 -04001960#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001961
1962#Example
Cary Clark154beea2017-10-26 07:58:48 -04001963 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1964 SkIRect round;
1965 rect.roundOut(&round);
1966 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001967#StdOut
1968round: 30, 50, 41, 61
1969##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001970##
1971
Cary Clark7fc1d122017-10-09 14:07:42 -04001972#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001973
1974##
1975
Cary Clark7fc1d122017-10-09 14:07:42 -04001976# ------------------------------------------------------------------------------
1977
Cary Clark682c58d2018-05-16 07:07:07 -04001978#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001979
Cary Clarkab2621d2018-01-30 10:08:57 -05001980#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04001981Sets Rect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05001982rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04001983#Formula
1984(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1985 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1986##
1987.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001988
Cary Clark7fc1d122017-10-09 14:07:42 -04001989#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001990
1991#Example
Cary Clark154beea2017-10-26 07:58:48 -04001992 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1993 SkRect round;
1994 rect.roundOut(&round);
1995 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001996#StdOut
1997round: 30, 50, 41, 61
1998##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001999##
2000
Cary Clark7fc1d122017-10-09 14:07:42 -04002001#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002002
2003##
2004
Cary Clark7fc1d122017-10-09 14:07:42 -04002005# ------------------------------------------------------------------------------
2006
Cary Clarkbc5697d2017-10-04 14:31:33 -04002007#Method void roundIn(SkIRect* dst) const
2008
Cary Clarkab2621d2018-01-30 10:08:57 -05002009#In Rounding
2010#Line # sets members to nearest integer value towards opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002011Sets Rect by rounding up fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002012discarding the fractional portion of fRight and fBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002013
Cary Clark7fc1d122017-10-09 14:07:42 -04002014#Formula
2015(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2016 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2017##
2018.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002019
Cary Clark7fc1d122017-10-09 14:07:42 -04002020#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002021
2022#Example
Cary Clark154beea2017-10-26 07:58:48 -04002023 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2024 SkIRect round;
2025 rect.roundIn(&round);
2026 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002027#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002028round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002029##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002030##
2031
Cary Clark7fc1d122017-10-09 14:07:42 -04002032#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002033
2034##
2035
Cary Clark7fc1d122017-10-09 14:07:42 -04002036# ------------------------------------------------------------------------------
2037
Cary Clarkbc5697d2017-10-04 14:31:33 -04002038#Method SkIRect round() const
2039
Cary Clarkab2621d2018-01-30 10:08:57 -05002040#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002041Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2042members, using
2043#Formula
2044(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2045 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2046##
2047.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002048
Cary Clark7fc1d122017-10-09 14:07:42 -04002049#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002050
2051#Example
Cary Clark154beea2017-10-26 07:58:48 -04002052 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2053 SkIRect round = rect.round();
2054 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002055#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002056round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002057##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002058##
2059
Cary Clark7fc1d122017-10-09 14:07:42 -04002060#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002061
2062##
2063
Cary Clark7fc1d122017-10-09 14:07:42 -04002064# ------------------------------------------------------------------------------
2065
Cary Clarkbc5697d2017-10-04 14:31:33 -04002066#Method SkIRect roundOut() const
2067
Cary Clarkab2621d2018-01-30 10:08:57 -05002068#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002069Sets IRect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002070rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04002071#Formula
2072(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2073 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2074##
2075.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002076
Cary Clark7fc1d122017-10-09 14:07:42 -04002077#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002078
2079#Example
Cary Clark154beea2017-10-26 07:58:48 -04002080 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2081 SkIRect round = rect.roundOut();
2082 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002083#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002084round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002085##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002086##
2087
Cary Clark7fc1d122017-10-09 14:07:42 -04002088#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002089
2090##
2091
Cary Clark2dc84ad2018-01-26 12:56:22 -05002092#Subtopic Rounding ##
2093
2094#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002095#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002096
Cary Clark4855f782018-02-06 09:41:53 -05002097#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04002098
2099# ------------------------------------------------------------------------------
2100
Cary Clarkbc5697d2017-10-04 14:31:33 -04002101#Method void sort()
2102
Cary Clarkab2621d2018-01-30 10:08:57 -05002103#In Sorting
2104#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002105Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2106fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2107and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002108
2109#Example
Cary Clark154beea2017-10-26 07:58:48 -04002110 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2111 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2112 rect.sort();
2113 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002114#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002115rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002116sorted: 20.5, 10.5, 30.5, 50.5
2117##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002118##
2119
Cary Clark2dc84ad2018-01-26 12:56:22 -05002120#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002121
2122##
2123
Cary Clark7fc1d122017-10-09 14:07:42 -04002124# ------------------------------------------------------------------------------
2125
Cary Clarkbc5697d2017-10-04 14:31:33 -04002126#Method SkRect makeSorted() const
2127
Cary Clarkab2621d2018-01-30 10:08:57 -05002128#In Sorting
Cary Clark4855f782018-02-06 09:41:53 -05002129#In Constructor
Cary Clark682c58d2018-05-16 07:07:07 -04002130#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002131Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2132with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2133and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002134
Cary Clark7fc1d122017-10-09 14:07:42 -04002135#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002136
2137#Example
Cary Clark154beea2017-10-26 07:58:48 -04002138 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2139 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2140 SkRect sort = rect.makeSorted();
2141 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002142#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002143rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002144sorted: 20.5, 10.5, 30.5, 50.5
2145##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002146##
2147
Cary Clark2dc84ad2018-01-26 12:56:22 -05002148#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002149
2150##
2151
Cary Clark2dc84ad2018-01-26 12:56:22 -05002152#Subtopic Sorting ##
2153
Cary Clark7fc1d122017-10-09 14:07:42 -04002154# ------------------------------------------------------------------------------
2155
Cary Clarkbc5697d2017-10-04 14:31:33 -04002156#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002157#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002158#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002159Returns pointer to first Scalar in Rect, to treat it as an array with four
2160entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002161
Cary Clark7fc1d122017-10-09 14:07:42 -04002162#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002163
2164#Example
Cary Clark154beea2017-10-26 07:58:48 -04002165 SkRect rect = {7, 11, 13, 17};
2166SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2167#StdOut
2168rect.asScalars() == &rect.fLeft
2169##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002170##
2171
Cary Clark7fc1d122017-10-09 14:07:42 -04002172#SeeAlso toQuad
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(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002179#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002180#Line # sends text representation to standard output using floats ##
Cary Clark682c58d2018-05-16 07:07:07 -04002181Writes text representation of Rect to standard output. Set asHex to true to
Cary Clark7fc1d122017-10-09 14:07:42 -04002182generate exact binary representations of floating point numbers.
2183
2184#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002185
2186#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002187 SkRect rect = {20, 30, 40, 50};
2188 for (bool dumpAsHex : { false, true } ) {
2189 rect.dump(dumpAsHex);
2190 SkDebugf("\n");
2191 }
2192#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002193SkRect::MakeLTRB(20, 30, 40, 50);
2194
2195SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2196 SkBits2Float(0x41f00000), /* 30.000000 */
2197 SkBits2Float(0x42200000), /* 40.000000 */
2198 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002199##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002200##
2201
Cary Clark7fc1d122017-10-09 14:07:42 -04002202#SeeAlso dumpHex
2203
Cary Clarkbc5697d2017-10-04 14:31:33 -04002204##
2205
Cary Clark7fc1d122017-10-09 14:07:42 -04002206# ------------------------------------------------------------------------------
2207
Cary Clarkbc5697d2017-10-04 14:31:33 -04002208#Method void dump() const
2209
Cary Clark7fc1d122017-10-09 14:07:42 -04002210Writes text representation of Rect to standard output. The representation may be
2211directly compiled as C++ code. Floating point values are written
2212with limited precision; it may not be possible to reconstruct original Rect
2213from output.
2214
Cary Clarkbc5697d2017-10-04 14:31:33 -04002215#Example
Cary Clark154beea2017-10-26 07:58:48 -04002216SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2217rect.dump();
2218SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2219SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002220#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002221SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002222rect is not equal to copy
2223##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002224##
2225
Cary Clark7fc1d122017-10-09 14:07:42 -04002226#SeeAlso dumpHex
2227
Cary Clarkbc5697d2017-10-04 14:31:33 -04002228##
2229
Cary Clark7fc1d122017-10-09 14:07:42 -04002230# ------------------------------------------------------------------------------
2231
Cary Clarkbc5697d2017-10-04 14:31:33 -04002232#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002233#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002234#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002235Writes text representation of Rect to standard output. The representation may be
2236directly compiled as C++ code. Floating point values are written
2237in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2238original Rect.
2239
Cary Clark682c58d2018-05-16 07:07:07 -04002240Use instead of dump() when submitting
2241#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002242.
2243
Cary Clarkbc5697d2017-10-04 14:31:33 -04002244#Example
Cary Clark154beea2017-10-26 07:58:48 -04002245 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2246rect.dumpHex();
2247SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2248 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2249 SkBits2Float(0x40266666), /* 2.600000 */
2250 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002251SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2252#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002253SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2254 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2255 SkBits2Float(0x40266666), /* 2.600000 */
2256 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002257rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002258##
Cary Clark7fc1d122017-10-09 14:07:42 -04002259##
2260
2261#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002262
2263##
2264
Cary Clark0c95aab2018-01-08 16:20:59 -05002265#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05002266#Deprecated
2267##
2268
Cary Clarkbc5697d2017-10-04 14:31:33 -04002269#Struct SkRect ##
2270
2271#Topic Rect ##