blob: 136ef29d5fd08ea43c98077624c1640bf3c57af6 [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 Clark61313f32018-10-08 14:57:48 -04007#Code
8#Populate
9##
10
Cary Clark7fc1d122017-10-09 14:07:42 -040011SkRect holds four SkScalar coordinates describing the upper and
Cary Clark682c58d2018-05-16 07:07:07 -040012lower bounds of a rectangle. SkRect may be created from outer bounds or
Cary Clark7fc1d122017-10-09 14:07:42 -040013from position, width, and height. SkRect describes an area; if its right
14is less than or equal to its left, or if its bottom is less than or equal to
15its top, it is considered empty.
16
17# move to topic about MakeIWH and friends
18SkRect can be constructed from int values to avoid compiler warnings that
19integer input cannot convert to SkScalar without loss of precision.
20
Cary Clarkbc5697d2017-10-04 14:31:33 -040021#Member SkScalar fLeft
Cary Clark08895c42018-02-01 09:37:32 -050022#Line # smaller x-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040023May contain any value, including infinities and NaN. The smaller of the
24horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040025##
26
27#Member SkScalar fTop
Cary Clark08895c42018-02-01 09:37:32 -050028#Line # smaller y-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040029May contain any value, including infinities and NaN. The smaller of the
30vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040031##
32
33#Member SkScalar fRight
Cary Clark08895c42018-02-01 09:37:32 -050034#Line # larger x-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040035May contain any value, including infinities and NaN. The larger of the
36horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040037##
38
39#Member SkScalar fBottom
Cary Clark08895c42018-02-01 09:37:32 -050040#Line # larger y-axis bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -040041May contain any value, including infinities and NaN. The larger of the
42vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -040043##
44
Cary Clark61313f32018-10-08 14:57:48 -040045#Subtopic Constructors
Cary Clark2dc84ad2018-01-26 12:56:22 -050046
Cary Clarkbc5697d2017-10-04 14:31:33 -040047# ------------------------------------------------------------------------------
48
Cary Clark61313f32018-10-08 14:57:48 -040049#Method static constexpr SkRect MakeEmpty()
Cary Clarkbc5697d2017-10-04 14:31:33 -040050
Cary Clark61313f32018-10-08 14:57:48 -040051#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050052#Line # constructs from bounds of (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040053Returns constructed Rect set to (0, 0, 0, 0).
54Many other rectangles are empty; if left is equal to or greater than right,
55or if top is equal to or greater than bottom. Setting all members to zero
56is a convenience, but does not designate a special empty rectangle.
Cary Clark682c58d2018-05-16 07:07:07 -040057
Cary Clark7fc1d122017-10-09 14:07:42 -040058#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040059
60#Example
Cary Clark154beea2017-10-26 07:58:48 -040061 SkRect rect = SkRect::MakeEmpty();
62 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
63 rect.offset(10, 10);
64 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
65 rect.inset(10, 10);
66 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
67 rect.outset(20, 20);
68 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
69#StdOut
70MakeEmpty isEmpty: true
71offset rect isEmpty: true
72inset rect isEmpty: true
73outset rect isEmpty: false
74##
Cary Clarkbc5697d2017-10-04 14:31:33 -040075##
76
Mike Reed274218e2018-01-08 15:05:02 -050077#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -040078
79##
80
81# ------------------------------------------------------------------------------
82
Cary Clark61313f32018-10-08 14:57:48 -040083#Method static constexpr SkRect MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -040084
Cary Clark61313f32018-10-08 14:57:48 -040085#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050086#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040087Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
88validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -040089
Cary Clark7fc1d122017-10-09 14:07:42 -040090Passing integer values may generate a compiler warning since Rect cannot
91represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
92
93#Param w SkScalar width of constructed Rect ##
94#Param h SkScalar height of constructed Rect ##
95
96#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040097
98#Example
Cary Clark154beea2017-10-26 07:58:48 -040099 SkRect rect1 = SkRect::MakeWH(25, 35);
100 SkRect rect2 = SkRect::MakeIWH(25, 35);
101 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
102 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
103 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400104 "" : "not ");
105#StdOut
106all equal
107##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400108##
109
Cary Clark7fc1d122017-10-09 14:07:42 -0400110#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400111
112##
113
114# ------------------------------------------------------------------------------
115
Cary Clark61313f32018-10-08 14:57:48 -0400116#Method static SkRect MakeIWH(int w, int h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400117
Cary Clark61313f32018-10-08 14:57:48 -0400118#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500119#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400120Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
121input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400122
Cary Clark7fc1d122017-10-09 14:07:42 -0400123Use to avoid a compiler warning that input may lose precision when stored.
124Use SkIRect for an exact integer rectangle.
125
126#Param w integer width of constructed Rect ##
127#Param h integer height of constructed Rect ##
128
129#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400130
131#Example
Cary Clark154beea2017-10-26 07:58:48 -0400132 SkIRect i_rect = SkIRect::MakeWH(25, 35);
133 SkRect f_rect = SkRect::MakeIWH(25, 35);
134 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
135 i_rect = SkIRect::MakeWH(125000111, 0);
136 f_rect = SkRect::MakeIWH(125000111, 0);
137 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400138#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400139i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400140i_rect width: 125000111 f_rect width:125000112
141##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400142##
143
Cary Clark7fc1d122017-10-09 14:07:42 -0400144#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400145
146##
147
148# ------------------------------------------------------------------------------
149
Cary Clark61313f32018-10-08 14:57:48 -0400150#Method static constexpr SkRect MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400151
Cary Clark61313f32018-10-08 14:57:48 -0400152#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500153#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400154Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
155validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400156
Cary Clark7fc1d122017-10-09 14:07:42 -0400157#Param size SkScalar values for Rect width and height ##
158
159#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400160
161#Example
Cary Clark154beea2017-10-26 07:58:48 -0400162 SkSize size = {25.5f, 35.5f};
163 SkRect rect = SkRect::MakeSize(size);
164 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
165 SkISize floor = size.toFloor();
166 rect = SkRect::MakeSize(SkSize::Make(floor));
167 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400168#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400169rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400170floor width: 25 height: 35
171##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400172##
173
Cary Clark7fc1d122017-10-09 14:07:42 -0400174#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400175
176##
177
178# ------------------------------------------------------------------------------
179
Cary Clark61313f32018-10-08 14:57:48 -0400180#Method static constexpr SkRect MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
Cary Clarkbc5697d2017-10-04 14:31:33 -0400181 SkScalar b)
Cary Clark61313f32018-10-08 14:57:48 -0400182#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500183#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400184
Cary Clark7fc1d122017-10-09 14:07:42 -0400185Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
186result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400187
Cary Clark7fc1d122017-10-09 14:07:42 -0400188#Param l SkScalar stored in fLeft ##
189#Param t SkScalar stored in fTop ##
190#Param r SkScalar stored in fRight ##
191#Param b SkScalar stored in fBottom ##
192
193#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400194
195#Example
Cary Clark154beea2017-10-26 07:58:48 -0400196 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
197 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
198 rect.bottom(), rect.isEmpty() ? "true" : "false");
199 rect.sort();
200 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
201 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400202#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400203rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400204rect: 5, 25, 15, 35 isEmpty: false
205##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400206##
207
Cary Clark7fc1d122017-10-09 14:07:42 -0400208#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400209
210##
211
212# ------------------------------------------------------------------------------
213
Cary Clark61313f32018-10-08 14:57:48 -0400214#Method static constexpr SkRect MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400215
Cary Clark61313f32018-10-08 14:57:48 -0400216#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500217#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400218Returns constructed Rect set to #Formula # (x, y, x + w, y + h) ##.
219Does not validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400220
Cary Clark7fc1d122017-10-09 14:07:42 -0400221#Param x stored in fLeft ##
222#Param y stored in fTop ##
223#Param w added to x and stored in fRight ##
224#Param h added to y and stored in fBottom ##
225
Cary Clark884dd7d2017-10-11 10:37:52 -0400226#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400227
228#Example
Cary Clark154beea2017-10-26 07:58:48 -0400229 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
230 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
231 rect.bottom(), rect.isEmpty() ? "true" : "false");
232 rect.sort();
233 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
234 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400235#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400236rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400237rect: -10, 35, 5, 60 isEmpty: false
238##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400239##
240
Cary Clark7fc1d122017-10-09 14:07:42 -0400241#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400242
243##
244
245# ------------------------------------------------------------------------------
246
Cary Clarkbc5697d2017-10-04 14:31:33 -0400247#Method static SkRect Make(const SkISize& size)
248
Cary Clark61313f32018-10-08 14:57:48 -0400249#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500250#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark682c58d2018-05-16 07:07:07 -0400251Returns constructed IRect set to (0, 0, size.width(), size.height()).
Cary Clark7fc1d122017-10-09 14:07:42 -0400252Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400253
Cary Clark7fc1d122017-10-09 14:07:42 -0400254#Param size integer values for Rect width and height ##
255
256#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400257
258#Example
Cary Clark154beea2017-10-26 07:58:48 -0400259 SkRect rect1 = SkRect::MakeSize({2, 35});
260 SkRect rect2 = SkRect::MakeIWH(2, 35);
261 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400262#StdOut
263rect1 == rect2
264##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400265##
266
Cary Clark7fc1d122017-10-09 14:07:42 -0400267#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400268
269##
270
271# ------------------------------------------------------------------------------
272
Cary Clark61313f32018-10-08 14:57:48 -0400273#Method static SkRect Make(const SkIRect& irect)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400274
Cary Clark61313f32018-10-08 14:57:48 -0400275#In Constructors
Cary Clark7fc1d122017-10-09 14:07:42 -0400276Returns constructed IRect set to irect, promoting integers to Scalar.
277Does not validate input; fLeft may be greater than fRight, fTop may be greater
278than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400279
Cary Clark7fc1d122017-10-09 14:07:42 -0400280#Param irect integer unsorted bounds ##
281
282#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400283
284#Example
Cary Clark154beea2017-10-26 07:58:48 -0400285 SkIRect i_rect1 = {2, 35, 22, 53};
286 SkRect f_rect = SkRect::Make(i_rect1);
287 f_rect.offset(0.49f, 0.49f);
288 SkIRect i_rect2;
289 f_rect.round(&i_rect2);
290 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400291##
292
Cary Clark7fc1d122017-10-09 14:07:42 -0400293#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
295##
296
Cary Clark61313f32018-10-08 14:57:48 -0400297#Subtopic Constructors ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500298
Cary Clark4855f782018-02-06 09:41:53 -0500299#Subtopic Property
300#Line # member values, center, validity ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500301
Cary Clarkbc5697d2017-10-04 14:31:33 -0400302# ------------------------------------------------------------------------------
303
304#Method bool isEmpty() const
305
Cary Clark4855f782018-02-06 09:41:53 -0500306#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500307#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400308Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
309to or greater than fBottom. Call sort() to reverse rectangles with negative
310width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400311
Cary Clark61313f32018-10-08 14:57:48 -0400312#Return true if width() or height() are not positive and valid ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400313
314#Example
Cary Clark154beea2017-10-26 07:58:48 -0400315 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
316 for (auto rect : tests) {
317 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
318 rect.bottom(), rect.isEmpty() ? "" : " not");
319 rect.sort();
320 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
321 rect.bottom(), rect.isEmpty() ? "" : " not");
322 }
323#StdOut
324rect: {20, 40, 10, 50} is empty
325sorted: {10, 40, 20, 50} is not empty
326rect: {20, 40, 20, 50} is empty
327sorted: {20, 40, 20, 50} is empty
328##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400329##
330
Cary Clark7fc1d122017-10-09 14:07:42 -0400331#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400332
333##
334
335# ------------------------------------------------------------------------------
336
337#Method bool isSorted() const
338
Cary Clark4855f782018-02-06 09:41:53 -0500339#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500340#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400341Returns true if fLeft is equal to or less than fRight, or if fTop is equal
342to or less than fBottom. Call sort() to reverse rectangles with negative
343width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400344
Cary Clark7fc1d122017-10-09 14:07:42 -0400345#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400346
347#Example
Cary Clark154beea2017-10-26 07:58:48 -0400348 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
349 for (auto rect : tests) {
350 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
351 rect.bottom(), rect.isSorted() ? "" : " not");
352 rect.sort();
353 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
354 rect.bottom(), rect.isSorted() ? "" : " not");
355 }
356#StdOut
357rect: {20, 40, 10, 50} is not sorted
358sorted: {10, 40, 20, 50} is sorted
359rect: {20, 40, 20, 50} is sorted
360sorted: {20, 40, 20, 50} is sorted
361##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400362##
363
Cary Clark7fc1d122017-10-09 14:07:42 -0400364#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400365
366##
367
368# ------------------------------------------------------------------------------
369
Cary Clarkbc5697d2017-10-04 14:31:33 -0400370#Method bool isFinite() const
371
Cary Clark4855f782018-02-06 09:41:53 -0500372#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500373#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400374Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
Cary Clark682c58d2018-05-16 07:07:07 -0400375and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400376
Cary Clark7fc1d122017-10-09 14:07:42 -0400377#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400378
379#Example
Mike Reed274218e2018-01-08 15:05:02 -0500380SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400381 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
382 SkDebugf("large width %g\n", largest.width());
383 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
384 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
385#StdOut
386largest is finite: true
387large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400388widest is finite: false
389##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400390##
391
Cary Clark7fc1d122017-10-09 14:07:42 -0400392#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400393
394##
395
396# ------------------------------------------------------------------------------
397
398#Method SkScalar x() const
399
Cary Clark4855f782018-02-06 09:41:53 -0500400#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500401#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400402Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
403Call sort() to reverse fLeft and fRight if needed.
404
405#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400406
407#Example
Cary Clark154beea2017-10-26 07:58:48 -0400408 SkRect unsorted = { 15, 5, 10, 25 };
409 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
410 SkRect sorted = unsorted.makeSorted();
411 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400412#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400413unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400414sorted.fLeft: 10 sorted.x(): 10
415##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400416##
417
Cary Clark7fc1d122017-10-09 14:07:42 -0400418#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400419
420##
421
422# ------------------------------------------------------------------------------
423
424#Method SkScalar y() const
425
Cary Clark4855f782018-02-06 09:41:53 -0500426#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500427#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400428Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
429and sort() to reverse fTop and fBottom if needed.
430
431#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400432
433#Example
Cary Clark154beea2017-10-26 07:58:48 -0400434 SkRect unsorted = { 15, 25, 10, 5 };
435 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
436 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400437 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
438#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400439unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400440sorted.fTop: 5 sorted.y(): 5
441##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400442##
443
Cary Clark7fc1d122017-10-09 14:07:42 -0400444#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400445
446##
447
448# ------------------------------------------------------------------------------
449
450#Method SkScalar left() const
451
Cary Clark4855f782018-02-06 09:41:53 -0500452#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500453#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400454Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
455Call sort() to reverse fLeft and fRight if needed.
456
457#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400458
459#Example
Cary Clark154beea2017-10-26 07:58:48 -0400460 SkRect unsorted = { 15, 5, 10, 25 };
461 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
462 SkRect sorted = unsorted.makeSorted();
463 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400464#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400465unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400466sorted.fLeft: 10 sorted.left(): 10
467##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400468##
469
Cary Clark7fc1d122017-10-09 14:07:42 -0400470#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400471
472##
473
474# ------------------------------------------------------------------------------
475
476#Method SkScalar top() const
477
Cary Clark4855f782018-02-06 09:41:53 -0500478#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500479#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400480Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
481and sort() to reverse fTop and fBottom if needed.
482
483#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400484
485#Example
Cary Clark154beea2017-10-26 07:58:48 -0400486 SkRect unsorted = { 15, 25, 10, 5 };
487 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
488 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400489 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
490#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400491unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400492sorted.fTop: 5 sorted.top(): 5
493##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400494##
495
Cary Clark7fc1d122017-10-09 14:07:42 -0400496#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400497
498##
499
500# ------------------------------------------------------------------------------
501
502#Method SkScalar right() const
503
Cary Clark4855f782018-02-06 09:41:53 -0500504#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500505#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400506Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
507Call sort() to reverse fLeft and fRight if needed.
508
509#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400510
511#Example
Cary Clark154beea2017-10-26 07:58:48 -0400512 SkRect unsorted = { 15, 25, 10, 5 };
513 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
514 SkRect sorted = unsorted.makeSorted();
515 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400516#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400517unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400518sorted.fRight: 15 sorted.right(): 15
519##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400520##
521
Cary Clark7fc1d122017-10-09 14:07:42 -0400522#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400523
524##
525
526# ------------------------------------------------------------------------------
527
528#Method SkScalar bottom() const
529
Cary Clark4855f782018-02-06 09:41:53 -0500530#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500531#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400532Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
533and sort() to reverse fTop and fBottom if needed.
534
535#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400536
537#Example
Cary Clark154beea2017-10-26 07:58:48 -0400538 SkRect unsorted = { 15, 25, 10, 5 };
539 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
540 SkRect sorted = unsorted.makeSorted();
541 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400542#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400543unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400544sorted.fBottom: 25 sorted.bottom(): 25
545##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400546##
547
Cary Clark7fc1d122017-10-09 14:07:42 -0400548#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400549
550##
551
552# ------------------------------------------------------------------------------
553
554#Method SkScalar width() const
555
Cary Clark4855f782018-02-06 09:41:53 -0500556#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500557#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400558Returns span on the x-axis. This does not check if Rect is sorted, or if
559result fits in 32-bit float; result may be negative or infinity.
560
561#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400562
563#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400564#Description
565Compare with SkIRect::width() example.
566##
Cary Clark154beea2017-10-26 07:58:48 -0400567 SkRect unsorted = { 15, 25, 10, 5 };
568 SkDebugf("unsorted width: %g\n", unsorted.width());
569 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
570 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400571#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400572unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400573large width: 4294967296
574##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400575##
576
Cary Clark7fc1d122017-10-09 14:07:42 -0400577#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400578
579##
580
581# ------------------------------------------------------------------------------
582
583#Method SkScalar height() const
584
Cary Clark4855f782018-02-06 09:41:53 -0500585#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500586#Line # returns span in y ##
Cary Clark224c7002018-06-27 11:00:21 -0400587Returns span on the y-axis. This does not check if Rect is sorted, or if
Cary Clark7fc1d122017-10-09 14:07:42 -0400588result fits in 32-bit float; result may be negative or infinity.
589
590#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400591
592#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400593#Description
594Compare with SkIRect::height() example.
595##
Cary Clark154beea2017-10-26 07:58:48 -0400596 SkRect unsorted = { 15, 25, 10, 20 };
597 SkDebugf("unsorted height: %g\n", unsorted.height());
598 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
599 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400600#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400601unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400602large height: 4294967296
603##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400604##
605
Cary Clark7fc1d122017-10-09 14:07:42 -0400606#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400607
608##
609
610# ------------------------------------------------------------------------------
611
612#Method SkScalar centerX() const
613
Cary Clark4855f782018-02-06 09:41:53 -0500614#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500615#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400616Returns average of left edge and right edge. Result does not change if Rect
617is sorted. Result may overflow to infinity if Rect is far from the origin.
618
619#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400620
621#Example
Cary Clark154beea2017-10-26 07:58:48 -0400622 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
623 for (auto rect : tests) {
624 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
625 rect.sort();
626 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
627 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400628#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400629left: 20 right: 41 centerX: 30.5
630left: 20 right: 41 centerX: 30.5
631left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400632left: -41 right: -20 centerX: -30.5
633##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400634##
635
Cary Clark47d7dae2018-04-11 16:54:35 -0400636#SeeAlso centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400637
638##
639
640# ------------------------------------------------------------------------------
641
642#Method SkScalar centerY() const
643
Cary Clark4855f782018-02-06 09:41:53 -0500644#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500645#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400646Returns average of top edge and bottom edge. Result does not change if Rect
Cary Clark75fd4492018-06-20 12:45:16 -0400647is sorted.
Cary Clark7fc1d122017-10-09 14:07:42 -0400648
649#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400650
651#Example
Cary Clark154beea2017-10-26 07:58:48 -0400652 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
653 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
654 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400655#StdOut
Cary Clark75fd4492018-06-20 12:45:16 -0400656left: 2e+38 right: 3e+38 centerX: 2.5e+38 safe mid x: 2.5e+38
Cary Clark7fc1d122017-10-09 14:07:42 -0400657##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400658##
659
Cary Clark47d7dae2018-04-11 16:54:35 -0400660#SeeAlso centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400661
662##
663
Cary Clark4855f782018-02-06 09:41:53 -0500664#Subtopic Property ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500665
Cary Clark61313f32018-10-08 14:57:48 -0400666#Subtopic Operators
Cary Clark2dc84ad2018-01-26 12:56:22 -0500667
Cary Clarkbc5697d2017-10-04 14:31:33 -0400668# ------------------------------------------------------------------------------
669
Cary Clark884dd7d2017-10-11 10:37:52 -0400670#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400671
Cary Clark61313f32018-10-08 14:57:48 -0400672#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500673#Line # returns true if members are equal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400674Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
Cary Clark7fc1d122017-10-09 14:07:42 -0400675equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400676
Cary Clark7fc1d122017-10-09 14:07:42 -0400677a and b are not equal if either contain NaN. a and b are equal if members
678contain zeroes width different signs.
679
680#Param a Rect to compare ##
681#Param b Rect to compare ##
682
683#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400684
685#Example
Cary Clark154beea2017-10-26 07:58:48 -0400686 auto debugster = [](const SkRect& test) -> void {
687 SkRect negZero = {-0.0f, -0.0f, 2, 2};
688 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
689 test.fLeft, test.fTop, test.fRight, test.fBottom,
690 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
691 test == negZero ? '=' : '!',
692 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
693 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
694 "and are" : "yet are not");
695 };
696 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
697 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
698 for (auto rect : tests) {
699 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400700 }
Cary Clark154beea2017-10-26 07:58:48 -0400701#StdOut
702tests are equal
703{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
704{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark682c58d2018-05-16 07:07:07 -0400705{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400706##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400707##
708
Cary Clark7fc1d122017-10-09 14:07:42 -0400709#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400710
711##
712
713# ------------------------------------------------------------------------------
714
Cary Clark884dd7d2017-10-11 10:37:52 -0400715#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400716
Cary Clark61313f32018-10-08 14:57:48 -0400717#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500718#Line # returns true if members are unequal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400719Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
Cary Clark7fc1d122017-10-09 14:07:42 -0400720equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400721
Cary Clark7fc1d122017-10-09 14:07:42 -0400722a and b are not equal if either contain NaN. a and b are equal if members
723contain zeroes width different signs.
724
725#Param a Rect to compare ##
726#Param b Rect to compare ##
727
728#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400729
730#Example
Cary Clark154beea2017-10-26 07:58:48 -0400731 SkRect test = {0, 0, 2, SK_ScalarNaN};
732 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
733#StdOut
Cary Clark682c58d2018-05-16 07:07:07 -0400734test with NaN is not equal to itself
Cary Clark7fc1d122017-10-09 14:07:42 -0400735##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400736##
737
Cary Clark7fc1d122017-10-09 14:07:42 -0400738#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400739
740##
741
Cary Clark61313f32018-10-08 14:57:48 -0400742#Subtopic Operators ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500743
744#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500745#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500746
Cary Clarkbc5697d2017-10-04 14:31:33 -0400747# ------------------------------------------------------------------------------
748
749#Method void toQuad(SkPoint quad[4]) const
750
Cary Clarkab2621d2018-01-30 10:08:57 -0500751#In As_Points
752#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400753Returns four points in quad that enclose Rect ordered as: top-left, top-right,
Cary Clark682c58d2018-05-16 07:07:07 -0400754bottom-right, bottom-left.
Cary Clark7fc1d122017-10-09 14:07:42 -0400755
756#Private
Cary Clark682c58d2018-05-16 07:07:07 -0400757Consider adding param to control whether quad is clockwise or counterclockwise.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400758##
759
Cary Clark7fc1d122017-10-09 14:07:42 -0400760#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400761
762#Example
Cary Clark154beea2017-10-26 07:58:48 -0400763 SkRect rect = {1, 2, 3, 4};
764 SkPoint corners[4];
765 rect.toQuad(corners);
766 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
767 SkDebugf("corners:");
768 for (auto corner : corners) {
769 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
770 }
771 SkDebugf("\n");
772#StdOut
773rect: {1, 2, 3, 4}
Cary Clark682c58d2018-05-16 07:07:07 -0400774corners: {1, 2} {3, 2} {3, 4} {1, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400775##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400776##
777
Cary Clark7fc1d122017-10-09 14:07:42 -0400778#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400779
780##
781
782# ------------------------------------------------------------------------------
783
Cary Clark2dc84ad2018-01-26 12:56:22 -0500784#Method void setBounds(const SkPoint pts[], int count)
785
Cary Clarkab2621d2018-01-30 10:08:57 -0500786#In As_Points
787#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500788Sets to bounds of Point array with count entries. If count is zero or smaller,
789or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
790
791Result is either empty or sorted: fLeft is less than or equal to fRight, and
792fTop is less than or equal to fBottom.
793
794#Param pts Point array ##
795#Param count entries in array ##
796
797#Example
798 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
799 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
800 SkRect rect;
801 rect.setBounds(points, count);
802 if (count > 0) {
803 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
804 } else {
805 SkDebugf("%14s", " ");
806 }
807 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
808 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
809 }
810#StdOut
811 count: 0 rect: 0, 0, 0, 0
812added: 3, 4 count: 1 rect: 3, 4, 3, 4
813added: 1, 2 count: 2 rect: 1, 2, 3, 4
814added: 5, 6 count: 3 rect: 1, 2, 5, 6
815added: nan, 8 count: 4 rect: 0, 0, 0, 0
816##
817##
818
819#SeeAlso set setBoundsCheck SkPath::addPoly
820
821##
822
823# ------------------------------------------------------------------------------
824
825#Method bool setBoundsCheck(const SkPoint pts[], int count)
826
Cary Clarkab2621d2018-01-30 10:08:57 -0500827#In As_Points
828#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500829Sets to bounds of Point array with count entries. Returns false if count is
830zero or smaller, or if Point array contains an infinity or NaN; in these cases
831sets Rect to (0, 0, 0, 0).
832
833Result is either empty or sorted: fLeft is less than or equal to fRight, and
834fTop is less than or equal to fBottom.
835
836#Param pts Point array ##
837#Param count entries in array ##
838
839#Return true if all Point values are finite ##
840
841#Example
842 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
843 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
844 SkRect rect;
845 bool success = rect.setBoundsCheck(points, count);
846 if (count > 0) {
847 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
848 } else {
849 SkDebugf("%14s", " ");
850 }
851 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
852 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
853 }
854#StdOut
855 count: 0 rect: 0, 0, 0, 0 success: true
856added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
857added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
858added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
859added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
860##
861##
862
863#SeeAlso set setBounds SkPath::addPoly
864
865##
866
867#Subtopic As_Points ##
868
869#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500870#Line # replaces all values ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500871
872# ------------------------------------------------------------------------------
873
Cary Clarkc06754b2018-05-16 21:28:55 -0400874#Method void setBoundsNoCheck(const SkPoint pts[], int count)
875#In Set
876#Line # sets to upper and lower limits of Point array ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400877Sets to bounds of Point pts array with count entries. If any Point in pts
Cary Clark8f288d92018-05-17 15:16:57 -0400878contains infinity or NaN, all Rect dimensions are set to NaN.
Cary Clarkc06754b2018-05-16 21:28:55 -0400879
880#Param pts Point array ##
881#Param count entries in array ##
882
883#Example
Cary Clark8f288d92018-05-17 15:16:57 -0400884 SkPoint points[] = {{3, 4}, {1, 2}, {SK_ScalarInfinity, 6}, {SK_ScalarNaN, 8}};
Cary Clarkffb3d682018-05-17 12:17:28 -0400885 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
886 SkRect rect;
887 rect.setBoundsNoCheck(points, count);
888 if (count > 0) {
889 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
890 } else {
891 SkDebugf("%14s", " ");
892 }
893 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
894 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
895 }
Cary Clarkc06754b2018-05-16 21:28:55 -0400896##
897
898#SeeAlso setBoundsCheck
899#Method ##
900
901# ------------------------------------------------------------------------------
902
Cary Clarkbc5697d2017-10-04 14:31:33 -0400903#Method void setEmpty()
904
Cary Clarkab2621d2018-01-30 10:08:57 -0500905#In Set
906#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400907Sets Rect to (0, 0, 0, 0).
908
909Many other rectangles are empty; if left is equal to or greater than right,
910or if top is equal to or greater than bottom. Setting all members to zero
911is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400912
913#Example
Cary Clark154beea2017-10-26 07:58:48 -0400914 SkRect rect = {3, 4, 1, 2};
915 for (int i = 0; i < 2; ++i) {
916 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
917 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
918 rect.setEmpty();
919 }
920#StdOut
921rect: {3, 4, 1, 2} is empty
922rect: {0, 0, 0, 0} is empty
923##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400924##
925
Cary Clark7fc1d122017-10-09 14:07:42 -0400926#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400927
928##
929
930# ------------------------------------------------------------------------------
931
932#Method void set(const SkIRect& src)
933
Cary Clarkab2621d2018-01-30 10:08:57 -0500934#In Set
935#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400936Sets Rect to src, promoting src members from integer to Scalar.
Cary Clark682c58d2018-05-16 07:07:07 -0400937Very large values in src may lose precision.
Cary Clark7fc1d122017-10-09 14:07:42 -0400938
939#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400940
941#Example
Cary Clark154beea2017-10-26 07:58:48 -0400942 SkIRect i_rect = {3, 4, 1, 2};
943 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
944 SkRect f_rect;
945 f_rect.set(i_rect);
946 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
947#StdOut
948i_rect: {3, 4, 1, 2}
949f_rect: {3, 4, 1, 2}
950##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400951##
952
Cary Clark7fc1d122017-10-09 14:07:42 -0400953#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400954
955##
956
957# ------------------------------------------------------------------------------
958
959#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
960
Cary Clarkab2621d2018-01-30 10:08:57 -0500961#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400962Sets Rect to (left, top, right, bottom).
963left and right are not sorted; left is not necessarily less than right.
964top and bottom are not sorted; top is not necessarily less than bottom.
965
966#Param left stored in fLeft ##
967#Param top stored in fTop ##
968#Param right stored in fRight ##
969#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400970
971#Example
Cary Clark154beea2017-10-26 07:58:48 -0400972 SkRect rect1 = {3, 4, 1, 2};
973 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
974 SkRect rect2;
975 rect2.set(3, 4, 1, 2);
976 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
977#StdOut
978rect1: {3, 4, 1, 2}
979rect2: {3, 4, 1, 2}
980##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400981##
982
Cary Clark7fc1d122017-10-09 14:07:42 -0400983#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400984
985##
986
987# ------------------------------------------------------------------------------
988
989#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
990
Cary Clarkab2621d2018-01-30 10:08:57 -0500991#In Set
992#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400993Sets Rect to (left, top, right, bottom).
994left and right are not sorted; left is not necessarily less than right.
995top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400996
Cary Clark7fc1d122017-10-09 14:07:42 -0400997#Param left stored in fLeft ##
998#Param top stored in fTop ##
999#Param right stored in fRight ##
1000#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001001
1002#Example
Cary Clark154beea2017-10-26 07:58:48 -04001003 SkRect rect1 = {3, 4, 1, 2};
1004 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1005 SkRect rect2;
1006 rect2.setLTRB(3, 4, 1, 2);
1007 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1008#StdOut
1009rect1: {3, 4, 1, 2}
1010rect2: {3, 4, 1, 2}
1011##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001012##
1013
Cary Clark7fc1d122017-10-09 14:07:42 -04001014#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001015
1016##
1017
1018# ------------------------------------------------------------------------------
1019
Cary Clarkbc5697d2017-10-04 14:31:33 -04001020#Method void set(const SkPoint pts[], int count)
1021
Cary Clarkab2621d2018-01-30 10:08:57 -05001022#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001023Sets to bounds of Point array with count entries. If count is zero or smaller,
1024or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001025
Cary Clark7fc1d122017-10-09 14:07:42 -04001026Result is either empty or sorted: fLeft is less than or equal to fRight, and
1027fTop is less than or equal to fBottom.
1028
1029#Param pts Point array ##
1030#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001031
1032#Example
Cary Clark154beea2017-10-26 07:58:48 -04001033 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1034 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1035 SkRect rect;
1036 rect.set(points, count);
1037 if (count > 0) {
1038 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1039 } else {
1040 SkDebugf("%14s", " ");
1041 }
1042 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1043 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1044 }
1045#StdOut
1046 count: 0 rect: 0, 0, 0, 0
1047added: 3, 4 count: 1 rect: 3, 4, 3, 4
1048added: 1, 2 count: 2 rect: 1, 2, 3, 4
1049added: 5, 6 count: 3 rect: 1, 2, 5, 6
1050added: nan, 8 count: 4 rect: 0, 0, 0, 0
1051##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001052##
1053
Cary Clark7fc1d122017-10-09 14:07:42 -04001054#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001055
1056##
1057
1058# ------------------------------------------------------------------------------
1059
Cary Clarkbc5697d2017-10-04 14:31:33 -04001060#Method void set(const SkPoint& p0, const SkPoint& p1)
1061
Cary Clarkab2621d2018-01-30 10:08:57 -05001062#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001063Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1064sorted and may be empty. Does not check to see if values are finite.
1065
1066#Param p0 corner to include ##
1067#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001068
1069#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001070#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001071p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -04001072##
Cary Clark154beea2017-10-26 07:58:48 -04001073 SkPoint point1 = {SK_ScalarNaN, 8};
1074 SkPoint point2 = {3, 4};
1075 SkRect rect;
1076 rect.set(point1, point2);
1077 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1078 rect.set(point2, point1);
1079 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001080##
1081
Cary Clark7fc1d122017-10-09 14:07:42 -04001082#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001083
1084##
1085
1086# ------------------------------------------------------------------------------
1087
1088#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1089
Cary Clarkab2621d2018-01-30 10:08:57 -05001090#In Set
1091#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001092Sets Rect to #Formula # (x, y, x + width, y + height) ##.
1093Does not validate input; width or height may be negative.
Cary Clark7fc1d122017-10-09 14:07:42 -04001094
1095#Param x stored in fLeft ##
1096#Param y stored in fTop ##
1097#Param width added to x and stored in fRight ##
1098#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001099
1100#Example
Cary Clark154beea2017-10-26 07:58:48 -04001101 SkRect rect;
1102 rect.setXYWH(5, 35, -15, 25);
1103 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1104 rect.bottom(), rect.isEmpty() ? "true" : "false");
1105 rect.sort();
1106 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1107 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001108#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001109rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001110rect: -10, 35, 5, 60 isEmpty: false
1111##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001112##
1113
Cary Clark7fc1d122017-10-09 14:07:42 -04001114#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001115
1116##
1117
1118# ------------------------------------------------------------------------------
1119
1120#Method void setWH(SkScalar width, SkScalar height)
1121
Cary Clarkab2621d2018-01-30 10:08:57 -05001122#In Set
1123#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001124Sets Rect to (0, 0, width, height). Does not validate input;
1125width or height may be negative.
1126
1127#Param width stored in fRight ##
1128#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001129
1130#Example
Cary Clark154beea2017-10-26 07:58:48 -04001131 SkRect rect;
1132 rect.setWH(-15, 25);
1133 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1134 rect.bottom(), rect.isEmpty() ? "true" : "false");
1135 rect.sort();
1136 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1137 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001138#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001139rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001140rect: -15, 0, 0, 25 isEmpty: false
1141##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001142##
1143
Cary Clark7fc1d122017-10-09 14:07:42 -04001144#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001145
1146##
1147
Cary Clark2dc84ad2018-01-26 12:56:22 -05001148#Subtopic Set ##
1149
1150#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -04001151#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001152
Cary Clark2dc84ad2018-01-26 12:56:22 -05001153# ------------------------------------------------------------------------------
1154
1155#Method void iset(int left, int top, int right, int bottom)
1156
Cary Clarkab2621d2018-01-30 10:08:57 -05001157#In From_Integers
1158#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001159Sets Rect to (left, top, right, bottom).
1160All parameters are promoted from integer to Scalar.
1161left and right are not sorted; left is not necessarily less than right.
1162top and bottom are not sorted; top is not necessarily less than bottom.
1163
1164#Param left promoted to SkScalar and stored in fLeft ##
1165#Param top promoted to SkScalar and stored in fTop ##
1166#Param right promoted to SkScalar and stored in fRight ##
1167#Param bottom promoted to SkScalar and stored in fBottom ##
1168
1169#Example
1170 SkRect rect1 = {3, 4, 1, 2};
1171 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1172 SkRect rect2;
1173 rect2.iset(3, 4, 1, 2);
1174 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1175#StdOut
1176rect1: {3, 4, 1, 2}
1177rect2: {3, 4, 1, 2}
1178##
1179##
1180
1181#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1182
1183##
1184
1185# ------------------------------------------------------------------------------
1186
1187#Method void isetWH(int width, int height)
1188
Cary Clarkab2621d2018-01-30 10:08:57 -05001189#In From_Integers
1190#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001191Sets Rect to (0, 0, width, height).
1192width and height may be zero or negative. width and height are promoted from
1193integer to SkScalar, large values may lose precision.
1194
1195#Param width promoted to SkScalar and stored in fRight ##
1196#Param height promoted to SkScalar and stored in fBottom ##
1197
1198#Example
1199 SkRect rect1 = {0, 0, 1, 2};
1200 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1201 SkRect rect2;
1202 rect2.isetWH(1, 2);
1203 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1204#StdOut
1205rect1: {0, 0, 1, 2}
1206rect2: {0, 0, 1, 2}
1207##
1208##
1209
1210#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1211
1212##
1213
1214#Subtopic From_Integers ##
1215
1216#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001217#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001218
Cary Clarkbc5697d2017-10-04 14:31:33 -04001219# ------------------------------------------------------------------------------
1220
Cary Clarkbc5697d2017-10-04 14:31:33 -04001221#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1222
Cary Clarkab2621d2018-01-30 10:08:57 -05001223#In Inset_Outset_Offset
1224#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001225Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001226
Cary Clark7fc1d122017-10-09 14:07:42 -04001227If dx is negative, Rect returned is moved to the left.
1228If dx is positive, Rect returned is moved to the right.
1229If dy is negative, Rect returned is moved upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001230If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001231
Cary Clark7fc1d122017-10-09 14:07:42 -04001232#Param dx added to fLeft and fRight ##
1233#Param dy added to fTop and fBottom ##
1234
Cary Clark5538c132018-06-14 12:28:14 -04001235#Return Rect offset on axes, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001236
1237#Example
Cary Clark154beea2017-10-26 07:58:48 -04001238 SkRect rect = { 10, 50, 20, 60 };
1239 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1240 rect.bottom(), rect.isEmpty() ? "true" : "false");
1241 rect = rect.makeOffset(15, 32);
1242 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1243 rect.bottom(), rect.isEmpty() ? "true" : "false");
1244#StdOut
1245rect: 10, 50, 20, 60 isEmpty: false
1246rect: 25, 82, 35, 92 isEmpty: false
1247##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001248##
1249
Cary Clark7fc1d122017-10-09 14:07:42 -04001250#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001251
1252##
1253
1254# ------------------------------------------------------------------------------
1255
1256#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1257
Cary Clarkab2621d2018-01-30 10:08:57 -05001258#In Inset_Outset_Offset
1259#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001260Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001261
Cary Clark7fc1d122017-10-09 14:07:42 -04001262If dx is negative, Rect returned is wider.
1263If dx is positive, Rect returned is narrower.
1264If dy is negative, Rect returned is taller.
Cary Clark682c58d2018-05-16 07:07:07 -04001265If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001266
Cary Clark7fc1d122017-10-09 14:07:42 -04001267#Param dx added to fLeft and subtracted from fRight ##
1268#Param dy added to fTop and subtracted from fBottom ##
1269
1270#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001271
1272#Example
Cary Clark154beea2017-10-26 07:58:48 -04001273 SkRect rect = { 10, 50, 20, 60 };
1274 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1275 rect.bottom(), rect.isEmpty() ? "true" : "false");
1276 rect = rect.makeInset(15, 32);
1277 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1278 rect.bottom(), rect.isEmpty() ? "true" : "false");
1279#StdOut
1280rect: 10, 50, 20, 60 isEmpty: false
1281rect: 25, 82, 5, 28 isEmpty: true
1282##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001283##
1284
Cary Clark7fc1d122017-10-09 14:07:42 -04001285#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001286
1287##
1288
1289# ------------------------------------------------------------------------------
1290
1291#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1292
Cary Clarkab2621d2018-01-30 10:08:57 -05001293#In Inset_Outset_Offset
1294#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001295Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001296
Cary Clark7fc1d122017-10-09 14:07:42 -04001297If dx is negative, Rect returned is narrower.
1298If dx is positive, Rect returned is wider.
1299If dy is negative, Rect returned is shorter.
Cary Clark682c58d2018-05-16 07:07:07 -04001300If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001301
Cary Clark7fc1d122017-10-09 14:07:42 -04001302#Param dx subtracted to fLeft and added from fRight ##
1303#Param dy subtracted to fTop and added from fBottom ##
1304
1305#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001306
1307#Example
Cary Clark154beea2017-10-26 07:58:48 -04001308 SkRect rect = { 10, 50, 20, 60 };
1309 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1310 rect.bottom(), rect.isEmpty() ? "true" : "false");
1311 rect = rect.makeOutset(15, 32);
1312 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1313 rect.bottom(), rect.isEmpty() ? "true" : "false");
1314#StdOut
1315rect: 10, 50, 20, 60 isEmpty: false
1316rect: -5, 18, 35, 92 isEmpty: false
1317##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001318##
1319
Cary Clark7fc1d122017-10-09 14:07:42 -04001320#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001321
1322##
1323
1324# ------------------------------------------------------------------------------
1325
1326#Method void offset(SkScalar dx, SkScalar dy)
1327
Cary Clarkab2621d2018-01-30 10:08:57 -05001328#In Inset_Outset_Offset
1329#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001330Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001331
Cary Clark7fc1d122017-10-09 14:07:42 -04001332If dx is negative, moves Rect to the left.
1333If dx is positive, moves Rect to the right.
1334If dy is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001335If dy is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001336
1337#Param dx offset added to fLeft and fRight ##
1338#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001339
1340#Example
Cary Clark154beea2017-10-26 07:58:48 -04001341 SkRect rect = { 10, 14, 50, 73 };
1342 rect.offset(5, 13);
1343 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1344#StdOut
1345rect: 15, 27, 55, 86
1346##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001347##
1348
Cary Clark7fc1d122017-10-09 14:07:42 -04001349#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001350
1351##
1352
1353# ------------------------------------------------------------------------------
1354
1355#Method void offset(const SkPoint& delta)
1356
Cary Clarkab2621d2018-01-30 10:08:57 -05001357#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001358Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1359fTop, fBottom.
1360
1361If delta.fX is negative, moves Rect to the left.
1362If delta.fX is positive, moves Rect to the right.
1363If delta.fY is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001364If delta.fY is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001365
1366#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001367
1368#Example
Cary Clark154beea2017-10-26 07:58:48 -04001369 SkRect rect = { 10, 14, 50, 73 };
1370 rect.offset({5, 13});
1371 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1372#StdOut
1373rect: 15, 27, 55, 86
1374##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001375##
1376
Cary Clark7fc1d122017-10-09 14:07:42 -04001377#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001378
1379##
1380
1381# ------------------------------------------------------------------------------
1382
1383#Method void offsetTo(SkScalar newX, SkScalar newY)
1384
Cary Clarkab2621d2018-01-30 10:08:57 -05001385#In Inset_Outset_Offset
1386#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001387Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1388are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001389
Cary Clark7fc1d122017-10-09 14:07:42 -04001390#Param newX stored in fLeft, preserving width() ##
1391#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001392
1393#Example
Cary Clark154beea2017-10-26 07:58:48 -04001394 SkRect rect = { 10, 14, 50, 73 };
1395 rect.offsetTo(15, 27);
1396 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1397#StdOut
1398rect: 15, 27, 55, 86
1399##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001400##
1401
Cary Clark7fc1d122017-10-09 14:07:42 -04001402#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001403
1404##
1405
1406# ------------------------------------------------------------------------------
1407
1408#Method void inset(SkScalar dx, SkScalar dy)
1409
Cary Clarkab2621d2018-01-30 10:08:57 -05001410#In Inset_Outset_Offset
1411#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001412Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001413
Cary Clark7fc1d122017-10-09 14:07:42 -04001414If dx is positive, makes Rect narrower.
1415If dx is negative, makes Rect wider.
1416If dy is positive, makes Rect shorter.
1417If dy is negative, makes Rect taller.
1418
1419#Param dx added to fLeft and subtracted from fRight ##
1420#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001421
1422#Example
Cary Clark154beea2017-10-26 07:58:48 -04001423 SkRect rect = { 10, 14, 50, 73 };
1424 rect.inset(5, 13);
1425 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1426#StdOut
1427rect: 15, 27, 45, 60
1428##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001429##
1430
Cary Clark7fc1d122017-10-09 14:07:42 -04001431#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001432
1433##
1434
1435# ------------------------------------------------------------------------------
1436
1437#Method void outset(SkScalar dx, SkScalar dy)
1438
Cary Clarkab2621d2018-01-30 10:08:57 -05001439#In Inset_Outset_Offset
1440#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001441Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001442
Cary Clark7fc1d122017-10-09 14:07:42 -04001443If dx is positive, makes Rect wider.
1444If dx is negative, makes Rect narrower.
1445If dy is positive, makes Rect taller.
1446If dy is negative, makes Rect shorter.
1447
1448#Param dx subtracted to fLeft and added from fRight ##
1449#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001450
1451#Example
Cary Clark154beea2017-10-26 07:58:48 -04001452 SkRect rect = { 10, 14, 50, 73 };
1453 rect.outset(5, 13);
1454 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1455#StdOut
1456rect: 5, 1, 55, 86
1457##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001458##
1459
Cary Clark7fc1d122017-10-09 14:07:42 -04001460#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001461
1462##
1463
Cary Clark2dc84ad2018-01-26 12:56:22 -05001464#Subtopic Inset_Outset_Offset ##
1465
1466#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001467#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001468
Cary Clark682c58d2018-05-16 07:07:07 -04001469Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001470must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001471empty() returns false. The intersection of Rect pair can be described by:
Cary Clark2be81cf2018-09-13 12:04:30 -04001472#Formula # (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1473 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) ##.
Cary Clark154beea2017-10-26 07:58:48 -04001474
Cary Clark7fc1d122017-10-09 14:07:42 -04001475The intersection is only meaningful if the resulting Rect is not empty and
1476describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1477
Cary Clark2dc84ad2018-01-26 12:56:22 -05001478# ------------------------------------------------------------------------------
1479
Florin Malitaeb420452018-02-20 11:44:43 -05001480#Method bool contains(SkScalar x, SkScalar y) const
1481
1482#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001483#Line # returns true if points are equal or inside ##
Florin Malitaeb420452018-02-20 11:44:43 -05001484Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
1485Returns false if SkRect is empty.
1486
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001487#Param x test Point x-coordinate ##
1488#Param y test Point y-coordinate ##
Florin Malitaeb420452018-02-20 11:44:43 -05001489
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001490#Return true if (x, y) is inside Rect ##
Florin Malitaeb420452018-02-20 11:44:43 -05001491
1492#Example
1493 SkRect rect = { 30, 50, 40, 60 };
1494 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1495 for (auto contained : tests) {
1496 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1497 rect.left(), rect.top(), rect.right(), rect.bottom(),
1498 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1499 contained.x(), contained.y());
1500 }
1501#StdOut
1502rect: (30, 50, 40, 60) contains (30, 50)
1503rect: (30, 50, 40, 60) does not contain (39, 49)
1504rect: (30, 50, 40, 60) does not contain (29, 59)
1505##
1506##
1507
Cary Clark53498e92018-06-28 19:13:56 -04001508#SeeAlso SkIRect::contains SkRRect::contains
Florin Malitaeb420452018-02-20 11:44:43 -05001509
1510##
1511
1512# ------------------------------------------------------------------------------
1513
Cary Clark2dc84ad2018-01-26 12:56:22 -05001514#Method bool contains(const SkRect& r) const
1515
Cary Clarkab2621d2018-01-30 10:08:57 -05001516#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001517Returns true if Rect contains r.
1518Returns false if Rect is empty or r is empty.
1519
1520Rect contains r when Rect area completely includes r area.
1521
1522#Param r Rect contained ##
1523
1524#Return true if all sides of Rect are outside r ##
1525
1526#Example
1527 SkRect rect = { 30, 50, 40, 60 };
1528 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1529 for (auto contained : tests) {
1530 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1531 rect.left(), rect.top(), rect.right(), rect.bottom(),
1532 rect.contains(contained) ? "contains" : "does not contain",
1533 contained.left(), contained.top(), contained.right(), contained.bottom());
1534 }
1535#StdOut
1536rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1537rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1538rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1539##
1540##
1541
1542#SeeAlso SkIRect::contains
1543
1544##
1545
1546# ------------------------------------------------------------------------------
1547
1548#Method bool contains(const SkIRect& r) const
1549
Cary Clarkab2621d2018-01-30 10:08:57 -05001550#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001551Returns true if Rect contains r.
1552Returns false if Rect is empty or r is empty.
1553
1554Rect contains r when Rect area completely includes r area.
1555
1556#Param r IRect contained ##
1557
1558#Return true if all sides of Rect are outside r ##
1559
1560#Example
1561 SkRect rect = { 30, 50, 40, 60 };
1562 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1563 for (auto contained : tests) {
1564 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1565 rect.left(), rect.top(), rect.right(), rect.bottom(),
1566 rect.contains(contained) ? "contains" : "does not contain",
1567 contained.left(), contained.top(), contained.right(), contained.bottom());
1568 }
1569#StdOut
1570rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1571rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1572rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1573##
1574##
1575
1576#SeeAlso SkIRect::contains
1577
1578##
1579
Cary Clarkbc5697d2017-10-04 14:31:33 -04001580# ------------------------------------------------------------------------------
1581
1582#Method bool intersect(const SkRect& r)
1583
Cary Clarkab2621d2018-01-30 10:08:57 -05001584#In Intersection
1585#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001586Returns true if Rect intersects r, and sets Rect to intersection.
1587Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001588
Cary Clark7fc1d122017-10-09 14:07:42 -04001589Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001590
Cary Clark7fc1d122017-10-09 14:07:42 -04001591#Param r limit of result ##
1592
1593#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001594
1595#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001596#Description
1597Two SkDebugf calls are required. If the calls are combined, their arguments
1598may not be evaluated in left to right order: the printed intersection may
1599be before or after the call to intersect.
1600##
Cary Clark154beea2017-10-26 07:58:48 -04001601 SkRect leftRect = { 10, 40, 50, 80 };
1602 SkRect rightRect = { 30, 60, 70, 90 };
1603 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001604 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001605 leftRect.right(), leftRect.bottom());
1606#StdOut
1607 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001608##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001609##
1610
Cary Clark7fc1d122017-10-09 14:07:42 -04001611#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001612
1613##
1614
1615# ------------------------------------------------------------------------------
1616
1617#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1618
Cary Clarkab2621d2018-01-30 10:08:57 -05001619#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001620Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1621construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001622
Cary Clark7fc1d122017-10-09 14:07:42 -04001623Returns true if Rect intersects construction, and sets Rect to intersection.
1624Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001625
Cary Clark7fc1d122017-10-09 14:07:42 -04001626Returns false if either construction or Rect is empty, leaving Rect unchanged.
1627
Cary Clark5538c132018-06-14 12:28:14 -04001628#Param left x-axis minimum of constructed Rect ##
1629#Param top y-axis minimum of constructed Rect ##
1630#Param right x-axis maximum of constructed Rect ##
1631#Param bottom y-axis maximum of constructed Rect ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001632
1633#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001634
1635#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001636#Description
1637Two SkDebugf calls are required. If the calls are combined, their arguments
1638may not be evaluated in left to right order: the printed intersection may
1639be before or after the call to intersect.
1640##
Cary Clark154beea2017-10-26 07:58:48 -04001641 SkRect leftRect = { 10, 40, 50, 80 };
1642 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001643 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001644 leftRect.right(), leftRect.bottom());
1645#StdOut
1646 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001647##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001648##
1649
Cary Clark7fc1d122017-10-09 14:07:42 -04001650#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001651
1652##
1653
1654# ------------------------------------------------------------------------------
1655
Cary Clark61313f32018-10-08 14:57:48 -04001656#Method bool intersect(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04001657
Cary Clarkab2621d2018-01-30 10:08:57 -05001658#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001659Returns true if a intersects b, and sets Rect to intersection.
1660Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001661
Cary Clark7fc1d122017-10-09 14:07:42 -04001662Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001663
Cary Clark7fc1d122017-10-09 14:07:42 -04001664#Param a Rect to intersect ##
1665#Param b Rect to intersect ##
1666
1667#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001668
1669#Example
Cary Clark154beea2017-10-26 07:58:48 -04001670 SkRect result;
1671 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1672 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1673 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001674#StdOut
1675 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001676##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001677##
1678
Cary Clark7fc1d122017-10-09 14:07:42 -04001679#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001680
1681##
1682
Cary Clark7fc1d122017-10-09 14:07:42 -04001683# ------------------------------------------------------------------------------
1684
Cary Clarkbc5697d2017-10-04 14:31:33 -04001685#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1686
Cary Clarkab2621d2018-01-30 10:08:57 -05001687#In Intersection
1688#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001689Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1690construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001691
Cary Clark7fc1d122017-10-09 14:07:42 -04001692Returns true if Rect intersects construction.
1693Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001694
Cary Clark5538c132018-06-14 12:28:14 -04001695#Param left x-axis minimum of constructed Rect ##
1696#Param top y-axis minimum of constructed Rect ##
1697#Param right x-axis maximum of constructed Rect ##
1698#Param bottom y-axis maximum of constructed Rect ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001699
1700#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001701
1702#Example
Cary Clark154beea2017-10-26 07:58:48 -04001703 SkRect rect = { 10, 40, 50, 80 };
1704 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001705#StdOut
1706 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001707##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001708##
1709
Cary Clark7fc1d122017-10-09 14:07:42 -04001710#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001711
1712##
1713
Cary Clark7fc1d122017-10-09 14:07:42 -04001714# ------------------------------------------------------------------------------
1715
Cary Clarkbc5697d2017-10-04 14:31:33 -04001716#Method bool intersects(const SkRect& r) const
1717
Cary Clarkab2621d2018-01-30 10:08:57 -05001718#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001719Returns true if Rect intersects r.
1720Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001721
Cary Clark7fc1d122017-10-09 14:07:42 -04001722#Param r Rect to intersect ##
1723
1724#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001725
1726#Example
Cary Clark154beea2017-10-26 07:58:48 -04001727 SkRect rect = { 10, 40, 50, 80 };
1728 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001729#StdOut
1730 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001731##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001732##
1733
Cary Clark7fc1d122017-10-09 14:07:42 -04001734#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001735
1736##
1737
Cary Clark7fc1d122017-10-09 14:07:42 -04001738# ------------------------------------------------------------------------------
1739
Cary Clarkbc5697d2017-10-04 14:31:33 -04001740#Method static bool Intersects(const SkRect& a, const SkRect& b)
1741
Cary Clarkab2621d2018-01-30 10:08:57 -05001742#In Intersection
1743#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001744Returns true if a intersects b.
1745Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746
Cary Clark7fc1d122017-10-09 14:07:42 -04001747#Param a Rect to intersect ##
1748#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001749
Cary Clark7fc1d122017-10-09 14:07:42 -04001750#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001751
1752#Example
Cary Clark154beea2017-10-26 07:58:48 -04001753 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001754#StdOut
1755 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001756##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001757##
1758
Cary Clark7fc1d122017-10-09 14:07:42 -04001759#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001760
1761##
1762
Cary Clark2dc84ad2018-01-26 12:56:22 -05001763#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001764
Cary Clark2dc84ad2018-01-26 12:56:22 -05001765#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001766#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001767
Cary Clark7fc1d122017-10-09 14:07:42 -04001768# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769
1770#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1771
Cary Clarkab2621d2018-01-30 10:08:57 -05001772#In Join
1773#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001774Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1775construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001776
Cary Clark7fc1d122017-10-09 14:07:42 -04001777Sets Rect to the union of itself and the construction.
1778
1779Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1780Rect to construction.
1781
Cary Clark5538c132018-06-14 12:28:14 -04001782#Param left x-axis minimum of constructed Rect ##
1783#Param top y-axis minimum of constructed Rect ##
1784#Param right x-axis maximum of constructed Rect ##
1785#Param bottom y-axis maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001786
1787#Example
Cary Clark154beea2017-10-26 07:58:48 -04001788 SkRect rect = { 10, 20, 15, 25};
1789 rect.join(50, 60, 55, 65);
1790 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001791#StdOut
1792 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001793##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001794##
1795
Cary Clark7fc1d122017-10-09 14:07:42 -04001796#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001797
1798##
1799
Cary Clark7fc1d122017-10-09 14:07:42 -04001800# ------------------------------------------------------------------------------
1801
Cary Clarkbc5697d2017-10-04 14:31:33 -04001802#Method void join(const SkRect& r)
1803
Cary Clarkab2621d2018-01-30 10:08:57 -05001804#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001805Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001806
Cary Clark7fc1d122017-10-09 14:07:42 -04001807Has no effect if r is empty. Otherwise, if Rect is empty, sets
1808Rect to r.
1809
1810#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001811
1812#Example
Cary Clark154beea2017-10-26 07:58:48 -04001813 SkRect rect = { 10, 20, 15, 25};
1814 rect.join({50, 60, 55, 65});
1815 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001816#StdOut
1817 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001818##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001819##
1820
Cary Clark7fc1d122017-10-09 14:07:42 -04001821#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001822
1823##
1824
Cary Clark7fc1d122017-10-09 14:07:42 -04001825# ------------------------------------------------------------------------------
1826
Cary Clarkbc5697d2017-10-04 14:31:33 -04001827#Method void joinNonEmptyArg(const SkRect& r)
1828
Cary Clarkab2621d2018-01-30 10:08:57 -05001829#In Join
1830#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001831Sets Rect to the union of itself and r.
1832
1833Asserts if r is empty and SK_DEBUG is defined.
1834If Rect is empty, sets Rect to r.
1835
1836May produce incorrect results if r is empty.
1837
1838#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001839
1840#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001841#Description
1842Since Rect is not sorted, first result is copy of toJoin.
1843##
Cary Clark154beea2017-10-26 07:58:48 -04001844 SkRect rect = { 10, 100, 15, 0};
1845 SkRect sorted = rect.makeSorted();
1846 SkRect toJoin = { 50, 60, 55, 65 };
1847 rect.joinNonEmptyArg(toJoin);
1848 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1849 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001850 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1851#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001852rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001853sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001854##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001855##
1856
Cary Clark7fc1d122017-10-09 14:07:42 -04001857#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001858
1859##
1860
Cary Clark7fc1d122017-10-09 14:07:42 -04001861# ------------------------------------------------------------------------------
1862
Cary Clarkbc5697d2017-10-04 14:31:33 -04001863#Method void joinPossiblyEmptyRect(const SkRect& r)
1864
Cary Clarkab2621d2018-01-30 10:08:57 -05001865#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001866#Line # sets to union of bounds; skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001867Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001868
Cary Clark7fc1d122017-10-09 14:07:42 -04001869May produce incorrect results if Rect or r is empty.
1870
1871#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001872
1873#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001874#Description
1875Since Rect is not sorted, first result is not useful.
1876##
Cary Clark154beea2017-10-26 07:58:48 -04001877 SkRect rect = { 10, 100, 15, 0};
1878 SkRect sorted = rect.makeSorted();
1879 SkRect toJoin = { 50, 60, 55, 65 };
1880 rect.joinPossiblyEmptyRect(toJoin);
1881 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1882 sorted.joinPossiblyEmptyRect(toJoin);
1883 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001884#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001885rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001886sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001887##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001888##
1889
Cary Clark7fc1d122017-10-09 14:07:42 -04001890#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001891
1892##
1893
Cary Clark2dc84ad2018-01-26 12:56:22 -05001894#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001895
Cary Clark2dc84ad2018-01-26 12:56:22 -05001896#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001897#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001898
Cary Clarkbc5697d2017-10-04 14:31:33 -04001899#Method void round(SkIRect* dst) const
1900
Cary Clarkab2621d2018-01-30 10:08:57 -05001901#In Rounding
1902#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001903Sets IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04001904members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1905 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001906
Cary Clark7fc1d122017-10-09 14:07:42 -04001907#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001908
1909#Example
Cary Clark154beea2017-10-26 07:58:48 -04001910 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1911 SkIRect round;
1912 rect.round(&round);
1913 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001914#StdOut
1915round: 31, 51, 41, 61
1916##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001917##
1918
Cary Clark7fc1d122017-10-09 14:07:42 -04001919#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001920
1921##
1922
Cary Clark7fc1d122017-10-09 14:07:42 -04001923# ------------------------------------------------------------------------------
1924
Cary Clarkbc5697d2017-10-04 14:31:33 -04001925#Method void roundOut(SkIRect* dst) const
1926
Cary Clarkab2621d2018-01-30 10:08:57 -05001927#In Rounding
1928#Line # sets members to nearest integer value away from opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001929Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
1930up fRight and fBottom, using
1931#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1932 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001933
Cary Clark7fc1d122017-10-09 14:07:42 -04001934#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001935
1936#Example
Cary Clark154beea2017-10-26 07:58:48 -04001937 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1938 SkIRect round;
1939 rect.roundOut(&round);
1940 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001941#StdOut
1942round: 30, 50, 41, 61
1943##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001944##
1945
Cary Clark7fc1d122017-10-09 14:07:42 -04001946#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001947
1948##
1949
Cary Clark7fc1d122017-10-09 14:07:42 -04001950# ------------------------------------------------------------------------------
1951
Cary Clark682c58d2018-05-16 07:07:07 -04001952#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001953
Cary Clarkab2621d2018-01-30 10:08:57 -05001954#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04001955Sets Rect by discarding the fractional portion of fLeft and fTop; and rounding
1956up fRight and fBottom, using
1957#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1958 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001959
Cary Clark7fc1d122017-10-09 14:07:42 -04001960#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001961
1962#Example
Cary Clark154beea2017-10-26 07:58:48 -04001963 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1964 SkRect round;
1965 rect.roundOut(&round);
1966 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001967#StdOut
1968round: 30, 50, 41, 61
1969##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001970##
1971
Cary Clark7fc1d122017-10-09 14:07:42 -04001972#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001973
1974##
1975
Cary Clark7fc1d122017-10-09 14:07:42 -04001976# ------------------------------------------------------------------------------
1977
Cary Clarkbc5697d2017-10-04 14:31:33 -04001978#Method void roundIn(SkIRect* dst) const
1979
Cary Clarkab2621d2018-01-30 10:08:57 -05001980#In Rounding
1981#Line # sets members to nearest integer value towards opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001982Sets Rect by rounding up fLeft and fTop; and discarding the fractional portion
1983of fRight and fBottom, using
1984#Formula # (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1985 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001986
Cary Clark7fc1d122017-10-09 14:07:42 -04001987#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001988
1989#Example
Cary Clark154beea2017-10-26 07:58:48 -04001990 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1991 SkIRect round;
1992 rect.roundIn(&round);
1993 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001994#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001995round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04001996##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001997##
1998
Cary Clark7fc1d122017-10-09 14:07:42 -04001999#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002000
2001##
2002
Cary Clark7fc1d122017-10-09 14:07:42 -04002003# ------------------------------------------------------------------------------
2004
Cary Clarkbc5697d2017-10-04 14:31:33 -04002005#Method SkIRect round() const
2006
Cary Clarkab2621d2018-01-30 10:08:57 -05002007#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002008Returns IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04002009members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2010 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002011
Cary Clark7fc1d122017-10-09 14:07:42 -04002012#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002013
2014#Example
Cary Clark154beea2017-10-26 07:58:48 -04002015 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2016 SkIRect round = rect.round();
2017 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002018#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002019round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002020##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002021##
2022
Cary Clark7fc1d122017-10-09 14:07:42 -04002023#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002024
2025##
2026
Cary Clark7fc1d122017-10-09 14:07:42 -04002027# ------------------------------------------------------------------------------
2028
Cary Clarkbc5697d2017-10-04 14:31:33 -04002029#Method SkIRect roundOut() const
2030
Cary Clarkab2621d2018-01-30 10:08:57 -05002031#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04002032Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
2033up fRight and fBottom, using
2034#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2035 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002036
Cary Clark7fc1d122017-10-09 14:07:42 -04002037#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002038
2039#Example
Cary Clark154beea2017-10-26 07:58:48 -04002040 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2041 SkIRect round = rect.roundOut();
2042 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002043#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002044round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002045##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002046##
2047
Cary Clark7fc1d122017-10-09 14:07:42 -04002048#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002049
2050##
2051
Cary Clark2dc84ad2018-01-26 12:56:22 -05002052#Subtopic Rounding ##
2053
2054#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002055#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002056
Cary Clark7fc1d122017-10-09 14:07:42 -04002057# ------------------------------------------------------------------------------
2058
Cary Clarkbc5697d2017-10-04 14:31:33 -04002059#Method void sort()
2060
Cary Clarkab2621d2018-01-30 10:08:57 -05002061#In Sorting
2062#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002063Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2064fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2065and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002066
2067#Example
Cary Clark154beea2017-10-26 07:58:48 -04002068 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2069 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2070 rect.sort();
2071 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002072#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002073rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002074sorted: 20.5, 10.5, 30.5, 50.5
2075##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002076##
2077
Cary Clark2dc84ad2018-01-26 12:56:22 -05002078#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002079
2080##
2081
Cary Clark7fc1d122017-10-09 14:07:42 -04002082# ------------------------------------------------------------------------------
2083
Cary Clarkbc5697d2017-10-04 14:31:33 -04002084#Method SkRect makeSorted() const
2085
Cary Clarkab2621d2018-01-30 10:08:57 -05002086#In Sorting
Cary Clark61313f32018-10-08 14:57:48 -04002087#In Constructors
Cary Clark682c58d2018-05-16 07:07:07 -04002088#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002089Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2090with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2091and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002092
Cary Clark7fc1d122017-10-09 14:07:42 -04002093#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002094
2095#Example
Cary Clark154beea2017-10-26 07:58:48 -04002096 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2097 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2098 SkRect sort = rect.makeSorted();
2099 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002100#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002101rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002102sorted: 20.5, 10.5, 30.5, 50.5
2103##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104##
2105
Cary Clark2dc84ad2018-01-26 12:56:22 -05002106#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002107
2108##
2109
Cary Clark2dc84ad2018-01-26 12:56:22 -05002110#Subtopic Sorting ##
2111
Cary Clark7fc1d122017-10-09 14:07:42 -04002112# ------------------------------------------------------------------------------
2113
Cary Clarkbc5697d2017-10-04 14:31:33 -04002114#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002115#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002116#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002117Returns pointer to first Scalar in Rect, to treat it as an array with four
2118entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119
Cary Clark7fc1d122017-10-09 14:07:42 -04002120#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002121
2122#Example
Cary Clark154beea2017-10-26 07:58:48 -04002123 SkRect rect = {7, 11, 13, 17};
2124SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2125#StdOut
2126rect.asScalars() == &rect.fLeft
2127##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002128##
2129
Cary Clark7fc1d122017-10-09 14:07:42 -04002130#SeeAlso toQuad
2131
Cary Clarkbc5697d2017-10-04 14:31:33 -04002132##
2133
Cary Clark7fc1d122017-10-09 14:07:42 -04002134# ------------------------------------------------------------------------------
2135
Cary Clarkbc5697d2017-10-04 14:31:33 -04002136#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002137#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002138#Line # sends text representation to standard output using floats ##
Cary Clark682c58d2018-05-16 07:07:07 -04002139Writes text representation of Rect to standard output. Set asHex to true to
Cary Clark7fc1d122017-10-09 14:07:42 -04002140generate exact binary representations of floating point numbers.
2141
2142#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002143
2144#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002145 SkRect rect = {20, 30, 40, 50};
2146 for (bool dumpAsHex : { false, true } ) {
2147 rect.dump(dumpAsHex);
2148 SkDebugf("\n");
2149 }
2150#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002151SkRect::MakeLTRB(20, 30, 40, 50);
2152
2153SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2154 SkBits2Float(0x41f00000), /* 30.000000 */
2155 SkBits2Float(0x42200000), /* 40.000000 */
2156 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002157##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002158##
2159
Cary Clark7fc1d122017-10-09 14:07:42 -04002160#SeeAlso dumpHex
2161
Cary Clarkbc5697d2017-10-04 14:31:33 -04002162##
2163
Cary Clark7fc1d122017-10-09 14:07:42 -04002164# ------------------------------------------------------------------------------
2165
Cary Clarkbc5697d2017-10-04 14:31:33 -04002166#Method void dump() const
2167
Cary Clark7fc1d122017-10-09 14:07:42 -04002168Writes text representation of Rect to standard output. The representation may be
2169directly compiled as C++ code. Floating point values are written
2170with limited precision; it may not be possible to reconstruct original Rect
2171from output.
2172
Cary Clarkbc5697d2017-10-04 14:31:33 -04002173#Example
Cary Clark154beea2017-10-26 07:58:48 -04002174SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2175rect.dump();
2176SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2177SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002178#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002179SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002180rect is not equal to copy
2181##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002182##
2183
Cary Clark7fc1d122017-10-09 14:07:42 -04002184#SeeAlso dumpHex
2185
Cary Clarkbc5697d2017-10-04 14:31:33 -04002186##
2187
Cary Clark7fc1d122017-10-09 14:07:42 -04002188# ------------------------------------------------------------------------------
2189
Cary Clarkbc5697d2017-10-04 14:31:33 -04002190#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002191#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002192#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002193Writes text representation of Rect to standard output. The representation may be
2194directly compiled as C++ code. Floating point values are written
2195in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2196original Rect.
2197
Cary Clark682c58d2018-05-16 07:07:07 -04002198Use instead of dump() when submitting
2199#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002200.
2201
Cary Clarkbc5697d2017-10-04 14:31:33 -04002202#Example
Cary Clark154beea2017-10-26 07:58:48 -04002203 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2204rect.dumpHex();
2205SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2206 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2207 SkBits2Float(0x40266666), /* 2.600000 */
2208 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002209SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2210#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002211SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2212 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2213 SkBits2Float(0x40266666), /* 2.600000 */
2214 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002215rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002216##
Cary Clark7fc1d122017-10-09 14:07:42 -04002217##
2218
2219#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002220
2221##
2222
Cary Clark61313f32018-10-08 14:57:48 -04002223#Method static SkRect MakeLargest()
Cary Clark0c95aab2018-01-08 16:20:59 -05002224#Deprecated
2225##
2226
Cary Clarkbc5697d2017-10-04 14:31:33 -04002227#Struct SkRect ##
2228
2229#Topic Rect ##