blob: dce25882d8a312e3f399a70d8c5902e422dc9419 [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Rect
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Rects ##
3#Alias Rect_Reference ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004
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 Clark2be81cf2018-09-13 12:04:30 -0400232Returns constructed Rect set to #Formula # (x, y, x + w, y + h) ##.
233Does not validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400234
Cary Clark7fc1d122017-10-09 14:07:42 -0400235#Param x stored in fLeft ##
236#Param y stored in fTop ##
237#Param w added to x and stored in fRight ##
238#Param h added to y and stored in fBottom ##
239
Cary Clark884dd7d2017-10-11 10:37:52 -0400240#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400241
242#Example
Cary Clark154beea2017-10-26 07:58:48 -0400243 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
244 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
245 rect.bottom(), rect.isEmpty() ? "true" : "false");
246 rect.sort();
247 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
248 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400249#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400250rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400251rect: -10, 35, 5, 60 isEmpty: false
252##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400253##
254
Cary Clark7fc1d122017-10-09 14:07:42 -0400255#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400256
257##
258
259# ------------------------------------------------------------------------------
260
261#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
Cary Clark7fc1d122017-10-09 14:07:42 -0400262#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400263##
264
Cary Clarkbc5697d2017-10-04 14:31:33 -0400265# ------------------------------------------------------------------------------
266
267#Method static SkRect Make(const SkISize& size)
268
Cary Clark4855f782018-02-06 09:41:53 -0500269#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -0500270#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark682c58d2018-05-16 07:07:07 -0400271Returns constructed IRect set to (0, 0, size.width(), size.height()).
Cary Clark7fc1d122017-10-09 14:07:42 -0400272Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400273
Cary Clark7fc1d122017-10-09 14:07:42 -0400274#Param size integer values for Rect width and height ##
275
276#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400277
278#Example
Cary Clark154beea2017-10-26 07:58:48 -0400279 SkRect rect1 = SkRect::MakeSize({2, 35});
280 SkRect rect2 = SkRect::MakeIWH(2, 35);
281 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400282#StdOut
283rect1 == rect2
284##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400285##
286
Cary Clark7fc1d122017-10-09 14:07:42 -0400287#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400288
289##
290
291# ------------------------------------------------------------------------------
292
293#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
294
Cary Clark4855f782018-02-06 09:41:53 -0500295#In Constructor
Cary Clark7fc1d122017-10-09 14:07:42 -0400296Returns constructed IRect set to irect, promoting integers to Scalar.
297Does not validate input; fLeft may be greater than fRight, fTop may be greater
298than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400299
Cary Clark7fc1d122017-10-09 14:07:42 -0400300#Param irect integer unsorted bounds ##
301
302#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400303
304#Example
Cary Clark154beea2017-10-26 07:58:48 -0400305 SkIRect i_rect1 = {2, 35, 22, 53};
306 SkRect f_rect = SkRect::Make(i_rect1);
307 f_rect.offset(0.49f, 0.49f);
308 SkIRect i_rect2;
309 f_rect.round(&i_rect2);
310 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400311##
312
Cary Clark7fc1d122017-10-09 14:07:42 -0400313#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400314
315##
316
Cary Clark4855f782018-02-06 09:41:53 -0500317#Subtopic Constructor ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500318
Cary Clark4855f782018-02-06 09:41:53 -0500319#Subtopic Property
320#Line # member values, center, validity ##
321#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500322
Cary Clarkbc5697d2017-10-04 14:31:33 -0400323# ------------------------------------------------------------------------------
324
325#Method bool isEmpty() const
326
Cary Clark4855f782018-02-06 09:41:53 -0500327#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500328#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400329Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
330to or greater than fBottom. Call sort() to reverse rectangles with negative
331width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400332
Cary Clark7fc1d122017-10-09 14:07:42 -0400333#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400334
335#Example
Cary Clark154beea2017-10-26 07:58:48 -0400336 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
337 for (auto rect : tests) {
338 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
339 rect.bottom(), rect.isEmpty() ? "" : " not");
340 rect.sort();
341 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
342 rect.bottom(), rect.isEmpty() ? "" : " not");
343 }
344#StdOut
345rect: {20, 40, 10, 50} is empty
346sorted: {10, 40, 20, 50} is not empty
347rect: {20, 40, 20, 50} is empty
348sorted: {20, 40, 20, 50} is empty
349##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400350##
351
Cary Clark7fc1d122017-10-09 14:07:42 -0400352#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400353
354##
355
356# ------------------------------------------------------------------------------
357
358#Method bool isSorted() const
359
Cary Clark4855f782018-02-06 09:41:53 -0500360#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500361#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400362Returns true if fLeft is equal to or less than fRight, or if fTop is equal
363to or less than fBottom. Call sort() to reverse rectangles with negative
364width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400365
Cary Clark7fc1d122017-10-09 14:07:42 -0400366#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400367
368#Example
Cary Clark154beea2017-10-26 07:58:48 -0400369 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
370 for (auto rect : tests) {
371 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
372 rect.bottom(), rect.isSorted() ? "" : " not");
373 rect.sort();
374 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
375 rect.bottom(), rect.isSorted() ? "" : " not");
376 }
377#StdOut
378rect: {20, 40, 10, 50} is not sorted
379sorted: {10, 40, 20, 50} is sorted
380rect: {20, 40, 20, 50} is sorted
381sorted: {20, 40, 20, 50} is sorted
382##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400383##
384
Cary Clark7fc1d122017-10-09 14:07:42 -0400385#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400386
387##
388
389# ------------------------------------------------------------------------------
390
Cary Clarkbc5697d2017-10-04 14:31:33 -0400391#Method bool isFinite() const
392
Cary Clark4855f782018-02-06 09:41:53 -0500393#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500394#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400395Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
Cary Clark682c58d2018-05-16 07:07:07 -0400396and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400397
Cary Clark7fc1d122017-10-09 14:07:42 -0400398#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400399
400#Example
Mike Reed274218e2018-01-08 15:05:02 -0500401SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400402 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
403 SkDebugf("large width %g\n", largest.width());
404 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
405 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
406#StdOut
407largest is finite: true
408large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400409widest is finite: false
410##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400411##
412
Cary Clark7fc1d122017-10-09 14:07:42 -0400413#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400414
415##
416
417# ------------------------------------------------------------------------------
418
419#Method SkScalar x() const
420
Cary Clark4855f782018-02-06 09:41:53 -0500421#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500422#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400423Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
424Call sort() to reverse fLeft and fRight if needed.
425
426#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400427
428#Example
Cary Clark154beea2017-10-26 07:58:48 -0400429 SkRect unsorted = { 15, 5, 10, 25 };
430 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
431 SkRect sorted = unsorted.makeSorted();
432 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400433#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400434unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400435sorted.fLeft: 10 sorted.x(): 10
436##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400437##
438
Cary Clark7fc1d122017-10-09 14:07:42 -0400439#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400440
441##
442
443# ------------------------------------------------------------------------------
444
445#Method SkScalar y() const
446
Cary Clark4855f782018-02-06 09:41:53 -0500447#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500448#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400449Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
450and sort() to reverse fTop and fBottom if needed.
451
452#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400453
454#Example
Cary Clark154beea2017-10-26 07:58:48 -0400455 SkRect unsorted = { 15, 25, 10, 5 };
456 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
457 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400458 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
459#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400460unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400461sorted.fTop: 5 sorted.y(): 5
462##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400463##
464
Cary Clark7fc1d122017-10-09 14:07:42 -0400465#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400466
467##
468
469# ------------------------------------------------------------------------------
470
471#Method SkScalar left() const
472
Cary Clark4855f782018-02-06 09:41:53 -0500473#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500474#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400475Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
476Call sort() to reverse fLeft and fRight if needed.
477
478#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400479
480#Example
Cary Clark154beea2017-10-26 07:58:48 -0400481 SkRect unsorted = { 15, 5, 10, 25 };
482 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
483 SkRect sorted = unsorted.makeSorted();
484 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400485#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400486unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400487sorted.fLeft: 10 sorted.left(): 10
488##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400489##
490
Cary Clark7fc1d122017-10-09 14:07:42 -0400491#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400492
493##
494
495# ------------------------------------------------------------------------------
496
497#Method SkScalar top() const
498
Cary Clark4855f782018-02-06 09:41:53 -0500499#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500500#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400501Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
502and sort() to reverse fTop and fBottom if needed.
503
504#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400505
506#Example
Cary Clark154beea2017-10-26 07:58:48 -0400507 SkRect unsorted = { 15, 25, 10, 5 };
508 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
509 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400510 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
511#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400512unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400513sorted.fTop: 5 sorted.top(): 5
514##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400515##
516
Cary Clark7fc1d122017-10-09 14:07:42 -0400517#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400518
519##
520
521# ------------------------------------------------------------------------------
522
523#Method SkScalar right() const
524
Cary Clark4855f782018-02-06 09:41:53 -0500525#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500526#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400527Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
528Call sort() to reverse fLeft and fRight if needed.
529
530#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400531
532#Example
Cary Clark154beea2017-10-26 07:58:48 -0400533 SkRect unsorted = { 15, 25, 10, 5 };
534 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
535 SkRect sorted = unsorted.makeSorted();
536 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400537#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400538unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400539sorted.fRight: 15 sorted.right(): 15
540##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400541##
542
Cary Clark7fc1d122017-10-09 14:07:42 -0400543#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400544
545##
546
547# ------------------------------------------------------------------------------
548
549#Method SkScalar bottom() const
550
Cary Clark4855f782018-02-06 09:41:53 -0500551#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500552#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400553Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
554and sort() to reverse fTop and fBottom if needed.
555
556#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400557
558#Example
Cary Clark154beea2017-10-26 07:58:48 -0400559 SkRect unsorted = { 15, 25, 10, 5 };
560 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
561 SkRect sorted = unsorted.makeSorted();
562 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400563#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400564unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400565sorted.fBottom: 25 sorted.bottom(): 25
566##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400567##
568
Cary Clark7fc1d122017-10-09 14:07:42 -0400569#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400570
571##
572
573# ------------------------------------------------------------------------------
574
575#Method SkScalar width() const
576
Cary Clark4855f782018-02-06 09:41:53 -0500577#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500578#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400579Returns span on the x-axis. This does not check if Rect is sorted, or if
580result fits in 32-bit float; result may be negative or infinity.
581
582#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400583
584#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400585#Description
586Compare with SkIRect::width() example.
587##
Cary Clark154beea2017-10-26 07:58:48 -0400588 SkRect unsorted = { 15, 25, 10, 5 };
589 SkDebugf("unsorted width: %g\n", unsorted.width());
590 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
591 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400592#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400593unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400594large width: 4294967296
595##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400596##
597
Cary Clark7fc1d122017-10-09 14:07:42 -0400598#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400599
600##
601
602# ------------------------------------------------------------------------------
603
604#Method SkScalar height() const
605
Cary Clark4855f782018-02-06 09:41:53 -0500606#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500607#Line # returns span in y ##
Cary Clark224c7002018-06-27 11:00:21 -0400608Returns span on the y-axis. This does not check if Rect is sorted, or if
Cary Clark7fc1d122017-10-09 14:07:42 -0400609result fits in 32-bit float; result may be negative or infinity.
610
611#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400612
613#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400614#Description
615Compare with SkIRect::height() example.
616##
Cary Clark154beea2017-10-26 07:58:48 -0400617 SkRect unsorted = { 15, 25, 10, 20 };
618 SkDebugf("unsorted height: %g\n", unsorted.height());
619 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
620 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400621#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400622unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400623large height: 4294967296
624##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400625##
626
Cary Clark7fc1d122017-10-09 14:07:42 -0400627#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400628
629##
630
631# ------------------------------------------------------------------------------
632
633#Method SkScalar centerX() const
634
Cary Clark4855f782018-02-06 09:41:53 -0500635#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500636#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400637Returns average of left edge and right edge. Result does not change if Rect
638is sorted. Result may overflow to infinity if Rect is far from the origin.
639
640#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400641
642#Example
Cary Clark154beea2017-10-26 07:58:48 -0400643 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
644 for (auto rect : tests) {
645 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
646 rect.sort();
647 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
648 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400649#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400650left: 20 right: 41 centerX: 30.5
651left: 20 right: 41 centerX: 30.5
652left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400653left: -41 right: -20 centerX: -30.5
654##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400655##
656
Cary Clark47d7dae2018-04-11 16:54:35 -0400657#SeeAlso centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400658
659##
660
661# ------------------------------------------------------------------------------
662
663#Method SkScalar centerY() const
664
Cary Clark4855f782018-02-06 09:41:53 -0500665#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500666#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400667Returns average of top edge and bottom edge. Result does not change if Rect
Cary Clark75fd4492018-06-20 12:45:16 -0400668is sorted.
Cary Clark7fc1d122017-10-09 14:07:42 -0400669
670#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400671
672#Example
Cary Clark154beea2017-10-26 07:58:48 -0400673 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
674 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
675 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400676#StdOut
Cary Clark75fd4492018-06-20 12:45:16 -0400677left: 2e+38 right: 3e+38 centerX: 2.5e+38 safe mid x: 2.5e+38
Cary Clark7fc1d122017-10-09 14:07:42 -0400678##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400679##
680
Cary Clark47d7dae2018-04-11 16:54:35 -0400681#SeeAlso centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400682
683##
684
Cary Clark4855f782018-02-06 09:41:53 -0500685#Subtopic Property ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500686
Cary Clark4855f782018-02-06 09:41:53 -0500687#Subtopic Operator
Cary Clark2dc84ad2018-01-26 12:56:22 -0500688
Cary Clark4855f782018-02-06 09:41:53 -0500689#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500690
Cary Clarkbc5697d2017-10-04 14:31:33 -0400691# ------------------------------------------------------------------------------
692
Cary Clark884dd7d2017-10-11 10:37:52 -0400693#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400694
Cary Clark4855f782018-02-06 09:41:53 -0500695#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500696#Line # returns true if members are equal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400697Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
Cary Clark7fc1d122017-10-09 14:07:42 -0400698equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400699
Cary Clark7fc1d122017-10-09 14:07:42 -0400700a and b are not equal if either contain NaN. a and b are equal if members
701contain zeroes width different signs.
702
703#Param a Rect to compare ##
704#Param b Rect to compare ##
705
706#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400707
708#Example
Cary Clark154beea2017-10-26 07:58:48 -0400709 auto debugster = [](const SkRect& test) -> void {
710 SkRect negZero = {-0.0f, -0.0f, 2, 2};
711 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
712 test.fLeft, test.fTop, test.fRight, test.fBottom,
713 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
714 test == negZero ? '=' : '!',
715 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
716 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
717 "and are" : "yet are not");
718 };
719 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
720 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
721 for (auto rect : tests) {
722 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400723 }
Cary Clark154beea2017-10-26 07:58:48 -0400724#StdOut
725tests are equal
726{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
727{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark682c58d2018-05-16 07:07:07 -0400728{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400729##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400730##
731
Cary Clark7fc1d122017-10-09 14:07:42 -0400732#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400733
734##
735
736# ------------------------------------------------------------------------------
737
Cary Clark884dd7d2017-10-11 10:37:52 -0400738#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400739
Cary Clark4855f782018-02-06 09:41:53 -0500740#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500741#Line # returns true if members are unequal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400742Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
Cary Clark7fc1d122017-10-09 14:07:42 -0400743equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400744
Cary Clark7fc1d122017-10-09 14:07:42 -0400745a and b are not equal if either contain NaN. a and b are equal if members
746contain zeroes width different signs.
747
748#Param a Rect to compare ##
749#Param b Rect to compare ##
750
751#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400752
753#Example
Cary Clark154beea2017-10-26 07:58:48 -0400754 SkRect test = {0, 0, 2, SK_ScalarNaN};
755 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
756#StdOut
Cary Clark682c58d2018-05-16 07:07:07 -0400757test with NaN is not equal to itself
Cary Clark7fc1d122017-10-09 14:07:42 -0400758##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400759##
760
Cary Clark7fc1d122017-10-09 14:07:42 -0400761#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400762
763##
764
Cary Clark4855f782018-02-06 09:41:53 -0500765#Subtopic Operator ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500766
767#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500768#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500769
Cary Clark4855f782018-02-06 09:41:53 -0500770#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500771
Cary Clarkbc5697d2017-10-04 14:31:33 -0400772# ------------------------------------------------------------------------------
773
774#Method void toQuad(SkPoint quad[4]) const
775
Cary Clarkab2621d2018-01-30 10:08:57 -0500776#In As_Points
777#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400778Returns four points in quad that enclose Rect ordered as: top-left, top-right,
Cary Clark682c58d2018-05-16 07:07:07 -0400779bottom-right, bottom-left.
Cary Clark7fc1d122017-10-09 14:07:42 -0400780
781#Private
Cary Clark682c58d2018-05-16 07:07:07 -0400782Consider adding param to control whether quad is clockwise or counterclockwise.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400783##
784
Cary Clark7fc1d122017-10-09 14:07:42 -0400785#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400786
787#Example
Cary Clark154beea2017-10-26 07:58:48 -0400788 SkRect rect = {1, 2, 3, 4};
789 SkPoint corners[4];
790 rect.toQuad(corners);
791 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
792 SkDebugf("corners:");
793 for (auto corner : corners) {
794 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
795 }
796 SkDebugf("\n");
797#StdOut
798rect: {1, 2, 3, 4}
Cary Clark682c58d2018-05-16 07:07:07 -0400799corners: {1, 2} {3, 2} {3, 4} {1, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400800##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400801##
802
Cary Clark7fc1d122017-10-09 14:07:42 -0400803#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400804
805##
806
807# ------------------------------------------------------------------------------
808
Cary Clark2dc84ad2018-01-26 12:56:22 -0500809#Method void setBounds(const SkPoint pts[], int count)
810
Cary Clarkab2621d2018-01-30 10:08:57 -0500811#In As_Points
812#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500813Sets to bounds of Point array with count entries. If count is zero or smaller,
814or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
815
816Result is either empty or sorted: fLeft is less than or equal to fRight, and
817fTop is less than or equal to fBottom.
818
819#Param pts Point array ##
820#Param count entries in array ##
821
822#Example
823 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
824 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
825 SkRect rect;
826 rect.setBounds(points, count);
827 if (count > 0) {
828 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
829 } else {
830 SkDebugf("%14s", " ");
831 }
832 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
833 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
834 }
835#StdOut
836 count: 0 rect: 0, 0, 0, 0
837added: 3, 4 count: 1 rect: 3, 4, 3, 4
838added: 1, 2 count: 2 rect: 1, 2, 3, 4
839added: 5, 6 count: 3 rect: 1, 2, 5, 6
840added: nan, 8 count: 4 rect: 0, 0, 0, 0
841##
842##
843
844#SeeAlso set setBoundsCheck SkPath::addPoly
845
846##
847
848# ------------------------------------------------------------------------------
849
850#Method bool setBoundsCheck(const SkPoint pts[], int count)
851
Cary Clarkab2621d2018-01-30 10:08:57 -0500852#In As_Points
853#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500854Sets to bounds of Point array with count entries. Returns false if count is
855zero or smaller, or if Point array contains an infinity or NaN; in these cases
856sets Rect to (0, 0, 0, 0).
857
858Result is either empty or sorted: fLeft is less than or equal to fRight, and
859fTop is less than or equal to fBottom.
860
861#Param pts Point array ##
862#Param count entries in array ##
863
864#Return true if all Point values are finite ##
865
866#Example
867 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
868 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
869 SkRect rect;
870 bool success = rect.setBoundsCheck(points, count);
871 if (count > 0) {
872 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
873 } else {
874 SkDebugf("%14s", " ");
875 }
876 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
877 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
878 }
879#StdOut
880 count: 0 rect: 0, 0, 0, 0 success: true
881added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
882added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
883added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
884added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
885##
886##
887
888#SeeAlso set setBounds SkPath::addPoly
889
890##
891
892#Subtopic As_Points ##
893
894#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500895#Line # replaces all values ##
Cary Clark4855f782018-02-06 09:41:53 -0500896#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500897
898# ------------------------------------------------------------------------------
899
Cary Clarkc06754b2018-05-16 21:28:55 -0400900#Method void setBoundsNoCheck(const SkPoint pts[], int count)
901#In Set
902#Line # sets to upper and lower limits of Point array ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400903Sets to bounds of Point pts array with count entries. If any Point in pts
Cary Clark8f288d92018-05-17 15:16:57 -0400904contains infinity or NaN, all Rect dimensions are set to NaN.
Cary Clarkc06754b2018-05-16 21:28:55 -0400905
906#Param pts Point array ##
907#Param count entries in array ##
908
909#Example
Cary Clark8f288d92018-05-17 15:16:57 -0400910 SkPoint points[] = {{3, 4}, {1, 2}, {SK_ScalarInfinity, 6}, {SK_ScalarNaN, 8}};
Cary Clarkffb3d682018-05-17 12:17:28 -0400911 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
912 SkRect rect;
913 rect.setBoundsNoCheck(points, count);
914 if (count > 0) {
915 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
916 } else {
917 SkDebugf("%14s", " ");
918 }
919 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
920 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
921 }
Cary Clarkc06754b2018-05-16 21:28:55 -0400922##
923
924#SeeAlso setBoundsCheck
925#Method ##
926
927# ------------------------------------------------------------------------------
928
Cary Clarkbc5697d2017-10-04 14:31:33 -0400929#Method void setEmpty()
930
Cary Clarkab2621d2018-01-30 10:08:57 -0500931#In Set
932#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400933Sets Rect to (0, 0, 0, 0).
934
935Many other rectangles are empty; if left is equal to or greater than right,
936or if top is equal to or greater than bottom. Setting all members to zero
937is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400938
939#Example
Cary Clark154beea2017-10-26 07:58:48 -0400940 SkRect rect = {3, 4, 1, 2};
941 for (int i = 0; i < 2; ++i) {
942 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
943 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
944 rect.setEmpty();
945 }
946#StdOut
947rect: {3, 4, 1, 2} is empty
948rect: {0, 0, 0, 0} is empty
949##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400950##
951
Cary Clark7fc1d122017-10-09 14:07:42 -0400952#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400953
954##
955
956# ------------------------------------------------------------------------------
957
958#Method void set(const SkIRect& src)
959
Cary Clarkab2621d2018-01-30 10:08:57 -0500960#In Set
961#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400962Sets Rect to src, promoting src members from integer to Scalar.
Cary Clark682c58d2018-05-16 07:07:07 -0400963Very large values in src may lose precision.
Cary Clark7fc1d122017-10-09 14:07:42 -0400964
965#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400966
967#Example
Cary Clark154beea2017-10-26 07:58:48 -0400968 SkIRect i_rect = {3, 4, 1, 2};
969 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
970 SkRect f_rect;
971 f_rect.set(i_rect);
972 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
973#StdOut
974i_rect: {3, 4, 1, 2}
975f_rect: {3, 4, 1, 2}
976##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400977##
978
Cary Clark7fc1d122017-10-09 14:07:42 -0400979#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400980
981##
982
983# ------------------------------------------------------------------------------
984
985#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
986
Cary Clarkab2621d2018-01-30 10:08:57 -0500987#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400988Sets Rect to (left, top, right, bottom).
989left and right are not sorted; left is not necessarily less than right.
990top and bottom are not sorted; top is not necessarily less than bottom.
991
992#Param left stored in fLeft ##
993#Param top stored in fTop ##
994#Param right stored in fRight ##
995#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400996
997#Example
Cary Clark154beea2017-10-26 07:58:48 -0400998 SkRect rect1 = {3, 4, 1, 2};
999 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1000 SkRect rect2;
1001 rect2.set(3, 4, 1, 2);
1002 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1003#StdOut
1004rect1: {3, 4, 1, 2}
1005rect2: {3, 4, 1, 2}
1006##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001007##
1008
Cary Clark7fc1d122017-10-09 14:07:42 -04001009#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001010
1011##
1012
1013# ------------------------------------------------------------------------------
1014
1015#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1016
Cary Clarkab2621d2018-01-30 10:08:57 -05001017#In Set
1018#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001019Sets Rect to (left, top, right, bottom).
1020left and right are not sorted; left is not necessarily less than right.
1021top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001022
Cary Clark7fc1d122017-10-09 14:07:42 -04001023#Param left stored in fLeft ##
1024#Param top stored in fTop ##
1025#Param right stored in fRight ##
1026#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001027
1028#Example
Cary Clark154beea2017-10-26 07:58:48 -04001029 SkRect rect1 = {3, 4, 1, 2};
1030 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1031 SkRect rect2;
1032 rect2.setLTRB(3, 4, 1, 2);
1033 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1034#StdOut
1035rect1: {3, 4, 1, 2}
1036rect2: {3, 4, 1, 2}
1037##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001038##
1039
Cary Clark7fc1d122017-10-09 14:07:42 -04001040#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001041
1042##
1043
1044# ------------------------------------------------------------------------------
1045
Cary Clarkbc5697d2017-10-04 14:31:33 -04001046#Method void set(const SkPoint pts[], int count)
1047
Cary Clarkab2621d2018-01-30 10:08:57 -05001048#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001049Sets to bounds of Point array with count entries. If count is zero or smaller,
1050or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001051
Cary Clark7fc1d122017-10-09 14:07:42 -04001052Result is either empty or sorted: fLeft is less than or equal to fRight, and
1053fTop is less than or equal to fBottom.
1054
1055#Param pts Point array ##
1056#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001057
1058#Example
Cary Clark154beea2017-10-26 07:58:48 -04001059 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1060 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1061 SkRect rect;
1062 rect.set(points, count);
1063 if (count > 0) {
1064 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1065 } else {
1066 SkDebugf("%14s", " ");
1067 }
1068 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1069 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1070 }
1071#StdOut
1072 count: 0 rect: 0, 0, 0, 0
1073added: 3, 4 count: 1 rect: 3, 4, 3, 4
1074added: 1, 2 count: 2 rect: 1, 2, 3, 4
1075added: 5, 6 count: 3 rect: 1, 2, 5, 6
1076added: nan, 8 count: 4 rect: 0, 0, 0, 0
1077##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001078##
1079
Cary Clark7fc1d122017-10-09 14:07:42 -04001080#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001081
1082##
1083
1084# ------------------------------------------------------------------------------
1085
Cary Clarkbc5697d2017-10-04 14:31:33 -04001086#Method void set(const SkPoint& p0, const SkPoint& p1)
1087
Cary Clarkab2621d2018-01-30 10:08:57 -05001088#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001089Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1090sorted and may be empty. Does not check to see if values are finite.
1091
1092#Param p0 corner to include ##
1093#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001094
1095#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001096#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001097p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -04001098##
Cary Clark154beea2017-10-26 07:58:48 -04001099 SkPoint point1 = {SK_ScalarNaN, 8};
1100 SkPoint point2 = {3, 4};
1101 SkRect rect;
1102 rect.set(point1, point2);
1103 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1104 rect.set(point2, point1);
1105 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001106##
1107
Cary Clark7fc1d122017-10-09 14:07:42 -04001108#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001109
1110##
1111
1112# ------------------------------------------------------------------------------
1113
1114#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1115
Cary Clarkab2621d2018-01-30 10:08:57 -05001116#In Set
1117#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001118Sets Rect to #Formula # (x, y, x + width, y + height) ##.
1119Does not validate input; width or height may be negative.
Cary Clark7fc1d122017-10-09 14:07:42 -04001120
1121#Param x stored in fLeft ##
1122#Param y stored in fTop ##
1123#Param width added to x and stored in fRight ##
1124#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001125
1126#Example
Cary Clark154beea2017-10-26 07:58:48 -04001127 SkRect rect;
1128 rect.setXYWH(5, 35, -15, 25);
1129 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1130 rect.bottom(), rect.isEmpty() ? "true" : "false");
1131 rect.sort();
1132 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1133 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001134#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001135rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001136rect: -10, 35, 5, 60 isEmpty: false
1137##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001138##
1139
Cary Clark7fc1d122017-10-09 14:07:42 -04001140#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001141
1142##
1143
1144# ------------------------------------------------------------------------------
1145
1146#Method void setWH(SkScalar width, SkScalar height)
1147
Cary Clarkab2621d2018-01-30 10:08:57 -05001148#In Set
1149#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001150Sets Rect to (0, 0, width, height). Does not validate input;
1151width or height may be negative.
1152
1153#Param width stored in fRight ##
1154#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001155
1156#Example
Cary Clark154beea2017-10-26 07:58:48 -04001157 SkRect rect;
1158 rect.setWH(-15, 25);
1159 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1160 rect.bottom(), rect.isEmpty() ? "true" : "false");
1161 rect.sort();
1162 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1163 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001164#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001165rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001166rect: -15, 0, 0, 25 isEmpty: false
1167##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001168##
1169
Cary Clark7fc1d122017-10-09 14:07:42 -04001170#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001171
1172##
1173
Cary Clark2dc84ad2018-01-26 12:56:22 -05001174#Subtopic Set ##
1175
1176#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -04001177#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001178
Cary Clark4855f782018-02-06 09:41:53 -05001179#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001180
1181# ------------------------------------------------------------------------------
1182
1183#Method void iset(int left, int top, int right, int bottom)
1184
Cary Clarkab2621d2018-01-30 10:08:57 -05001185#In From_Integers
1186#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001187Sets Rect to (left, top, right, bottom).
1188All parameters are promoted from integer to Scalar.
1189left and right are not sorted; left is not necessarily less than right.
1190top and bottom are not sorted; top is not necessarily less than bottom.
1191
1192#Param left promoted to SkScalar and stored in fLeft ##
1193#Param top promoted to SkScalar and stored in fTop ##
1194#Param right promoted to SkScalar and stored in fRight ##
1195#Param bottom promoted to SkScalar and stored in fBottom ##
1196
1197#Example
1198 SkRect rect1 = {3, 4, 1, 2};
1199 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1200 SkRect rect2;
1201 rect2.iset(3, 4, 1, 2);
1202 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1203#StdOut
1204rect1: {3, 4, 1, 2}
1205rect2: {3, 4, 1, 2}
1206##
1207##
1208
1209#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1210
1211##
1212
1213# ------------------------------------------------------------------------------
1214
1215#Method void isetWH(int width, int height)
1216
Cary Clarkab2621d2018-01-30 10:08:57 -05001217#In From_Integers
1218#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001219Sets Rect to (0, 0, width, height).
1220width and height may be zero or negative. width and height are promoted from
1221integer to SkScalar, large values may lose precision.
1222
1223#Param width promoted to SkScalar and stored in fRight ##
1224#Param height promoted to SkScalar and stored in fBottom ##
1225
1226#Example
1227 SkRect rect1 = {0, 0, 1, 2};
1228 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1229 SkRect rect2;
1230 rect2.isetWH(1, 2);
1231 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1232#StdOut
1233rect1: {0, 0, 1, 2}
1234rect2: {0, 0, 1, 2}
1235##
1236##
1237
1238#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1239
1240##
1241
1242#Subtopic From_Integers ##
1243
1244#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001245#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001246
Cary Clark4855f782018-02-06 09:41:53 -05001247#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001248
Cary Clarkbc5697d2017-10-04 14:31:33 -04001249# ------------------------------------------------------------------------------
1250
Cary Clarkbc5697d2017-10-04 14:31:33 -04001251#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1252
Cary Clarkab2621d2018-01-30 10:08:57 -05001253#In Inset_Outset_Offset
1254#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001255Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001256
Cary Clark7fc1d122017-10-09 14:07:42 -04001257If dx is negative, Rect returned is moved to the left.
1258If dx is positive, Rect returned is moved to the right.
1259If dy is negative, Rect returned is moved upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001260If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001261
Cary Clark7fc1d122017-10-09 14:07:42 -04001262#Param dx added to fLeft and fRight ##
1263#Param dy added to fTop and fBottom ##
1264
Cary Clark5538c132018-06-14 12:28:14 -04001265#Return Rect offset on axes, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001266
1267#Example
Cary Clark154beea2017-10-26 07:58:48 -04001268 SkRect rect = { 10, 50, 20, 60 };
1269 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1270 rect.bottom(), rect.isEmpty() ? "true" : "false");
1271 rect = rect.makeOffset(15, 32);
1272 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1273 rect.bottom(), rect.isEmpty() ? "true" : "false");
1274#StdOut
1275rect: 10, 50, 20, 60 isEmpty: false
1276rect: 25, 82, 35, 92 isEmpty: false
1277##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001278##
1279
Cary Clark7fc1d122017-10-09 14:07:42 -04001280#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001281
1282##
1283
1284# ------------------------------------------------------------------------------
1285
1286#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1287
Cary Clarkab2621d2018-01-30 10:08:57 -05001288#In Inset_Outset_Offset
1289#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001290Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001291
Cary Clark7fc1d122017-10-09 14:07:42 -04001292If dx is negative, Rect returned is wider.
1293If dx is positive, Rect returned is narrower.
1294If dy is negative, Rect returned is taller.
Cary Clark682c58d2018-05-16 07:07:07 -04001295If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001296
Cary Clark7fc1d122017-10-09 14:07:42 -04001297#Param dx added to fLeft and subtracted from fRight ##
1298#Param dy added to fTop and subtracted from fBottom ##
1299
1300#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001301
1302#Example
Cary Clark154beea2017-10-26 07:58:48 -04001303 SkRect rect = { 10, 50, 20, 60 };
1304 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1305 rect.bottom(), rect.isEmpty() ? "true" : "false");
1306 rect = rect.makeInset(15, 32);
1307 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1308 rect.bottom(), rect.isEmpty() ? "true" : "false");
1309#StdOut
1310rect: 10, 50, 20, 60 isEmpty: false
1311rect: 25, 82, 5, 28 isEmpty: true
1312##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001313##
1314
Cary Clark7fc1d122017-10-09 14:07:42 -04001315#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001316
1317##
1318
1319# ------------------------------------------------------------------------------
1320
1321#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1322
Cary Clarkab2621d2018-01-30 10:08:57 -05001323#In Inset_Outset_Offset
1324#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001325Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001326
Cary Clark7fc1d122017-10-09 14:07:42 -04001327If dx is negative, Rect returned is narrower.
1328If dx is positive, Rect returned is wider.
1329If dy is negative, Rect returned is shorter.
Cary Clark682c58d2018-05-16 07:07:07 -04001330If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001331
Cary Clark7fc1d122017-10-09 14:07:42 -04001332#Param dx subtracted to fLeft and added from fRight ##
1333#Param dy subtracted to fTop and added from fBottom ##
1334
1335#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001336
1337#Example
Cary Clark154beea2017-10-26 07:58:48 -04001338 SkRect rect = { 10, 50, 20, 60 };
1339 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1340 rect.bottom(), rect.isEmpty() ? "true" : "false");
1341 rect = rect.makeOutset(15, 32);
1342 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1343 rect.bottom(), rect.isEmpty() ? "true" : "false");
1344#StdOut
1345rect: 10, 50, 20, 60 isEmpty: false
1346rect: -5, 18, 35, 92 isEmpty: false
1347##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001348##
1349
Cary Clark7fc1d122017-10-09 14:07:42 -04001350#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001351
1352##
1353
1354# ------------------------------------------------------------------------------
1355
1356#Method void offset(SkScalar dx, SkScalar dy)
1357
Cary Clarkab2621d2018-01-30 10:08:57 -05001358#In Inset_Outset_Offset
1359#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001360Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001361
Cary Clark7fc1d122017-10-09 14:07:42 -04001362If dx is negative, moves Rect to the left.
1363If dx is positive, moves Rect to the right.
1364If dy is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001365If dy is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001366
1367#Param dx offset added to fLeft and fRight ##
1368#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
1370#Example
Cary Clark154beea2017-10-26 07:58:48 -04001371 SkRect rect = { 10, 14, 50, 73 };
1372 rect.offset(5, 13);
1373 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1374#StdOut
1375rect: 15, 27, 55, 86
1376##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001377##
1378
Cary Clark7fc1d122017-10-09 14:07:42 -04001379#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001380
1381##
1382
1383# ------------------------------------------------------------------------------
1384
1385#Method void offset(const SkPoint& delta)
1386
Cary Clarkab2621d2018-01-30 10:08:57 -05001387#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001388Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1389fTop, fBottom.
1390
1391If delta.fX is negative, moves Rect to the left.
1392If delta.fX is positive, moves Rect to the right.
1393If delta.fY is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001394If delta.fY is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001395
1396#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001397
1398#Example
Cary Clark154beea2017-10-26 07:58:48 -04001399 SkRect rect = { 10, 14, 50, 73 };
1400 rect.offset({5, 13});
1401 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1402#StdOut
1403rect: 15, 27, 55, 86
1404##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001405##
1406
Cary Clark7fc1d122017-10-09 14:07:42 -04001407#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001408
1409##
1410
1411# ------------------------------------------------------------------------------
1412
1413#Method void offsetTo(SkScalar newX, SkScalar newY)
1414
Cary Clarkab2621d2018-01-30 10:08:57 -05001415#In Inset_Outset_Offset
1416#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001417Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1418are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001419
Cary Clark7fc1d122017-10-09 14:07:42 -04001420#Param newX stored in fLeft, preserving width() ##
1421#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001422
1423#Example
Cary Clark154beea2017-10-26 07:58:48 -04001424 SkRect rect = { 10, 14, 50, 73 };
1425 rect.offsetTo(15, 27);
1426 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1427#StdOut
1428rect: 15, 27, 55, 86
1429##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001430##
1431
Cary Clark7fc1d122017-10-09 14:07:42 -04001432#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001433
1434##
1435
1436# ------------------------------------------------------------------------------
1437
1438#Method void inset(SkScalar dx, SkScalar dy)
1439
Cary Clarkab2621d2018-01-30 10:08:57 -05001440#In Inset_Outset_Offset
1441#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001442Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001443
Cary Clark7fc1d122017-10-09 14:07:42 -04001444If dx is positive, makes Rect narrower.
1445If dx is negative, makes Rect wider.
1446If dy is positive, makes Rect shorter.
1447If dy is negative, makes Rect taller.
1448
1449#Param dx added to fLeft and subtracted from fRight ##
1450#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001451
1452#Example
Cary Clark154beea2017-10-26 07:58:48 -04001453 SkRect rect = { 10, 14, 50, 73 };
1454 rect.inset(5, 13);
1455 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1456#StdOut
1457rect: 15, 27, 45, 60
1458##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001459##
1460
Cary Clark7fc1d122017-10-09 14:07:42 -04001461#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001462
1463##
1464
1465# ------------------------------------------------------------------------------
1466
1467#Method void outset(SkScalar dx, SkScalar dy)
1468
Cary Clarkab2621d2018-01-30 10:08:57 -05001469#In Inset_Outset_Offset
1470#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001471Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001472
Cary Clark7fc1d122017-10-09 14:07:42 -04001473If dx is positive, makes Rect wider.
1474If dx is negative, makes Rect narrower.
1475If dy is positive, makes Rect taller.
1476If dy is negative, makes Rect shorter.
1477
1478#Param dx subtracted to fLeft and added from fRight ##
1479#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001480
1481#Example
Cary Clark154beea2017-10-26 07:58:48 -04001482 SkRect rect = { 10, 14, 50, 73 };
1483 rect.outset(5, 13);
1484 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1485#StdOut
1486rect: 5, 1, 55, 86
1487##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488##
1489
Cary Clark7fc1d122017-10-09 14:07:42 -04001490#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001491
1492##
1493
Cary Clark2dc84ad2018-01-26 12:56:22 -05001494#Subtopic Inset_Outset_Offset ##
1495
1496#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001497#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001498
Cary Clark682c58d2018-05-16 07:07:07 -04001499Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001500must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001501empty() returns false. The intersection of Rect pair can be described by:
Cary Clark2be81cf2018-09-13 12:04:30 -04001502#Formula # (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1503 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) ##.
Cary Clark154beea2017-10-26 07:58:48 -04001504
Cary Clark7fc1d122017-10-09 14:07:42 -04001505The intersection is only meaningful if the resulting Rect is not empty and
1506describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1507
Cary Clark4855f782018-02-06 09:41:53 -05001508#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001509
1510# ------------------------------------------------------------------------------
1511
Florin Malitaeb420452018-02-20 11:44:43 -05001512#Method bool contains(SkScalar x, SkScalar y) const
1513
1514#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001515#Line # returns true if points are equal or inside ##
Florin Malitaeb420452018-02-20 11:44:43 -05001516Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
1517Returns false if SkRect is empty.
1518
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001519#Param x test Point x-coordinate ##
1520#Param y test Point y-coordinate ##
Florin Malitaeb420452018-02-20 11:44:43 -05001521
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001522#Return true if (x, y) is inside Rect ##
Florin Malitaeb420452018-02-20 11:44:43 -05001523
1524#Example
1525 SkRect rect = { 30, 50, 40, 60 };
1526 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1527 for (auto contained : tests) {
1528 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1529 rect.left(), rect.top(), rect.right(), rect.bottom(),
1530 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1531 contained.x(), contained.y());
1532 }
1533#StdOut
1534rect: (30, 50, 40, 60) contains (30, 50)
1535rect: (30, 50, 40, 60) does not contain (39, 49)
1536rect: (30, 50, 40, 60) does not contain (29, 59)
1537##
1538##
1539
Cary Clark53498e92018-06-28 19:13:56 -04001540#SeeAlso SkIRect::contains SkRRect::contains
Florin Malitaeb420452018-02-20 11:44:43 -05001541
1542##
1543
1544# ------------------------------------------------------------------------------
1545
Cary Clark2dc84ad2018-01-26 12:56:22 -05001546#Method bool contains(const SkRect& r) const
1547
Cary Clarkab2621d2018-01-30 10:08:57 -05001548#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001549Returns true if Rect contains r.
1550Returns false if Rect is empty or r is empty.
1551
1552Rect contains r when Rect area completely includes r area.
1553
1554#Param r Rect contained ##
1555
1556#Return true if all sides of Rect are outside r ##
1557
1558#Example
1559 SkRect rect = { 30, 50, 40, 60 };
1560 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1561 for (auto contained : tests) {
1562 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1563 rect.left(), rect.top(), rect.right(), rect.bottom(),
1564 rect.contains(contained) ? "contains" : "does not contain",
1565 contained.left(), contained.top(), contained.right(), contained.bottom());
1566 }
1567#StdOut
1568rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1569rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1570rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1571##
1572##
1573
1574#SeeAlso SkIRect::contains
1575
1576##
1577
1578# ------------------------------------------------------------------------------
1579
1580#Method bool contains(const SkIRect& r) const
1581
Cary Clarkab2621d2018-01-30 10:08:57 -05001582#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001583Returns true if Rect contains r.
1584Returns false if Rect is empty or r is empty.
1585
1586Rect contains r when Rect area completely includes r area.
1587
1588#Param r IRect contained ##
1589
1590#Return true if all sides of Rect are outside r ##
1591
1592#Example
1593 SkRect rect = { 30, 50, 40, 60 };
1594 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1595 for (auto contained : tests) {
1596 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1597 rect.left(), rect.top(), rect.right(), rect.bottom(),
1598 rect.contains(contained) ? "contains" : "does not contain",
1599 contained.left(), contained.top(), contained.right(), contained.bottom());
1600 }
1601#StdOut
1602rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1603rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1604rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1605##
1606##
1607
1608#SeeAlso SkIRect::contains
1609
1610##
1611
Cary Clarkbc5697d2017-10-04 14:31:33 -04001612# ------------------------------------------------------------------------------
1613
1614#Method bool intersect(const SkRect& r)
1615
Cary Clarkab2621d2018-01-30 10:08:57 -05001616#In Intersection
1617#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001618Returns true if Rect intersects r, and sets Rect to intersection.
1619Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001620
Cary Clark7fc1d122017-10-09 14:07:42 -04001621Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001622
Cary Clark7fc1d122017-10-09 14:07:42 -04001623#Param r limit of result ##
1624
1625#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001626
1627#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001628#Description
1629Two SkDebugf calls are required. If the calls are combined, their arguments
1630may not be evaluated in left to right order: the printed intersection may
1631be before or after the call to intersect.
1632##
Cary Clark154beea2017-10-26 07:58:48 -04001633 SkRect leftRect = { 10, 40, 50, 80 };
1634 SkRect rightRect = { 30, 60, 70, 90 };
1635 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001636 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001637 leftRect.right(), leftRect.bottom());
1638#StdOut
1639 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001640##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001641##
1642
Cary Clark7fc1d122017-10-09 14:07:42 -04001643#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001644
1645##
1646
1647# ------------------------------------------------------------------------------
1648
1649#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1650
Cary Clarkab2621d2018-01-30 10:08:57 -05001651#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001652Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1653construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001654
Cary Clark7fc1d122017-10-09 14:07:42 -04001655Returns true if Rect intersects construction, and sets Rect to intersection.
1656Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001657
Cary Clark7fc1d122017-10-09 14:07:42 -04001658Returns false if either construction or Rect is empty, leaving Rect unchanged.
1659
Cary Clark5538c132018-06-14 12:28:14 -04001660#Param left x-axis minimum of constructed Rect ##
1661#Param top y-axis minimum of constructed Rect ##
1662#Param right x-axis maximum of constructed Rect ##
1663#Param bottom y-axis maximum of constructed Rect ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001664
1665#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001666
1667#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001668#Description
1669Two SkDebugf calls are required. If the calls are combined, their arguments
1670may not be evaluated in left to right order: the printed intersection may
1671be before or after the call to intersect.
1672##
Cary Clark154beea2017-10-26 07:58:48 -04001673 SkRect leftRect = { 10, 40, 50, 80 };
1674 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001675 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001676 leftRect.right(), leftRect.bottom());
1677#StdOut
1678 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001679##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001680##
1681
Cary Clark7fc1d122017-10-09 14:07:42 -04001682#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001683
1684##
1685
1686# ------------------------------------------------------------------------------
1687
1688#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1689
Cary Clarkab2621d2018-01-30 10:08:57 -05001690#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001691Returns true if a intersects b, and sets Rect to intersection.
1692Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001693
Cary Clark7fc1d122017-10-09 14:07:42 -04001694Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001695
Cary Clark7fc1d122017-10-09 14:07:42 -04001696#Param a Rect to intersect ##
1697#Param b Rect to intersect ##
1698
1699#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001700
1701#Example
Cary Clark154beea2017-10-26 07:58:48 -04001702 SkRect result;
1703 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1704 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1705 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001706#StdOut
1707 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001708##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001709##
1710
Cary Clark7fc1d122017-10-09 14:07:42 -04001711#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001712
1713##
1714
Cary Clark7fc1d122017-10-09 14:07:42 -04001715# ------------------------------------------------------------------------------
1716
Cary Clarkbc5697d2017-10-04 14:31:33 -04001717#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1718
Cary Clarkab2621d2018-01-30 10:08:57 -05001719#In Intersection
1720#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001721Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1722construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723
Cary Clark7fc1d122017-10-09 14:07:42 -04001724Returns true if Rect intersects construction.
1725Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001726
Cary Clark5538c132018-06-14 12:28:14 -04001727#Param left x-axis minimum of constructed Rect ##
1728#Param top y-axis minimum of constructed Rect ##
1729#Param right x-axis maximum of constructed Rect ##
1730#Param bottom y-axis maximum of constructed Rect ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001731
1732#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001733
1734#Example
Cary Clark154beea2017-10-26 07:58:48 -04001735 SkRect rect = { 10, 40, 50, 80 };
1736 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001737#StdOut
1738 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001739##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001740##
1741
Cary Clark7fc1d122017-10-09 14:07:42 -04001742#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001743
1744##
1745
Cary Clark7fc1d122017-10-09 14:07:42 -04001746# ------------------------------------------------------------------------------
1747
Cary Clarkbc5697d2017-10-04 14:31:33 -04001748#Method bool intersects(const SkRect& r) const
1749
Cary Clarkab2621d2018-01-30 10:08:57 -05001750#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001751Returns true if Rect intersects r.
1752Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001753
Cary Clark7fc1d122017-10-09 14:07:42 -04001754#Param r Rect to intersect ##
1755
1756#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001757
1758#Example
Cary Clark154beea2017-10-26 07:58:48 -04001759 SkRect rect = { 10, 40, 50, 80 };
1760 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001761#StdOut
1762 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001763##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001764##
1765
Cary Clark7fc1d122017-10-09 14:07:42 -04001766#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001767
1768##
1769
Cary Clark7fc1d122017-10-09 14:07:42 -04001770# ------------------------------------------------------------------------------
1771
Cary Clarkbc5697d2017-10-04 14:31:33 -04001772#Method static bool Intersects(const SkRect& a, const SkRect& b)
1773
Cary Clarkab2621d2018-01-30 10:08:57 -05001774#In Intersection
1775#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001776Returns true if a intersects b.
1777Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001778
Cary Clark7fc1d122017-10-09 14:07:42 -04001779#Param a Rect to intersect ##
1780#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001781
Cary Clark7fc1d122017-10-09 14:07:42 -04001782#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001783
1784#Example
Cary Clark154beea2017-10-26 07:58:48 -04001785 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001786#StdOut
1787 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001788##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001789##
1790
Cary Clark7fc1d122017-10-09 14:07:42 -04001791#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001792
1793##
1794
Cary Clark2dc84ad2018-01-26 12:56:22 -05001795#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001796
Cary Clark2dc84ad2018-01-26 12:56:22 -05001797#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001798#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001799
Cary Clark4855f782018-02-06 09:41:53 -05001800#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001801
1802# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001803
1804#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1805
Cary Clarkab2621d2018-01-30 10:08:57 -05001806#In Join
1807#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001808Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1809construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001810
Cary Clark7fc1d122017-10-09 14:07:42 -04001811Sets Rect to the union of itself and the construction.
1812
1813Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1814Rect to construction.
1815
Cary Clark5538c132018-06-14 12:28:14 -04001816#Param left x-axis minimum of constructed Rect ##
1817#Param top y-axis minimum of constructed Rect ##
1818#Param right x-axis maximum of constructed Rect ##
1819#Param bottom y-axis maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001820
1821#Example
Cary Clark154beea2017-10-26 07:58:48 -04001822 SkRect rect = { 10, 20, 15, 25};
1823 rect.join(50, 60, 55, 65);
1824 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001825#StdOut
1826 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001827##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001828##
1829
Cary Clark7fc1d122017-10-09 14:07:42 -04001830#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001831
1832##
1833
Cary Clark7fc1d122017-10-09 14:07:42 -04001834# ------------------------------------------------------------------------------
1835
Cary Clarkbc5697d2017-10-04 14:31:33 -04001836#Method void join(const SkRect& r)
1837
Cary Clarkab2621d2018-01-30 10:08:57 -05001838#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001839Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001840
Cary Clark7fc1d122017-10-09 14:07:42 -04001841Has no effect if r is empty. Otherwise, if Rect is empty, sets
1842Rect to r.
1843
1844#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001845
1846#Example
Cary Clark154beea2017-10-26 07:58:48 -04001847 SkRect rect = { 10, 20, 15, 25};
1848 rect.join({50, 60, 55, 65});
1849 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001850#StdOut
1851 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001852##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001853##
1854
Cary Clark7fc1d122017-10-09 14:07:42 -04001855#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001856
1857##
1858
Cary Clark7fc1d122017-10-09 14:07:42 -04001859# ------------------------------------------------------------------------------
1860
Cary Clarkbc5697d2017-10-04 14:31:33 -04001861#Method void joinNonEmptyArg(const SkRect& r)
1862
Cary Clarkab2621d2018-01-30 10:08:57 -05001863#In Join
1864#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001865Sets Rect to the union of itself and r.
1866
1867Asserts if r is empty and SK_DEBUG is defined.
1868If Rect is empty, sets Rect to r.
1869
1870May produce incorrect results if r is empty.
1871
1872#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001873
1874#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001875#Description
1876Since Rect is not sorted, first result is copy of toJoin.
1877##
Cary Clark154beea2017-10-26 07:58:48 -04001878 SkRect rect = { 10, 100, 15, 0};
1879 SkRect sorted = rect.makeSorted();
1880 SkRect toJoin = { 50, 60, 55, 65 };
1881 rect.joinNonEmptyArg(toJoin);
1882 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1883 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001884 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1885#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001886rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001887sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001888##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001889##
1890
Cary Clark7fc1d122017-10-09 14:07:42 -04001891#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001892
1893##
1894
Cary Clark7fc1d122017-10-09 14:07:42 -04001895# ------------------------------------------------------------------------------
1896
Cary Clarkbc5697d2017-10-04 14:31:33 -04001897#Method void joinPossiblyEmptyRect(const SkRect& r)
1898
Cary Clarkab2621d2018-01-30 10:08:57 -05001899#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001900#Line # sets to union of bounds; skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001901Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001902
Cary Clark7fc1d122017-10-09 14:07:42 -04001903May produce incorrect results if Rect or r is empty.
1904
1905#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001906
1907#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001908#Description
1909Since Rect is not sorted, first result is not useful.
1910##
Cary Clark154beea2017-10-26 07:58:48 -04001911 SkRect rect = { 10, 100, 15, 0};
1912 SkRect sorted = rect.makeSorted();
1913 SkRect toJoin = { 50, 60, 55, 65 };
1914 rect.joinPossiblyEmptyRect(toJoin);
1915 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1916 sorted.joinPossiblyEmptyRect(toJoin);
1917 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001918#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001919rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001920sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001921##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001922##
1923
Cary Clark7fc1d122017-10-09 14:07:42 -04001924#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001925
1926##
1927
Cary Clark2dc84ad2018-01-26 12:56:22 -05001928#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001929
Cary Clark2dc84ad2018-01-26 12:56:22 -05001930#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001931#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001932
Cary Clark4855f782018-02-06 09:41:53 -05001933#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001934
Cary Clarkbc5697d2017-10-04 14:31:33 -04001935#Method void round(SkIRect* dst) const
1936
Cary Clarkab2621d2018-01-30 10:08:57 -05001937#In Rounding
1938#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001939Sets IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04001940members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1941 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001942
Cary Clark7fc1d122017-10-09 14:07:42 -04001943#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001944
1945#Example
Cary Clark154beea2017-10-26 07:58:48 -04001946 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1947 SkIRect round;
1948 rect.round(&round);
1949 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001950#StdOut
1951round: 31, 51, 41, 61
1952##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001953##
1954
Cary Clark7fc1d122017-10-09 14:07:42 -04001955#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001956
1957##
1958
Cary Clark7fc1d122017-10-09 14:07:42 -04001959# ------------------------------------------------------------------------------
1960
Cary Clarkbc5697d2017-10-04 14:31:33 -04001961#Method void roundOut(SkIRect* dst) const
1962
Cary Clarkab2621d2018-01-30 10:08:57 -05001963#In Rounding
1964#Line # sets members to nearest integer value away from opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001965Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
1966up fRight and fBottom, using
1967#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1968 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001969
Cary Clark7fc1d122017-10-09 14:07:42 -04001970#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001971
1972#Example
Cary Clark154beea2017-10-26 07:58:48 -04001973 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1974 SkIRect round;
1975 rect.roundOut(&round);
1976 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001977#StdOut
1978round: 30, 50, 41, 61
1979##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001980##
1981
Cary Clark7fc1d122017-10-09 14:07:42 -04001982#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001983
1984##
1985
Cary Clark7fc1d122017-10-09 14:07:42 -04001986# ------------------------------------------------------------------------------
1987
Cary Clark682c58d2018-05-16 07:07:07 -04001988#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001989
Cary Clarkab2621d2018-01-30 10:08:57 -05001990#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04001991Sets Rect by discarding the fractional portion of fLeft and fTop; and rounding
1992up fRight and fBottom, using
1993#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1994 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001995
Cary Clark7fc1d122017-10-09 14:07:42 -04001996#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001997
1998#Example
Cary Clark154beea2017-10-26 07:58:48 -04001999 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2000 SkRect round;
2001 rect.roundOut(&round);
2002 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002003#StdOut
2004round: 30, 50, 41, 61
2005##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002006##
2007
Cary Clark7fc1d122017-10-09 14:07:42 -04002008#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002009
2010##
2011
Cary Clark7fc1d122017-10-09 14:07:42 -04002012# ------------------------------------------------------------------------------
2013
Cary Clarkbc5697d2017-10-04 14:31:33 -04002014#Method void roundIn(SkIRect* dst) const
2015
Cary Clarkab2621d2018-01-30 10:08:57 -05002016#In Rounding
2017#Line # sets members to nearest integer value towards opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04002018Sets Rect by rounding up fLeft and fTop; and discarding the fractional portion
2019of fRight and fBottom, using
2020#Formula # (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2021 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002022
Cary Clark7fc1d122017-10-09 14:07:42 -04002023#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002024
2025#Example
Cary Clark154beea2017-10-26 07:58:48 -04002026 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2027 SkIRect round;
2028 rect.roundIn(&round);
2029 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002030#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002031round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002032##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002033##
2034
Cary Clark7fc1d122017-10-09 14:07:42 -04002035#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002036
2037##
2038
Cary Clark7fc1d122017-10-09 14:07:42 -04002039# ------------------------------------------------------------------------------
2040
Cary Clarkbc5697d2017-10-04 14:31:33 -04002041#Method SkIRect round() const
2042
Cary Clarkab2621d2018-01-30 10:08:57 -05002043#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002044Returns IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04002045members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2046 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002047
Cary Clark7fc1d122017-10-09 14:07:42 -04002048#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002049
2050#Example
Cary Clark154beea2017-10-26 07:58:48 -04002051 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2052 SkIRect round = rect.round();
2053 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002054#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002055round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002056##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002057##
2058
Cary Clark7fc1d122017-10-09 14:07:42 -04002059#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002060
2061##
2062
Cary Clark7fc1d122017-10-09 14:07:42 -04002063# ------------------------------------------------------------------------------
2064
Cary Clarkbc5697d2017-10-04 14:31:33 -04002065#Method SkIRect roundOut() const
2066
Cary Clarkab2621d2018-01-30 10:08:57 -05002067#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04002068Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
2069up fRight and fBottom, using
2070#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2071 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002072
Cary Clark7fc1d122017-10-09 14:07:42 -04002073#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002074
2075#Example
Cary Clark154beea2017-10-26 07:58:48 -04002076 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2077 SkIRect round = rect.roundOut();
2078 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002079#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002080round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002081##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002082##
2083
Cary Clark7fc1d122017-10-09 14:07:42 -04002084#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002085
2086##
2087
Cary Clark2dc84ad2018-01-26 12:56:22 -05002088#Subtopic Rounding ##
2089
2090#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002091#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002092
Cary Clark4855f782018-02-06 09:41:53 -05002093#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04002094
2095# ------------------------------------------------------------------------------
2096
Cary Clarkbc5697d2017-10-04 14:31:33 -04002097#Method void sort()
2098
Cary Clarkab2621d2018-01-30 10:08:57 -05002099#In Sorting
2100#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002101Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2102fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2103and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104
2105#Example
Cary Clark154beea2017-10-26 07:58:48 -04002106 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2107 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2108 rect.sort();
2109 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002110#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002111rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002112sorted: 20.5, 10.5, 30.5, 50.5
2113##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002114##
2115
Cary Clark2dc84ad2018-01-26 12:56:22 -05002116#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002117
2118##
2119
Cary Clark7fc1d122017-10-09 14:07:42 -04002120# ------------------------------------------------------------------------------
2121
Cary Clarkbc5697d2017-10-04 14:31:33 -04002122#Method SkRect makeSorted() const
2123
Cary Clarkab2621d2018-01-30 10:08:57 -05002124#In Sorting
Cary Clark4855f782018-02-06 09:41:53 -05002125#In Constructor
Cary Clark682c58d2018-05-16 07:07:07 -04002126#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002127Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2128with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2129and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002130
Cary Clark7fc1d122017-10-09 14:07:42 -04002131#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002132
2133#Example
Cary Clark154beea2017-10-26 07:58:48 -04002134 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2135 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2136 SkRect sort = rect.makeSorted();
2137 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002138#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002139rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002140sorted: 20.5, 10.5, 30.5, 50.5
2141##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002142##
2143
Cary Clark2dc84ad2018-01-26 12:56:22 -05002144#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002145
2146##
2147
Cary Clark2dc84ad2018-01-26 12:56:22 -05002148#Subtopic Sorting ##
2149
Cary Clark7fc1d122017-10-09 14:07:42 -04002150# ------------------------------------------------------------------------------
2151
Cary Clarkbc5697d2017-10-04 14:31:33 -04002152#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002153#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002154#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002155Returns pointer to first Scalar in Rect, to treat it as an array with four
2156entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002157
Cary Clark7fc1d122017-10-09 14:07:42 -04002158#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002159
2160#Example
Cary Clark154beea2017-10-26 07:58:48 -04002161 SkRect rect = {7, 11, 13, 17};
2162SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2163#StdOut
2164rect.asScalars() == &rect.fLeft
2165##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002166##
2167
Cary Clark7fc1d122017-10-09 14:07:42 -04002168#SeeAlso toQuad
2169
Cary Clarkbc5697d2017-10-04 14:31:33 -04002170##
2171
Cary Clark7fc1d122017-10-09 14:07:42 -04002172# ------------------------------------------------------------------------------
2173
Cary Clarkbc5697d2017-10-04 14:31:33 -04002174#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002175#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002176#Line # sends text representation to standard output using floats ##
Cary Clark682c58d2018-05-16 07:07:07 -04002177Writes text representation of Rect to standard output. Set asHex to true to
Cary Clark7fc1d122017-10-09 14:07:42 -04002178generate exact binary representations of floating point numbers.
2179
2180#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002181
2182#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002183 SkRect rect = {20, 30, 40, 50};
2184 for (bool dumpAsHex : { false, true } ) {
2185 rect.dump(dumpAsHex);
2186 SkDebugf("\n");
2187 }
2188#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002189SkRect::MakeLTRB(20, 30, 40, 50);
2190
2191SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2192 SkBits2Float(0x41f00000), /* 30.000000 */
2193 SkBits2Float(0x42200000), /* 40.000000 */
2194 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002195##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002196##
2197
Cary Clark7fc1d122017-10-09 14:07:42 -04002198#SeeAlso dumpHex
2199
Cary Clarkbc5697d2017-10-04 14:31:33 -04002200##
2201
Cary Clark7fc1d122017-10-09 14:07:42 -04002202# ------------------------------------------------------------------------------
2203
Cary Clarkbc5697d2017-10-04 14:31:33 -04002204#Method void dump() const
2205
Cary Clark7fc1d122017-10-09 14:07:42 -04002206Writes text representation of Rect to standard output. The representation may be
2207directly compiled as C++ code. Floating point values are written
2208with limited precision; it may not be possible to reconstruct original Rect
2209from output.
2210
Cary Clarkbc5697d2017-10-04 14:31:33 -04002211#Example
Cary Clark154beea2017-10-26 07:58:48 -04002212SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2213rect.dump();
2214SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2215SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002216#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002217SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002218rect is not equal to copy
2219##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002220##
2221
Cary Clark7fc1d122017-10-09 14:07:42 -04002222#SeeAlso dumpHex
2223
Cary Clarkbc5697d2017-10-04 14:31:33 -04002224##
2225
Cary Clark7fc1d122017-10-09 14:07:42 -04002226# ------------------------------------------------------------------------------
2227
Cary Clarkbc5697d2017-10-04 14:31:33 -04002228#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002229#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002230#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002231Writes text representation of Rect to standard output. The representation may be
2232directly compiled as C++ code. Floating point values are written
2233in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2234original Rect.
2235
Cary Clark682c58d2018-05-16 07:07:07 -04002236Use instead of dump() when submitting
2237#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002238.
2239
Cary Clarkbc5697d2017-10-04 14:31:33 -04002240#Example
Cary Clark154beea2017-10-26 07:58:48 -04002241 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2242rect.dumpHex();
2243SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2244 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2245 SkBits2Float(0x40266666), /* 2.600000 */
2246 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002247SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2248#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002249SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2250 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2251 SkBits2Float(0x40266666), /* 2.600000 */
2252 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002253rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002254##
Cary Clark7fc1d122017-10-09 14:07:42 -04002255##
2256
2257#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002258
2259##
2260
Cary Clark0c95aab2018-01-08 16:20:59 -05002261#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05002262#Deprecated
2263##
2264
Cary Clarkbc5697d2017-10-04 14:31:33 -04002265#Struct SkRect ##
2266
2267#Topic Rect ##