blob: 12f5a6208debaa83a0599abd5a0c2f36046a808f [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 Clarkc06754b2018-05-16 21:28:55 -0400904#Method void setBoundsNoCheck(const SkPoint pts[], int count)
905#In Set
906#Line # sets to upper and lower limits of Point array ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400907Sets to bounds of Point pts array with count entries. If any Point in pts
908contains Infinity or NaN, all Rect dimensions are set to NaN.
Cary Clarkc06754b2018-05-16 21:28:55 -0400909
910#Param pts Point array ##
911#Param count entries in array ##
912
913#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400914 SkPoint points[] = {{3, 4}, {1, 2}, {SkScalar_Inf, 6}, {SK_ScalarNaN, 8}};
915 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
916 SkRect rect;
917 rect.setBoundsNoCheck(points, count);
918 if (count > 0) {
919 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
920 } else {
921 SkDebugf("%14s", " ");
922 }
923 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
924 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
925 }
Cary Clarkc06754b2018-05-16 21:28:55 -0400926##
927
928#SeeAlso setBoundsCheck
929#Method ##
930
931# ------------------------------------------------------------------------------
932
Cary Clarkbc5697d2017-10-04 14:31:33 -0400933#Method void setEmpty()
934
Cary Clarkab2621d2018-01-30 10:08:57 -0500935#In Set
936#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400937Sets Rect to (0, 0, 0, 0).
938
939Many other rectangles are empty; if left is equal to or greater than right,
940or if top is equal to or greater than bottom. Setting all members to zero
941is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400942
943#Example
Cary Clark154beea2017-10-26 07:58:48 -0400944 SkRect rect = {3, 4, 1, 2};
945 for (int i = 0; i < 2; ++i) {
946 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
947 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
948 rect.setEmpty();
949 }
950#StdOut
951rect: {3, 4, 1, 2} is empty
952rect: {0, 0, 0, 0} is empty
953##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400954##
955
Cary Clark7fc1d122017-10-09 14:07:42 -0400956#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400957
958##
959
960# ------------------------------------------------------------------------------
961
962#Method void set(const SkIRect& src)
963
Cary Clarkab2621d2018-01-30 10:08:57 -0500964#In Set
965#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400966Sets Rect to src, promoting src members from integer to Scalar.
Cary Clark682c58d2018-05-16 07:07:07 -0400967Very large values in src may lose precision.
Cary Clark7fc1d122017-10-09 14:07:42 -0400968
969#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400970
971#Example
Cary Clark154beea2017-10-26 07:58:48 -0400972 SkIRect i_rect = {3, 4, 1, 2};
973 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
974 SkRect f_rect;
975 f_rect.set(i_rect);
976 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
977#StdOut
978i_rect: {3, 4, 1, 2}
979f_rect: {3, 4, 1, 2}
980##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400981##
982
Cary Clark7fc1d122017-10-09 14:07:42 -0400983#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400984
985##
986
987# ------------------------------------------------------------------------------
988
989#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
990
Cary Clarkab2621d2018-01-30 10:08:57 -0500991#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400992Sets Rect to (left, top, right, bottom).
993left and right are not sorted; left is not necessarily less than right.
994top and bottom are not sorted; top is not necessarily less than bottom.
995
996#Param left stored in fLeft ##
997#Param top stored in fTop ##
998#Param right stored in fRight ##
999#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001000
1001#Example
Cary Clark154beea2017-10-26 07:58:48 -04001002 SkRect rect1 = {3, 4, 1, 2};
1003 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1004 SkRect rect2;
1005 rect2.set(3, 4, 1, 2);
1006 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1007#StdOut
1008rect1: {3, 4, 1, 2}
1009rect2: {3, 4, 1, 2}
1010##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001011##
1012
Cary Clark7fc1d122017-10-09 14:07:42 -04001013#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001014
1015##
1016
1017# ------------------------------------------------------------------------------
1018
1019#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1020
Cary Clarkab2621d2018-01-30 10:08:57 -05001021#In Set
1022#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001023Sets Rect to (left, top, right, bottom).
1024left and right are not sorted; left is not necessarily less than right.
1025top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001026
Cary Clark7fc1d122017-10-09 14:07:42 -04001027#Param left stored in fLeft ##
1028#Param top stored in fTop ##
1029#Param right stored in fRight ##
1030#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001031
1032#Example
Cary Clark154beea2017-10-26 07:58:48 -04001033 SkRect rect1 = {3, 4, 1, 2};
1034 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1035 SkRect rect2;
1036 rect2.setLTRB(3, 4, 1, 2);
1037 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1038#StdOut
1039rect1: {3, 4, 1, 2}
1040rect2: {3, 4, 1, 2}
1041##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001042##
1043
Cary Clark7fc1d122017-10-09 14:07:42 -04001044#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001045
1046##
1047
1048# ------------------------------------------------------------------------------
1049
Cary Clarkbc5697d2017-10-04 14:31:33 -04001050#Method void set(const SkPoint pts[], int count)
1051
Cary Clarkab2621d2018-01-30 10:08:57 -05001052#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001053Sets to bounds of Point array with count entries. If count is zero or smaller,
1054or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001055
Cary Clark7fc1d122017-10-09 14:07:42 -04001056Result is either empty or sorted: fLeft is less than or equal to fRight, and
1057fTop is less than or equal to fBottom.
1058
1059#Param pts Point array ##
1060#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001061
1062#Example
Cary Clark154beea2017-10-26 07:58:48 -04001063 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1064 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1065 SkRect rect;
1066 rect.set(points, count);
1067 if (count > 0) {
1068 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1069 } else {
1070 SkDebugf("%14s", " ");
1071 }
1072 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1073 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1074 }
1075#StdOut
1076 count: 0 rect: 0, 0, 0, 0
1077added: 3, 4 count: 1 rect: 3, 4, 3, 4
1078added: 1, 2 count: 2 rect: 1, 2, 3, 4
1079added: 5, 6 count: 3 rect: 1, 2, 5, 6
1080added: nan, 8 count: 4 rect: 0, 0, 0, 0
1081##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001082##
1083
Cary Clark7fc1d122017-10-09 14:07:42 -04001084#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001085
1086##
1087
1088# ------------------------------------------------------------------------------
1089
Cary Clarkbc5697d2017-10-04 14:31:33 -04001090#Method void set(const SkPoint& p0, const SkPoint& p1)
1091
Cary Clarkab2621d2018-01-30 10:08:57 -05001092#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001093Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1094sorted and may be empty. Does not check to see if values are finite.
1095
1096#Param p0 corner to include ##
1097#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001098
1099#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001100#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001101p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -04001102##
Cary Clark154beea2017-10-26 07:58:48 -04001103 SkPoint point1 = {SK_ScalarNaN, 8};
1104 SkPoint point2 = {3, 4};
1105 SkRect rect;
1106 rect.set(point1, point2);
1107 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1108 rect.set(point2, point1);
1109 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001110##
1111
Cary Clark7fc1d122017-10-09 14:07:42 -04001112#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001113
1114##
1115
1116# ------------------------------------------------------------------------------
1117
1118#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1119
Cary Clarkab2621d2018-01-30 10:08:57 -05001120#In Set
1121#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark682c58d2018-05-16 07:07:07 -04001122Sets Rect to
Cary Clark7fc1d122017-10-09 14:07:42 -04001123#Formula
1124(x, y, x + width, y + height)
1125##
1126. Does not validate input;
1127width or height may be negative.
1128
1129#Param x stored in fLeft ##
1130#Param y stored in fTop ##
1131#Param width added to x and stored in fRight ##
1132#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001133
1134#Example
Cary Clark154beea2017-10-26 07:58:48 -04001135 SkRect rect;
1136 rect.setXYWH(5, 35, -15, 25);
1137 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1138 rect.bottom(), rect.isEmpty() ? "true" : "false");
1139 rect.sort();
1140 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1141 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001142#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001143rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001144rect: -10, 35, 5, 60 isEmpty: false
1145##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001146##
1147
Cary Clark7fc1d122017-10-09 14:07:42 -04001148#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001149
1150##
1151
1152# ------------------------------------------------------------------------------
1153
1154#Method void setWH(SkScalar width, SkScalar height)
1155
Cary Clarkab2621d2018-01-30 10:08:57 -05001156#In Set
1157#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001158Sets Rect to (0, 0, width, height). Does not validate input;
1159width or height may be negative.
1160
1161#Param width stored in fRight ##
1162#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001163
1164#Example
Cary Clark154beea2017-10-26 07:58:48 -04001165 SkRect rect;
1166 rect.setWH(-15, 25);
1167 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1168 rect.bottom(), rect.isEmpty() ? "true" : "false");
1169 rect.sort();
1170 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1171 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001172#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001173rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001174rect: -15, 0, 0, 25 isEmpty: false
1175##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001176##
1177
Cary Clark7fc1d122017-10-09 14:07:42 -04001178#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001179
1180##
1181
Cary Clark2dc84ad2018-01-26 12:56:22 -05001182#Subtopic Set ##
1183
1184#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -04001185#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001186
Cary Clark4855f782018-02-06 09:41:53 -05001187#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001188
1189# ------------------------------------------------------------------------------
1190
1191#Method void iset(int left, int top, int right, int bottom)
1192
Cary Clarkab2621d2018-01-30 10:08:57 -05001193#In From_Integers
1194#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001195Sets Rect to (left, top, right, bottom).
1196All parameters are promoted from integer to Scalar.
1197left and right are not sorted; left is not necessarily less than right.
1198top and bottom are not sorted; top is not necessarily less than bottom.
1199
1200#Param left promoted to SkScalar and stored in fLeft ##
1201#Param top promoted to SkScalar and stored in fTop ##
1202#Param right promoted to SkScalar and stored in fRight ##
1203#Param bottom promoted to SkScalar and stored in fBottom ##
1204
1205#Example
1206 SkRect rect1 = {3, 4, 1, 2};
1207 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1208 SkRect rect2;
1209 rect2.iset(3, 4, 1, 2);
1210 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1211#StdOut
1212rect1: {3, 4, 1, 2}
1213rect2: {3, 4, 1, 2}
1214##
1215##
1216
1217#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1218
1219##
1220
1221# ------------------------------------------------------------------------------
1222
1223#Method void isetWH(int width, int height)
1224
Cary Clarkab2621d2018-01-30 10:08:57 -05001225#In From_Integers
1226#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001227Sets Rect to (0, 0, width, height).
1228width and height may be zero or negative. width and height are promoted from
1229integer to SkScalar, large values may lose precision.
1230
1231#Param width promoted to SkScalar and stored in fRight ##
1232#Param height promoted to SkScalar and stored in fBottom ##
1233
1234#Example
1235 SkRect rect1 = {0, 0, 1, 2};
1236 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1237 SkRect rect2;
1238 rect2.isetWH(1, 2);
1239 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1240#StdOut
1241rect1: {0, 0, 1, 2}
1242rect2: {0, 0, 1, 2}
1243##
1244##
1245
1246#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1247
1248##
1249
1250#Subtopic From_Integers ##
1251
1252#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001253#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001254
Cary Clark4855f782018-02-06 09:41:53 -05001255#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001256
Cary Clarkbc5697d2017-10-04 14:31:33 -04001257# ------------------------------------------------------------------------------
1258
Cary Clarkbc5697d2017-10-04 14:31:33 -04001259#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1260
Cary Clarkab2621d2018-01-30 10:08:57 -05001261#In Inset_Outset_Offset
1262#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001263Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001264
Cary Clark7fc1d122017-10-09 14:07:42 -04001265If dx is negative, Rect returned is moved to the left.
1266If dx is positive, Rect returned is moved to the right.
1267If dy is negative, Rect returned is moved upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001268If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001269
Cary Clark7fc1d122017-10-09 14:07:42 -04001270#Param dx added to fLeft and fRight ##
1271#Param dy added to fTop and fBottom ##
1272
1273#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001274
1275#Example
Cary Clark154beea2017-10-26 07:58:48 -04001276 SkRect rect = { 10, 50, 20, 60 };
1277 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1278 rect.bottom(), rect.isEmpty() ? "true" : "false");
1279 rect = rect.makeOffset(15, 32);
1280 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1281 rect.bottom(), rect.isEmpty() ? "true" : "false");
1282#StdOut
1283rect: 10, 50, 20, 60 isEmpty: false
1284rect: 25, 82, 35, 92 isEmpty: false
1285##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001286##
1287
Cary Clark7fc1d122017-10-09 14:07:42 -04001288#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001289
1290##
1291
1292# ------------------------------------------------------------------------------
1293
1294#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1295
Cary Clarkab2621d2018-01-30 10:08:57 -05001296#In Inset_Outset_Offset
1297#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001298Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001299
Cary Clark7fc1d122017-10-09 14:07:42 -04001300If dx is negative, Rect returned is wider.
1301If dx is positive, Rect returned is narrower.
1302If dy is negative, Rect returned is taller.
Cary Clark682c58d2018-05-16 07:07:07 -04001303If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001304
Cary Clark7fc1d122017-10-09 14:07:42 -04001305#Param dx added to fLeft and subtracted from fRight ##
1306#Param dy added to fTop and subtracted from fBottom ##
1307
1308#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001309
1310#Example
Cary Clark154beea2017-10-26 07:58:48 -04001311 SkRect rect = { 10, 50, 20, 60 };
1312 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1313 rect.bottom(), rect.isEmpty() ? "true" : "false");
1314 rect = rect.makeInset(15, 32);
1315 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1316 rect.bottom(), rect.isEmpty() ? "true" : "false");
1317#StdOut
1318rect: 10, 50, 20, 60 isEmpty: false
1319rect: 25, 82, 5, 28 isEmpty: true
1320##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001321##
1322
Cary Clark7fc1d122017-10-09 14:07:42 -04001323#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001324
1325##
1326
1327# ------------------------------------------------------------------------------
1328
1329#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1330
Cary Clarkab2621d2018-01-30 10:08:57 -05001331#In Inset_Outset_Offset
1332#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001333Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001334
Cary Clark7fc1d122017-10-09 14:07:42 -04001335If dx is negative, Rect returned is narrower.
1336If dx is positive, Rect returned is wider.
1337If dy is negative, Rect returned is shorter.
Cary Clark682c58d2018-05-16 07:07:07 -04001338If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001339
Cary Clark7fc1d122017-10-09 14:07:42 -04001340#Param dx subtracted to fLeft and added from fRight ##
1341#Param dy subtracted to fTop and added from fBottom ##
1342
1343#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001344
1345#Example
Cary Clark154beea2017-10-26 07:58:48 -04001346 SkRect rect = { 10, 50, 20, 60 };
1347 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1348 rect.bottom(), rect.isEmpty() ? "true" : "false");
1349 rect = rect.makeOutset(15, 32);
1350 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1351 rect.bottom(), rect.isEmpty() ? "true" : "false");
1352#StdOut
1353rect: 10, 50, 20, 60 isEmpty: false
1354rect: -5, 18, 35, 92 isEmpty: false
1355##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001356##
1357
Cary Clark7fc1d122017-10-09 14:07:42 -04001358#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001359
1360##
1361
1362# ------------------------------------------------------------------------------
1363
1364#Method void offset(SkScalar dx, SkScalar dy)
1365
Cary Clarkab2621d2018-01-30 10:08:57 -05001366#In Inset_Outset_Offset
1367#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001368Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
Cary Clark7fc1d122017-10-09 14:07:42 -04001370If dx is negative, moves Rect to the left.
1371If dx is positive, moves Rect to the right.
1372If dy is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001373If dy is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001374
1375#Param dx offset added to fLeft and fRight ##
1376#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001377
1378#Example
Cary Clark154beea2017-10-26 07:58:48 -04001379 SkRect rect = { 10, 14, 50, 73 };
1380 rect.offset(5, 13);
1381 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1382#StdOut
1383rect: 15, 27, 55, 86
1384##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001385##
1386
Cary Clark7fc1d122017-10-09 14:07:42 -04001387#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001388
1389##
1390
1391# ------------------------------------------------------------------------------
1392
1393#Method void offset(const SkPoint& delta)
1394
Cary Clarkab2621d2018-01-30 10:08:57 -05001395#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001396Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1397fTop, fBottom.
1398
1399If delta.fX is negative, moves Rect to the left.
1400If delta.fX is positive, moves Rect to the right.
1401If delta.fY is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001402If delta.fY is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001403
1404#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001405
1406#Example
Cary Clark154beea2017-10-26 07:58:48 -04001407 SkRect rect = { 10, 14, 50, 73 };
1408 rect.offset({5, 13});
1409 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1410#StdOut
1411rect: 15, 27, 55, 86
1412##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001413##
1414
Cary Clark7fc1d122017-10-09 14:07:42 -04001415#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001416
1417##
1418
1419# ------------------------------------------------------------------------------
1420
1421#Method void offsetTo(SkScalar newX, SkScalar newY)
1422
Cary Clarkab2621d2018-01-30 10:08:57 -05001423#In Inset_Outset_Offset
1424#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001425Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1426are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001427
Cary Clark7fc1d122017-10-09 14:07:42 -04001428#Param newX stored in fLeft, preserving width() ##
1429#Param newY stored in fTop, preserving height() ##
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.offsetTo(15, 27);
1434 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1435#StdOut
1436rect: 15, 27, 55, 86
1437##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001438##
1439
Cary Clark7fc1d122017-10-09 14:07:42 -04001440#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001441
1442##
1443
1444# ------------------------------------------------------------------------------
1445
1446#Method void inset(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 -04001450Insets 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 narrower.
1453If dx is negative, makes Rect wider.
1454If dy is positive, makes Rect shorter.
1455If dy is negative, makes Rect taller.
1456
1457#Param dx added to fLeft and subtracted from fRight ##
1458#Param dy added to fTop and subtracted 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.inset(5, 13);
1463 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1464#StdOut
1465rect: 15, 27, 45, 60
1466##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001467##
1468
Cary Clark7fc1d122017-10-09 14:07:42 -04001469#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001470
1471##
1472
1473# ------------------------------------------------------------------------------
1474
1475#Method void outset(SkScalar dx, SkScalar dy)
1476
Cary Clarkab2621d2018-01-30 10:08:57 -05001477#In Inset_Outset_Offset
1478#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001479Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001480
Cary Clark7fc1d122017-10-09 14:07:42 -04001481If dx is positive, makes Rect wider.
1482If dx is negative, makes Rect narrower.
1483If dy is positive, makes Rect taller.
1484If dy is negative, makes Rect shorter.
1485
1486#Param dx subtracted to fLeft and added from fRight ##
1487#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488
1489#Example
Cary Clark154beea2017-10-26 07:58:48 -04001490 SkRect rect = { 10, 14, 50, 73 };
1491 rect.outset(5, 13);
1492 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1493#StdOut
1494rect: 5, 1, 55, 86
1495##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001496##
1497
Cary Clark7fc1d122017-10-09 14:07:42 -04001498#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001499
1500##
1501
Cary Clark2dc84ad2018-01-26 12:56:22 -05001502#Subtopic Inset_Outset_Offset ##
1503
1504#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001505#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001506
Cary Clark682c58d2018-05-16 07:07:07 -04001507Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001508must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001509empty() returns false. The intersection of Rect pair can be described by:
1510
Cary Clark7fc1d122017-10-09 14:07:42 -04001511#Formula
1512(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1513 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1514##
Cary Clark154beea2017-10-26 07:58:48 -04001515.
1516
Cary Clark7fc1d122017-10-09 14:07:42 -04001517The intersection is only meaningful if the resulting Rect is not empty and
1518describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1519
Cary Clark4855f782018-02-06 09:41:53 -05001520#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001521
1522# ------------------------------------------------------------------------------
1523
Florin Malitaeb420452018-02-20 11:44:43 -05001524#Method bool contains(SkScalar x, SkScalar y) const
1525
1526#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001527#Line # returns true if points are equal or inside ##
Florin Malitaeb420452018-02-20 11:44:43 -05001528Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
1529Returns false if SkRect is empty.
1530
1531#Param x test SkPoint x-coordinate ##
1532#Param y test SkPoint y-coordinate ##
1533
1534#Return true if (x, y) is inside SkRect ##
1535
1536#Example
1537 SkRect rect = { 30, 50, 40, 60 };
1538 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1539 for (auto contained : tests) {
1540 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1541 rect.left(), rect.top(), rect.right(), rect.bottom(),
1542 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1543 contained.x(), contained.y());
1544 }
1545#StdOut
1546rect: (30, 50, 40, 60) contains (30, 50)
1547rect: (30, 50, 40, 60) does not contain (39, 49)
1548rect: (30, 50, 40, 60) does not contain (29, 59)
1549##
1550##
1551
1552#SeeAlso SkIRect::contains
1553
1554##
1555
1556# ------------------------------------------------------------------------------
1557
Cary Clark2dc84ad2018-01-26 12:56:22 -05001558#Method bool contains(const SkRect& r) const
1559
Cary Clarkab2621d2018-01-30 10:08:57 -05001560#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001561Returns true if Rect contains r.
1562Returns false if Rect is empty or r is empty.
1563
1564Rect contains r when Rect area completely includes r area.
1565
1566#Param r Rect contained ##
1567
1568#Return true if all sides of Rect are outside r ##
1569
1570#Example
1571 SkRect rect = { 30, 50, 40, 60 };
1572 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1573 for (auto contained : tests) {
1574 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1575 rect.left(), rect.top(), rect.right(), rect.bottom(),
1576 rect.contains(contained) ? "contains" : "does not contain",
1577 contained.left(), contained.top(), contained.right(), contained.bottom());
1578 }
1579#StdOut
1580rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1581rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1582rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1583##
1584##
1585
1586#SeeAlso SkIRect::contains
1587
1588##
1589
1590# ------------------------------------------------------------------------------
1591
1592#Method bool contains(const SkIRect& r) const
1593
Cary Clarkab2621d2018-01-30 10:08:57 -05001594#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001595Returns true if Rect contains r.
1596Returns false if Rect is empty or r is empty.
1597
1598Rect contains r when Rect area completely includes r area.
1599
1600#Param r IRect contained ##
1601
1602#Return true if all sides of Rect are outside r ##
1603
1604#Example
1605 SkRect rect = { 30, 50, 40, 60 };
1606 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1607 for (auto contained : tests) {
1608 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1609 rect.left(), rect.top(), rect.right(), rect.bottom(),
1610 rect.contains(contained) ? "contains" : "does not contain",
1611 contained.left(), contained.top(), contained.right(), contained.bottom());
1612 }
1613#StdOut
1614rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1615rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1616rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1617##
1618##
1619
1620#SeeAlso SkIRect::contains
1621
1622##
1623
Cary Clarkbc5697d2017-10-04 14:31:33 -04001624# ------------------------------------------------------------------------------
1625
1626#Method bool intersect(const SkRect& r)
1627
Cary Clarkab2621d2018-01-30 10:08:57 -05001628#In Intersection
1629#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001630Returns true if Rect intersects r, and sets Rect to intersection.
1631Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001632
Cary Clark7fc1d122017-10-09 14:07:42 -04001633Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001634
Cary Clark7fc1d122017-10-09 14:07:42 -04001635#Param r limit of result ##
1636
1637#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001638
1639#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001640#Description
1641Two SkDebugf calls are required. If the calls are combined, their arguments
1642may not be evaluated in left to right order: the printed intersection may
1643be before or after the call to intersect.
1644##
Cary Clark154beea2017-10-26 07:58:48 -04001645 SkRect leftRect = { 10, 40, 50, 80 };
1646 SkRect rightRect = { 30, 60, 70, 90 };
1647 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001648 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001649 leftRect.right(), leftRect.bottom());
1650#StdOut
1651 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001652##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001653##
1654
Cary Clark7fc1d122017-10-09 14:07:42 -04001655#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001656
1657##
1658
1659# ------------------------------------------------------------------------------
1660
1661#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1662
Cary Clarkab2621d2018-01-30 10:08:57 -05001663#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001664Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1665construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001666
Cary Clark7fc1d122017-10-09 14:07:42 -04001667Returns true if Rect intersects construction, and sets Rect to intersection.
1668Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001669
Cary Clark7fc1d122017-10-09 14:07:42 -04001670Returns false if either construction or Rect is empty, leaving Rect unchanged.
1671
1672#Param left x minimum of constructed Rect ##
1673#Param top y minimum of constructed Rect ##
1674#Param right x maximum of constructed Rect ##
1675#Param bottom y maximum of constructed Rect ##
1676
1677#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001678
1679#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001680#Description
1681Two SkDebugf calls are required. If the calls are combined, their arguments
1682may not be evaluated in left to right order: the printed intersection may
1683be before or after the call to intersect.
1684##
Cary Clark154beea2017-10-26 07:58:48 -04001685 SkRect leftRect = { 10, 40, 50, 80 };
1686 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001687 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001688 leftRect.right(), leftRect.bottom());
1689#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
1698# ------------------------------------------------------------------------------
1699
1700#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1701
Cary Clarkab2621d2018-01-30 10:08:57 -05001702#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001703Returns true if a intersects b, and sets Rect to intersection.
1704Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001705
Cary Clark7fc1d122017-10-09 14:07:42 -04001706Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001707
Cary Clark7fc1d122017-10-09 14:07:42 -04001708#Param a Rect to intersect ##
1709#Param b Rect to intersect ##
1710
1711#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001712
1713#Example
Cary Clark154beea2017-10-26 07:58:48 -04001714 SkRect result;
1715 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1716 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1717 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001718#StdOut
1719 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001720##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001721##
1722
Cary Clark7fc1d122017-10-09 14:07:42 -04001723#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001724
1725##
1726
Cary Clark7fc1d122017-10-09 14:07:42 -04001727# ------------------------------------------------------------------------------
1728
Cary Clarkbc5697d2017-10-04 14:31:33 -04001729#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1730
Cary Clarkab2621d2018-01-30 10:08:57 -05001731#In Intersection
1732#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001733Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1734construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001735
Cary Clark7fc1d122017-10-09 14:07:42 -04001736Returns true if Rect intersects construction.
1737Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001738
Cary Clark7fc1d122017-10-09 14:07:42 -04001739#Param left x minimum of constructed Rect ##
1740#Param top y minimum of constructed Rect ##
1741#Param right x maximum of constructed Rect ##
1742#Param bottom y maximum of constructed Rect ##
1743
1744#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001745
1746#Example
Cary Clark154beea2017-10-26 07:58:48 -04001747 SkRect rect = { 10, 40, 50, 80 };
1748 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001749#StdOut
1750 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001751##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001752##
1753
Cary Clark7fc1d122017-10-09 14:07:42 -04001754#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001755
1756##
1757
Cary Clark7fc1d122017-10-09 14:07:42 -04001758# ------------------------------------------------------------------------------
1759
Cary Clarkbc5697d2017-10-04 14:31:33 -04001760#Method bool intersects(const SkRect& r) const
1761
Cary Clarkab2621d2018-01-30 10:08:57 -05001762#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001763Returns true if Rect intersects r.
1764Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001765
Cary Clark7fc1d122017-10-09 14:07:42 -04001766#Param r Rect to intersect ##
1767
1768#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769
1770#Example
Cary Clark154beea2017-10-26 07:58:48 -04001771 SkRect rect = { 10, 40, 50, 80 };
1772 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001773#StdOut
1774 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001775##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001776##
1777
Cary Clark7fc1d122017-10-09 14:07:42 -04001778#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001779
1780##
1781
Cary Clark7fc1d122017-10-09 14:07:42 -04001782# ------------------------------------------------------------------------------
1783
Cary Clarkbc5697d2017-10-04 14:31:33 -04001784#Method static bool Intersects(const SkRect& a, const SkRect& b)
1785
Cary Clarkab2621d2018-01-30 10:08:57 -05001786#In Intersection
1787#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001788Returns true if a intersects b.
1789Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001790
Cary Clark7fc1d122017-10-09 14:07:42 -04001791#Param a Rect to intersect ##
1792#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793
Cary Clark7fc1d122017-10-09 14:07:42 -04001794#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001795
1796#Example
Cary Clark154beea2017-10-26 07:58:48 -04001797 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001798#StdOut
1799 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001800##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001801##
1802
Cary Clark7fc1d122017-10-09 14:07:42 -04001803#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001804
1805##
1806
Cary Clark2dc84ad2018-01-26 12:56:22 -05001807#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001808
Cary Clark2dc84ad2018-01-26 12:56:22 -05001809#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001810#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001811
Cary Clark4855f782018-02-06 09:41:53 -05001812#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001813
1814# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001815
1816#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1817
Cary Clarkab2621d2018-01-30 10:08:57 -05001818#In Join
1819#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001820Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1821construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001822
Cary Clark7fc1d122017-10-09 14:07:42 -04001823Sets Rect to the union of itself and the construction.
1824
1825Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1826Rect to construction.
1827
1828#Param left x minimum of constructed Rect ##
1829#Param top y minimum of constructed Rect ##
1830#Param right x maximum of constructed Rect ##
1831#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001832
1833#Example
Cary Clark154beea2017-10-26 07:58:48 -04001834 SkRect rect = { 10, 20, 15, 25};
1835 rect.join(50, 60, 55, 65);
1836 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001837#StdOut
1838 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001839##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001840##
1841
Cary Clark7fc1d122017-10-09 14:07:42 -04001842#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001843
1844##
1845
Cary Clark7fc1d122017-10-09 14:07:42 -04001846# ------------------------------------------------------------------------------
1847
Cary Clarkbc5697d2017-10-04 14:31:33 -04001848#Method void join(const SkRect& r)
1849
Cary Clarkab2621d2018-01-30 10:08:57 -05001850#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001851Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001852
Cary Clark7fc1d122017-10-09 14:07:42 -04001853Has no effect if r is empty. Otherwise, if Rect is empty, sets
1854Rect to r.
1855
1856#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001857
1858#Example
Cary Clark154beea2017-10-26 07:58:48 -04001859 SkRect rect = { 10, 20, 15, 25};
1860 rect.join({50, 60, 55, 65});
1861 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001862#StdOut
1863 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001864##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001865##
1866
Cary Clark7fc1d122017-10-09 14:07:42 -04001867#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001868
1869##
1870
Cary Clark7fc1d122017-10-09 14:07:42 -04001871# ------------------------------------------------------------------------------
1872
Cary Clarkbc5697d2017-10-04 14:31:33 -04001873#Method void joinNonEmptyArg(const SkRect& r)
1874
Cary Clarkab2621d2018-01-30 10:08:57 -05001875#In Join
1876#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001877Sets Rect to the union of itself and r.
1878
1879Asserts if r is empty and SK_DEBUG is defined.
1880If Rect is empty, sets Rect to r.
1881
1882May produce incorrect results if r is empty.
1883
1884#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885
1886#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001887#Description
1888Since Rect is not sorted, first result is copy of toJoin.
1889##
Cary Clark154beea2017-10-26 07:58:48 -04001890 SkRect rect = { 10, 100, 15, 0};
1891 SkRect sorted = rect.makeSorted();
1892 SkRect toJoin = { 50, 60, 55, 65 };
1893 rect.joinNonEmptyArg(toJoin);
1894 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1895 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001896 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1897#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001898rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001899sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001900##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001901##
1902
Cary Clark7fc1d122017-10-09 14:07:42 -04001903#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001904
1905##
1906
Cary Clark7fc1d122017-10-09 14:07:42 -04001907# ------------------------------------------------------------------------------
1908
Cary Clarkbc5697d2017-10-04 14:31:33 -04001909#Method void joinPossiblyEmptyRect(const SkRect& r)
1910
Cary Clarkab2621d2018-01-30 10:08:57 -05001911#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001912#Line # sets to union of bounds; skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001913Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001914
Cary Clark7fc1d122017-10-09 14:07:42 -04001915May produce incorrect results if Rect or r is empty.
1916
1917#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918
1919#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001920#Description
1921Since Rect is not sorted, first result is not useful.
1922##
Cary Clark154beea2017-10-26 07:58:48 -04001923 SkRect rect = { 10, 100, 15, 0};
1924 SkRect sorted = rect.makeSorted();
1925 SkRect toJoin = { 50, 60, 55, 65 };
1926 rect.joinPossiblyEmptyRect(toJoin);
1927 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1928 sorted.joinPossiblyEmptyRect(toJoin);
1929 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001930#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001931rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001932sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001933##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001934##
1935
Cary Clark7fc1d122017-10-09 14:07:42 -04001936#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001937
1938##
1939
Cary Clark2dc84ad2018-01-26 12:56:22 -05001940#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001941
Cary Clark2dc84ad2018-01-26 12:56:22 -05001942#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001943#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001944
Cary Clark4855f782018-02-06 09:41:53 -05001945#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001946
Cary Clarkbc5697d2017-10-04 14:31:33 -04001947#Method void round(SkIRect* dst) const
1948
Cary Clarkab2621d2018-01-30 10:08:57 -05001949#In Rounding
1950#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001951Sets IRect by adding 0.5 and discarding the fractional portion of Rect
1952members, using
1953#Formula
1954(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1955 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
1956##
1957.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001958
Cary Clark7fc1d122017-10-09 14:07:42 -04001959#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001960
1961#Example
Cary Clark154beea2017-10-26 07:58:48 -04001962 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1963 SkIRect round;
1964 rect.round(&round);
1965 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001966#StdOut
1967round: 31, 51, 41, 61
1968##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001969##
1970
Cary Clark7fc1d122017-10-09 14:07:42 -04001971#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001972
1973##
1974
Cary Clark7fc1d122017-10-09 14:07:42 -04001975# ------------------------------------------------------------------------------
1976
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977#Method void roundOut(SkIRect* dst) const
1978
Cary Clarkab2621d2018-01-30 10:08:57 -05001979#In Rounding
1980#Line # sets members to nearest integer value away from opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001981Sets IRect 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 IRect ##
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 SkIRect round;
1994 rect.roundOut(&round);
1995 SkDebugf("round: %d, %d, %d, %d\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 Clark682c58d2018-05-16 07:07:07 -04002007#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04002008
Cary Clarkab2621d2018-01-30 10:08:57 -05002009#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002010Sets Rect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002011rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04002012#Formula
2013(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2014 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2015##
2016.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002017
Cary Clark7fc1d122017-10-09 14:07:42 -04002018#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002019
2020#Example
Cary Clark154beea2017-10-26 07:58:48 -04002021 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2022 SkRect round;
2023 rect.roundOut(&round);
2024 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002025#StdOut
2026round: 30, 50, 41, 61
2027##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002028##
2029
Cary Clark7fc1d122017-10-09 14:07:42 -04002030#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002031
2032##
2033
Cary Clark7fc1d122017-10-09 14:07:42 -04002034# ------------------------------------------------------------------------------
2035
Cary Clarkbc5697d2017-10-04 14:31:33 -04002036#Method void roundIn(SkIRect* dst) const
2037
Cary Clarkab2621d2018-01-30 10:08:57 -05002038#In Rounding
2039#Line # sets members to nearest integer value towards opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002040Sets Rect by rounding up fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002041discarding the fractional portion of fRight and fBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002042
Cary Clark7fc1d122017-10-09 14:07:42 -04002043#Formula
2044(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2045 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2046##
2047.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002048
Cary Clark7fc1d122017-10-09 14:07:42 -04002049#Param dst storage for 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;
2054 rect.roundIn(&round);
2055 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002056#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002057round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002058##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002059##
2060
Cary Clark7fc1d122017-10-09 14:07:42 -04002061#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002062
2063##
2064
Cary Clark7fc1d122017-10-09 14:07:42 -04002065# ------------------------------------------------------------------------------
2066
Cary Clarkbc5697d2017-10-04 14:31:33 -04002067#Method SkIRect round() const
2068
Cary Clarkab2621d2018-01-30 10:08:57 -05002069#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002070Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2071members, using
2072#Formula
2073(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2074 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2075##
2076.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002077
Cary Clark7fc1d122017-10-09 14:07:42 -04002078#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002079
2080#Example
Cary Clark154beea2017-10-26 07:58:48 -04002081 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2082 SkIRect round = rect.round();
2083 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002084#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002085round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002086##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002087##
2088
Cary Clark7fc1d122017-10-09 14:07:42 -04002089#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002090
2091##
2092
Cary Clark7fc1d122017-10-09 14:07:42 -04002093# ------------------------------------------------------------------------------
2094
Cary Clarkbc5697d2017-10-04 14:31:33 -04002095#Method SkIRect roundOut() const
2096
Cary Clarkab2621d2018-01-30 10:08:57 -05002097#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002098Sets IRect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002099rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04002100#Formula
2101(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2102 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2103##
2104.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002105
Cary Clark7fc1d122017-10-09 14:07:42 -04002106#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002107
2108#Example
Cary Clark154beea2017-10-26 07:58:48 -04002109 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2110 SkIRect round = rect.roundOut();
2111 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002112#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002113round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002114##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002115##
2116
Cary Clark7fc1d122017-10-09 14:07:42 -04002117#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002118
2119##
2120
Cary Clark2dc84ad2018-01-26 12:56:22 -05002121#Subtopic Rounding ##
2122
2123#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002124#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002125
Cary Clark4855f782018-02-06 09:41:53 -05002126#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04002127
2128# ------------------------------------------------------------------------------
2129
Cary Clarkbc5697d2017-10-04 14:31:33 -04002130#Method void sort()
2131
Cary Clarkab2621d2018-01-30 10:08:57 -05002132#In Sorting
2133#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002134Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2135fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2136and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002137
2138#Example
Cary Clark154beea2017-10-26 07:58:48 -04002139 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2140 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2141 rect.sort();
2142 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002143#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002144rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002145sorted: 20.5, 10.5, 30.5, 50.5
2146##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002147##
2148
Cary Clark2dc84ad2018-01-26 12:56:22 -05002149#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002150
2151##
2152
Cary Clark7fc1d122017-10-09 14:07:42 -04002153# ------------------------------------------------------------------------------
2154
Cary Clarkbc5697d2017-10-04 14:31:33 -04002155#Method SkRect makeSorted() const
2156
Cary Clarkab2621d2018-01-30 10:08:57 -05002157#In Sorting
Cary Clark4855f782018-02-06 09:41:53 -05002158#In Constructor
Cary Clark682c58d2018-05-16 07:07:07 -04002159#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002160Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2161with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2162and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002163
Cary Clark7fc1d122017-10-09 14:07:42 -04002164#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002165
2166#Example
Cary Clark154beea2017-10-26 07:58:48 -04002167 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2168 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2169 SkRect sort = rect.makeSorted();
2170 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002171#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002172rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002173sorted: 20.5, 10.5, 30.5, 50.5
2174##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002175##
2176
Cary Clark2dc84ad2018-01-26 12:56:22 -05002177#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002178
2179##
2180
Cary Clark2dc84ad2018-01-26 12:56:22 -05002181#Subtopic Sorting ##
2182
Cary Clark7fc1d122017-10-09 14:07:42 -04002183# ------------------------------------------------------------------------------
2184
Cary Clarkbc5697d2017-10-04 14:31:33 -04002185#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002186#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002187#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002188Returns pointer to first Scalar in Rect, to treat it as an array with four
2189entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002190
Cary Clark7fc1d122017-10-09 14:07:42 -04002191#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002192
2193#Example
Cary Clark154beea2017-10-26 07:58:48 -04002194 SkRect rect = {7, 11, 13, 17};
2195SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2196#StdOut
2197rect.asScalars() == &rect.fLeft
2198##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002199##
2200
Cary Clark7fc1d122017-10-09 14:07:42 -04002201#SeeAlso toQuad
2202
Cary Clarkbc5697d2017-10-04 14:31:33 -04002203##
2204
Cary Clark7fc1d122017-10-09 14:07:42 -04002205# ------------------------------------------------------------------------------
2206
Cary Clarkbc5697d2017-10-04 14:31:33 -04002207#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002208#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002209#Line # sends text representation to standard output using floats ##
Cary Clark682c58d2018-05-16 07:07:07 -04002210Writes text representation of Rect to standard output. Set asHex to true to
Cary Clark7fc1d122017-10-09 14:07:42 -04002211generate exact binary representations of floating point numbers.
2212
2213#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002214
2215#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002216 SkRect rect = {20, 30, 40, 50};
2217 for (bool dumpAsHex : { false, true } ) {
2218 rect.dump(dumpAsHex);
2219 SkDebugf("\n");
2220 }
2221#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002222SkRect::MakeLTRB(20, 30, 40, 50);
2223
2224SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2225 SkBits2Float(0x41f00000), /* 30.000000 */
2226 SkBits2Float(0x42200000), /* 40.000000 */
2227 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002228##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002229##
2230
Cary Clark7fc1d122017-10-09 14:07:42 -04002231#SeeAlso dumpHex
2232
Cary Clarkbc5697d2017-10-04 14:31:33 -04002233##
2234
Cary Clark7fc1d122017-10-09 14:07:42 -04002235# ------------------------------------------------------------------------------
2236
Cary Clarkbc5697d2017-10-04 14:31:33 -04002237#Method void dump() const
2238
Cary Clark7fc1d122017-10-09 14:07:42 -04002239Writes text representation of Rect to standard output. The representation may be
2240directly compiled as C++ code. Floating point values are written
2241with limited precision; it may not be possible to reconstruct original Rect
2242from output.
2243
Cary Clarkbc5697d2017-10-04 14:31:33 -04002244#Example
Cary Clark154beea2017-10-26 07:58:48 -04002245SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2246rect.dump();
2247SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2248SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002249#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002250SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002251rect is not equal to copy
2252##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002253##
2254
Cary Clark7fc1d122017-10-09 14:07:42 -04002255#SeeAlso dumpHex
2256
Cary Clarkbc5697d2017-10-04 14:31:33 -04002257##
2258
Cary Clark7fc1d122017-10-09 14:07:42 -04002259# ------------------------------------------------------------------------------
2260
Cary Clarkbc5697d2017-10-04 14:31:33 -04002261#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002262#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002263#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002264Writes text representation of Rect to standard output. The representation may be
2265directly compiled as C++ code. Floating point values are written
2266in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2267original Rect.
2268
Cary Clark682c58d2018-05-16 07:07:07 -04002269Use instead of dump() when submitting
2270#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002271.
2272
Cary Clarkbc5697d2017-10-04 14:31:33 -04002273#Example
Cary Clark154beea2017-10-26 07:58:48 -04002274 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2275rect.dumpHex();
2276SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2277 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2278 SkBits2Float(0x40266666), /* 2.600000 */
2279 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002280SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2281#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002282SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2283 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2284 SkBits2Float(0x40266666), /* 2.600000 */
2285 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002286rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002287##
Cary Clark7fc1d122017-10-09 14:07:42 -04002288##
2289
2290#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002291
2292##
2293
Cary Clark0c95aab2018-01-08 16:20:59 -05002294#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05002295#Deprecated
2296##
2297
Cary Clarkbc5697d2017-10-04 14:31:33 -04002298#Struct SkRect ##
2299
2300#Topic Rect ##