blob: 7571937b5d62f73cb81c623b1769e968c6ba08e2 [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
45# ------------------------------------------------------------------------------
46
Cary Clark61313f32018-10-08 14:57:48 -040047#Method static constexpr SkRect MakeEmpty()
Cary Clarkbc5697d2017-10-04 14:31:33 -040048
Cary Clark61313f32018-10-08 14:57:48 -040049#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050050#Line # constructs from bounds of (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040051Returns constructed Rect set to (0, 0, 0, 0).
52Many other rectangles are empty; if left is equal to or greater than right,
53or if top is equal to or greater than bottom. Setting all members to zero
54is a convenience, but does not designate a special empty rectangle.
Cary Clark682c58d2018-05-16 07:07:07 -040055
Cary Clark7fc1d122017-10-09 14:07:42 -040056#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040057
58#Example
Cary Clark154beea2017-10-26 07:58:48 -040059 SkRect rect = SkRect::MakeEmpty();
60 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
61 rect.offset(10, 10);
62 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
63 rect.inset(10, 10);
64 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
65 rect.outset(20, 20);
66 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
67#StdOut
68MakeEmpty isEmpty: true
69offset rect isEmpty: true
70inset rect isEmpty: true
71outset rect isEmpty: false
72##
Cary Clarkbc5697d2017-10-04 14:31:33 -040073##
74
Mike Reed274218e2018-01-08 15:05:02 -050075#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -040076
77##
78
79# ------------------------------------------------------------------------------
80
Cary Clark61313f32018-10-08 14:57:48 -040081#Method static constexpr SkRect MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -040082
Cary Clark61313f32018-10-08 14:57:48 -040083#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050084#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -040085Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
86validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -040087
Cary Clark7fc1d122017-10-09 14:07:42 -040088Passing integer values may generate a compiler warning since Rect cannot
89represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
90
91#Param w SkScalar width of constructed Rect ##
92#Param h SkScalar height of constructed Rect ##
93
94#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040095
96#Example
Cary Clark154beea2017-10-26 07:58:48 -040097 SkRect rect1 = SkRect::MakeWH(25, 35);
98 SkRect rect2 = SkRect::MakeIWH(25, 35);
99 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
100 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
101 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400102 "" : "not ");
103#StdOut
104all equal
105##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400106##
107
Cary Clark7fc1d122017-10-09 14:07:42 -0400108#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400109
110##
111
112# ------------------------------------------------------------------------------
113
Cary Clark61313f32018-10-08 14:57:48 -0400114#Method static SkRect MakeIWH(int w, int h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400115
Cary Clark61313f32018-10-08 14:57:48 -0400116#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500117#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400118Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
119input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400120
Cary Clark7fc1d122017-10-09 14:07:42 -0400121Use to avoid a compiler warning that input may lose precision when stored.
122Use SkIRect for an exact integer rectangle.
123
124#Param w integer width of constructed Rect ##
125#Param h integer height of constructed Rect ##
126
127#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400128
129#Example
Cary Clark154beea2017-10-26 07:58:48 -0400130 SkIRect i_rect = SkIRect::MakeWH(25, 35);
131 SkRect f_rect = SkRect::MakeIWH(25, 35);
132 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
133 i_rect = SkIRect::MakeWH(125000111, 0);
134 f_rect = SkRect::MakeIWH(125000111, 0);
135 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400136#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400137i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400138i_rect width: 125000111 f_rect width:125000112
139##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400140##
141
Cary Clark7fc1d122017-10-09 14:07:42 -0400142#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400143
144##
145
146# ------------------------------------------------------------------------------
147
Cary Clark61313f32018-10-08 14:57:48 -0400148#Method static constexpr SkRect MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400149
Cary Clark61313f32018-10-08 14:57:48 -0400150#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500151#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400152Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
153validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400154
Cary Clark7fc1d122017-10-09 14:07:42 -0400155#Param size SkScalar values for Rect width and height ##
156
157#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400158
159#Example
Cary Clark154beea2017-10-26 07:58:48 -0400160 SkSize size = {25.5f, 35.5f};
161 SkRect rect = SkRect::MakeSize(size);
162 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
163 SkISize floor = size.toFloor();
164 rect = SkRect::MakeSize(SkSize::Make(floor));
165 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400166#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400167rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400168floor width: 25 height: 35
169##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400170##
171
Cary Clark7fc1d122017-10-09 14:07:42 -0400172#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400173
174##
175
176# ------------------------------------------------------------------------------
177
Cary Clark61313f32018-10-08 14:57:48 -0400178#Method static constexpr SkRect MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
Cary Clarkbc5697d2017-10-04 14:31:33 -0400179 SkScalar b)
Cary Clark61313f32018-10-08 14:57:48 -0400180#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500181#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400182
Cary Clark7fc1d122017-10-09 14:07:42 -0400183Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
184result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400185
Cary Clark7fc1d122017-10-09 14:07:42 -0400186#Param l SkScalar stored in fLeft ##
187#Param t SkScalar stored in fTop ##
188#Param r SkScalar stored in fRight ##
189#Param b SkScalar stored in fBottom ##
190
191#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400192
193#Example
Cary Clark154beea2017-10-26 07:58:48 -0400194 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
195 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
196 rect.bottom(), rect.isEmpty() ? "true" : "false");
197 rect.sort();
198 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
199 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400200#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400201rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400202rect: 5, 25, 15, 35 isEmpty: false
203##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400204##
205
Cary Clark7fc1d122017-10-09 14:07:42 -0400206#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400207
208##
209
210# ------------------------------------------------------------------------------
211
Cary Clark61313f32018-10-08 14:57:48 -0400212#Method static constexpr SkRect MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400213
Cary Clark61313f32018-10-08 14:57:48 -0400214#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500215#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400216Returns constructed Rect set to #Formula # (x, y, x + w, y + h) ##.
217Does not validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400218
Cary Clark7fc1d122017-10-09 14:07:42 -0400219#Param x stored in fLeft ##
220#Param y stored in fTop ##
221#Param w added to x and stored in fRight ##
222#Param h added to y and stored in fBottom ##
223
Cary Clark884dd7d2017-10-11 10:37:52 -0400224#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400225
226#Example
Cary Clark154beea2017-10-26 07:58:48 -0400227 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
228 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
229 rect.bottom(), rect.isEmpty() ? "true" : "false");
230 rect.sort();
231 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
232 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400233#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400234rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400235rect: -10, 35, 5, 60 isEmpty: false
236##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400237##
238
Cary Clark7fc1d122017-10-09 14:07:42 -0400239#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400240
241##
242
243# ------------------------------------------------------------------------------
244
Cary Clarkbc5697d2017-10-04 14:31:33 -0400245#Method static SkRect Make(const SkISize& size)
246
Cary Clark61313f32018-10-08 14:57:48 -0400247#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500248#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clarka64e4ee2018-10-18 08:30:34 -0400249#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400250
251#Example
Cary Clark154beea2017-10-26 07:58:48 -0400252 SkRect rect1 = SkRect::MakeSize({2, 35});
253 SkRect rect2 = SkRect::MakeIWH(2, 35);
254 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400255#StdOut
256rect1 == rect2
257##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400258##
259
Cary Clark7fc1d122017-10-09 14:07:42 -0400260#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400261
262##
263
264# ------------------------------------------------------------------------------
265
Cary Clark61313f32018-10-08 14:57:48 -0400266#Method static SkRect Make(const SkIRect& irect)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400267
Cary Clark61313f32018-10-08 14:57:48 -0400268#In Constructors
Cary Clark7fc1d122017-10-09 14:07:42 -0400269Returns constructed IRect set to irect, promoting integers to Scalar.
270Does not validate input; fLeft may be greater than fRight, fTop may be greater
271than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400272
Cary Clark7fc1d122017-10-09 14:07:42 -0400273#Param irect integer unsorted bounds ##
274
275#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400276
277#Example
Cary Clark154beea2017-10-26 07:58:48 -0400278 SkIRect i_rect1 = {2, 35, 22, 53};
279 SkRect f_rect = SkRect::Make(i_rect1);
280 f_rect.offset(0.49f, 0.49f);
281 SkIRect i_rect2;
282 f_rect.round(&i_rect2);
283 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400284##
285
Cary Clark7fc1d122017-10-09 14:07:42 -0400286#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400287
288##
289
Cary Clark4855f782018-02-06 09:41:53 -0500290#Subtopic Property
291#Line # member values, center, validity ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500292
Cary Clarkbc5697d2017-10-04 14:31:33 -0400293# ------------------------------------------------------------------------------
294
295#Method bool isEmpty() const
296
Cary Clark4855f782018-02-06 09:41:53 -0500297#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500298#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400299Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
300to or greater than fBottom. Call sort() to reverse rectangles with negative
301width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400302
Cary Clark61313f32018-10-08 14:57:48 -0400303#Return true if width() or height() are not positive and valid ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400304
305#Example
Cary Clark154beea2017-10-26 07:58:48 -0400306 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
307 for (auto rect : tests) {
308 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
309 rect.bottom(), rect.isEmpty() ? "" : " not");
310 rect.sort();
311 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
312 rect.bottom(), rect.isEmpty() ? "" : " not");
313 }
314#StdOut
315rect: {20, 40, 10, 50} is empty
316sorted: {10, 40, 20, 50} is not empty
317rect: {20, 40, 20, 50} is empty
318sorted: {20, 40, 20, 50} is empty
319##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400320##
321
Cary Clark7fc1d122017-10-09 14:07:42 -0400322#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400323
324##
325
326# ------------------------------------------------------------------------------
327
328#Method bool isSorted() const
329
Cary Clark4855f782018-02-06 09:41:53 -0500330#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500331#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400332Returns true if fLeft is equal to or less than fRight, or if fTop is equal
333to or less than fBottom. Call sort() to reverse rectangles with negative
334width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400335
Cary Clark7fc1d122017-10-09 14:07:42 -0400336#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400337
338#Example
Cary Clark154beea2017-10-26 07:58:48 -0400339 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
340 for (auto rect : tests) {
341 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
342 rect.bottom(), rect.isSorted() ? "" : " not");
343 rect.sort();
344 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
345 rect.bottom(), rect.isSorted() ? "" : " not");
346 }
347#StdOut
348rect: {20, 40, 10, 50} is not sorted
349sorted: {10, 40, 20, 50} is sorted
350rect: {20, 40, 20, 50} is sorted
351sorted: {20, 40, 20, 50} is sorted
352##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400353##
354
Cary Clark7fc1d122017-10-09 14:07:42 -0400355#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400356
357##
358
359# ------------------------------------------------------------------------------
360
Cary Clarkbc5697d2017-10-04 14:31:33 -0400361#Method bool isFinite() const
362
Cary Clark4855f782018-02-06 09:41:53 -0500363#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500364#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400365Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
Cary Clark682c58d2018-05-16 07:07:07 -0400366and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400367
Cary Clark7fc1d122017-10-09 14:07:42 -0400368#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400369
370#Example
Mike Reed274218e2018-01-08 15:05:02 -0500371SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400372 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
373 SkDebugf("large width %g\n", largest.width());
374 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
375 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
376#StdOut
377largest is finite: true
378large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400379widest is finite: false
380##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400381##
382
Cary Clark7fc1d122017-10-09 14:07:42 -0400383#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400384
385##
386
387# ------------------------------------------------------------------------------
388
389#Method SkScalar x() const
390
Cary Clark4855f782018-02-06 09:41:53 -0500391#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500392#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400393Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
394Call sort() to reverse fLeft and fRight if needed.
395
396#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400397
398#Example
Cary Clark154beea2017-10-26 07:58:48 -0400399 SkRect unsorted = { 15, 5, 10, 25 };
400 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
401 SkRect sorted = unsorted.makeSorted();
402 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400403#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400404unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400405sorted.fLeft: 10 sorted.x(): 10
406##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400407##
408
Cary Clark7fc1d122017-10-09 14:07:42 -0400409#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400410
411##
412
413# ------------------------------------------------------------------------------
414
415#Method SkScalar y() const
416
Cary Clark4855f782018-02-06 09:41:53 -0500417#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500418#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400419Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
420and sort() to reverse fTop and fBottom if needed.
421
422#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400423
424#Example
Cary Clark154beea2017-10-26 07:58:48 -0400425 SkRect unsorted = { 15, 25, 10, 5 };
426 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
427 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400428 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
429#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400430unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400431sorted.fTop: 5 sorted.y(): 5
432##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400433##
434
Cary Clark7fc1d122017-10-09 14:07:42 -0400435#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400436
437##
438
439# ------------------------------------------------------------------------------
440
441#Method SkScalar left() const
442
Cary Clark4855f782018-02-06 09:41:53 -0500443#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500444#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400445Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
446Call sort() to reverse fLeft and fRight if needed.
447
448#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400449
450#Example
Cary Clark154beea2017-10-26 07:58:48 -0400451 SkRect unsorted = { 15, 5, 10, 25 };
452 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
453 SkRect sorted = unsorted.makeSorted();
454 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400455#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400456unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400457sorted.fLeft: 10 sorted.left(): 10
458##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400459##
460
Cary Clark7fc1d122017-10-09 14:07:42 -0400461#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400462
463##
464
465# ------------------------------------------------------------------------------
466
467#Method SkScalar top() const
468
Cary Clark4855f782018-02-06 09:41:53 -0500469#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500470#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400471Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
472and sort() to reverse fTop and fBottom if needed.
473
474#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400475
476#Example
Cary Clark154beea2017-10-26 07:58:48 -0400477 SkRect unsorted = { 15, 25, 10, 5 };
478 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
479 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400480 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
481#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400482unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400483sorted.fTop: 5 sorted.top(): 5
484##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400485##
486
Cary Clark7fc1d122017-10-09 14:07:42 -0400487#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400488
489##
490
491# ------------------------------------------------------------------------------
492
493#Method SkScalar right() const
494
Cary Clark4855f782018-02-06 09:41:53 -0500495#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500496#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400497Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
498Call sort() to reverse fLeft and fRight if needed.
499
500#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400501
502#Example
Cary Clark154beea2017-10-26 07:58:48 -0400503 SkRect unsorted = { 15, 25, 10, 5 };
504 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
505 SkRect sorted = unsorted.makeSorted();
506 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400507#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400508unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400509sorted.fRight: 15 sorted.right(): 15
510##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400511##
512
Cary Clark7fc1d122017-10-09 14:07:42 -0400513#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400514
515##
516
517# ------------------------------------------------------------------------------
518
519#Method SkScalar bottom() const
520
Cary Clark4855f782018-02-06 09:41:53 -0500521#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500522#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400523Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
524and sort() to reverse fTop and fBottom if needed.
525
526#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400527
528#Example
Cary Clark154beea2017-10-26 07:58:48 -0400529 SkRect unsorted = { 15, 25, 10, 5 };
530 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
531 SkRect sorted = unsorted.makeSorted();
532 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400533#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400534unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400535sorted.fBottom: 25 sorted.bottom(): 25
536##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400537##
538
Cary Clark7fc1d122017-10-09 14:07:42 -0400539#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400540
541##
542
543# ------------------------------------------------------------------------------
544
545#Method SkScalar width() const
546
Cary Clark4855f782018-02-06 09:41:53 -0500547#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500548#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400549Returns span on the x-axis. This does not check if Rect is sorted, or if
550result fits in 32-bit float; result may be negative or infinity.
551
552#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400553
554#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400555#Description
556Compare with SkIRect::width() example.
557##
Cary Clark154beea2017-10-26 07:58:48 -0400558 SkRect unsorted = { 15, 25, 10, 5 };
559 SkDebugf("unsorted width: %g\n", unsorted.width());
560 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
561 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400562#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400563unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400564large width: 4294967296
565##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400566##
567
Cary Clark7fc1d122017-10-09 14:07:42 -0400568#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400569
570##
571
572# ------------------------------------------------------------------------------
573
574#Method SkScalar height() const
575
Cary Clark4855f782018-02-06 09:41:53 -0500576#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500577#Line # returns span in y ##
Cary Clark224c7002018-06-27 11:00:21 -0400578Returns span on the y-axis. This does not check if Rect is sorted, or if
Cary Clark7fc1d122017-10-09 14:07:42 -0400579result fits in 32-bit float; result may be negative or infinity.
580
581#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400582
583#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400584#Description
585Compare with SkIRect::height() example.
586##
Cary Clark154beea2017-10-26 07:58:48 -0400587 SkRect unsorted = { 15, 25, 10, 20 };
588 SkDebugf("unsorted height: %g\n", unsorted.height());
589 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
590 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400591#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400592unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400593large height: 4294967296
594##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400595##
596
Cary Clark7fc1d122017-10-09 14:07:42 -0400597#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400598
599##
600
601# ------------------------------------------------------------------------------
602
603#Method SkScalar centerX() const
604
Cary Clark4855f782018-02-06 09:41:53 -0500605#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500606#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400607Returns average of left edge and right edge. Result does not change if Rect
608is sorted. Result may overflow to infinity if Rect is far from the origin.
609
610#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400611
612#Example
Cary Clark154beea2017-10-26 07:58:48 -0400613 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
614 for (auto rect : tests) {
615 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
616 rect.sort();
617 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
618 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400619#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400620left: 20 right: 41 centerX: 30.5
621left: 20 right: 41 centerX: 30.5
622left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400623left: -41 right: -20 centerX: -30.5
624##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400625##
626
Cary Clark47d7dae2018-04-11 16:54:35 -0400627#SeeAlso centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400628
629##
630
631# ------------------------------------------------------------------------------
632
633#Method SkScalar centerY() const
634
Cary Clark4855f782018-02-06 09:41:53 -0500635#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500636#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400637Returns average of top edge and bottom edge. Result does not change if Rect
Cary Clark75fd4492018-06-20 12:45:16 -0400638is sorted.
Cary Clark7fc1d122017-10-09 14:07:42 -0400639
640#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400641
642#Example
Cary Clark154beea2017-10-26 07:58:48 -0400643 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
644 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
645 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400646#StdOut
Cary Clark75fd4492018-06-20 12:45:16 -0400647left: 2e+38 right: 3e+38 centerX: 2.5e+38 safe mid x: 2.5e+38
Cary Clark7fc1d122017-10-09 14:07:42 -0400648##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400649##
650
Cary Clark47d7dae2018-04-11 16:54:35 -0400651#SeeAlso centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400652
653##
654
Cary Clark4855f782018-02-06 09:41:53 -0500655#Subtopic Property ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500656
Cary Clark61313f32018-10-08 14:57:48 -0400657#Subtopic Operators
Cary Clark2dc84ad2018-01-26 12:56:22 -0500658
Cary Clarkbc5697d2017-10-04 14:31:33 -0400659# ------------------------------------------------------------------------------
660
Cary Clark884dd7d2017-10-11 10:37:52 -0400661#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400662
Cary Clark61313f32018-10-08 14:57:48 -0400663#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500664#Line # returns true if members are equal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400665Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
Cary Clark7fc1d122017-10-09 14:07:42 -0400666equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400667
Cary Clark7fc1d122017-10-09 14:07:42 -0400668a and b are not equal if either contain NaN. a and b are equal if members
669contain zeroes width different signs.
670
671#Param a Rect to compare ##
672#Param b Rect to compare ##
673
674#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400675
676#Example
Cary Clark154beea2017-10-26 07:58:48 -0400677 auto debugster = [](const SkRect& test) -> void {
678 SkRect negZero = {-0.0f, -0.0f, 2, 2};
679 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
680 test.fLeft, test.fTop, test.fRight, test.fBottom,
681 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
682 test == negZero ? '=' : '!',
683 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
684 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
685 "and are" : "yet are not");
686 };
687 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
688 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
689 for (auto rect : tests) {
690 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400691 }
Cary Clark154beea2017-10-26 07:58:48 -0400692#StdOut
693tests are equal
694{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
695{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark682c58d2018-05-16 07:07:07 -0400696{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400697##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400698##
699
Cary Clark7fc1d122017-10-09 14:07:42 -0400700#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400701
702##
703
704# ------------------------------------------------------------------------------
705
Cary Clark884dd7d2017-10-11 10:37:52 -0400706#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400707
Cary Clark61313f32018-10-08 14:57:48 -0400708#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500709#Line # returns true if members are unequal ##
Cary Clark682c58d2018-05-16 07:07:07 -0400710Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
Cary Clark7fc1d122017-10-09 14:07:42 -0400711equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400712
Cary Clark7fc1d122017-10-09 14:07:42 -0400713a and b are not equal if either contain NaN. a and b are equal if members
714contain zeroes width different signs.
715
716#Param a Rect to compare ##
717#Param b Rect to compare ##
718
719#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400720
721#Example
Cary Clark154beea2017-10-26 07:58:48 -0400722 SkRect test = {0, 0, 2, SK_ScalarNaN};
723 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
724#StdOut
Cary Clark682c58d2018-05-16 07:07:07 -0400725test with NaN is not equal to itself
Cary Clark7fc1d122017-10-09 14:07:42 -0400726##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400727##
728
Cary Clark7fc1d122017-10-09 14:07:42 -0400729#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400730
731##
732
Cary Clark61313f32018-10-08 14:57:48 -0400733#Subtopic Operators ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500734
735#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500736#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500737
Cary Clarkbc5697d2017-10-04 14:31:33 -0400738# ------------------------------------------------------------------------------
739
740#Method void toQuad(SkPoint quad[4]) const
741
Cary Clarkab2621d2018-01-30 10:08:57 -0500742#In As_Points
743#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400744Returns four points in quad that enclose Rect ordered as: top-left, top-right,
Cary Clark682c58d2018-05-16 07:07:07 -0400745bottom-right, bottom-left.
Cary Clark7fc1d122017-10-09 14:07:42 -0400746
747#Private
Cary Clark682c58d2018-05-16 07:07:07 -0400748Consider adding param to control whether quad is clockwise or counterclockwise.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400749##
750
Cary Clark7fc1d122017-10-09 14:07:42 -0400751#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400752
753#Example
Cary Clark154beea2017-10-26 07:58:48 -0400754 SkRect rect = {1, 2, 3, 4};
755 SkPoint corners[4];
756 rect.toQuad(corners);
757 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
758 SkDebugf("corners:");
759 for (auto corner : corners) {
760 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
761 }
762 SkDebugf("\n");
763#StdOut
764rect: {1, 2, 3, 4}
Cary Clark682c58d2018-05-16 07:07:07 -0400765corners: {1, 2} {3, 2} {3, 4} {1, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400766##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400767##
768
Cary Clark7fc1d122017-10-09 14:07:42 -0400769#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400770
771##
772
773# ------------------------------------------------------------------------------
774
Cary Clark2dc84ad2018-01-26 12:56:22 -0500775#Method void setBounds(const SkPoint pts[], int count)
776
Cary Clarkab2621d2018-01-30 10:08:57 -0500777#In As_Points
778#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500779Sets to bounds of Point array with count entries. If count is zero or smaller,
780or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
781
782Result is either empty or sorted: fLeft is less than or equal to fRight, and
783fTop is less than or equal to fBottom.
784
785#Param pts Point array ##
786#Param count entries in array ##
787
788#Example
789 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
790 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
791 SkRect rect;
792 rect.setBounds(points, count);
793 if (count > 0) {
794 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
795 } else {
796 SkDebugf("%14s", " ");
797 }
798 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
799 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
800 }
801#StdOut
802 count: 0 rect: 0, 0, 0, 0
803added: 3, 4 count: 1 rect: 3, 4, 3, 4
804added: 1, 2 count: 2 rect: 1, 2, 3, 4
805added: 5, 6 count: 3 rect: 1, 2, 5, 6
806added: nan, 8 count: 4 rect: 0, 0, 0, 0
807##
808##
809
810#SeeAlso set setBoundsCheck SkPath::addPoly
811
812##
813
814# ------------------------------------------------------------------------------
815
816#Method bool setBoundsCheck(const SkPoint pts[], int count)
817
Cary Clarkab2621d2018-01-30 10:08:57 -0500818#In As_Points
819#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500820Sets to bounds of Point array with count entries. Returns false if count is
821zero or smaller, or if Point array contains an infinity or NaN; in these cases
822sets Rect to (0, 0, 0, 0).
823
824Result is either empty or sorted: fLeft is less than or equal to fRight, and
825fTop is less than or equal to fBottom.
826
827#Param pts Point array ##
828#Param count entries in array ##
829
830#Return true if all Point values are finite ##
831
832#Example
833 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
834 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
835 SkRect rect;
836 bool success = rect.setBoundsCheck(points, count);
837 if (count > 0) {
838 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
839 } else {
840 SkDebugf("%14s", " ");
841 }
842 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
843 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
844 }
845#StdOut
846 count: 0 rect: 0, 0, 0, 0 success: true
847added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
848added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
849added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
850added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
851##
852##
853
854#SeeAlso set setBounds SkPath::addPoly
855
856##
857
858#Subtopic As_Points ##
859
860#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500861#Line # replaces all values ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500862
863# ------------------------------------------------------------------------------
864
Cary Clarkc06754b2018-05-16 21:28:55 -0400865#Method void setBoundsNoCheck(const SkPoint pts[], int count)
866#In Set
867#Line # sets to upper and lower limits of Point array ##
Cary Clarkffb3d682018-05-17 12:17:28 -0400868Sets to bounds of Point pts array with count entries. If any Point in pts
Cary Clark8f288d92018-05-17 15:16:57 -0400869contains infinity or NaN, all Rect dimensions are set to NaN.
Cary Clarkc06754b2018-05-16 21:28:55 -0400870
871#Param pts Point array ##
872#Param count entries in array ##
873
874#Example
Cary Clark8f288d92018-05-17 15:16:57 -0400875 SkPoint points[] = {{3, 4}, {1, 2}, {SK_ScalarInfinity, 6}, {SK_ScalarNaN, 8}};
Cary Clarkffb3d682018-05-17 12:17:28 -0400876 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
877 SkRect rect;
878 rect.setBoundsNoCheck(points, count);
879 if (count > 0) {
880 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
881 } else {
882 SkDebugf("%14s", " ");
883 }
884 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
885 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
886 }
Cary Clarkc06754b2018-05-16 21:28:55 -0400887##
888
889#SeeAlso setBoundsCheck
890#Method ##
891
892# ------------------------------------------------------------------------------
893
Cary Clarkbc5697d2017-10-04 14:31:33 -0400894#Method void setEmpty()
895
Cary Clarkab2621d2018-01-30 10:08:57 -0500896#In Set
897#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400898Sets Rect to (0, 0, 0, 0).
899
900Many other rectangles are empty; if left is equal to or greater than right,
901or if top is equal to or greater than bottom. Setting all members to zero
902is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400903
904#Example
Cary Clark154beea2017-10-26 07:58:48 -0400905 SkRect rect = {3, 4, 1, 2};
906 for (int i = 0; i < 2; ++i) {
907 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
908 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
909 rect.setEmpty();
910 }
911#StdOut
912rect: {3, 4, 1, 2} is empty
913rect: {0, 0, 0, 0} is empty
914##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400915##
916
Cary Clark7fc1d122017-10-09 14:07:42 -0400917#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400918
919##
920
921# ------------------------------------------------------------------------------
922
923#Method void set(const SkIRect& src)
924
Cary Clarkab2621d2018-01-30 10:08:57 -0500925#In Set
926#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400927Sets Rect to src, promoting src members from integer to Scalar.
Cary Clark682c58d2018-05-16 07:07:07 -0400928Very large values in src may lose precision.
Cary Clark7fc1d122017-10-09 14:07:42 -0400929
930#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400931
932#Example
Cary Clark154beea2017-10-26 07:58:48 -0400933 SkIRect i_rect = {3, 4, 1, 2};
934 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
935 SkRect f_rect;
936 f_rect.set(i_rect);
937 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
938#StdOut
939i_rect: {3, 4, 1, 2}
940f_rect: {3, 4, 1, 2}
941##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400942##
943
Cary Clark7fc1d122017-10-09 14:07:42 -0400944#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400945
946##
947
948# ------------------------------------------------------------------------------
949
950#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
951
Cary Clarkab2621d2018-01-30 10:08:57 -0500952#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -0400953Sets Rect to (left, top, right, bottom).
954left and right are not sorted; left is not necessarily less than right.
955top and bottom are not sorted; top is not necessarily less than bottom.
956
957#Param left stored in fLeft ##
958#Param top stored in fTop ##
959#Param right stored in fRight ##
960#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400961
962#Example
Cary Clark154beea2017-10-26 07:58:48 -0400963 SkRect rect1 = {3, 4, 1, 2};
964 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
965 SkRect rect2;
966 rect2.set(3, 4, 1, 2);
967 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
968#StdOut
969rect1: {3, 4, 1, 2}
970rect2: {3, 4, 1, 2}
971##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400972##
973
Cary Clark7fc1d122017-10-09 14:07:42 -0400974#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400975
976##
977
978# ------------------------------------------------------------------------------
979
980#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
981
Cary Clarkab2621d2018-01-30 10:08:57 -0500982#In Set
983#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400984Sets Rect to (left, top, right, bottom).
985left and right are not sorted; left is not necessarily less than right.
986top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400987
Cary Clark7fc1d122017-10-09 14:07:42 -0400988#Param left stored in fLeft ##
989#Param top stored in fTop ##
990#Param right stored in fRight ##
991#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400992
993#Example
Cary Clark154beea2017-10-26 07:58:48 -0400994 SkRect rect1 = {3, 4, 1, 2};
995 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
996 SkRect rect2;
997 rect2.setLTRB(3, 4, 1, 2);
998 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
999#StdOut
1000rect1: {3, 4, 1, 2}
1001rect2: {3, 4, 1, 2}
1002##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001003##
1004
Cary Clark7fc1d122017-10-09 14:07:42 -04001005#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001006
1007##
1008
1009# ------------------------------------------------------------------------------
1010
Cary Clarkbc5697d2017-10-04 14:31:33 -04001011#Method void set(const SkPoint pts[], int count)
1012
Cary Clarkab2621d2018-01-30 10:08:57 -05001013#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001014Sets to bounds of Point array with count entries. If count is zero or smaller,
1015or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001016
Cary Clark7fc1d122017-10-09 14:07:42 -04001017Result is either empty or sorted: fLeft is less than or equal to fRight, and
1018fTop is less than or equal to fBottom.
1019
1020#Param pts Point array ##
1021#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001022
1023#Example
Cary Clark154beea2017-10-26 07:58:48 -04001024 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1025 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1026 SkRect rect;
1027 rect.set(points, count);
1028 if (count > 0) {
1029 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1030 } else {
1031 SkDebugf("%14s", " ");
1032 }
1033 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1034 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1035 }
1036#StdOut
1037 count: 0 rect: 0, 0, 0, 0
1038added: 3, 4 count: 1 rect: 3, 4, 3, 4
1039added: 1, 2 count: 2 rect: 1, 2, 3, 4
1040added: 5, 6 count: 3 rect: 1, 2, 5, 6
1041added: nan, 8 count: 4 rect: 0, 0, 0, 0
1042##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001043##
1044
Cary Clark7fc1d122017-10-09 14:07:42 -04001045#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001046
1047##
1048
1049# ------------------------------------------------------------------------------
1050
Cary Clarkbc5697d2017-10-04 14:31:33 -04001051#Method void set(const SkPoint& p0, const SkPoint& p1)
1052
Cary Clarkab2621d2018-01-30 10:08:57 -05001053#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001054Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1055sorted and may be empty. Does not check to see if values are finite.
1056
1057#Param p0 corner to include ##
1058#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001059
1060#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001061#Description
Cary Clark682c58d2018-05-16 07:07:07 -04001062p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -04001063##
Cary Clark154beea2017-10-26 07:58:48 -04001064 SkPoint point1 = {SK_ScalarNaN, 8};
1065 SkPoint point2 = {3, 4};
1066 SkRect rect;
1067 rect.set(point1, point2);
1068 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1069 rect.set(point2, point1);
1070 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001071##
1072
Cary Clark7fc1d122017-10-09 14:07:42 -04001073#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001074
1075##
1076
1077# ------------------------------------------------------------------------------
1078
1079#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1080
Cary Clarkab2621d2018-01-30 10:08:57 -05001081#In Set
1082#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001083Sets Rect to #Formula # (x, y, x + width, y + height) ##.
1084Does not validate input; width or height may be negative.
Cary Clark7fc1d122017-10-09 14:07:42 -04001085
1086#Param x stored in fLeft ##
1087#Param y stored in fTop ##
1088#Param width added to x and stored in fRight ##
1089#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001090
1091#Example
Cary Clark154beea2017-10-26 07:58:48 -04001092 SkRect rect;
1093 rect.setXYWH(5, 35, -15, 25);
1094 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1095 rect.bottom(), rect.isEmpty() ? "true" : "false");
1096 rect.sort();
1097 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1098 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001099#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001100rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001101rect: -10, 35, 5, 60 isEmpty: false
1102##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001103##
1104
Cary Clark7fc1d122017-10-09 14:07:42 -04001105#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001106
1107##
1108
1109# ------------------------------------------------------------------------------
1110
1111#Method void setWH(SkScalar width, SkScalar height)
1112
Cary Clarkab2621d2018-01-30 10:08:57 -05001113#In Set
1114#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001115Sets Rect to (0, 0, width, height). Does not validate input;
1116width or height may be negative.
1117
1118#Param width stored in fRight ##
1119#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001120
1121#Example
Cary Clark154beea2017-10-26 07:58:48 -04001122 SkRect rect;
1123 rect.setWH(-15, 25);
1124 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1125 rect.bottom(), rect.isEmpty() ? "true" : "false");
1126 rect.sort();
1127 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1128 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001129#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001130rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001131rect: -15, 0, 0, 25 isEmpty: false
1132##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001133##
1134
Cary Clark7fc1d122017-10-09 14:07:42 -04001135#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001136
1137##
1138
Cary Clark2dc84ad2018-01-26 12:56:22 -05001139#Subtopic Set ##
1140
1141#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -04001142#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001143
Cary Clark2dc84ad2018-01-26 12:56:22 -05001144# ------------------------------------------------------------------------------
1145
1146#Method void iset(int left, int top, int right, int bottom)
1147
Cary Clarkab2621d2018-01-30 10:08:57 -05001148#In From_Integers
1149#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001150Sets Rect to (left, top, right, bottom).
1151All parameters are promoted from integer to Scalar.
1152left and right are not sorted; left is not necessarily less than right.
1153top and bottom are not sorted; top is not necessarily less than bottom.
1154
1155#Param left promoted to SkScalar and stored in fLeft ##
1156#Param top promoted to SkScalar and stored in fTop ##
1157#Param right promoted to SkScalar and stored in fRight ##
1158#Param bottom promoted to SkScalar and stored in fBottom ##
1159
1160#Example
1161 SkRect rect1 = {3, 4, 1, 2};
1162 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1163 SkRect rect2;
1164 rect2.iset(3, 4, 1, 2);
1165 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1166#StdOut
1167rect1: {3, 4, 1, 2}
1168rect2: {3, 4, 1, 2}
1169##
1170##
1171
1172#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1173
1174##
1175
1176# ------------------------------------------------------------------------------
1177
1178#Method void isetWH(int width, int height)
1179
Cary Clarkab2621d2018-01-30 10:08:57 -05001180#In From_Integers
1181#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001182Sets Rect to (0, 0, width, height).
1183width and height may be zero or negative. width and height are promoted from
1184integer to SkScalar, large values may lose precision.
1185
1186#Param width promoted to SkScalar and stored in fRight ##
1187#Param height promoted to SkScalar and stored in fBottom ##
1188
1189#Example
1190 SkRect rect1 = {0, 0, 1, 2};
1191 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1192 SkRect rect2;
1193 rect2.isetWH(1, 2);
1194 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1195#StdOut
1196rect1: {0, 0, 1, 2}
1197rect2: {0, 0, 1, 2}
1198##
1199##
1200
1201#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1202
1203##
1204
1205#Subtopic From_Integers ##
1206
1207#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001208#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001209
Cary Clarkbc5697d2017-10-04 14:31:33 -04001210# ------------------------------------------------------------------------------
1211
Cary Clarkbc5697d2017-10-04 14:31:33 -04001212#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1213
Cary Clarkab2621d2018-01-30 10:08:57 -05001214#In Inset_Outset_Offset
1215#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001216Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001217
Cary Clark7fc1d122017-10-09 14:07:42 -04001218If dx is negative, Rect returned is moved to the left.
1219If dx is positive, Rect returned is moved to the right.
1220If dy is negative, Rect returned is moved upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001221If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001222
Cary Clark7fc1d122017-10-09 14:07:42 -04001223#Param dx added to fLeft and fRight ##
1224#Param dy added to fTop and fBottom ##
1225
Cary Clark5538c132018-06-14 12:28:14 -04001226#Return Rect offset on axes, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001227
1228#Example
Cary Clark154beea2017-10-26 07:58:48 -04001229 SkRect rect = { 10, 50, 20, 60 };
1230 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1231 rect.bottom(), rect.isEmpty() ? "true" : "false");
1232 rect = rect.makeOffset(15, 32);
1233 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1234 rect.bottom(), rect.isEmpty() ? "true" : "false");
1235#StdOut
1236rect: 10, 50, 20, 60 isEmpty: false
1237rect: 25, 82, 35, 92 isEmpty: false
1238##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001239##
1240
Cary Clark7fc1d122017-10-09 14:07:42 -04001241#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001242
1243##
1244
1245# ------------------------------------------------------------------------------
1246
1247#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1248
Cary Clarkab2621d2018-01-30 10:08:57 -05001249#In Inset_Outset_Offset
1250#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001251Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001252
Cary Clark7fc1d122017-10-09 14:07:42 -04001253If dx is negative, Rect returned is wider.
1254If dx is positive, Rect returned is narrower.
1255If dy is negative, Rect returned is taller.
Cary Clark682c58d2018-05-16 07:07:07 -04001256If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001257
Cary Clark7fc1d122017-10-09 14:07:42 -04001258#Param dx added to fLeft and subtracted from fRight ##
1259#Param dy added to fTop and subtracted from fBottom ##
1260
1261#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001262
1263#Example
Cary Clark154beea2017-10-26 07:58:48 -04001264 SkRect rect = { 10, 50, 20, 60 };
1265 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1266 rect.bottom(), rect.isEmpty() ? "true" : "false");
1267 rect = rect.makeInset(15, 32);
1268 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1269 rect.bottom(), rect.isEmpty() ? "true" : "false");
1270#StdOut
1271rect: 10, 50, 20, 60 isEmpty: false
1272rect: 25, 82, 5, 28 isEmpty: true
1273##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001274##
1275
Cary Clark7fc1d122017-10-09 14:07:42 -04001276#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001277
1278##
1279
1280# ------------------------------------------------------------------------------
1281
1282#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1283
Cary Clarkab2621d2018-01-30 10:08:57 -05001284#In Inset_Outset_Offset
1285#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001286Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001287
Cary Clark7fc1d122017-10-09 14:07:42 -04001288If dx is negative, Rect returned is narrower.
1289If dx is positive, Rect returned is wider.
1290If dy is negative, Rect returned is shorter.
Cary Clark682c58d2018-05-16 07:07:07 -04001291If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001292
Cary Clark7fc1d122017-10-09 14:07:42 -04001293#Param dx subtracted to fLeft and added from fRight ##
1294#Param dy subtracted to fTop and added from fBottom ##
1295
1296#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001297
1298#Example
Cary Clark154beea2017-10-26 07:58:48 -04001299 SkRect rect = { 10, 50, 20, 60 };
1300 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1301 rect.bottom(), rect.isEmpty() ? "true" : "false");
1302 rect = rect.makeOutset(15, 32);
1303 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1304 rect.bottom(), rect.isEmpty() ? "true" : "false");
1305#StdOut
1306rect: 10, 50, 20, 60 isEmpty: false
1307rect: -5, 18, 35, 92 isEmpty: false
1308##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001309##
1310
Cary Clark7fc1d122017-10-09 14:07:42 -04001311#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001312
1313##
1314
1315# ------------------------------------------------------------------------------
1316
1317#Method void offset(SkScalar dx, SkScalar dy)
1318
Cary Clarkab2621d2018-01-30 10:08:57 -05001319#In Inset_Outset_Offset
1320#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001321Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001322
Cary Clark7fc1d122017-10-09 14:07:42 -04001323If dx is negative, moves Rect to the left.
1324If dx is positive, moves Rect to the right.
1325If dy is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001326If dy is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001327
1328#Param dx offset added to fLeft and fRight ##
1329#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001330
1331#Example
Cary Clark154beea2017-10-26 07:58:48 -04001332 SkRect rect = { 10, 14, 50, 73 };
1333 rect.offset(5, 13);
1334 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1335#StdOut
1336rect: 15, 27, 55, 86
1337##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001338##
1339
Cary Clark7fc1d122017-10-09 14:07:42 -04001340#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001341
1342##
1343
1344# ------------------------------------------------------------------------------
1345
1346#Method void offset(const SkPoint& delta)
1347
Cary Clarkab2621d2018-01-30 10:08:57 -05001348#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001349Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1350fTop, fBottom.
1351
1352If delta.fX is negative, moves Rect to the left.
1353If delta.fX is positive, moves Rect to the right.
1354If delta.fY is negative, moves Rect upward.
Cary Clark682c58d2018-05-16 07:07:07 -04001355If delta.fY is positive, moves Rect downward.
Cary Clark7fc1d122017-10-09 14:07:42 -04001356
1357#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358
1359#Example
Cary Clark154beea2017-10-26 07:58:48 -04001360 SkRect rect = { 10, 14, 50, 73 };
1361 rect.offset({5, 13});
1362 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1363#StdOut
1364rect: 15, 27, 55, 86
1365##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001366##
1367
Cary Clark7fc1d122017-10-09 14:07:42 -04001368#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
1370##
1371
1372# ------------------------------------------------------------------------------
1373
1374#Method void offsetTo(SkScalar newX, SkScalar newY)
1375
Cary Clarkab2621d2018-01-30 10:08:57 -05001376#In Inset_Outset_Offset
1377#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001378Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1379are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001380
Cary Clark7fc1d122017-10-09 14:07:42 -04001381#Param newX stored in fLeft, preserving width() ##
1382#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001383
1384#Example
Cary Clark154beea2017-10-26 07:58:48 -04001385 SkRect rect = { 10, 14, 50, 73 };
1386 rect.offsetTo(15, 27);
1387 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1388#StdOut
1389rect: 15, 27, 55, 86
1390##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001391##
1392
Cary Clark7fc1d122017-10-09 14:07:42 -04001393#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001394
1395##
1396
1397# ------------------------------------------------------------------------------
1398
1399#Method void inset(SkScalar dx, SkScalar dy)
1400
Cary Clarkab2621d2018-01-30 10:08:57 -05001401#In Inset_Outset_Offset
1402#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001403Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001404
Cary Clark7fc1d122017-10-09 14:07:42 -04001405If dx is positive, makes Rect narrower.
1406If dx is negative, makes Rect wider.
1407If dy is positive, makes Rect shorter.
1408If dy is negative, makes Rect taller.
1409
1410#Param dx added to fLeft and subtracted from fRight ##
1411#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001412
1413#Example
Cary Clark154beea2017-10-26 07:58:48 -04001414 SkRect rect = { 10, 14, 50, 73 };
1415 rect.inset(5, 13);
1416 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1417#StdOut
1418rect: 15, 27, 45, 60
1419##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001420##
1421
Cary Clark7fc1d122017-10-09 14:07:42 -04001422#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001423
1424##
1425
1426# ------------------------------------------------------------------------------
1427
1428#Method void outset(SkScalar dx, SkScalar dy)
1429
Cary Clarkab2621d2018-01-30 10:08:57 -05001430#In Inset_Outset_Offset
1431#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001432Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001433
Cary Clark7fc1d122017-10-09 14:07:42 -04001434If dx is positive, makes Rect wider.
1435If dx is negative, makes Rect narrower.
1436If dy is positive, makes Rect taller.
1437If dy is negative, makes Rect shorter.
1438
1439#Param dx subtracted to fLeft and added from fRight ##
1440#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001441
1442#Example
Cary Clark154beea2017-10-26 07:58:48 -04001443 SkRect rect = { 10, 14, 50, 73 };
1444 rect.outset(5, 13);
1445 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1446#StdOut
1447rect: 5, 1, 55, 86
1448##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001449##
1450
Cary Clark7fc1d122017-10-09 14:07:42 -04001451#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001452
1453##
1454
Cary Clark2dc84ad2018-01-26 12:56:22 -05001455#Subtopic Inset_Outset_Offset ##
1456
1457#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001458#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001459
Cary Clark682c58d2018-05-16 07:07:07 -04001460Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001461must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001462empty() returns false. The intersection of Rect pair can be described by:
Cary Clark2be81cf2018-09-13 12:04:30 -04001463#Formula # (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1464 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) ##.
Cary Clark154beea2017-10-26 07:58:48 -04001465
Cary Clark7fc1d122017-10-09 14:07:42 -04001466The intersection is only meaningful if the resulting Rect is not empty and
1467describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1468
Cary Clark2dc84ad2018-01-26 12:56:22 -05001469# ------------------------------------------------------------------------------
1470
Florin Malitaeb420452018-02-20 11:44:43 -05001471#Method bool contains(SkScalar x, SkScalar y) const
1472
1473#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001474#Line # returns true if points are equal or inside ##
Florin Malitaeb420452018-02-20 11:44:43 -05001475Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
1476Returns false if SkRect is empty.
1477
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001478#Param x test Point x-coordinate ##
1479#Param y test Point y-coordinate ##
Florin Malitaeb420452018-02-20 11:44:43 -05001480
Cary Clarkd2ca79c2018-08-10 13:09:13 -04001481#Return true if (x, y) is inside Rect ##
Florin Malitaeb420452018-02-20 11:44:43 -05001482
1483#Example
1484 SkRect rect = { 30, 50, 40, 60 };
1485 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1486 for (auto contained : tests) {
1487 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1488 rect.left(), rect.top(), rect.right(), rect.bottom(),
1489 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1490 contained.x(), contained.y());
1491 }
1492#StdOut
1493rect: (30, 50, 40, 60) contains (30, 50)
1494rect: (30, 50, 40, 60) does not contain (39, 49)
1495rect: (30, 50, 40, 60) does not contain (29, 59)
1496##
1497##
1498
Cary Clark53498e92018-06-28 19:13:56 -04001499#SeeAlso SkIRect::contains SkRRect::contains
Florin Malitaeb420452018-02-20 11:44:43 -05001500
1501##
1502
1503# ------------------------------------------------------------------------------
1504
Cary Clark2dc84ad2018-01-26 12:56:22 -05001505#Method bool contains(const SkRect& r) const
1506
Cary Clarkab2621d2018-01-30 10:08:57 -05001507#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001508Returns true if Rect contains r.
1509Returns false if Rect is empty or r is empty.
1510
1511Rect contains r when Rect area completely includes r area.
1512
1513#Param r Rect contained ##
1514
1515#Return true if all sides of Rect are outside r ##
1516
1517#Example
1518 SkRect rect = { 30, 50, 40, 60 };
1519 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1520 for (auto contained : tests) {
1521 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1522 rect.left(), rect.top(), rect.right(), rect.bottom(),
1523 rect.contains(contained) ? "contains" : "does not contain",
1524 contained.left(), contained.top(), contained.right(), contained.bottom());
1525 }
1526#StdOut
1527rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1528rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1529rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1530##
1531##
1532
1533#SeeAlso SkIRect::contains
1534
1535##
1536
1537# ------------------------------------------------------------------------------
1538
1539#Method bool contains(const SkIRect& r) const
1540
Cary Clarkab2621d2018-01-30 10:08:57 -05001541#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001542Returns true if Rect contains r.
1543Returns false if Rect is empty or r is empty.
1544
1545Rect contains r when Rect area completely includes r area.
1546
1547#Param r IRect contained ##
1548
1549#Return true if all sides of Rect are outside r ##
1550
1551#Example
1552 SkRect rect = { 30, 50, 40, 60 };
1553 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1554 for (auto contained : tests) {
1555 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1556 rect.left(), rect.top(), rect.right(), rect.bottom(),
1557 rect.contains(contained) ? "contains" : "does not contain",
1558 contained.left(), contained.top(), contained.right(), contained.bottom());
1559 }
1560#StdOut
1561rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1562rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1563rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1564##
1565##
1566
1567#SeeAlso SkIRect::contains
1568
1569##
1570
Cary Clarkbc5697d2017-10-04 14:31:33 -04001571# ------------------------------------------------------------------------------
1572
1573#Method bool intersect(const SkRect& r)
1574
Cary Clarkab2621d2018-01-30 10:08:57 -05001575#In Intersection
1576#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001577Returns true if Rect intersects r, and sets Rect to intersection.
1578Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001579
Cary Clark7fc1d122017-10-09 14:07:42 -04001580Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001581
Cary Clark7fc1d122017-10-09 14:07:42 -04001582#Param r limit of result ##
1583
1584#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001585
1586#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001587#Description
1588Two SkDebugf calls are required. If the calls are combined, their arguments
1589may not be evaluated in left to right order: the printed intersection may
1590be before or after the call to intersect.
1591##
Cary Clark154beea2017-10-26 07:58:48 -04001592 SkRect leftRect = { 10, 40, 50, 80 };
1593 SkRect rightRect = { 30, 60, 70, 90 };
1594 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001595 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001596 leftRect.right(), leftRect.bottom());
1597#StdOut
1598 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001599##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001600##
1601
Cary Clark7fc1d122017-10-09 14:07:42 -04001602#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001603
1604##
1605
1606# ------------------------------------------------------------------------------
1607
1608#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1609
Cary Clarkab2621d2018-01-30 10:08:57 -05001610#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001611Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1612construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001613
Cary Clark7fc1d122017-10-09 14:07:42 -04001614Returns true if Rect intersects construction, and sets Rect to intersection.
1615Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001616
Cary Clark7fc1d122017-10-09 14:07:42 -04001617Returns false if either construction or Rect is empty, leaving Rect unchanged.
1618
Cary Clark5538c132018-06-14 12:28:14 -04001619#Param left x-axis minimum of constructed Rect ##
1620#Param top y-axis minimum of constructed Rect ##
1621#Param right x-axis maximum of constructed Rect ##
1622#Param bottom y-axis maximum of constructed Rect ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001623
1624#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001625
1626#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001627#Description
1628Two SkDebugf calls are required. If the calls are combined, their arguments
1629may not be evaluated in left to right order: the printed intersection may
1630be before or after the call to intersect.
1631##
Cary Clark154beea2017-10-26 07:58:48 -04001632 SkRect leftRect = { 10, 40, 50, 80 };
1633 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001634 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001635 leftRect.right(), leftRect.bottom());
1636#StdOut
1637 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001638##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001639##
1640
Cary Clark7fc1d122017-10-09 14:07:42 -04001641#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001642
1643##
1644
1645# ------------------------------------------------------------------------------
1646
Cary Clark61313f32018-10-08 14:57:48 -04001647#Method bool intersect(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04001648
Cary Clarkab2621d2018-01-30 10:08:57 -05001649#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001650Returns true if a intersects b, and sets Rect to intersection.
1651Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001652
Cary Clark7fc1d122017-10-09 14:07:42 -04001653Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001654
Cary Clark7fc1d122017-10-09 14:07:42 -04001655#Param a Rect to intersect ##
1656#Param b Rect to intersect ##
1657
1658#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001659
1660#Example
Cary Clark154beea2017-10-26 07:58:48 -04001661 SkRect result;
1662 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1663 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1664 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001665#StdOut
1666 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001667##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001668##
1669
Cary Clark7fc1d122017-10-09 14:07:42 -04001670#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001671
1672##
1673
Cary Clark7fc1d122017-10-09 14:07:42 -04001674# ------------------------------------------------------------------------------
1675
Cary Clarkbc5697d2017-10-04 14:31:33 -04001676#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1677
Cary Clarkab2621d2018-01-30 10:08:57 -05001678#In Intersection
1679#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001680Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1681construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001682
Cary Clark7fc1d122017-10-09 14:07:42 -04001683Returns true if Rect intersects construction.
1684Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001685
Cary Clark5538c132018-06-14 12:28:14 -04001686#Param left x-axis minimum of constructed Rect ##
1687#Param top y-axis minimum of constructed Rect ##
1688#Param right x-axis maximum of constructed Rect ##
1689#Param bottom y-axis maximum of constructed Rect ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001690
1691#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001692
1693#Example
Cary Clark154beea2017-10-26 07:58:48 -04001694 SkRect rect = { 10, 40, 50, 80 };
1695 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001696#StdOut
1697 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001698##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001699##
1700
Cary Clark7fc1d122017-10-09 14:07:42 -04001701#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001702
1703##
1704
Cary Clark7fc1d122017-10-09 14:07:42 -04001705# ------------------------------------------------------------------------------
1706
Cary Clarkbc5697d2017-10-04 14:31:33 -04001707#Method bool intersects(const SkRect& r) const
1708
Cary Clarkab2621d2018-01-30 10:08:57 -05001709#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001710Returns true if Rect intersects r.
1711Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001712
Cary Clark7fc1d122017-10-09 14:07:42 -04001713#Param r Rect to intersect ##
1714
1715#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001716
1717#Example
Cary Clark154beea2017-10-26 07:58:48 -04001718 SkRect rect = { 10, 40, 50, 80 };
1719 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001720#StdOut
1721 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001722##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723##
1724
Cary Clark7fc1d122017-10-09 14:07:42 -04001725#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001726
1727##
1728
Cary Clark7fc1d122017-10-09 14:07:42 -04001729# ------------------------------------------------------------------------------
1730
Cary Clarkbc5697d2017-10-04 14:31:33 -04001731#Method static bool Intersects(const SkRect& a, const SkRect& b)
1732
Cary Clarkab2621d2018-01-30 10:08:57 -05001733#In Intersection
1734#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001735Returns true if a intersects b.
1736Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001737
Cary Clark7fc1d122017-10-09 14:07:42 -04001738#Param a Rect to intersect ##
1739#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001740
Cary Clark7fc1d122017-10-09 14:07:42 -04001741#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001742
1743#Example
Cary Clark154beea2017-10-26 07:58:48 -04001744 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001745#StdOut
1746 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001747##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001748##
1749
Cary Clark7fc1d122017-10-09 14:07:42 -04001750#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001751
1752##
1753
Cary Clark2dc84ad2018-01-26 12:56:22 -05001754#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001755
Cary Clark2dc84ad2018-01-26 12:56:22 -05001756#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001757#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001758
Cary Clark7fc1d122017-10-09 14:07:42 -04001759# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001760
1761#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1762
Cary Clarkab2621d2018-01-30 10:08:57 -05001763#In Join
1764#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001765Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1766construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001767
Cary Clark7fc1d122017-10-09 14:07:42 -04001768Sets Rect to the union of itself and the construction.
1769
1770Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1771Rect to construction.
1772
Cary Clark5538c132018-06-14 12:28:14 -04001773#Param left x-axis minimum of constructed Rect ##
1774#Param top y-axis minimum of constructed Rect ##
1775#Param right x-axis maximum of constructed Rect ##
1776#Param bottom y-axis maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001777
1778#Example
Cary Clark154beea2017-10-26 07:58:48 -04001779 SkRect rect = { 10, 20, 15, 25};
1780 rect.join(50, 60, 55, 65);
1781 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001782#StdOut
1783 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001784##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001785##
1786
Cary Clark7fc1d122017-10-09 14:07:42 -04001787#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001788
1789##
1790
Cary Clark7fc1d122017-10-09 14:07:42 -04001791# ------------------------------------------------------------------------------
1792
Cary Clarkbc5697d2017-10-04 14:31:33 -04001793#Method void join(const SkRect& r)
1794
Cary Clarkab2621d2018-01-30 10:08:57 -05001795#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001796Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001797
Cary Clark7fc1d122017-10-09 14:07:42 -04001798Has no effect if r is empty. Otherwise, if Rect is empty, sets
1799Rect to r.
1800
1801#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001802
1803#Example
Cary Clark154beea2017-10-26 07:58:48 -04001804 SkRect rect = { 10, 20, 15, 25};
1805 rect.join({50, 60, 55, 65});
1806 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001807#StdOut
1808 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001809##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001810##
1811
Cary Clark7fc1d122017-10-09 14:07:42 -04001812#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001813
1814##
1815
Cary Clark7fc1d122017-10-09 14:07:42 -04001816# ------------------------------------------------------------------------------
1817
Cary Clarkbc5697d2017-10-04 14:31:33 -04001818#Method void joinNonEmptyArg(const SkRect& r)
1819
Cary Clarkab2621d2018-01-30 10:08:57 -05001820#In Join
1821#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001822Sets Rect to the union of itself and r.
1823
1824Asserts if r is empty and SK_DEBUG is defined.
1825If Rect is empty, sets Rect to r.
1826
1827May produce incorrect results if r is empty.
1828
1829#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001830
1831#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001832#Description
1833Since Rect is not sorted, first result is copy of toJoin.
1834##
Cary Clark154beea2017-10-26 07:58:48 -04001835 SkRect rect = { 10, 100, 15, 0};
1836 SkRect sorted = rect.makeSorted();
1837 SkRect toJoin = { 50, 60, 55, 65 };
1838 rect.joinNonEmptyArg(toJoin);
1839 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1840 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001841 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1842#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001843rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001844sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001845##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001846##
1847
Cary Clark7fc1d122017-10-09 14:07:42 -04001848#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001849
1850##
1851
Cary Clark7fc1d122017-10-09 14:07:42 -04001852# ------------------------------------------------------------------------------
1853
Cary Clarkbc5697d2017-10-04 14:31:33 -04001854#Method void joinPossiblyEmptyRect(const SkRect& r)
1855
Cary Clarkab2621d2018-01-30 10:08:57 -05001856#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001857#Line # sets to union of bounds; skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001858Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001859
Cary Clark7fc1d122017-10-09 14:07:42 -04001860May produce incorrect results if Rect or r is empty.
1861
1862#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001863
1864#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001865#Description
1866Since Rect is not sorted, first result is not useful.
1867##
Cary Clark154beea2017-10-26 07:58:48 -04001868 SkRect rect = { 10, 100, 15, 0};
1869 SkRect sorted = rect.makeSorted();
1870 SkRect toJoin = { 50, 60, 55, 65 };
1871 rect.joinPossiblyEmptyRect(toJoin);
1872 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1873 sorted.joinPossiblyEmptyRect(toJoin);
1874 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001875#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001876rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001877sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001878##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001879##
1880
Cary Clark7fc1d122017-10-09 14:07:42 -04001881#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001882
1883##
1884
Cary Clark2dc84ad2018-01-26 12:56:22 -05001885#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001886
Cary Clark2dc84ad2018-01-26 12:56:22 -05001887#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001888#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001889
Cary Clarkbc5697d2017-10-04 14:31:33 -04001890#Method void round(SkIRect* dst) const
1891
Cary Clarkab2621d2018-01-30 10:08:57 -05001892#In Rounding
1893#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001894Sets IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04001895members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1896 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001897
Cary Clark7fc1d122017-10-09 14:07:42 -04001898#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001899
1900#Example
Cary Clark154beea2017-10-26 07:58:48 -04001901 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1902 SkIRect round;
1903 rect.round(&round);
1904 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001905#StdOut
1906round: 31, 51, 41, 61
1907##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001908##
1909
Cary Clark7fc1d122017-10-09 14:07:42 -04001910#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001911
1912##
1913
Cary Clark7fc1d122017-10-09 14:07:42 -04001914# ------------------------------------------------------------------------------
1915
Cary Clarkbc5697d2017-10-04 14:31:33 -04001916#Method void roundOut(SkIRect* dst) const
1917
Cary Clarkab2621d2018-01-30 10:08:57 -05001918#In Rounding
1919#Line # sets members to nearest integer value away from opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001920Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
1921up fRight and fBottom, using
1922#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1923 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001924
Cary Clark7fc1d122017-10-09 14:07:42 -04001925#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001926
1927#Example
Cary Clark154beea2017-10-26 07:58:48 -04001928 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1929 SkIRect round;
1930 rect.roundOut(&round);
1931 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001932#StdOut
1933round: 30, 50, 41, 61
1934##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001935##
1936
Cary Clark7fc1d122017-10-09 14:07:42 -04001937#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001938
1939##
1940
Cary Clark7fc1d122017-10-09 14:07:42 -04001941# ------------------------------------------------------------------------------
1942
Cary Clark682c58d2018-05-16 07:07:07 -04001943#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001944
Cary Clarkab2621d2018-01-30 10:08:57 -05001945#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04001946Sets Rect by discarding the fractional portion of fLeft and fTop; and rounding
1947up fRight and fBottom, using
1948#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1949 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001950
Cary Clark7fc1d122017-10-09 14:07:42 -04001951#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001952
1953#Example
Cary Clark154beea2017-10-26 07:58:48 -04001954 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1955 SkRect round;
1956 rect.roundOut(&round);
1957 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001958#StdOut
1959round: 30, 50, 41, 61
1960##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001961##
1962
Cary Clark7fc1d122017-10-09 14:07:42 -04001963#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001964
1965##
1966
Cary Clark7fc1d122017-10-09 14:07:42 -04001967# ------------------------------------------------------------------------------
1968
Cary Clarkbc5697d2017-10-04 14:31:33 -04001969#Method void roundIn(SkIRect* dst) const
1970
Cary Clarkab2621d2018-01-30 10:08:57 -05001971#In Rounding
1972#Line # sets members to nearest integer value towards opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001973Sets Rect by rounding up fLeft and fTop; and discarding the fractional portion
1974of fRight and fBottom, using
1975#Formula # (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1976 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977
Cary Clark7fc1d122017-10-09 14:07:42 -04001978#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001979
1980#Example
Cary Clark154beea2017-10-26 07:58:48 -04001981 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1982 SkIRect round;
1983 rect.roundIn(&round);
1984 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001985#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001986round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04001987##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001988##
1989
Cary Clark7fc1d122017-10-09 14:07:42 -04001990#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001991
1992##
1993
Cary Clark7fc1d122017-10-09 14:07:42 -04001994# ------------------------------------------------------------------------------
1995
Cary Clarkbc5697d2017-10-04 14:31:33 -04001996#Method SkIRect round() const
1997
Cary Clarkab2621d2018-01-30 10:08:57 -05001998#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04001999Returns IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04002000members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2001 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002002
Cary Clark7fc1d122017-10-09 14:07:42 -04002003#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002004
2005#Example
Cary Clark154beea2017-10-26 07:58:48 -04002006 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2007 SkIRect round = rect.round();
2008 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002009#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002010round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002011##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002012##
2013
Cary Clark7fc1d122017-10-09 14:07:42 -04002014#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002015
2016##
2017
Cary Clark7fc1d122017-10-09 14:07:42 -04002018# ------------------------------------------------------------------------------
2019
Cary Clarkbc5697d2017-10-04 14:31:33 -04002020#Method SkIRect roundOut() const
2021
Cary Clarkab2621d2018-01-30 10:08:57 -05002022#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04002023Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
2024up fRight and fBottom, using
2025#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2026 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002027
Cary Clark7fc1d122017-10-09 14:07:42 -04002028#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002029
2030#Example
Cary Clark154beea2017-10-26 07:58:48 -04002031 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2032 SkIRect round = rect.roundOut();
2033 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002034#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002035round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002036##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002037##
2038
Cary Clark7fc1d122017-10-09 14:07:42 -04002039#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002040
2041##
2042
Cary Clark2dc84ad2018-01-26 12:56:22 -05002043#Subtopic Rounding ##
2044
2045#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05002046#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05002047
Cary Clark7fc1d122017-10-09 14:07:42 -04002048# ------------------------------------------------------------------------------
2049
Cary Clarkbc5697d2017-10-04 14:31:33 -04002050#Method void sort()
2051
Cary Clarkab2621d2018-01-30 10:08:57 -05002052#In Sorting
2053#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002054Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2055fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2056and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002057
2058#Example
Cary Clark154beea2017-10-26 07:58:48 -04002059 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2060 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2061 rect.sort();
2062 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002063#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002064rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002065sorted: 20.5, 10.5, 30.5, 50.5
2066##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002067##
2068
Cary Clark2dc84ad2018-01-26 12:56:22 -05002069#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002070
2071##
2072
Cary Clark7fc1d122017-10-09 14:07:42 -04002073# ------------------------------------------------------------------------------
2074
Cary Clarkbc5697d2017-10-04 14:31:33 -04002075#Method SkRect makeSorted() const
2076
Cary Clarkab2621d2018-01-30 10:08:57 -05002077#In Sorting
Cary Clark61313f32018-10-08 14:57:48 -04002078#In Constructors
Cary Clark682c58d2018-05-16 07:07:07 -04002079#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002080Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2081with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2082and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002083
Cary Clark7fc1d122017-10-09 14:07:42 -04002084#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002085
2086#Example
Cary Clark154beea2017-10-26 07:58:48 -04002087 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2088 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2089 SkRect sort = rect.makeSorted();
2090 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002091#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002092rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002093sorted: 20.5, 10.5, 30.5, 50.5
2094##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002095##
2096
Cary Clark2dc84ad2018-01-26 12:56:22 -05002097#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002098
2099##
2100
Cary Clark2dc84ad2018-01-26 12:56:22 -05002101#Subtopic Sorting ##
2102
Cary Clark7fc1d122017-10-09 14:07:42 -04002103# ------------------------------------------------------------------------------
2104
Cary Clarkbc5697d2017-10-04 14:31:33 -04002105#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05002106#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002107#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002108Returns pointer to first Scalar in Rect, to treat it as an array with four
2109entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002110
Cary Clark7fc1d122017-10-09 14:07:42 -04002111#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002112
2113#Example
Cary Clark154beea2017-10-26 07:58:48 -04002114 SkRect rect = {7, 11, 13, 17};
2115SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2116#StdOut
2117rect.asScalars() == &rect.fLeft
2118##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119##
2120
Cary Clark7fc1d122017-10-09 14:07:42 -04002121#SeeAlso toQuad
2122
Cary Clarkbc5697d2017-10-04 14:31:33 -04002123##
2124
Cary Clark7fc1d122017-10-09 14:07:42 -04002125# ------------------------------------------------------------------------------
2126
Cary Clarkbc5697d2017-10-04 14:31:33 -04002127#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05002128#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002129#Line # sends text representation to standard output using floats ##
Cary Clark682c58d2018-05-16 07:07:07 -04002130Writes text representation of Rect to standard output. Set asHex to true to
Cary Clark7fc1d122017-10-09 14:07:42 -04002131generate exact binary representations of floating point numbers.
2132
2133#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002134
2135#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002136 SkRect rect = {20, 30, 40, 50};
2137 for (bool dumpAsHex : { false, true } ) {
2138 rect.dump(dumpAsHex);
2139 SkDebugf("\n");
2140 }
2141#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002142SkRect::MakeLTRB(20, 30, 40, 50);
2143
2144SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2145 SkBits2Float(0x41f00000), /* 30.000000 */
2146 SkBits2Float(0x42200000), /* 40.000000 */
2147 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002148##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002149##
2150
Cary Clark7fc1d122017-10-09 14:07:42 -04002151#SeeAlso dumpHex
2152
Cary Clarkbc5697d2017-10-04 14:31:33 -04002153##
2154
Cary Clark7fc1d122017-10-09 14:07:42 -04002155# ------------------------------------------------------------------------------
2156
Cary Clarkbc5697d2017-10-04 14:31:33 -04002157#Method void dump() const
2158
Cary Clark7fc1d122017-10-09 14:07:42 -04002159Writes text representation of Rect to standard output. The representation may be
2160directly compiled as C++ code. Floating point values are written
2161with limited precision; it may not be possible to reconstruct original Rect
2162from output.
2163
Cary Clarkbc5697d2017-10-04 14:31:33 -04002164#Example
Cary Clark154beea2017-10-26 07:58:48 -04002165SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2166rect.dump();
2167SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2168SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002169#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002170SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002171rect is not equal to copy
2172##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002173##
2174
Cary Clark7fc1d122017-10-09 14:07:42 -04002175#SeeAlso dumpHex
2176
Cary Clarkbc5697d2017-10-04 14:31:33 -04002177##
2178
Cary Clark7fc1d122017-10-09 14:07:42 -04002179# ------------------------------------------------------------------------------
2180
Cary Clarkbc5697d2017-10-04 14:31:33 -04002181#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05002182#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05002183#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002184Writes text representation of Rect to standard output. The representation may be
2185directly compiled as C++ code. Floating point values are written
2186in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2187original Rect.
2188
Cary Clark682c58d2018-05-16 07:07:07 -04002189Use instead of dump() when submitting
2190#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002191.
2192
Cary Clarkbc5697d2017-10-04 14:31:33 -04002193#Example
Cary Clark154beea2017-10-26 07:58:48 -04002194 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2195rect.dumpHex();
2196SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2197 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2198 SkBits2Float(0x40266666), /* 2.600000 */
2199 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002200SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2201#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002202SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2203 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2204 SkBits2Float(0x40266666), /* 2.600000 */
2205 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002206rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002207##
Cary Clark7fc1d122017-10-09 14:07:42 -04002208##
2209
2210#SeeAlso dump
Cary Clark69261ba2018-10-11 15:28:31 -04002211
2212##
2213
2214#Struct SkRect ##
2215
2216#Topic Rect ##