blob: 2adfecf5bc67d999e50b051af575591986f9e24b [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 ##
907Sets to bounds of Point array with count entries. If any point contains a non-finite value
908then the rect will also be non-finite.
909
910#Param pts Point array ##
911#Param count entries in array ##
912
913#Example
914// incomplete
915##
916
917#SeeAlso setBoundsCheck
918#Method ##
919
920# ------------------------------------------------------------------------------
921
Cary Clarkbc5697d2017-10-04 14:31:33 -0400922#Method void setEmpty()
923
Cary Clarkab2621d2018-01-30 10:08:57 -0500924#In Set
925#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400926Sets Rect to (0, 0, 0, 0).
927
928Many other rectangles are empty; if left is equal to or greater than right,
929or if top is equal to or greater than bottom. Setting all members to zero
930is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400931
932#Example
Cary Clark154beea2017-10-26 07:58:48 -0400933 SkRect rect = {3, 4, 1, 2};
934 for (int i = 0; i < 2; ++i) {
935 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
936 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
937 rect.setEmpty();
938 }
939#StdOut
940rect: {3, 4, 1, 2} is empty
941rect: {0, 0, 0, 0} is empty
942##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400943##
944
Cary Clark7fc1d122017-10-09 14:07:42 -0400945#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400946
947##
948
949# ------------------------------------------------------------------------------
950
951#Method void set(const SkIRect& src)
952
Cary Clarkab2621d2018-01-30 10:08:57 -0500953#In Set
954#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400955Sets Rect to src, promoting src members from integer to Scalar.
Cary Clark682c58d2018-05-16 07:07:07 -0400956Very large values in src may lose precision.
Cary Clark7fc1d122017-10-09 14:07:42 -0400957
958#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400959
960#Example
Cary Clark154beea2017-10-26 07:58:48 -0400961 SkIRect i_rect = {3, 4, 1, 2};
962 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
963 SkRect f_rect;
964 f_rect.set(i_rect);
965 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
966#StdOut
967i_rect: {3, 4, 1, 2}
968f_rect: {3, 4, 1, 2}
969##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400970##
971
Cary Clark7fc1d122017-10-09 14:07:42 -0400972#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400973
974##
975
976# ------------------------------------------------------------------------------
977
978#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
979
Cary Clarkab2621d2018-01-30 10:08:57 -0500980#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400981Sets Rect to (left, top, right, bottom).
982left and right are not sorted; left is not necessarily less than right.
983top and bottom are not sorted; top is not necessarily less than bottom.
984
985#Param left stored in fLeft ##
986#Param top stored in fTop ##
987#Param right stored in fRight ##
988#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400989
990#Example
Cary Clark154beea2017-10-26 07:58:48 -0400991 SkRect rect1 = {3, 4, 1, 2};
992 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
993 SkRect rect2;
994 rect2.set(3, 4, 1, 2);
995 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
996#StdOut
997rect1: {3, 4, 1, 2}
998rect2: {3, 4, 1, 2}
999##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001000##
1001
Cary Clark7fc1d122017-10-09 14:07:42 -04001002#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001003
1004##
1005
1006# ------------------------------------------------------------------------------
1007
1008#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1009
Cary Clarkab2621d2018-01-30 10:08:57 -05001010#In Set
1011#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001012Sets Rect to (left, top, right, bottom).
1013left and right are not sorted; left is not necessarily less than right.
1014top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001015
Cary Clark7fc1d122017-10-09 14:07:42 -04001016#Param left stored in fLeft ##
1017#Param top stored in fTop ##
1018#Param right stored in fRight ##
1019#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001020
1021#Example
Cary Clark154beea2017-10-26 07:58:48 -04001022 SkRect rect1 = {3, 4, 1, 2};
1023 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1024 SkRect rect2;
1025 rect2.setLTRB(3, 4, 1, 2);
1026 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1027#StdOut
1028rect1: {3, 4, 1, 2}
1029rect2: {3, 4, 1, 2}
1030##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001031##
1032
Cary Clark7fc1d122017-10-09 14:07:42 -04001033#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001034
1035##
1036
1037# ------------------------------------------------------------------------------
1038
Cary Clarkbc5697d2017-10-04 14:31:33 -04001039#Method void set(const SkPoint pts[], int count)
1040
Cary Clarkab2621d2018-01-30 10:08:57 -05001041#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001042Sets to bounds of Point array with count entries. If count is zero or smaller,
1043or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001044
Cary Clark7fc1d122017-10-09 14:07:42 -04001045Result is either empty or sorted: fLeft is less than or equal to fRight, and
1046fTop is less than or equal to fBottom.
1047
1048#Param pts Point array ##
1049#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001050
1051#Example
Cary Clark154beea2017-10-26 07:58:48 -04001052 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1053 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1054 SkRect rect;
1055 rect.set(points, count);
1056 if (count > 0) {
1057 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1058 } else {
1059 SkDebugf("%14s", " ");
1060 }
1061 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1062 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1063 }
1064#StdOut
1065 count: 0 rect: 0, 0, 0, 0
1066added: 3, 4 count: 1 rect: 3, 4, 3, 4
1067added: 1, 2 count: 2 rect: 1, 2, 3, 4
1068added: 5, 6 count: 3 rect: 1, 2, 5, 6
1069added: nan, 8 count: 4 rect: 0, 0, 0, 0
1070##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001071##
1072
Cary Clark7fc1d122017-10-09 14:07:42 -04001073#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001074
1075##
1076
1077# ------------------------------------------------------------------------------
1078
Cary Clarkbc5697d2017-10-04 14:31:33 -04001079#Method void set(const SkPoint& p0, const SkPoint& p1)
1080
Cary Clarkab2621d2018-01-30 10:08:57 -05001081#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001082Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1083sorted and may be empty. Does not check to see if values are finite.
1084
1085#Param p0 corner to include ##
1086#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001087
1088#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001089#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001090p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -04001091##
Cary Clark154beea2017-10-26 07:58:48 -04001092 SkPoint point1 = {SK_ScalarNaN, 8};
1093 SkPoint point2 = {3, 4};
1094 SkRect rect;
1095 rect.set(point1, point2);
1096 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1097 rect.set(point2, point1);
1098 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001099##
1100
Cary Clark7fc1d122017-10-09 14:07:42 -04001101#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001102
1103##
1104
1105# ------------------------------------------------------------------------------
1106
1107#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1108
Cary Clarkab2621d2018-01-30 10:08:57 -05001109#In Set
1110#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark682c58d2018-05-16 07:07:07 -04001111Sets Rect to
Cary Clark7fc1d122017-10-09 14:07:42 -04001112#Formula
1113(x, y, x + width, y + height)
1114##
1115. Does not validate input;
1116width or height may be negative.
1117
1118#Param x stored in fLeft ##
1119#Param y stored in fTop ##
1120#Param width added to x and stored in fRight ##
1121#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001122
1123#Example
Cary Clark154beea2017-10-26 07:58:48 -04001124 SkRect rect;
1125 rect.setXYWH(5, 35, -15, 25);
1126 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1127 rect.bottom(), rect.isEmpty() ? "true" : "false");
1128 rect.sort();
1129 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1130 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001131#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001132rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001133rect: -10, 35, 5, 60 isEmpty: false
1134##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001135##
1136
Cary Clark7fc1d122017-10-09 14:07:42 -04001137#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001138
1139##
1140
1141# ------------------------------------------------------------------------------
1142
1143#Method void setWH(SkScalar width, SkScalar height)
1144
Cary Clarkab2621d2018-01-30 10:08:57 -05001145#In Set
1146#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001147Sets Rect to (0, 0, width, height). Does not validate input;
1148width or height may be negative.
1149
1150#Param width stored in fRight ##
1151#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001152
1153#Example
Cary Clark154beea2017-10-26 07:58:48 -04001154 SkRect rect;
1155 rect.setWH(-15, 25);
1156 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1157 rect.bottom(), rect.isEmpty() ? "true" : "false");
1158 rect.sort();
1159 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1160 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001161#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001162rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001163rect: -15, 0, 0, 25 isEmpty: false
1164##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001165##
1166
Cary Clark7fc1d122017-10-09 14:07:42 -04001167#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001168
1169##
1170
Cary Clark2dc84ad2018-01-26 12:56:22 -05001171#Subtopic Set ##
1172
1173#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -04001174#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001175
Cary Clark4855f782018-02-06 09:41:53 -05001176#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001177
1178# ------------------------------------------------------------------------------
1179
1180#Method void iset(int left, int top, int right, int bottom)
1181
Cary Clarkab2621d2018-01-30 10:08:57 -05001182#In From_Integers
1183#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001184Sets Rect to (left, top, right, bottom).
1185All parameters are promoted from integer to Scalar.
1186left and right are not sorted; left is not necessarily less than right.
1187top and bottom are not sorted; top is not necessarily less than bottom.
1188
1189#Param left promoted to SkScalar and stored in fLeft ##
1190#Param top promoted to SkScalar and stored in fTop ##
1191#Param right promoted to SkScalar and stored in fRight ##
1192#Param bottom promoted to SkScalar and stored in fBottom ##
1193
1194#Example
1195 SkRect rect1 = {3, 4, 1, 2};
1196 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1197 SkRect rect2;
1198 rect2.iset(3, 4, 1, 2);
1199 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1200#StdOut
1201rect1: {3, 4, 1, 2}
1202rect2: {3, 4, 1, 2}
1203##
1204##
1205
1206#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1207
1208##
1209
1210# ------------------------------------------------------------------------------
1211
1212#Method void isetWH(int width, int height)
1213
Cary Clarkab2621d2018-01-30 10:08:57 -05001214#In From_Integers
1215#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001216Sets Rect to (0, 0, width, height).
1217width and height may be zero or negative. width and height are promoted from
1218integer to SkScalar, large values may lose precision.
1219
1220#Param width promoted to SkScalar and stored in fRight ##
1221#Param height promoted to SkScalar and stored in fBottom ##
1222
1223#Example
1224 SkRect rect1 = {0, 0, 1, 2};
1225 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1226 SkRect rect2;
1227 rect2.isetWH(1, 2);
1228 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1229#StdOut
1230rect1: {0, 0, 1, 2}
1231rect2: {0, 0, 1, 2}
1232##
1233##
1234
1235#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1236
1237##
1238
1239#Subtopic From_Integers ##
1240
1241#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001242#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001243
Cary Clark4855f782018-02-06 09:41:53 -05001244#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001245
Cary Clarkbc5697d2017-10-04 14:31:33 -04001246# ------------------------------------------------------------------------------
1247
Cary Clarkbc5697d2017-10-04 14:31:33 -04001248#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1249
Cary Clarkab2621d2018-01-30 10:08:57 -05001250#In Inset_Outset_Offset
1251#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001252Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001253
Cary Clark7fc1d122017-10-09 14:07:42 -04001254If dx is negative, Rect returned is moved to the left.
1255If dx is positive, Rect returned is moved to the right.
1256If dy is negative, Rect returned is moved upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001257If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001258
Cary Clark7fc1d122017-10-09 14:07:42 -04001259#Param dx added to fLeft and fRight ##
1260#Param dy added to fTop and fBottom ##
1261
1262#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001263
1264#Example
Cary Clark154beea2017-10-26 07:58:48 -04001265 SkRect rect = { 10, 50, 20, 60 };
1266 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1267 rect.bottom(), rect.isEmpty() ? "true" : "false");
1268 rect = rect.makeOffset(15, 32);
1269 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1270 rect.bottom(), rect.isEmpty() ? "true" : "false");
1271#StdOut
1272rect: 10, 50, 20, 60 isEmpty: false
1273rect: 25, 82, 35, 92 isEmpty: false
1274##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001275##
1276
Cary Clark7fc1d122017-10-09 14:07:42 -04001277#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001278
1279##
1280
1281# ------------------------------------------------------------------------------
1282
1283#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1284
Cary Clarkab2621d2018-01-30 10:08:57 -05001285#In Inset_Outset_Offset
1286#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001287Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001288
Cary Clark7fc1d122017-10-09 14:07:42 -04001289If dx is negative, Rect returned is wider.
1290If dx is positive, Rect returned is narrower.
1291If dy is negative, Rect returned is taller.
Cary Clark682c58d2018-05-16 07:07:07 -04001292If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001293
Cary Clark7fc1d122017-10-09 14:07:42 -04001294#Param dx added to fLeft and subtracted from fRight ##
1295#Param dy added to fTop and subtracted from fBottom ##
1296
1297#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001298
1299#Example
Cary Clark154beea2017-10-26 07:58:48 -04001300 SkRect rect = { 10, 50, 20, 60 };
1301 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1302 rect.bottom(), rect.isEmpty() ? "true" : "false");
1303 rect = rect.makeInset(15, 32);
1304 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1305 rect.bottom(), rect.isEmpty() ? "true" : "false");
1306#StdOut
1307rect: 10, 50, 20, 60 isEmpty: false
1308rect: 25, 82, 5, 28 isEmpty: true
1309##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001310##
1311
Cary Clark7fc1d122017-10-09 14:07:42 -04001312#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001313
1314##
1315
1316# ------------------------------------------------------------------------------
1317
1318#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1319
Cary Clarkab2621d2018-01-30 10:08:57 -05001320#In Inset_Outset_Offset
1321#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001322Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001323
Cary Clark7fc1d122017-10-09 14:07:42 -04001324If dx is negative, Rect returned is narrower.
1325If dx is positive, Rect returned is wider.
1326If dy is negative, Rect returned is shorter.
Cary Clark682c58d2018-05-16 07:07:07 -04001327If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001328
Cary Clark7fc1d122017-10-09 14:07:42 -04001329#Param dx subtracted to fLeft and added from fRight ##
1330#Param dy subtracted to fTop and added from fBottom ##
1331
1332#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001333
1334#Example
Cary Clark154beea2017-10-26 07:58:48 -04001335 SkRect rect = { 10, 50, 20, 60 };
1336 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1337 rect.bottom(), rect.isEmpty() ? "true" : "false");
1338 rect = rect.makeOutset(15, 32);
1339 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1340 rect.bottom(), rect.isEmpty() ? "true" : "false");
1341#StdOut
1342rect: 10, 50, 20, 60 isEmpty: false
1343rect: -5, 18, 35, 92 isEmpty: false
1344##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001345##
1346
Cary Clark7fc1d122017-10-09 14:07:42 -04001347#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001348
1349##
1350
1351# ------------------------------------------------------------------------------
1352
1353#Method void offset(SkScalar dx, SkScalar dy)
1354
Cary Clarkab2621d2018-01-30 10:08:57 -05001355#In Inset_Outset_Offset
1356#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001357Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358
Cary Clark7fc1d122017-10-09 14:07:42 -04001359If dx is negative, moves Rect to the left.
1360If dx is positive, moves Rect to the right.
1361If dy is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001362If dy is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001363
1364#Param dx offset added to fLeft and fRight ##
1365#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001366
1367#Example
Cary Clark154beea2017-10-26 07:58:48 -04001368 SkRect rect = { 10, 14, 50, 73 };
1369 rect.offset(5, 13);
1370 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1371#StdOut
1372rect: 15, 27, 55, 86
1373##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001374##
1375
Cary Clark7fc1d122017-10-09 14:07:42 -04001376#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001377
1378##
1379
1380# ------------------------------------------------------------------------------
1381
1382#Method void offset(const SkPoint& delta)
1383
Cary Clarkab2621d2018-01-30 10:08:57 -05001384#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001385Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1386fTop, fBottom.
1387
1388If delta.fX is negative, moves Rect to the left.
1389If delta.fX is positive, moves Rect to the right.
1390If delta.fY is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001391If delta.fY is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001392
1393#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001394
1395#Example
Cary Clark154beea2017-10-26 07:58:48 -04001396 SkRect rect = { 10, 14, 50, 73 };
1397 rect.offset({5, 13});
1398 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1399#StdOut
1400rect: 15, 27, 55, 86
1401##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001402##
1403
Cary Clark7fc1d122017-10-09 14:07:42 -04001404#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001405
1406##
1407
1408# ------------------------------------------------------------------------------
1409
1410#Method void offsetTo(SkScalar newX, SkScalar newY)
1411
Cary Clarkab2621d2018-01-30 10:08:57 -05001412#In Inset_Outset_Offset
1413#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001414Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1415are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001416
Cary Clark7fc1d122017-10-09 14:07:42 -04001417#Param newX stored in fLeft, preserving width() ##
1418#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001419
1420#Example
Cary Clark154beea2017-10-26 07:58:48 -04001421 SkRect rect = { 10, 14, 50, 73 };
1422 rect.offsetTo(15, 27);
1423 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1424#StdOut
1425rect: 15, 27, 55, 86
1426##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001427##
1428
Cary Clark7fc1d122017-10-09 14:07:42 -04001429#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001430
1431##
1432
1433# ------------------------------------------------------------------------------
1434
1435#Method void inset(SkScalar dx, SkScalar dy)
1436
Cary Clarkab2621d2018-01-30 10:08:57 -05001437#In Inset_Outset_Offset
1438#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001439Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001440
Cary Clark7fc1d122017-10-09 14:07:42 -04001441If dx is positive, makes Rect narrower.
1442If dx is negative, makes Rect wider.
1443If dy is positive, makes Rect shorter.
1444If dy is negative, makes Rect taller.
1445
1446#Param dx added to fLeft and subtracted from fRight ##
1447#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001448
1449#Example
Cary Clark154beea2017-10-26 07:58:48 -04001450 SkRect rect = { 10, 14, 50, 73 };
1451 rect.inset(5, 13);
1452 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1453#StdOut
1454rect: 15, 27, 45, 60
1455##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001456##
1457
Cary Clark7fc1d122017-10-09 14:07:42 -04001458#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001459
1460##
1461
1462# ------------------------------------------------------------------------------
1463
1464#Method void outset(SkScalar dx, SkScalar dy)
1465
Cary Clarkab2621d2018-01-30 10:08:57 -05001466#In Inset_Outset_Offset
1467#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001468Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001469
Cary Clark7fc1d122017-10-09 14:07:42 -04001470If dx is positive, makes Rect wider.
1471If dx is negative, makes Rect narrower.
1472If dy is positive, makes Rect taller.
1473If dy is negative, makes Rect shorter.
1474
1475#Param dx subtracted to fLeft and added from fRight ##
1476#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001477
1478#Example
Cary Clark154beea2017-10-26 07:58:48 -04001479 SkRect rect = { 10, 14, 50, 73 };
1480 rect.outset(5, 13);
1481 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1482#StdOut
1483rect: 5, 1, 55, 86
1484##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001485##
1486
Cary Clark7fc1d122017-10-09 14:07:42 -04001487#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488
1489##
1490
Cary Clark2dc84ad2018-01-26 12:56:22 -05001491#Subtopic Inset_Outset_Offset ##
1492
1493#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001494#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001495
Cary Clark682c58d2018-05-16 07:07:07 -04001496Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001497must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001498empty() returns false. The intersection of Rect pair can be described by:
1499
Cary Clark7fc1d122017-10-09 14:07:42 -04001500#Formula
1501(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1502 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1503##
Cary Clark154beea2017-10-26 07:58:48 -04001504.
1505
Cary Clark7fc1d122017-10-09 14:07:42 -04001506The intersection is only meaningful if the resulting Rect is not empty and
1507describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1508
Cary Clark4855f782018-02-06 09:41:53 -05001509#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001510
1511# ------------------------------------------------------------------------------
1512
Florin Malitaeb420452018-02-20 11:44:43 -05001513#Method bool contains(SkScalar x, SkScalar y) const
1514
1515#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001516#Line # returns true if points are equal or inside ##
Florin Malitaeb420452018-02-20 11:44:43 -05001517Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
1518Returns false if SkRect is empty.
1519
1520#Param x test SkPoint x-coordinate ##
1521#Param y test SkPoint y-coordinate ##
1522
1523#Return true if (x, y) is inside SkRect ##
1524
1525#Example
1526 SkRect rect = { 30, 50, 40, 60 };
1527 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1528 for (auto contained : tests) {
1529 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1530 rect.left(), rect.top(), rect.right(), rect.bottom(),
1531 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1532 contained.x(), contained.y());
1533 }
1534#StdOut
1535rect: (30, 50, 40, 60) contains (30, 50)
1536rect: (30, 50, 40, 60) does not contain (39, 49)
1537rect: (30, 50, 40, 60) does not contain (29, 59)
1538##
1539##
1540
1541#SeeAlso SkIRect::contains
1542
1543##
1544
1545# ------------------------------------------------------------------------------
1546
Cary Clark2dc84ad2018-01-26 12:56:22 -05001547#Method bool contains(const SkRect& r) const
1548
Cary Clarkab2621d2018-01-30 10:08:57 -05001549#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001550Returns true if Rect contains r.
1551Returns false if Rect is empty or r is empty.
1552
1553Rect contains r when Rect area completely includes r area.
1554
1555#Param r Rect contained ##
1556
1557#Return true if all sides of Rect are outside r ##
1558
1559#Example
1560 SkRect rect = { 30, 50, 40, 60 };
1561 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1562 for (auto contained : tests) {
1563 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1564 rect.left(), rect.top(), rect.right(), rect.bottom(),
1565 rect.contains(contained) ? "contains" : "does not contain",
1566 contained.left(), contained.top(), contained.right(), contained.bottom());
1567 }
1568#StdOut
1569rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1570rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1571rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1572##
1573##
1574
1575#SeeAlso SkIRect::contains
1576
1577##
1578
1579# ------------------------------------------------------------------------------
1580
1581#Method bool contains(const SkIRect& r) const
1582
Cary Clarkab2621d2018-01-30 10:08:57 -05001583#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001584Returns true if Rect contains r.
1585Returns false if Rect is empty or r is empty.
1586
1587Rect contains r when Rect area completely includes r area.
1588
1589#Param r IRect contained ##
1590
1591#Return true if all sides of Rect are outside r ##
1592
1593#Example
1594 SkRect rect = { 30, 50, 40, 60 };
1595 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1596 for (auto contained : tests) {
1597 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1598 rect.left(), rect.top(), rect.right(), rect.bottom(),
1599 rect.contains(contained) ? "contains" : "does not contain",
1600 contained.left(), contained.top(), contained.right(), contained.bottom());
1601 }
1602#StdOut
1603rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1604rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1605rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1606##
1607##
1608
1609#SeeAlso SkIRect::contains
1610
1611##
1612
Cary Clarkbc5697d2017-10-04 14:31:33 -04001613# ------------------------------------------------------------------------------
1614
1615#Method bool intersect(const SkRect& r)
1616
Cary Clarkab2621d2018-01-30 10:08:57 -05001617#In Intersection
1618#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001619Returns true if Rect intersects r, and sets Rect to intersection.
1620Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001621
Cary Clark7fc1d122017-10-09 14:07:42 -04001622Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001623
Cary Clark7fc1d122017-10-09 14:07:42 -04001624#Param r limit of result ##
1625
1626#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001627
1628#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001629#Description
1630Two SkDebugf calls are required. If the calls are combined, their arguments
1631may not be evaluated in left to right order: the printed intersection may
1632be before or after the call to intersect.
1633##
Cary Clark154beea2017-10-26 07:58:48 -04001634 SkRect leftRect = { 10, 40, 50, 80 };
1635 SkRect rightRect = { 30, 60, 70, 90 };
1636 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001637 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001638 leftRect.right(), leftRect.bottom());
1639#StdOut
1640 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001641##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001642##
1643
Cary Clark7fc1d122017-10-09 14:07:42 -04001644#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001645
1646##
1647
1648# ------------------------------------------------------------------------------
1649
1650#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1651
Cary Clarkab2621d2018-01-30 10:08:57 -05001652#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001653Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1654construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001655
Cary Clark7fc1d122017-10-09 14:07:42 -04001656Returns true if Rect intersects construction, and sets Rect to intersection.
1657Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001658
Cary Clark7fc1d122017-10-09 14:07:42 -04001659Returns false if either construction or Rect is empty, leaving Rect unchanged.
1660
1661#Param left x minimum of constructed Rect ##
1662#Param top y minimum of constructed Rect ##
1663#Param right x maximum of constructed Rect ##
1664#Param bottom y maximum of constructed Rect ##
1665
1666#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001667
1668#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001669#Description
1670Two SkDebugf calls are required. If the calls are combined, their arguments
1671may not be evaluated in left to right order: the printed intersection may
1672be before or after the call to intersect.
1673##
Cary Clark154beea2017-10-26 07:58:48 -04001674 SkRect leftRect = { 10, 40, 50, 80 };
1675 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001676 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001677 leftRect.right(), leftRect.bottom());
1678#StdOut
1679 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001680##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001681##
1682
Cary Clark7fc1d122017-10-09 14:07:42 -04001683#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001684
1685##
1686
1687# ------------------------------------------------------------------------------
1688
1689#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1690
Cary Clarkab2621d2018-01-30 10:08:57 -05001691#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001692Returns true if a intersects b, and sets Rect to intersection.
1693Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001694
Cary Clark7fc1d122017-10-09 14:07:42 -04001695Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001696
Cary Clark7fc1d122017-10-09 14:07:42 -04001697#Param a Rect to intersect ##
1698#Param b Rect to intersect ##
1699
1700#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001701
1702#Example
Cary Clark154beea2017-10-26 07:58:48 -04001703 SkRect result;
1704 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1705 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1706 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001707#StdOut
1708 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001709##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001710##
1711
Cary Clark7fc1d122017-10-09 14:07:42 -04001712#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001713
1714##
1715
Cary Clark7fc1d122017-10-09 14:07:42 -04001716# ------------------------------------------------------------------------------
1717
Cary Clarkbc5697d2017-10-04 14:31:33 -04001718#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1719
Cary Clarkab2621d2018-01-30 10:08:57 -05001720#In Intersection
1721#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001722Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1723construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001724
Cary Clark7fc1d122017-10-09 14:07:42 -04001725Returns true if Rect intersects construction.
1726Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001727
Cary Clark7fc1d122017-10-09 14:07:42 -04001728#Param left x minimum of constructed Rect ##
1729#Param top y minimum of constructed Rect ##
1730#Param right x maximum of constructed Rect ##
1731#Param bottom y maximum of constructed Rect ##
1732
1733#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001734
1735#Example
Cary Clark154beea2017-10-26 07:58:48 -04001736 SkRect rect = { 10, 40, 50, 80 };
1737 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001738#StdOut
1739 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001740##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001741##
1742
Cary Clark7fc1d122017-10-09 14:07:42 -04001743#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001744
1745##
1746
Cary Clark7fc1d122017-10-09 14:07:42 -04001747# ------------------------------------------------------------------------------
1748
Cary Clarkbc5697d2017-10-04 14:31:33 -04001749#Method bool intersects(const SkRect& r) const
1750
Cary Clarkab2621d2018-01-30 10:08:57 -05001751#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001752Returns true if Rect intersects r.
1753Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001754
Cary Clark7fc1d122017-10-09 14:07:42 -04001755#Param r Rect to intersect ##
1756
1757#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001758
1759#Example
Cary Clark154beea2017-10-26 07:58:48 -04001760 SkRect rect = { 10, 40, 50, 80 };
1761 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001762#StdOut
1763 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001764##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001765##
1766
Cary Clark7fc1d122017-10-09 14:07:42 -04001767#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001768
1769##
1770
Cary Clark7fc1d122017-10-09 14:07:42 -04001771# ------------------------------------------------------------------------------
1772
Cary Clarkbc5697d2017-10-04 14:31:33 -04001773#Method static bool Intersects(const SkRect& a, const SkRect& b)
1774
Cary Clarkab2621d2018-01-30 10:08:57 -05001775#In Intersection
1776#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001777Returns true if a intersects b.
1778Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001779
Cary Clark7fc1d122017-10-09 14:07:42 -04001780#Param a Rect to intersect ##
1781#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001782
Cary Clark7fc1d122017-10-09 14:07:42 -04001783#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001784
1785#Example
Cary Clark154beea2017-10-26 07:58:48 -04001786 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001787#StdOut
1788 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001789##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001790##
1791
Cary Clark7fc1d122017-10-09 14:07:42 -04001792#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793
1794##
1795
Cary Clark2dc84ad2018-01-26 12:56:22 -05001796#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001797
Cary Clark2dc84ad2018-01-26 12:56:22 -05001798#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001799#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001800
Cary Clark4855f782018-02-06 09:41:53 -05001801#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001802
1803# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001804
1805#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1806
Cary Clarkab2621d2018-01-30 10:08:57 -05001807#In Join
1808#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001809Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1810construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001811
Cary Clark7fc1d122017-10-09 14:07:42 -04001812Sets Rect to the union of itself and the construction.
1813
1814Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1815Rect to construction.
1816
1817#Param left x minimum of constructed Rect ##
1818#Param top y minimum of constructed Rect ##
1819#Param right x maximum of constructed Rect ##
1820#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001821
1822#Example
Cary Clark154beea2017-10-26 07:58:48 -04001823 SkRect rect = { 10, 20, 15, 25};
1824 rect.join(50, 60, 55, 65);
1825 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001826#StdOut
1827 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001828##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001829##
1830
Cary Clark7fc1d122017-10-09 14:07:42 -04001831#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001832
1833##
1834
Cary Clark7fc1d122017-10-09 14:07:42 -04001835# ------------------------------------------------------------------------------
1836
Cary Clarkbc5697d2017-10-04 14:31:33 -04001837#Method void join(const SkRect& r)
1838
Cary Clarkab2621d2018-01-30 10:08:57 -05001839#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001840Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001841
Cary Clark7fc1d122017-10-09 14:07:42 -04001842Has no effect if r is empty. Otherwise, if Rect is empty, sets
1843Rect to r.
1844
1845#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001846
1847#Example
Cary Clark154beea2017-10-26 07:58:48 -04001848 SkRect rect = { 10, 20, 15, 25};
1849 rect.join({50, 60, 55, 65});
1850 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001851#StdOut
1852 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001853##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001854##
1855
Cary Clark7fc1d122017-10-09 14:07:42 -04001856#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001857
1858##
1859
Cary Clark7fc1d122017-10-09 14:07:42 -04001860# ------------------------------------------------------------------------------
1861
Cary Clarkbc5697d2017-10-04 14:31:33 -04001862#Method void joinNonEmptyArg(const SkRect& r)
1863
Cary Clarkab2621d2018-01-30 10:08:57 -05001864#In Join
1865#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001866Sets Rect to the union of itself and r.
1867
1868Asserts if r is empty and SK_DEBUG is defined.
1869If Rect is empty, sets Rect to r.
1870
1871May produce incorrect results if r is empty.
1872
1873#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001874
1875#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001876#Description
1877Since Rect is not sorted, first result is copy of toJoin.
1878##
Cary Clark154beea2017-10-26 07:58:48 -04001879 SkRect rect = { 10, 100, 15, 0};
1880 SkRect sorted = rect.makeSorted();
1881 SkRect toJoin = { 50, 60, 55, 65 };
1882 rect.joinNonEmptyArg(toJoin);
1883 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1884 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001885 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1886#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001887rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001888sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001889##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001890##
1891
Cary Clark7fc1d122017-10-09 14:07:42 -04001892#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001893
1894##
1895
Cary Clark7fc1d122017-10-09 14:07:42 -04001896# ------------------------------------------------------------------------------
1897
Cary Clarkbc5697d2017-10-04 14:31:33 -04001898#Method void joinPossiblyEmptyRect(const SkRect& r)
1899
Cary Clarkab2621d2018-01-30 10:08:57 -05001900#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001901#Line # sets to union of bounds; skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001902Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001903
Cary Clark7fc1d122017-10-09 14:07:42 -04001904May produce incorrect results if Rect or r is empty.
1905
1906#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001907
1908#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001909#Description
1910Since Rect is not sorted, first result is not useful.
1911##
Cary Clark154beea2017-10-26 07:58:48 -04001912 SkRect rect = { 10, 100, 15, 0};
1913 SkRect sorted = rect.makeSorted();
1914 SkRect toJoin = { 50, 60, 55, 65 };
1915 rect.joinPossiblyEmptyRect(toJoin);
1916 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1917 sorted.joinPossiblyEmptyRect(toJoin);
1918 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001919#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001920rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001921sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001922##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001923##
1924
Cary Clark7fc1d122017-10-09 14:07:42 -04001925#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001926
1927##
1928
Cary Clark2dc84ad2018-01-26 12:56:22 -05001929#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001930
Cary Clark2dc84ad2018-01-26 12:56:22 -05001931#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001932#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001933
Cary Clark4855f782018-02-06 09:41:53 -05001934#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001935
Cary Clarkbc5697d2017-10-04 14:31:33 -04001936#Method void round(SkIRect* dst) const
1937
Cary Clarkab2621d2018-01-30 10:08:57 -05001938#In Rounding
1939#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001940Sets IRect by adding 0.5 and discarding the fractional portion of Rect
1941members, using
1942#Formula
1943(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1944 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
1945##
1946.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001947
Cary Clark7fc1d122017-10-09 14:07:42 -04001948#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001949
1950#Example
Cary Clark154beea2017-10-26 07:58:48 -04001951 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1952 SkIRect round;
1953 rect.round(&round);
1954 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001955#StdOut
1956round: 31, 51, 41, 61
1957##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001958##
1959
Cary Clark7fc1d122017-10-09 14:07:42 -04001960#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001961
1962##
1963
Cary Clark7fc1d122017-10-09 14:07:42 -04001964# ------------------------------------------------------------------------------
1965
Cary Clarkbc5697d2017-10-04 14:31:33 -04001966#Method void roundOut(SkIRect* dst) const
1967
Cary Clarkab2621d2018-01-30 10:08:57 -05001968#In Rounding
1969#Line # sets members to nearest integer value away from opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001970Sets IRect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05001971rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04001972#Formula
1973(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1974 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
1975##
1976.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977
Cary Clark7fc1d122017-10-09 14:07:42 -04001978#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001979
1980#Example
Cary Clark154beea2017-10-26 07:58:48 -04001981 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1982 SkIRect round;
1983 rect.roundOut(&round);
1984 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001985#StdOut
1986round: 30, 50, 41, 61
1987##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001988##
1989
Cary Clark7fc1d122017-10-09 14:07:42 -04001990#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001991
1992##
1993
Cary Clark7fc1d122017-10-09 14:07:42 -04001994# ------------------------------------------------------------------------------
1995
Cary Clark682c58d2018-05-16 07:07:07 -04001996#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001997
Cary Clarkab2621d2018-01-30 10:08:57 -05001998#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04001999Sets Rect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002000rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04002001#Formula
2002(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2003 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2004##
2005.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002006
Cary Clark7fc1d122017-10-09 14:07:42 -04002007#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002008
2009#Example
Cary Clark154beea2017-10-26 07:58:48 -04002010 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2011 SkRect round;
2012 rect.roundOut(&round);
2013 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002014#StdOut
2015round: 30, 50, 41, 61
2016##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002017##
2018
Cary Clark7fc1d122017-10-09 14:07:42 -04002019#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002020
2021##
2022
Cary Clark7fc1d122017-10-09 14:07:42 -04002023# ------------------------------------------------------------------------------
2024
Cary Clarkbc5697d2017-10-04 14:31:33 -04002025#Method void roundIn(SkIRect* dst) const
2026
Cary Clarkab2621d2018-01-30 10:08:57 -05002027#In Rounding
2028#Line # sets members to nearest integer value towards opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002029Sets Rect by rounding up fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002030discarding the fractional portion of fRight and fBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002031
Cary Clark7fc1d122017-10-09 14:07:42 -04002032#Formula
2033(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2034 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2035##
2036.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002037
Cary Clark7fc1d122017-10-09 14:07:42 -04002038#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002039
2040#Example
Cary Clark154beea2017-10-26 07:58:48 -04002041 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2042 SkIRect round;
2043 rect.roundIn(&round);
2044 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002045#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002046round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002047##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002048##
2049
Cary Clark7fc1d122017-10-09 14:07:42 -04002050#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002051
2052##
2053
Cary Clark7fc1d122017-10-09 14:07:42 -04002054# ------------------------------------------------------------------------------
2055
Cary Clarkbc5697d2017-10-04 14:31:33 -04002056#Method SkIRect round() const
2057
Cary Clarkab2621d2018-01-30 10:08:57 -05002058#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002059Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2060members, using
2061#Formula
2062(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2063 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2064##
2065.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002066
Cary Clark7fc1d122017-10-09 14:07:42 -04002067#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002068
2069#Example
Cary Clark154beea2017-10-26 07:58:48 -04002070 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2071 SkIRect round = rect.round();
2072 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002073#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002074round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002075##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002076##
2077
Cary Clark7fc1d122017-10-09 14:07:42 -04002078#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002079
2080##
2081
Cary Clark7fc1d122017-10-09 14:07:42 -04002082# ------------------------------------------------------------------------------
2083
Cary Clarkbc5697d2017-10-04 14:31:33 -04002084#Method SkIRect roundOut() const
2085
Cary Clarkab2621d2018-01-30 10:08:57 -05002086#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002087Sets IRect by discarding the fractional portion of fLeft and fTop; and
Cary Clark78c110e2018-02-09 16:49:09 -05002088rounding up fRight and fBottom, using
Cary Clark7fc1d122017-10-09 14:07:42 -04002089#Formula
2090(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2091 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2092##
2093.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002094
Cary Clark7fc1d122017-10-09 14:07:42 -04002095#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002096
2097#Example
Cary Clark154beea2017-10-26 07:58:48 -04002098 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2099 SkIRect round = rect.roundOut();
2100 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002101#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002102round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002103##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104##
2105
Cary Clark7fc1d122017-10-09 14:07:42 -04002106#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002107
2108##
2109
Cary Clark2dc84ad2018-01-26 12:56:22 -05002110#Subtopic Rounding ##
2111
2112#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002113#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002114
Cary Clark4855f782018-02-06 09:41:53 -05002115#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04002116
2117# ------------------------------------------------------------------------------
2118
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119#Method void sort()
2120
Cary Clarkab2621d2018-01-30 10:08:57 -05002121#In Sorting
2122#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002123Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2124fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2125and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002126
2127#Example
Cary Clark154beea2017-10-26 07:58:48 -04002128 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2129 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2130 rect.sort();
2131 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002132#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002133rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002134sorted: 20.5, 10.5, 30.5, 50.5
2135##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002136##
2137
Cary Clark2dc84ad2018-01-26 12:56:22 -05002138#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002139
2140##
2141
Cary Clark7fc1d122017-10-09 14:07:42 -04002142# ------------------------------------------------------------------------------
2143
Cary Clarkbc5697d2017-10-04 14:31:33 -04002144#Method SkRect makeSorted() const
2145
Cary Clarkab2621d2018-01-30 10:08:57 -05002146#In Sorting
Cary Clark4855f782018-02-06 09:41:53 -05002147#In Constructor
Cary Clark682c58d2018-05-16 07:07:07 -04002148#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002149Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2150with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2151and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002152
Cary Clark7fc1d122017-10-09 14:07:42 -04002153#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002154
2155#Example
Cary Clark154beea2017-10-26 07:58:48 -04002156 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2157 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2158 SkRect sort = rect.makeSorted();
2159 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002160#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002161rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002162sorted: 20.5, 10.5, 30.5, 50.5
2163##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002164##
2165
Cary Clark2dc84ad2018-01-26 12:56:22 -05002166#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002167
2168##
2169
Cary Clark2dc84ad2018-01-26 12:56:22 -05002170#Subtopic Sorting ##
2171
Cary Clark7fc1d122017-10-09 14:07:42 -04002172# ------------------------------------------------------------------------------
2173
Cary Clarkbc5697d2017-10-04 14:31:33 -04002174#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002175#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002176#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002177Returns pointer to first Scalar in Rect, to treat it as an array with four
2178entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002179
Cary Clark7fc1d122017-10-09 14:07:42 -04002180#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002181
2182#Example
Cary Clark154beea2017-10-26 07:58:48 -04002183 SkRect rect = {7, 11, 13, 17};
2184SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2185#StdOut
2186rect.asScalars() == &rect.fLeft
2187##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002188##
2189
Cary Clark7fc1d122017-10-09 14:07:42 -04002190#SeeAlso toQuad
2191
Cary Clarkbc5697d2017-10-04 14:31:33 -04002192##
2193
Cary Clark7fc1d122017-10-09 14:07:42 -04002194# ------------------------------------------------------------------------------
2195
Cary Clarkbc5697d2017-10-04 14:31:33 -04002196#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002197#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002198#Line # sends text representation to standard output using floats ##
Cary Clark682c58d2018-05-16 07:07:07 -04002199Writes text representation of Rect to standard output. Set asHex to true to
Cary Clark7fc1d122017-10-09 14:07:42 -04002200generate exact binary representations of floating point numbers.
2201
2202#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002203
2204#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002205 SkRect rect = {20, 30, 40, 50};
2206 for (bool dumpAsHex : { false, true } ) {
2207 rect.dump(dumpAsHex);
2208 SkDebugf("\n");
2209 }
2210#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002211SkRect::MakeLTRB(20, 30, 40, 50);
2212
2213SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2214 SkBits2Float(0x41f00000), /* 30.000000 */
2215 SkBits2Float(0x42200000), /* 40.000000 */
2216 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002217##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002218##
2219
Cary Clark7fc1d122017-10-09 14:07:42 -04002220#SeeAlso dumpHex
2221
Cary Clarkbc5697d2017-10-04 14:31:33 -04002222##
2223
Cary Clark7fc1d122017-10-09 14:07:42 -04002224# ------------------------------------------------------------------------------
2225
Cary Clarkbc5697d2017-10-04 14:31:33 -04002226#Method void dump() const
2227
Cary Clark7fc1d122017-10-09 14:07:42 -04002228Writes text representation of Rect to standard output. The representation may be
2229directly compiled as C++ code. Floating point values are written
2230with limited precision; it may not be possible to reconstruct original Rect
2231from output.
2232
Cary Clarkbc5697d2017-10-04 14:31:33 -04002233#Example
Cary Clark154beea2017-10-26 07:58:48 -04002234SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2235rect.dump();
2236SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2237SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002238#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002239SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002240rect is not equal to copy
2241##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002242##
2243
Cary Clark7fc1d122017-10-09 14:07:42 -04002244#SeeAlso dumpHex
2245
Cary Clarkbc5697d2017-10-04 14:31:33 -04002246##
2247
Cary Clark7fc1d122017-10-09 14:07:42 -04002248# ------------------------------------------------------------------------------
2249
Cary Clarkbc5697d2017-10-04 14:31:33 -04002250#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002251#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002252#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002253Writes text representation of Rect to standard output. The representation may be
2254directly compiled as C++ code. Floating point values are written
2255in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2256original Rect.
2257
Cary Clark682c58d2018-05-16 07:07:07 -04002258Use instead of dump() when submitting
2259#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002260.
2261
Cary Clarkbc5697d2017-10-04 14:31:33 -04002262#Example
Cary Clark154beea2017-10-26 07:58:48 -04002263 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2264rect.dumpHex();
2265SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2266 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2267 SkBits2Float(0x40266666), /* 2.600000 */
2268 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002269SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2270#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002271SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2272 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2273 SkBits2Float(0x40266666), /* 2.600000 */
2274 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002275rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002276##
Cary Clark7fc1d122017-10-09 14:07:42 -04002277##
2278
2279#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002280
2281##
2282
Cary Clark0c95aab2018-01-08 16:20:59 -05002283#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05002284#Deprecated
2285##
2286
Cary Clarkbc5697d2017-10-04 14:31:33 -04002287#Struct SkRect ##
2288
2289#Topic Rect ##