blob: fa34825db0e9bc85c9dd5828d674ebb57b90cd15 [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 Clark09d80c02018-10-31 12:14:03 -040051#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040052
53#Example
Cary Clark154beea2017-10-26 07:58:48 -040054 SkRect rect = SkRect::MakeEmpty();
55 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
56 rect.offset(10, 10);
57 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
58 rect.inset(10, 10);
59 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
60 rect.outset(20, 20);
61 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
62#StdOut
63MakeEmpty isEmpty: true
64offset rect isEmpty: true
65inset rect isEmpty: true
66outset rect isEmpty: false
67##
Cary Clarkbc5697d2017-10-04 14:31:33 -040068##
69
Mike Reed274218e2018-01-08 15:05:02 -050070#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -040071
72##
73
74# ------------------------------------------------------------------------------
75
Cary Clark61313f32018-10-08 14:57:48 -040076#Method static constexpr SkRect MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -040077
Cary Clark61313f32018-10-08 14:57:48 -040078#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050079#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -040080#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -040081
82#Example
Cary Clark154beea2017-10-26 07:58:48 -040083 SkRect rect1 = SkRect::MakeWH(25, 35);
84 SkRect rect2 = SkRect::MakeIWH(25, 35);
85 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
86 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
87 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -040088 "" : "not ");
89#StdOut
90all equal
91##
Cary Clarkbc5697d2017-10-04 14:31:33 -040092##
93
Cary Clark7fc1d122017-10-09 14:07:42 -040094#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -040095
96##
97
98# ------------------------------------------------------------------------------
99
Cary Clark61313f32018-10-08 14:57:48 -0400100#Method static SkRect MakeIWH(int w, int h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400101
Cary Clark61313f32018-10-08 14:57:48 -0400102#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500103#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400104#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400105
106#Example
Cary Clark154beea2017-10-26 07:58:48 -0400107 SkIRect i_rect = SkIRect::MakeWH(25, 35);
108 SkRect f_rect = SkRect::MakeIWH(25, 35);
109 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
110 i_rect = SkIRect::MakeWH(125000111, 0);
111 f_rect = SkRect::MakeIWH(125000111, 0);
112 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400113#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400114i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400115i_rect width: 125000111 f_rect width:125000112
116##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400117##
118
Cary Clark7fc1d122017-10-09 14:07:42 -0400119#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400120
121##
122
123# ------------------------------------------------------------------------------
124
Cary Clark61313f32018-10-08 14:57:48 -0400125#Method static constexpr SkRect MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400126
Cary Clark61313f32018-10-08 14:57:48 -0400127#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500128#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400129#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400130
131#Example
Cary Clark154beea2017-10-26 07:58:48 -0400132 SkSize size = {25.5f, 35.5f};
133 SkRect rect = SkRect::MakeSize(size);
134 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
135 SkISize floor = size.toFloor();
136 rect = SkRect::MakeSize(SkSize::Make(floor));
137 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400138#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400139rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400140floor width: 25 height: 35
141##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400142##
143
Cary Clark7fc1d122017-10-09 14:07:42 -0400144#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400145
146##
147
148# ------------------------------------------------------------------------------
149
Cary Clark61313f32018-10-08 14:57:48 -0400150#Method static constexpr SkRect MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
Cary Clarkbc5697d2017-10-04 14:31:33 -0400151 SkScalar b)
Cary Clark61313f32018-10-08 14:57:48 -0400152#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500153#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clark09d80c02018-10-31 12:14:03 -0400154#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400155
156#Example
Cary Clark154beea2017-10-26 07:58:48 -0400157 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
158 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
159 rect.bottom(), rect.isEmpty() ? "true" : "false");
160 rect.sort();
161 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
162 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400163#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400164rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400165rect: 5, 25, 15, 35 isEmpty: false
166##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400167##
168
Cary Clark7fc1d122017-10-09 14:07:42 -0400169#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400170
171##
172
173# ------------------------------------------------------------------------------
174
Cary Clark61313f32018-10-08 14:57:48 -0400175#Method static constexpr SkRect MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400176
Cary Clark61313f32018-10-08 14:57:48 -0400177#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500178#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400179Returns constructed Rect set to #Formula # (x, y, x + w, y + h) ##.
180Does not validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400181
Cary Clark7fc1d122017-10-09 14:07:42 -0400182#Param x stored in fLeft ##
183#Param y stored in fTop ##
184#Param w added to x and stored in fRight ##
185#Param h added to y and stored in fBottom ##
186
Cary Clark884dd7d2017-10-11 10:37:52 -0400187#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400188
189#Example
Cary Clark154beea2017-10-26 07:58:48 -0400190 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
191 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
192 rect.bottom(), rect.isEmpty() ? "true" : "false");
193 rect.sort();
194 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
195 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400196#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400197rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400198rect: -10, 35, 5, 60 isEmpty: false
199##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400200##
201
Cary Clark7fc1d122017-10-09 14:07:42 -0400202#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400203
204##
205
206# ------------------------------------------------------------------------------
207
Cary Clarkbc5697d2017-10-04 14:31:33 -0400208#Method static SkRect Make(const SkISize& size)
209
Cary Clark61313f32018-10-08 14:57:48 -0400210#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -0500211#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clarka64e4ee2018-10-18 08:30:34 -0400212#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400213
214#Example
Cary Clark154beea2017-10-26 07:58:48 -0400215 SkRect rect1 = SkRect::MakeSize({2, 35});
216 SkRect rect2 = SkRect::MakeIWH(2, 35);
217 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400218#StdOut
219rect1 == rect2
220##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400221##
222
Cary Clark7fc1d122017-10-09 14:07:42 -0400223#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400224
225##
226
227# ------------------------------------------------------------------------------
228
Cary Clark61313f32018-10-08 14:57:48 -0400229#Method static SkRect Make(const SkIRect& irect)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400230
Cary Clark61313f32018-10-08 14:57:48 -0400231#In Constructors
Cary Clark09d80c02018-10-31 12:14:03 -0400232#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400233
234#Example
Cary Clark154beea2017-10-26 07:58:48 -0400235 SkIRect i_rect1 = {2, 35, 22, 53};
236 SkRect f_rect = SkRect::Make(i_rect1);
237 f_rect.offset(0.49f, 0.49f);
238 SkIRect i_rect2;
239 f_rect.round(&i_rect2);
240 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400241##
242
Cary Clark7fc1d122017-10-09 14:07:42 -0400243#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400244
245##
246
Cary Clark4855f782018-02-06 09:41:53 -0500247#Subtopic Property
248#Line # member values, center, validity ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500249
Cary Clarkbc5697d2017-10-04 14:31:33 -0400250# ------------------------------------------------------------------------------
251
252#Method bool isEmpty() const
253
Cary Clark4855f782018-02-06 09:41:53 -0500254#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500255#Line # returns true if width or height are zero or negative ##
Cary Clark09d80c02018-10-31 12:14:03 -0400256#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400257
258#Example
Cary Clark154beea2017-10-26 07:58:48 -0400259 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
260 for (auto rect : tests) {
261 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
262 rect.bottom(), rect.isEmpty() ? "" : " not");
263 rect.sort();
264 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
265 rect.bottom(), rect.isEmpty() ? "" : " not");
266 }
267#StdOut
268rect: {20, 40, 10, 50} is empty
269sorted: {10, 40, 20, 50} is not empty
270rect: {20, 40, 20, 50} is empty
271sorted: {20, 40, 20, 50} is empty
272##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400273##
274
Cary Clark7fc1d122017-10-09 14:07:42 -0400275#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400276
277##
278
279# ------------------------------------------------------------------------------
280
281#Method bool isSorted() const
282
Cary Clark4855f782018-02-06 09:41:53 -0500283#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500284#Line # returns true if width or height are zero or positive ##
Cary Clark09d80c02018-10-31 12:14:03 -0400285#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400286
287#Example
Cary Clark154beea2017-10-26 07:58:48 -0400288 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
289 for (auto rect : tests) {
290 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
291 rect.bottom(), rect.isSorted() ? "" : " not");
292 rect.sort();
293 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
294 rect.bottom(), rect.isSorted() ? "" : " not");
295 }
296#StdOut
297rect: {20, 40, 10, 50} is not sorted
298sorted: {10, 40, 20, 50} is sorted
299rect: {20, 40, 20, 50} is sorted
300sorted: {20, 40, 20, 50} is sorted
301##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400302##
303
Cary Clark7fc1d122017-10-09 14:07:42 -0400304#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400305
306##
307
308# ------------------------------------------------------------------------------
309
Cary Clarkbc5697d2017-10-04 14:31:33 -0400310#Method bool isFinite() const
311
Cary Clark4855f782018-02-06 09:41:53 -0500312#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500313#Line # returns true if no member is infinite or NaN ##
Cary Clark09d80c02018-10-31 12:14:03 -0400314#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400315
316#Example
Mike Reed274218e2018-01-08 15:05:02 -0500317SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400318 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
319 SkDebugf("large width %g\n", largest.width());
320 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
321 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
322#StdOut
323largest is finite: true
324large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400325widest is finite: false
326##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400327##
328
Cary Clark7fc1d122017-10-09 14:07:42 -0400329#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400330
331##
332
333# ------------------------------------------------------------------------------
334
335#Method SkScalar x() const
336
Cary Clark4855f782018-02-06 09:41:53 -0500337#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500338#Line # returns bounds left ##
Cary Clark09d80c02018-10-31 12:14:03 -0400339#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400340
341#Example
Cary Clark154beea2017-10-26 07:58:48 -0400342 SkRect unsorted = { 15, 5, 10, 25 };
343 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
344 SkRect sorted = unsorted.makeSorted();
345 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400346#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400347unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400348sorted.fLeft: 10 sorted.x(): 10
349##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400350##
351
Cary Clark7fc1d122017-10-09 14:07:42 -0400352#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400353
354##
355
356# ------------------------------------------------------------------------------
357
358#Method SkScalar y() const
359
Cary Clark4855f782018-02-06 09:41:53 -0500360#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500361#Line # returns bounds top ##
Cary Clark09d80c02018-10-31 12:14:03 -0400362#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400363
364#Example
Cary Clark154beea2017-10-26 07:58:48 -0400365 SkRect unsorted = { 15, 25, 10, 5 };
366 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
367 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400368 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
369#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400370unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400371sorted.fTop: 5 sorted.y(): 5
372##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400373##
374
Cary Clark7fc1d122017-10-09 14:07:42 -0400375#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400376
377##
378
379# ------------------------------------------------------------------------------
380
381#Method SkScalar left() const
382
Cary Clark4855f782018-02-06 09:41:53 -0500383#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500384#Line # returns smaller bounds in x, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400385#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400386
387#Example
Cary Clark154beea2017-10-26 07:58:48 -0400388 SkRect unsorted = { 15, 5, 10, 25 };
389 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
390 SkRect sorted = unsorted.makeSorted();
391 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400392#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400393unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400394sorted.fLeft: 10 sorted.left(): 10
395##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400396##
397
Cary Clark7fc1d122017-10-09 14:07:42 -0400398#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400399
400##
401
402# ------------------------------------------------------------------------------
403
404#Method SkScalar top() const
405
Cary Clark4855f782018-02-06 09:41:53 -0500406#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500407#Line # returns smaller bounds in y, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400408#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400409
410#Example
Cary Clark154beea2017-10-26 07:58:48 -0400411 SkRect unsorted = { 15, 25, 10, 5 };
412 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
413 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400414 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
415#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400416unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400417sorted.fTop: 5 sorted.top(): 5
418##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400419##
420
Cary Clark7fc1d122017-10-09 14:07:42 -0400421#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400422
423##
424
425# ------------------------------------------------------------------------------
426
427#Method SkScalar right() const
428
Cary Clark4855f782018-02-06 09:41:53 -0500429#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500430#Line # returns larger bounds in x, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400431#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400432
433#Example
Cary Clark154beea2017-10-26 07:58:48 -0400434 SkRect unsorted = { 15, 25, 10, 5 };
435 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
436 SkRect sorted = unsorted.makeSorted();
437 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400438#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400439unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400440sorted.fRight: 15 sorted.right(): 15
441##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400442##
443
Cary Clark7fc1d122017-10-09 14:07:42 -0400444#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400445
446##
447
448# ------------------------------------------------------------------------------
449
450#Method SkScalar bottom() const
451
Cary Clark4855f782018-02-06 09:41:53 -0500452#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500453#Line # returns larger bounds in y, if sorted ##
Cary Clark09d80c02018-10-31 12:14:03 -0400454#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400455
456#Example
Cary Clark154beea2017-10-26 07:58:48 -0400457 SkRect unsorted = { 15, 25, 10, 5 };
458 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
459 SkRect sorted = unsorted.makeSorted();
460 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400461#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400462unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400463sorted.fBottom: 25 sorted.bottom(): 25
464##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400465##
466
Cary Clark7fc1d122017-10-09 14:07:42 -0400467#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400468
469##
470
471# ------------------------------------------------------------------------------
472
473#Method SkScalar width() const
474
Cary Clark4855f782018-02-06 09:41:53 -0500475#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500476#Line # returns span in x ##
Cary Clark09d80c02018-10-31 12:14:03 -0400477#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400478
479#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400480#Description
481Compare with SkIRect::width() example.
482##
Cary Clark154beea2017-10-26 07:58:48 -0400483 SkRect unsorted = { 15, 25, 10, 5 };
484 SkDebugf("unsorted width: %g\n", unsorted.width());
485 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
486 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400487#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400488unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400489large width: 4294967296
490##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400491##
492
Cary Clark7fc1d122017-10-09 14:07:42 -0400493#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400494
495##
496
497# ------------------------------------------------------------------------------
498
499#Method SkScalar height() const
500
Cary Clark4855f782018-02-06 09:41:53 -0500501#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500502#Line # returns span in y ##
Cary Clark09d80c02018-10-31 12:14:03 -0400503#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400504
505#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400506#Description
507Compare with SkIRect::height() example.
508##
Cary Clark154beea2017-10-26 07:58:48 -0400509 SkRect unsorted = { 15, 25, 10, 20 };
510 SkDebugf("unsorted height: %g\n", unsorted.height());
511 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
512 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400513#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400514unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400515large height: 4294967296
516##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400517##
518
Cary Clark7fc1d122017-10-09 14:07:42 -0400519#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400520
521##
522
523# ------------------------------------------------------------------------------
524
525#Method SkScalar centerX() const
526
Cary Clark4855f782018-02-06 09:41:53 -0500527#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500528#Line # returns midpoint in x ##
Cary Clark09d80c02018-10-31 12:14:03 -0400529#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400530
531#Example
Cary Clark154beea2017-10-26 07:58:48 -0400532 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
533 for (auto rect : tests) {
534 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
535 rect.sort();
536 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
537 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400538#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400539left: 20 right: 41 centerX: 30.5
540left: 20 right: 41 centerX: 30.5
541left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400542left: -41 right: -20 centerX: -30.5
543##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400544##
545
Cary Clark47d7dae2018-04-11 16:54:35 -0400546#SeeAlso centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400547
548##
549
550# ------------------------------------------------------------------------------
551
552#Method SkScalar centerY() const
553
Cary Clark4855f782018-02-06 09:41:53 -0500554#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500555#Line # returns midpoint in y ##
Cary Clark09d80c02018-10-31 12:14:03 -0400556#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400557
558#Example
Cary Clark154beea2017-10-26 07:58:48 -0400559 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
560 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
561 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400562#StdOut
Cary Clark75fd4492018-06-20 12:45:16 -0400563left: 2e+38 right: 3e+38 centerX: 2.5e+38 safe mid x: 2.5e+38
Cary Clark7fc1d122017-10-09 14:07:42 -0400564##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400565##
566
Cary Clark47d7dae2018-04-11 16:54:35 -0400567#SeeAlso centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400568
569##
570
Cary Clark4855f782018-02-06 09:41:53 -0500571#Subtopic Property ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500572
Cary Clark61313f32018-10-08 14:57:48 -0400573#Subtopic Operators
Cary Clark2dc84ad2018-01-26 12:56:22 -0500574
Cary Clarkbc5697d2017-10-04 14:31:33 -0400575# ------------------------------------------------------------------------------
576
Cary Clark884dd7d2017-10-11 10:37:52 -0400577#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400578
Cary Clark61313f32018-10-08 14:57:48 -0400579#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500580#Line # returns true if members are equal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400581#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400582
583#Example
Cary Clark154beea2017-10-26 07:58:48 -0400584 auto debugster = [](const SkRect& test) -> void {
585 SkRect negZero = {-0.0f, -0.0f, 2, 2};
586 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
587 test.fLeft, test.fTop, test.fRight, test.fBottom,
588 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
589 test == negZero ? '=' : '!',
590 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
591 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
592 "and are" : "yet are not");
593 };
594 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
595 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
596 for (auto rect : tests) {
597 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400598 }
Cary Clark154beea2017-10-26 07:58:48 -0400599#StdOut
600tests are equal
601{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
602{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark682c58d2018-05-16 07:07:07 -0400603{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400604##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400605##
606
Cary Clark7fc1d122017-10-09 14:07:42 -0400607#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400608
609##
610
611# ------------------------------------------------------------------------------
612
Cary Clark884dd7d2017-10-11 10:37:52 -0400613#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400614
Cary Clark61313f32018-10-08 14:57:48 -0400615#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500616#Line # returns true if members are unequal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400617#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400618
619#Example
Cary Clark154beea2017-10-26 07:58:48 -0400620 SkRect test = {0, 0, 2, SK_ScalarNaN};
621 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
622#StdOut
Cary Clark682c58d2018-05-16 07:07:07 -0400623test with NaN is not equal to itself
Cary Clark7fc1d122017-10-09 14:07:42 -0400624##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400625##
626
Cary Clark7fc1d122017-10-09 14:07:42 -0400627#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400628
629##
630
Cary Clark61313f32018-10-08 14:57:48 -0400631#Subtopic Operators ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500632
633#Subtopic As_Points
Cary Clark08895c42018-02-01 09:37:32 -0500634#Line # conversion to and from Points ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500635
Cary Clarkbc5697d2017-10-04 14:31:33 -0400636# ------------------------------------------------------------------------------
637
638#Method void toQuad(SkPoint quad[4]) const
639
Cary Clarkab2621d2018-01-30 10:08:57 -0500640#In As_Points
641#Line # returns four corners as Point ##
Cary Clarkabaffd82018-11-15 08:25:12 -0500642#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400643
644#Example
Cary Clark154beea2017-10-26 07:58:48 -0400645 SkRect rect = {1, 2, 3, 4};
646 SkPoint corners[4];
647 rect.toQuad(corners);
648 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
649 SkDebugf("corners:");
650 for (auto corner : corners) {
651 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
652 }
653 SkDebugf("\n");
654#StdOut
655rect: {1, 2, 3, 4}
Cary Clark682c58d2018-05-16 07:07:07 -0400656corners: {1, 2} {3, 2} {3, 4} {1, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400657##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400658##
659
Cary Clark7fc1d122017-10-09 14:07:42 -0400660#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400661
662##
663
664# ------------------------------------------------------------------------------
665
Cary Clark2dc84ad2018-01-26 12:56:22 -0500666#Method void setBounds(const SkPoint pts[], int count)
667
Cary Clarkab2621d2018-01-30 10:08:57 -0500668#In As_Points
669#Line # sets to upper and lower limits of Point array ##
Cary Clark09d80c02018-10-31 12:14:03 -0400670#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500671
672#Example
673 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
674 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
675 SkRect rect;
676 rect.setBounds(points, count);
677 if (count > 0) {
678 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
679 } else {
680 SkDebugf("%14s", " ");
681 }
682 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
683 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
684 }
685#StdOut
686 count: 0 rect: 0, 0, 0, 0
687added: 3, 4 count: 1 rect: 3, 4, 3, 4
688added: 1, 2 count: 2 rect: 1, 2, 3, 4
689added: 5, 6 count: 3 rect: 1, 2, 5, 6
690added: nan, 8 count: 4 rect: 0, 0, 0, 0
691##
692##
693
694#SeeAlso set setBoundsCheck SkPath::addPoly
695
696##
697
698# ------------------------------------------------------------------------------
699
700#Method bool setBoundsCheck(const SkPoint pts[], int count)
701
Cary Clarkab2621d2018-01-30 10:08:57 -0500702#In As_Points
703#Line # sets to upper and lower limits of Point array ##
Cary Clark09d80c02018-10-31 12:14:03 -0400704#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500705
706#Example
707 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
708 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
709 SkRect rect;
710 bool success = rect.setBoundsCheck(points, count);
711 if (count > 0) {
712 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
713 } else {
714 SkDebugf("%14s", " ");
715 }
716 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
717 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
718 }
719#StdOut
720 count: 0 rect: 0, 0, 0, 0 success: true
721added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
722added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
723added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
724added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
725##
726##
727
728#SeeAlso set setBounds SkPath::addPoly
729
730##
731
732#Subtopic As_Points ##
733
734#Subtopic Set
Cary Clark08895c42018-02-01 09:37:32 -0500735#Line # replaces all values ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500736
737# ------------------------------------------------------------------------------
738
Cary Clarkc06754b2018-05-16 21:28:55 -0400739#Method void setBoundsNoCheck(const SkPoint pts[], int count)
740#In Set
741#Line # sets to upper and lower limits of Point array ##
Cary Clark09d80c02018-10-31 12:14:03 -0400742#Populate
Cary Clarkc06754b2018-05-16 21:28:55 -0400743
744#Example
Cary Clark8f288d92018-05-17 15:16:57 -0400745 SkPoint points[] = {{3, 4}, {1, 2}, {SK_ScalarInfinity, 6}, {SK_ScalarNaN, 8}};
Cary Clarkffb3d682018-05-17 12:17:28 -0400746 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
747 SkRect rect;
748 rect.setBoundsNoCheck(points, count);
749 if (count > 0) {
750 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
751 } else {
752 SkDebugf("%14s", " ");
753 }
754 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
755 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
756 }
Cary Clarkc06754b2018-05-16 21:28:55 -0400757##
758
759#SeeAlso setBoundsCheck
760#Method ##
761
762# ------------------------------------------------------------------------------
763
Cary Clarkbc5697d2017-10-04 14:31:33 -0400764#Method void setEmpty()
765
Cary Clarkab2621d2018-01-30 10:08:57 -0500766#In Set
767#Line # sets to (0, 0, 0, 0) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400768#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400769
770#Example
Cary Clark154beea2017-10-26 07:58:48 -0400771 SkRect rect = {3, 4, 1, 2};
772 for (int i = 0; i < 2; ++i) {
773 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
774 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
775 rect.setEmpty();
776 }
777#StdOut
778rect: {3, 4, 1, 2} is empty
779rect: {0, 0, 0, 0} is empty
780##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400781##
782
Cary Clark7fc1d122017-10-09 14:07:42 -0400783#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400784
785##
786
787# ------------------------------------------------------------------------------
788
789#Method void set(const SkIRect& src)
790
Cary Clarkab2621d2018-01-30 10:08:57 -0500791#In Set
792#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark09d80c02018-10-31 12:14:03 -0400793#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400794
795#Example
Cary Clark154beea2017-10-26 07:58:48 -0400796 SkIRect i_rect = {3, 4, 1, 2};
797 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
798 SkRect f_rect;
799 f_rect.set(i_rect);
800 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
801#StdOut
802i_rect: {3, 4, 1, 2}
803f_rect: {3, 4, 1, 2}
804##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400805##
806
Cary Clark7fc1d122017-10-09 14:07:42 -0400807#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400808
809##
810
811# ------------------------------------------------------------------------------
812
813#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
814
Cary Clarkab2621d2018-01-30 10:08:57 -0500815#In Set
Cary Clark09d80c02018-10-31 12:14:03 -0400816#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400817
818#Example
Cary Clark154beea2017-10-26 07:58:48 -0400819 SkRect rect1 = {3, 4, 1, 2};
820 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
821 SkRect rect2;
822 rect2.set(3, 4, 1, 2);
823 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
824#StdOut
825rect1: {3, 4, 1, 2}
826rect2: {3, 4, 1, 2}
827##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400828##
829
Cary Clark7fc1d122017-10-09 14:07:42 -0400830#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400831
832##
833
834# ------------------------------------------------------------------------------
835
836#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
837
Cary Clarkab2621d2018-01-30 10:08:57 -0500838#In Set
839#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400840#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400841
842#Example
Cary Clark154beea2017-10-26 07:58:48 -0400843 SkRect rect1 = {3, 4, 1, 2};
844 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
845 SkRect rect2;
846 rect2.setLTRB(3, 4, 1, 2);
847 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
848#StdOut
849rect1: {3, 4, 1, 2}
850rect2: {3, 4, 1, 2}
851##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400852##
853
Cary Clark7fc1d122017-10-09 14:07:42 -0400854#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400855
856##
857
858# ------------------------------------------------------------------------------
859
Cary Clarkbc5697d2017-10-04 14:31:33 -0400860#Method void set(const SkPoint pts[], int count)
861
Cary Clarkab2621d2018-01-30 10:08:57 -0500862#In Set
Cary Clark09d80c02018-10-31 12:14:03 -0400863#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400864
865#Example
Cary Clark154beea2017-10-26 07:58:48 -0400866 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
867 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
868 SkRect rect;
869 rect.set(points, count);
870 if (count > 0) {
871 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
872 } else {
873 SkDebugf("%14s", " ");
874 }
875 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
876 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
877 }
878#StdOut
879 count: 0 rect: 0, 0, 0, 0
880added: 3, 4 count: 1 rect: 3, 4, 3, 4
881added: 1, 2 count: 2 rect: 1, 2, 3, 4
882added: 5, 6 count: 3 rect: 1, 2, 5, 6
883added: nan, 8 count: 4 rect: 0, 0, 0, 0
884##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400885##
886
Cary Clark7fc1d122017-10-09 14:07:42 -0400887#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -0400888
889##
890
891# ------------------------------------------------------------------------------
892
Cary Clarkbc5697d2017-10-04 14:31:33 -0400893#Method void set(const SkPoint& p0, const SkPoint& p1)
894
Cary Clarkab2621d2018-01-30 10:08:57 -0500895#In Set
Cary Clark09d80c02018-10-31 12:14:03 -0400896#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400897
898#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400899#Description
Cary Clark682c58d2018-05-16 07:07:07 -0400900p0 and p1 may be swapped and have the same effect unless one contains NaN.
Cary Clark7fc1d122017-10-09 14:07:42 -0400901##
Cary Clark154beea2017-10-26 07:58:48 -0400902 SkPoint point1 = {SK_ScalarNaN, 8};
903 SkPoint point2 = {3, 4};
904 SkRect rect;
905 rect.set(point1, point2);
906 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
907 rect.set(point2, point1);
908 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -0400909##
910
Cary Clark7fc1d122017-10-09 14:07:42 -0400911#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -0400912
913##
914
915# ------------------------------------------------------------------------------
916
917#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
918
Cary Clarkab2621d2018-01-30 10:08:57 -0500919#In Set
920#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400921Sets Rect to #Formula # (x, y, x + width, y + height) ##.
922Does not validate input; width or height may be negative.
Cary Clark7fc1d122017-10-09 14:07:42 -0400923
924#Param x stored in fLeft ##
925#Param y stored in fTop ##
926#Param width added to x and stored in fRight ##
927#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400928
929#Example
Cary Clark154beea2017-10-26 07:58:48 -0400930 SkRect rect;
931 rect.setXYWH(5, 35, -15, 25);
932 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
933 rect.bottom(), rect.isEmpty() ? "true" : "false");
934 rect.sort();
935 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
936 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400937#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400938rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400939rect: -10, 35, 5, 60 isEmpty: false
940##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400941##
942
Cary Clark7fc1d122017-10-09 14:07:42 -0400943#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400944
945##
946
947# ------------------------------------------------------------------------------
948
949#Method void setWH(SkScalar width, SkScalar height)
950
Cary Clarkab2621d2018-01-30 10:08:57 -0500951#In Set
952#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400953#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400954
955#Example
Cary Clark154beea2017-10-26 07:58:48 -0400956 SkRect rect;
957 rect.setWH(-15, 25);
958 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
959 rect.bottom(), rect.isEmpty() ? "true" : "false");
960 rect.sort();
961 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
962 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400963#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400964rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400965rect: -15, 0, 0, 25 isEmpty: false
966##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400967##
968
Cary Clark7fc1d122017-10-09 14:07:42 -0400969#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400970
971##
972
Cary Clark2dc84ad2018-01-26 12:56:22 -0500973#Subtopic Set ##
974
975#Subtopic From_Integers
Cary Clark682c58d2018-05-16 07:07:07 -0400976#Line # sets Scalar values from integer input ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500977
Cary Clark2dc84ad2018-01-26 12:56:22 -0500978# ------------------------------------------------------------------------------
979
980#Method void iset(int left, int top, int right, int bottom)
981
Cary Clarkab2621d2018-01-30 10:08:57 -0500982#In From_Integers
983#Line # sets to int input (left, top, right, bottom) ##
Cary Clark09d80c02018-10-31 12:14:03 -0400984#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -0500985
986#Example
987 SkRect rect1 = {3, 4, 1, 2};
988 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
989 SkRect rect2;
990 rect2.iset(3, 4, 1, 2);
991 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
992#StdOut
993rect1: {3, 4, 1, 2}
994rect2: {3, 4, 1, 2}
995##
996##
997
998#SeeAlso set setLTRB SkIRect::set SkIntToScalar
999
1000##
1001
1002# ------------------------------------------------------------------------------
1003
1004#Method void isetWH(int width, int height)
1005
Cary Clarkab2621d2018-01-30 10:08:57 -05001006#In From_Integers
1007#Line # sets to int input (0, 0, width, height) ##
Cary Clark09d80c02018-10-31 12:14:03 -04001008#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001009
1010#Example
1011 SkRect rect1 = {0, 0, 1, 2};
1012 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1013 SkRect rect2;
1014 rect2.isetWH(1, 2);
1015 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1016#StdOut
1017rect1: {0, 0, 1, 2}
1018rect2: {0, 0, 1, 2}
1019##
1020##
1021
1022#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1023
1024##
1025
1026#Subtopic From_Integers ##
1027
1028#Subtopic Inset_Outset_Offset
Cary Clark08895c42018-02-01 09:37:32 -05001029#Line # moves sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001030
Cary Clarkbc5697d2017-10-04 14:31:33 -04001031# ------------------------------------------------------------------------------
1032
Cary Clarkbc5697d2017-10-04 14:31:33 -04001033#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1034
Cary Clarkab2621d2018-01-30 10:08:57 -05001035#In Inset_Outset_Offset
1036#Line # constructs from translated sides ##
Cary Clark09d80c02018-10-31 12:14:03 -04001037#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001038
1039#Example
Cary Clark154beea2017-10-26 07:58:48 -04001040 SkRect rect = { 10, 50, 20, 60 };
1041 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1042 rect.bottom(), rect.isEmpty() ? "true" : "false");
1043 rect = rect.makeOffset(15, 32);
1044 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1045 rect.bottom(), rect.isEmpty() ? "true" : "false");
1046#StdOut
1047rect: 10, 50, 20, 60 isEmpty: false
1048rect: 25, 82, 35, 92 isEmpty: false
1049##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001050##
1051
Cary Clark7fc1d122017-10-09 14:07:42 -04001052#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001053
1054##
1055
1056# ------------------------------------------------------------------------------
1057
1058#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1059
Cary Clarkab2621d2018-01-30 10:08:57 -05001060#In Inset_Outset_Offset
1061#Line # constructs from sides moved symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -04001062#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001063
1064#Example
Cary Clark154beea2017-10-26 07:58:48 -04001065 SkRect rect = { 10, 50, 20, 60 };
1066 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1067 rect.bottom(), rect.isEmpty() ? "true" : "false");
1068 rect = rect.makeInset(15, 32);
1069 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1070 rect.bottom(), rect.isEmpty() ? "true" : "false");
1071#StdOut
1072rect: 10, 50, 20, 60 isEmpty: false
1073rect: 25, 82, 5, 28 isEmpty: true
1074##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001075##
1076
Cary Clark7fc1d122017-10-09 14:07:42 -04001077#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001078
1079##
1080
1081# ------------------------------------------------------------------------------
1082
1083#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1084
Cary Clarkab2621d2018-01-30 10:08:57 -05001085#In Inset_Outset_Offset
1086#Line # constructs from sides moved symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -04001087#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001088
1089#Example
Cary Clark154beea2017-10-26 07:58:48 -04001090 SkRect rect = { 10, 50, 20, 60 };
1091 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1092 rect.bottom(), rect.isEmpty() ? "true" : "false");
1093 rect = rect.makeOutset(15, 32);
1094 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1095 rect.bottom(), rect.isEmpty() ? "true" : "false");
1096#StdOut
1097rect: 10, 50, 20, 60 isEmpty: false
1098rect: -5, 18, 35, 92 isEmpty: false
1099##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001100##
1101
Cary Clark7fc1d122017-10-09 14:07:42 -04001102#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001103
1104##
1105
1106# ------------------------------------------------------------------------------
1107
1108#Method void offset(SkScalar dx, SkScalar dy)
1109
Cary Clarkab2621d2018-01-30 10:08:57 -05001110#In Inset_Outset_Offset
1111#Line # translates sides without changing width and height ##
Cary Clark09d80c02018-10-31 12:14:03 -04001112#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001113
1114#Example
Cary Clark154beea2017-10-26 07:58:48 -04001115 SkRect rect = { 10, 14, 50, 73 };
1116 rect.offset(5, 13);
1117 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1118#StdOut
1119rect: 15, 27, 55, 86
1120##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001121##
1122
Cary Clark7fc1d122017-10-09 14:07:42 -04001123#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001124
1125##
1126
1127# ------------------------------------------------------------------------------
1128
1129#Method void offset(const SkPoint& delta)
1130
Cary Clarkab2621d2018-01-30 10:08:57 -05001131#In Inset_Outset_Offset
Cary Clark09d80c02018-10-31 12:14:03 -04001132#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001133
1134#Example
Cary Clark154beea2017-10-26 07:58:48 -04001135 SkRect rect = { 10, 14, 50, 73 };
1136 rect.offset({5, 13});
1137 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1138#StdOut
1139rect: 15, 27, 55, 86
1140##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001141##
1142
Cary Clark7fc1d122017-10-09 14:07:42 -04001143#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001144
1145##
1146
1147# ------------------------------------------------------------------------------
1148
1149#Method void offsetTo(SkScalar newX, SkScalar newY)
1150
Cary Clarkab2621d2018-01-30 10:08:57 -05001151#In Inset_Outset_Offset
1152#Line # translates to (x, y) without changing width and height ##
Cary Clark09d80c02018-10-31 12:14:03 -04001153#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001154
1155#Example
Cary Clark154beea2017-10-26 07:58:48 -04001156 SkRect rect = { 10, 14, 50, 73 };
1157 rect.offsetTo(15, 27);
1158 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1159#StdOut
1160rect: 15, 27, 55, 86
1161##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001162##
1163
Cary Clark7fc1d122017-10-09 14:07:42 -04001164#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001165
1166##
1167
1168# ------------------------------------------------------------------------------
1169
1170#Method void inset(SkScalar dx, SkScalar dy)
1171
Cary Clarkab2621d2018-01-30 10:08:57 -05001172#In Inset_Outset_Offset
1173#Line # moves the sides symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -04001174#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001175
1176#Example
Cary Clark154beea2017-10-26 07:58:48 -04001177 SkRect rect = { 10, 14, 50, 73 };
1178 rect.inset(5, 13);
1179 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1180#StdOut
1181rect: 15, 27, 45, 60
1182##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001183##
1184
Cary Clark7fc1d122017-10-09 14:07:42 -04001185#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001186
1187##
1188
1189# ------------------------------------------------------------------------------
1190
1191#Method void outset(SkScalar dx, SkScalar dy)
1192
Cary Clarkab2621d2018-01-30 10:08:57 -05001193#In Inset_Outset_Offset
1194#Line # moves the sides symmetrically about the center ##
Cary Clark09d80c02018-10-31 12:14:03 -04001195#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001196
1197#Example
Cary Clark154beea2017-10-26 07:58:48 -04001198 SkRect rect = { 10, 14, 50, 73 };
1199 rect.outset(5, 13);
1200 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1201#StdOut
1202rect: 5, 1, 55, 86
1203##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001204##
1205
Cary Clark7fc1d122017-10-09 14:07:42 -04001206#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001207
1208##
1209
Cary Clark2dc84ad2018-01-26 12:56:22 -05001210#Subtopic Inset_Outset_Offset ##
1211
1212#Subtopic Intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001213#Line # sets to shared bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001214
Cary Clark682c58d2018-05-16 07:07:07 -04001215Rects intersect when they enclose a common area. To intersect, each of the pair
Cary Clark7fc1d122017-10-09 14:07:42 -04001216must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark77b3f3a2018-11-07 14:59:03 -05001217isEmpty() returns false. The intersection of Rect pair can be described by:
Cary Clark2be81cf2018-09-13 12:04:30 -04001218#Formula # (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1219 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) ##.
Cary Clark154beea2017-10-26 07:58:48 -04001220
Cary Clark7fc1d122017-10-09 14:07:42 -04001221The intersection is only meaningful if the resulting Rect is not empty and
1222describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1223
Cary Clark2dc84ad2018-01-26 12:56:22 -05001224# ------------------------------------------------------------------------------
1225
Florin Malitaeb420452018-02-20 11:44:43 -05001226#Method bool contains(SkScalar x, SkScalar y) const
1227
1228#In Intersection
Cary Clarkedfe6702018-02-20 14:33:13 -05001229#Line # returns true if points are equal or inside ##
Cary Clark09d80c02018-10-31 12:14:03 -04001230#Populate
Florin Malitaeb420452018-02-20 11:44:43 -05001231
1232#Example
1233 SkRect rect = { 30, 50, 40, 60 };
1234 SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
1235 for (auto contained : tests) {
1236 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
1237 rect.left(), rect.top(), rect.right(), rect.bottom(),
1238 rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
1239 contained.x(), contained.y());
1240 }
1241#StdOut
1242rect: (30, 50, 40, 60) contains (30, 50)
1243rect: (30, 50, 40, 60) does not contain (39, 49)
1244rect: (30, 50, 40, 60) does not contain (29, 59)
1245##
1246##
1247
Cary Clark53498e92018-06-28 19:13:56 -04001248#SeeAlso SkIRect::contains SkRRect::contains
Florin Malitaeb420452018-02-20 11:44:43 -05001249
1250##
1251
1252# ------------------------------------------------------------------------------
1253
Cary Clark2dc84ad2018-01-26 12:56:22 -05001254#Method bool contains(const SkRect& r) const
1255
Cary Clarkab2621d2018-01-30 10:08:57 -05001256#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001257#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001258
1259#Example
1260 SkRect rect = { 30, 50, 40, 60 };
1261 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1262 for (auto contained : tests) {
1263 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1264 rect.left(), rect.top(), rect.right(), rect.bottom(),
1265 rect.contains(contained) ? "contains" : "does not contain",
1266 contained.left(), contained.top(), contained.right(), contained.bottom());
1267 }
1268#StdOut
1269rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1270rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1271rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1272##
1273##
1274
1275#SeeAlso SkIRect::contains
1276
1277##
1278
1279# ------------------------------------------------------------------------------
1280
1281#Method bool contains(const SkIRect& r) const
1282
Cary Clarkab2621d2018-01-30 10:08:57 -05001283#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001284#Populate
Cary Clark2dc84ad2018-01-26 12:56:22 -05001285
1286#Example
1287 SkRect rect = { 30, 50, 40, 60 };
1288 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1289 for (auto contained : tests) {
1290 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1291 rect.left(), rect.top(), rect.right(), rect.bottom(),
1292 rect.contains(contained) ? "contains" : "does not contain",
1293 contained.left(), contained.top(), contained.right(), contained.bottom());
1294 }
1295#StdOut
1296rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1297rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1298rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1299##
1300##
1301
1302#SeeAlso SkIRect::contains
1303
1304##
1305
Cary Clarkbc5697d2017-10-04 14:31:33 -04001306# ------------------------------------------------------------------------------
1307
1308#Method bool intersect(const SkRect& r)
1309
Cary Clarkab2621d2018-01-30 10:08:57 -05001310#In Intersection
1311#Line # sets to shared area; returns true if not empty ##
Cary Clark09d80c02018-10-31 12:14:03 -04001312#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001313
1314#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001315#Description
1316Two SkDebugf calls are required. If the calls are combined, their arguments
1317may not be evaluated in left to right order: the printed intersection may
1318be before or after the call to intersect.
1319##
Cary Clark154beea2017-10-26 07:58:48 -04001320 SkRect leftRect = { 10, 40, 50, 80 };
1321 SkRect rightRect = { 30, 60, 70, 90 };
1322 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001323 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001324 leftRect.right(), leftRect.bottom());
1325#StdOut
1326 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001327##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001328##
1329
Cary Clark7fc1d122017-10-09 14:07:42 -04001330#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001331
1332##
1333
1334# ------------------------------------------------------------------------------
1335
1336#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1337
Cary Clarkab2621d2018-01-30 10:08:57 -05001338#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001339#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001340
1341#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001342#Description
1343Two SkDebugf calls are required. If the calls are combined, their arguments
1344may not be evaluated in left to right order: the printed intersection may
1345be before or after the call to intersect.
1346##
Cary Clark154beea2017-10-26 07:58:48 -04001347 SkRect leftRect = { 10, 40, 50, 80 };
1348 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
Cary Clark682c58d2018-05-16 07:07:07 -04001349 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001350 leftRect.right(), leftRect.bottom());
1351#StdOut
1352 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001353##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001354##
1355
Cary Clark7fc1d122017-10-09 14:07:42 -04001356#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001357
1358##
1359
1360# ------------------------------------------------------------------------------
1361
Cary Clark61313f32018-10-08 14:57:48 -04001362#Method bool intersect(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04001363
Cary Clarkab2621d2018-01-30 10:08:57 -05001364#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001365#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001366
1367#Example
Cary Clark154beea2017-10-26 07:58:48 -04001368 SkRect result;
1369 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1370 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1371 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001372#StdOut
1373 intersection: 30, 60, 50, 80
Cary Clark682c58d2018-05-16 07:07:07 -04001374##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001375##
1376
Cary Clark7fc1d122017-10-09 14:07:42 -04001377#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001378
1379##
1380
Cary Clark7fc1d122017-10-09 14:07:42 -04001381# ------------------------------------------------------------------------------
1382
Cary Clarkbc5697d2017-10-04 14:31:33 -04001383#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1384
Cary Clarkab2621d2018-01-30 10:08:57 -05001385#In Intersection
1386#Line # returns true if areas overlap ##
Cary Clark09d80c02018-10-31 12:14:03 -04001387#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001388
1389#Example
Cary Clark154beea2017-10-26 07:58:48 -04001390 SkRect rect = { 10, 40, 50, 80 };
1391 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001392#StdOut
1393 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001394##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001395##
1396
Cary Clark7fc1d122017-10-09 14:07:42 -04001397#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001398
1399##
1400
Cary Clark7fc1d122017-10-09 14:07:42 -04001401# ------------------------------------------------------------------------------
1402
Cary Clarkbc5697d2017-10-04 14:31:33 -04001403#Method bool intersects(const SkRect& r) const
1404
Cary Clarkab2621d2018-01-30 10:08:57 -05001405#In Intersection
Cary Clark09d80c02018-10-31 12:14:03 -04001406#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001407
1408#Example
Cary Clark154beea2017-10-26 07:58:48 -04001409 SkRect rect = { 10, 40, 50, 80 };
1410 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001411#StdOut
1412 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001413##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001414##
1415
Cary Clark7fc1d122017-10-09 14:07:42 -04001416#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001417
1418##
1419
Cary Clark7fc1d122017-10-09 14:07:42 -04001420# ------------------------------------------------------------------------------
1421
Cary Clarkbc5697d2017-10-04 14:31:33 -04001422#Method static bool Intersects(const SkRect& a, const SkRect& b)
1423
Cary Clarkab2621d2018-01-30 10:08:57 -05001424#In Intersection
1425#Line # returns true if areas overlap ##
Cary Clark09d80c02018-10-31 12:14:03 -04001426#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001427
1428#Example
Cary Clark154beea2017-10-26 07:58:48 -04001429 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001430#StdOut
1431 intersection
Cary Clark682c58d2018-05-16 07:07:07 -04001432##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001433##
1434
Cary Clark7fc1d122017-10-09 14:07:42 -04001435#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001436
1437##
1438
Cary Clark2dc84ad2018-01-26 12:56:22 -05001439#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001440
Cary Clark2dc84ad2018-01-26 12:56:22 -05001441#Subtopic Join
Cary Clark682c58d2018-05-16 07:07:07 -04001442#Line # sets to union of bounds ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001443
Cary Clark7fc1d122017-10-09 14:07:42 -04001444# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001445
1446#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1447
Cary Clarkab2621d2018-01-30 10:08:57 -05001448#In Join
1449#Line # sets to union of bounds ##
Cary Clark09d80c02018-10-31 12:14:03 -04001450#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001451
1452#Example
Cary Clark154beea2017-10-26 07:58:48 -04001453 SkRect rect = { 10, 20, 15, 25};
1454 rect.join(50, 60, 55, 65);
1455 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001456#StdOut
1457 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001458##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001459##
1460
Cary Clark7fc1d122017-10-09 14:07:42 -04001461#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001462
1463##
1464
Cary Clark7fc1d122017-10-09 14:07:42 -04001465# ------------------------------------------------------------------------------
1466
Cary Clarkbc5697d2017-10-04 14:31:33 -04001467#Method void join(const SkRect& r)
1468
Cary Clarkab2621d2018-01-30 10:08:57 -05001469#In Join
Cary Clark09d80c02018-10-31 12:14:03 -04001470#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001471
1472#Example
Cary Clark154beea2017-10-26 07:58:48 -04001473 SkRect rect = { 10, 20, 15, 25};
1474 rect.join({50, 60, 55, 65});
1475 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001476#StdOut
1477 join: 10, 20, 55, 65
Cary Clark682c58d2018-05-16 07:07:07 -04001478##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001479##
1480
Cary Clark7fc1d122017-10-09 14:07:42 -04001481#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001482
1483##
1484
Cary Clark7fc1d122017-10-09 14:07:42 -04001485# ------------------------------------------------------------------------------
1486
Cary Clarkbc5697d2017-10-04 14:31:33 -04001487#Method void joinNonEmptyArg(const SkRect& r)
1488
Cary Clarkab2621d2018-01-30 10:08:57 -05001489#In Join
1490#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark09d80c02018-10-31 12:14:03 -04001491#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001492
1493#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001494#Description
1495Since Rect is not sorted, first result is copy of toJoin.
1496##
Cary Clark154beea2017-10-26 07:58:48 -04001497 SkRect rect = { 10, 100, 15, 0};
1498 SkRect sorted = rect.makeSorted();
1499 SkRect toJoin = { 50, 60, 55, 65 };
1500 rect.joinNonEmptyArg(toJoin);
1501 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1502 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001503 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1504#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001505rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001506sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001507##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001508##
1509
Cary Clark7fc1d122017-10-09 14:07:42 -04001510#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001511
1512##
1513
Cary Clark7fc1d122017-10-09 14:07:42 -04001514# ------------------------------------------------------------------------------
1515
Cary Clarkbc5697d2017-10-04 14:31:33 -04001516#Method void joinPossiblyEmptyRect(const SkRect& r)
1517
Cary Clarkab2621d2018-01-30 10:08:57 -05001518#In Join
Cary Clark682c58d2018-05-16 07:07:07 -04001519#Line # sets to union of bounds; skips empty check for both ##
Cary Clark09d80c02018-10-31 12:14:03 -04001520#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001521
1522#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001523#Description
1524Since Rect is not sorted, first result is not useful.
1525##
Cary Clark154beea2017-10-26 07:58:48 -04001526 SkRect rect = { 10, 100, 15, 0};
1527 SkRect sorted = rect.makeSorted();
1528 SkRect toJoin = { 50, 60, 55, 65 };
1529 rect.joinPossiblyEmptyRect(toJoin);
1530 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1531 sorted.joinPossiblyEmptyRect(toJoin);
1532 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001533#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001534rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001535sorted: 10, 0, 55, 100
Cary Clark682c58d2018-05-16 07:07:07 -04001536##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001537##
1538
Cary Clark7fc1d122017-10-09 14:07:42 -04001539#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001540
1541##
1542
Cary Clark2dc84ad2018-01-26 12:56:22 -05001543#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001544
Cary Clark2dc84ad2018-01-26 12:56:22 -05001545#Subtopic Rounding
Cary Clark08895c42018-02-01 09:37:32 -05001546#Line # adjust to integer bounds ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001547
Cary Clarkbc5697d2017-10-04 14:31:33 -04001548#Method void round(SkIRect* dst) const
1549
Cary Clarkab2621d2018-01-30 10:08:57 -05001550#In Rounding
1551#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001552Sets IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04001553members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1554 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001555
Cary Clark7fc1d122017-10-09 14:07:42 -04001556#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001557
1558#Example
Cary Clark154beea2017-10-26 07:58:48 -04001559 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1560 SkIRect round;
1561 rect.round(&round);
1562 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001563#StdOut
1564round: 31, 51, 41, 61
1565##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001566##
1567
Cary Clark7fc1d122017-10-09 14:07:42 -04001568#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001569
1570##
1571
Cary Clark7fc1d122017-10-09 14:07:42 -04001572# ------------------------------------------------------------------------------
1573
Cary Clarkbc5697d2017-10-04 14:31:33 -04001574#Method void roundOut(SkIRect* dst) const
1575
Cary Clarkab2621d2018-01-30 10:08:57 -05001576#In Rounding
1577#Line # sets members to nearest integer value away from opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001578Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
1579up fRight and fBottom, using
1580#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1581 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001582
Cary Clark7fc1d122017-10-09 14:07:42 -04001583#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001584
1585#Example
Cary Clark154beea2017-10-26 07:58:48 -04001586 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1587 SkIRect round;
1588 rect.roundOut(&round);
1589 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001590#StdOut
1591round: 30, 50, 41, 61
1592##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001593##
1594
Cary Clark7fc1d122017-10-09 14:07:42 -04001595#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001596
1597##
1598
Cary Clark7fc1d122017-10-09 14:07:42 -04001599# ------------------------------------------------------------------------------
1600
Cary Clark682c58d2018-05-16 07:07:07 -04001601#Method void roundOut(SkRect* dst) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04001602
Cary Clarkab2621d2018-01-30 10:08:57 -05001603#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04001604Sets Rect by discarding the fractional portion of fLeft and fTop; and rounding
1605up fRight and fBottom, using
1606#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1607 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001608
Cary Clark7fc1d122017-10-09 14:07:42 -04001609#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001610
1611#Example
Cary Clark154beea2017-10-26 07:58:48 -04001612 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1613 SkRect round;
1614 rect.roundOut(&round);
1615 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001616#StdOut
1617round: 30, 50, 41, 61
1618##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001619##
1620
Cary Clark7fc1d122017-10-09 14:07:42 -04001621#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001622
1623##
1624
Cary Clark7fc1d122017-10-09 14:07:42 -04001625# ------------------------------------------------------------------------------
1626
Cary Clarkbc5697d2017-10-04 14:31:33 -04001627#Method void roundIn(SkIRect* dst) const
1628
Cary Clarkab2621d2018-01-30 10:08:57 -05001629#In Rounding
1630#Line # sets members to nearest integer value towards opposite ##
Cary Clark2be81cf2018-09-13 12:04:30 -04001631Sets Rect by rounding up fLeft and fTop; and discarding the fractional portion
1632of fRight and fBottom, using
1633#Formula # (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
1634 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001635
Cary Clark7fc1d122017-10-09 14:07:42 -04001636#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001637
1638#Example
Cary Clark154beea2017-10-26 07:58:48 -04001639 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1640 SkIRect round;
1641 rect.roundIn(&round);
1642 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001643#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001644round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04001645##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001646##
1647
Cary Clark7fc1d122017-10-09 14:07:42 -04001648#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001649
1650##
1651
Cary Clark7fc1d122017-10-09 14:07:42 -04001652# ------------------------------------------------------------------------------
1653
Cary Clarkbc5697d2017-10-04 14:31:33 -04001654#Method SkIRect round() const
1655
Cary Clarkab2621d2018-01-30 10:08:57 -05001656#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04001657Returns IRect by adding 0.5 and discarding the fractional portion of Rect
Cary Clark2be81cf2018-09-13 12:04:30 -04001658members, using #Formula # (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1659 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001660
Cary Clark7fc1d122017-10-09 14:07:42 -04001661#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001662
1663#Example
Cary Clark154beea2017-10-26 07:58:48 -04001664 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1665 SkIRect round = rect.round();
1666 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001667#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001668round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04001669##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001670##
1671
Cary Clark7fc1d122017-10-09 14:07:42 -04001672#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001673
1674##
1675
Cary Clark7fc1d122017-10-09 14:07:42 -04001676# ------------------------------------------------------------------------------
1677
Cary Clarkbc5697d2017-10-04 14:31:33 -04001678#Method SkIRect roundOut() const
1679
Cary Clarkab2621d2018-01-30 10:08:57 -05001680#In Rounding
Cary Clark2be81cf2018-09-13 12:04:30 -04001681Sets IRect by discarding the fractional portion of fLeft and fTop; and rounding
1682up fRight and fBottom, using
1683#Formula # (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
1684 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) ##.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001685
Cary Clark7fc1d122017-10-09 14:07:42 -04001686#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001687
1688#Example
Cary Clark154beea2017-10-26 07:58:48 -04001689 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
1690 SkIRect round = rect.roundOut();
1691 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001692#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001693round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04001694##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001695##
1696
Cary Clark7fc1d122017-10-09 14:07:42 -04001697#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04001698
1699##
1700
Cary Clark2dc84ad2018-01-26 12:56:22 -05001701#Subtopic Rounding ##
1702
1703#Subtopic Sorting
Cary Clark08895c42018-02-01 09:37:32 -05001704#Line # orders sides ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001705
Cary Clark7fc1d122017-10-09 14:07:42 -04001706# ------------------------------------------------------------------------------
1707
Cary Clarkbc5697d2017-10-04 14:31:33 -04001708#Method void sort()
1709
Cary Clarkab2621d2018-01-30 10:08:57 -05001710#In Sorting
1711#Line # orders sides from smaller to larger ##
Cary Clark09d80c02018-10-31 12:14:03 -04001712#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001713
1714#Example
Cary Clark154beea2017-10-26 07:58:48 -04001715 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
1716 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1717 rect.sort();
1718 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001719#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001720rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04001721sorted: 20.5, 10.5, 30.5, 50.5
1722##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723##
1724
Cary Clark2dc84ad2018-01-26 12:56:22 -05001725#SeeAlso makeSorted SkIRect::sort isSorted
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 SkRect makeSorted() const
1732
Cary Clarkab2621d2018-01-30 10:08:57 -05001733#In Sorting
Cary Clark61313f32018-10-08 14:57:48 -04001734#In Constructors
Cary Clark682c58d2018-05-16 07:07:07 -04001735#Line # constructs Rect, ordering sides from smaller to larger ##
Cary Clark09d80c02018-10-31 12:14:03 -04001736#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001737
1738#Example
Cary Clark154beea2017-10-26 07:58:48 -04001739 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
1740 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1741 SkRect sort = rect.makeSorted();
1742 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001743#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001744rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04001745sorted: 20.5, 10.5, 30.5, 50.5
1746##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001747##
1748
Cary Clark2dc84ad2018-01-26 12:56:22 -05001749#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04001750
1751##
1752
Cary Clark2dc84ad2018-01-26 12:56:22 -05001753#Subtopic Sorting ##
1754
Cary Clark7fc1d122017-10-09 14:07:42 -04001755# ------------------------------------------------------------------------------
1756
Cary Clarkbc5697d2017-10-04 14:31:33 -04001757#Method const SkScalar* asScalars() const
Cary Clark4855f782018-02-06 09:41:53 -05001758#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001759#Line # returns pointer to members as array ##
Cary Clark09d80c02018-10-31 12:14:03 -04001760#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001761
1762#Example
Cary Clark154beea2017-10-26 07:58:48 -04001763 SkRect rect = {7, 11, 13, 17};
1764SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
1765#StdOut
1766rect.asScalars() == &rect.fLeft
1767##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001768##
1769
Cary Clark7fc1d122017-10-09 14:07:42 -04001770#SeeAlso toQuad
1771
Cary Clarkbc5697d2017-10-04 14:31:33 -04001772##
1773
Cary Clark7fc1d122017-10-09 14:07:42 -04001774# ------------------------------------------------------------------------------
1775
Cary Clarkbc5697d2017-10-04 14:31:33 -04001776#Method void dump(bool asHex) const
Cary Clark4855f782018-02-06 09:41:53 -05001777#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001778#Line # sends text representation to standard output using floats ##
Cary Clark09d80c02018-10-31 12:14:03 -04001779#Populate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001780
1781#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001782 SkRect rect = {20, 30, 40, 50};
1783 for (bool dumpAsHex : { false, true } ) {
1784 rect.dump(dumpAsHex);
1785 SkDebugf("\n");
1786 }
1787#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001788SkRect::MakeLTRB(20, 30, 40, 50);
1789
1790SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
1791 SkBits2Float(0x41f00000), /* 30.000000 */
1792 SkBits2Float(0x42200000), /* 40.000000 */
1793 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04001794##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001795##
1796
Cary Clark7fc1d122017-10-09 14:07:42 -04001797#SeeAlso dumpHex
1798
Cary Clarkbc5697d2017-10-04 14:31:33 -04001799##
1800
Cary Clark7fc1d122017-10-09 14:07:42 -04001801# ------------------------------------------------------------------------------
1802
Cary Clarkbc5697d2017-10-04 14:31:33 -04001803#Method void dump() const
Cary Clark09d80c02018-10-31 12:14:03 -04001804#Populate
Cary Clark7fc1d122017-10-09 14:07:42 -04001805
Cary Clarkbc5697d2017-10-04 14:31:33 -04001806#Example
Cary Clark154beea2017-10-26 07:58:48 -04001807SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
1808rect.dump();
1809SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
1810SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001811#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001812SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04001813rect is not equal to copy
1814##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001815##
1816
Cary Clark7fc1d122017-10-09 14:07:42 -04001817#SeeAlso dumpHex
1818
Cary Clarkbc5697d2017-10-04 14:31:33 -04001819##
1820
Cary Clark7fc1d122017-10-09 14:07:42 -04001821# ------------------------------------------------------------------------------
1822
Cary Clarkbc5697d2017-10-04 14:31:33 -04001823#Method void dumpHex() const
Cary Clark4855f782018-02-06 09:41:53 -05001824#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -05001825#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001826Writes text representation of Rect to standard output. The representation may be
1827directly compiled as C++ code. Floating point values are written
1828in hexadecimal to preserve their exact bit pattern. The output reconstructs the
1829original Rect.
1830
Cary Clark682c58d2018-05-16 07:07:07 -04001831Use instead of dump() when submitting
1832#A bug reports against Skia # https://bug.skia.org ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001833.
1834
Cary Clarkbc5697d2017-10-04 14:31:33 -04001835#Example
Cary Clark154beea2017-10-26 07:58:48 -04001836 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
1837rect.dumpHex();
1838SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
1839 SkBits2Float(0x3f2aaaab), /* 0.666667 */
1840 SkBits2Float(0x40266666), /* 2.600000 */
1841 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04001842SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
1843#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001844SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
1845 SkBits2Float(0x3f2aaaab), /* 0.666667 */
1846 SkBits2Float(0x40266666), /* 2.600000 */
1847 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04001848rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04001849##
Cary Clark7fc1d122017-10-09 14:07:42 -04001850##
1851
1852#SeeAlso dump
Cary Clark69261ba2018-10-11 15:28:31 -04001853
1854##
1855
1856#Struct SkRect ##
1857
1858#Topic Rect ##