blob: fd223d1f012110075f4710816d95c58563fdec50 [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Rect
2#Alias Rects
3#Alias Rect_Reference
4
Cary Clark2dc84ad2018-01-26 12:56:22 -05005#Topic Overview
6
7#Subtopic Subtopics
8#Table
9#Legend
10# name # description ##
11#Legend ##
12# Constructors # functions that construct SkRect ##
13# Member_Functions # static functions and member methods ##
14# Members # member values ##
15# Operators # operator overloading methods ##
16# Related_Functions # similar methods grouped together ##
17#Table ##
18##
19
20#Topic Overview ##
21
Cary Clarkbc5697d2017-10-04 14:31:33 -040022#Struct SkRect
23
Cary Clark7fc1d122017-10-09 14:07:42 -040024SkRect holds four SkScalar coordinates describing the upper and
25lower bounds of a rectangle. SkRect may be created from outer bounds or
26from position, width, and height. SkRect describes an area; if its right
27is less than or equal to its left, or if its bottom is less than or equal to
28its top, it is considered empty.
29
30# move to topic about MakeIWH and friends
31SkRect can be constructed from int values to avoid compiler warnings that
32integer input cannot convert to SkScalar without loss of precision.
33
Cary Clark2dc84ad2018-01-26 12:56:22 -050034#Subtopic Related_Functions
Cary Clarkbc5697d2017-10-04 14:31:33 -040035#Table
36#Legend
Cary Clark2dc84ad2018-01-26 12:56:22 -050037# name # description ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040038#Legend ##
Cary Clark2dc84ad2018-01-26 12:56:22 -050039# As_Points # conversion to and from Points ##
40# From_Integers # set Scalar values from integer input ##
41# Inset_Outset_Offset # moves sides ##
42# Intersection # set to shared bounds ##
43# Join # set to union of bounds ##
44# Properties # side values, center, validity ##
45# Rounding # adjust to integer bounds ##
46# Set # replaces all values ##
47# Sorting # orders sides ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040048#Table ##
49#Subtopic ##
50
51#Subtopic Member_Functions
52#Table
53#Legend
Cary Clark7fc1d122017-10-09 14:07:42 -040054# description # function ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040055#Legend ##
Cary Clark5081eed2018-01-22 07:55:48 -050056# Intersects # returns true if areas overlap ##
57# Make # constructs from ISize returning (0, 0, width, height) ##
58# MakeEmpty # constructs from bounds of (0, 0, 0, 0) ##
59# MakeFromIRect # deprecated ##
60# MakeIWH # constructs from int input returning (0, 0, width, height) ##
61# MakeLTRB # constructs from SkScalar left, top, right, bottom ##
62# MakeLargest # deprecated ##
63# MakeSize # constructs from Size returning (0, 0, width, height) ##
64# MakeWH # constructs from SkScalar input returning (0, 0, width, height) ##
65# MakeXYWH # constructs from SkScalar input returning (x, y, width, height) ##
66# asScalars # returns pointer to members as array ##
67# bottom() # returns larger bounds in y, if sorted ##
68# centerX # returns midpoint in x ##
69# centerY # returns midpoint in y ##
70# contains() # returns true if points are equal or inside ##
71# dump() # sends text representation to standard output using floats ##
72# dumpHex # sends text representation to standard output using hexadecimal ##
73# height() # returns span in y ##
74# inset() # moves the sides symmetrically about the center ##
75# intersect() # sets to shared area; returns true if not empty ##
76# intersects() # returns true if areas overlap ##
77# isEmpty # returns true if width or height are zero or negative ##
78# isFinite # returns true if no member is infinite or NaN ##
79# isSorted # returns true if width or height are zero or positive ##
80# iset() # sets to int input (left, top, right, bottom) ##
81# isetWH # sets to int input (0, 0, width, height) ##
82# join() # sets to union of bounds ##
83# joinNonEmptyArg # sets to union of bounds, asserting that argument is not empty ##
84# joinPossiblyEmptyRect # sets to union of bounds. Skips empty check for both ##
85# left() # returns smaller bounds in x, if sorted ##
86# makeInset # constructs from sides moved symmetrically about the center ##
87# makeOffset # constructs from translated sides ##
88# makeOutset # constructs from sides moved symmetrically about the center ##
89# makeSorted # constructs, ordering sides from smaller to larger ##
90# offset() # translates sides without changing width and height ##
91# offsetTo # translates to (x, y) without changing width and height ##
92# outset() # moves the sides symmetrically about the center ##
93# right() # returns larger bounds in x, if sorted ##
94# round() # sets members to nearest integer value ##
95# roundIn # sets members to nearest integer value towards opposite ##
96# roundOut # sets members to nearest integer value away from opposite ##
97# set() # sets to SkScalar input (left, top, right, bottom) and others ##
98# setBounds # sets to upper and lower limits of Point array ##
99# setBoundsCheck # sets to upper and lower limits of Point array ##
100# setEmpty # sets to (0, 0, 0, 0) ##
101# setLTRB # sets to SkScalar input (left, top, right, bottom) ##
102# setWH # sets to SkScalar input (0, 0, width, height) ##
103# setXYWH # sets to SkScalar input (x, y, width, height) ##
104# sort() # orders sides from smaller to larger ##
105# toQuad # returns four corners as Point ##
106# top() # returns smaller bounds in y, if sorted ##
107# width() # returns span in x ##
108# x() # returns bounds left ##
109# y() # returns bounds top ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400110#Table ##
111#Subtopic ##
112
Cary Clark2dc84ad2018-01-26 12:56:22 -0500113#Subtopic Members
Cary Clarkbc5697d2017-10-04 14:31:33 -0400114
115#Member SkScalar fLeft
Cary Clark7fc1d122017-10-09 14:07:42 -0400116May contain any value, including infinities and NaN. The smaller of the
117horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400118##
119
120#Member SkScalar fTop
Cary Clark7fc1d122017-10-09 14:07:42 -0400121May contain any value, including infinities and NaN. The smaller of the
122vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400123##
124
125#Member SkScalar fRight
Cary Clark7fc1d122017-10-09 14:07:42 -0400126May contain any value, including infinities and NaN. The larger of the
127horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400128##
129
130#Member SkScalar fBottom
Cary Clark7fc1d122017-10-09 14:07:42 -0400131May contain any value, including infinities and NaN. The larger of the
132vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400133##
134
Cary Clark2dc84ad2018-01-26 12:56:22 -0500135#Subtopic Members ##
136
137#Subtopic Constructors
138#Table
139#Legend
140# name # description ##
141#Legend ##
142# Make # constructs from ISize returning (0, 0, width, height) ##
143# MakeEmpty # constructs from bounds of (0, 0, 0, 0) ##
144# MakeFromIRect # deprecated ##
145# MakeIWH # constructs from int input returning (0, 0, width, height) ##
146# MakeLTRB # constructs from SkScalar left, top, right, bottom ##
147# MakeLargest # deprecated ##
148# MakeSize # constructs from Size returning (0, 0, width, height) ##
149# MakeWH # constructs from SkScalar input returning (0, 0, width, height) ##
150# MakeXYWH # constructs from SkScalar input returning (x, y, width, height) ##
151# makeInset # constructs from sides moved symmetrically about the center ##
152# makeOffset # constructs from translated sides ##
153# makeOutset # constructs from sides moved symmetrically about the center ##
154# makeSorted # constructs, ordering sides from smaller to larger ##
155#Table ##
156
Cary Clarkbc5697d2017-10-04 14:31:33 -0400157# ------------------------------------------------------------------------------
158
159#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
160
Cary Clark7fc1d122017-10-09 14:07:42 -0400161Returns constructed Rect set to (0, 0, 0, 0).
162Many other rectangles are empty; if left is equal to or greater than right,
163or if top is equal to or greater than bottom. Setting all members to zero
164is a convenience, but does not designate a special empty rectangle.
165
166#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400167
168#Example
Cary Clark154beea2017-10-26 07:58:48 -0400169 SkRect rect = SkRect::MakeEmpty();
170 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
171 rect.offset(10, 10);
172 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
173 rect.inset(10, 10);
174 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
175 rect.outset(20, 20);
176 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
177#StdOut
178MakeEmpty isEmpty: true
179offset rect isEmpty: true
180inset rect isEmpty: true
181outset rect isEmpty: false
182##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400183##
184
Mike Reed274218e2018-01-08 15:05:02 -0500185#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -0400186
187##
188
189# ------------------------------------------------------------------------------
190
191#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400192
Cary Clark7fc1d122017-10-09 14:07:42 -0400193Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
194validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400195
Cary Clark7fc1d122017-10-09 14:07:42 -0400196Passing integer values may generate a compiler warning since Rect cannot
197represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
198
199#Param w SkScalar width of constructed Rect ##
200#Param h SkScalar height of constructed Rect ##
201
202#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400203
204#Example
Cary Clark154beea2017-10-26 07:58:48 -0400205 SkRect rect1 = SkRect::MakeWH(25, 35);
206 SkRect rect2 = SkRect::MakeIWH(25, 35);
207 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
208 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
209 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400210 "" : "not ");
211#StdOut
212all equal
213##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400214##
215
Cary Clark7fc1d122017-10-09 14:07:42 -0400216#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400217
218##
219
220# ------------------------------------------------------------------------------
221
222#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
223
Cary Clark7fc1d122017-10-09 14:07:42 -0400224Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
225input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400226
Cary Clark7fc1d122017-10-09 14:07:42 -0400227Use to avoid a compiler warning that input may lose precision when stored.
228Use SkIRect for an exact integer rectangle.
229
230#Param w integer width of constructed Rect ##
231#Param h integer height of constructed Rect ##
232
233#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400234
235#Example
Cary Clark154beea2017-10-26 07:58:48 -0400236 SkIRect i_rect = SkIRect::MakeWH(25, 35);
237 SkRect f_rect = SkRect::MakeIWH(25, 35);
238 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
239 i_rect = SkIRect::MakeWH(125000111, 0);
240 f_rect = SkRect::MakeIWH(125000111, 0);
241 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400242#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400243i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400244i_rect width: 125000111 f_rect width:125000112
245##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400246##
247
Cary Clark7fc1d122017-10-09 14:07:42 -0400248#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400249
250##
251
252# ------------------------------------------------------------------------------
253
Cary Clark884dd7d2017-10-11 10:37:52 -0400254#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400255
Cary Clark7fc1d122017-10-09 14:07:42 -0400256Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
257validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400258
Cary Clark7fc1d122017-10-09 14:07:42 -0400259#Param size SkScalar values for Rect width and height ##
260
261#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400262
263#Example
Cary Clark154beea2017-10-26 07:58:48 -0400264 SkSize size = {25.5f, 35.5f};
265 SkRect rect = SkRect::MakeSize(size);
266 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
267 SkISize floor = size.toFloor();
268 rect = SkRect::MakeSize(SkSize::Make(floor));
269 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400270#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400271rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400272floor width: 25 height: 35
273##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400274##
275
Cary Clark7fc1d122017-10-09 14:07:42 -0400276#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400277
278##
279
280# ------------------------------------------------------------------------------
281
282#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
283 SkScalar b)
284
Cary Clark7fc1d122017-10-09 14:07:42 -0400285Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
286result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400287
Cary Clark7fc1d122017-10-09 14:07:42 -0400288#Param l SkScalar stored in fLeft ##
289#Param t SkScalar stored in fTop ##
290#Param r SkScalar stored in fRight ##
291#Param b SkScalar stored in fBottom ##
292
293#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
295#Example
Cary Clark154beea2017-10-26 07:58:48 -0400296 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
297 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
298 rect.bottom(), rect.isEmpty() ? "true" : "false");
299 rect.sort();
300 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
301 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400302#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400303rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400304rect: 5, 25, 15, 35 isEmpty: false
305##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400306##
307
Cary Clark7fc1d122017-10-09 14:07:42 -0400308#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309
310##
311
312# ------------------------------------------------------------------------------
313
Cary Clark884dd7d2017-10-11 10:37:52 -0400314#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400315
Cary Clark7fc1d122017-10-09 14:07:42 -0400316Returns constructed Rect set to
317#Formula
318(x, y, x + w, y + h)
319##
320. Does not validate input;
321w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400322
Cary Clark7fc1d122017-10-09 14:07:42 -0400323#Param x stored in fLeft ##
324#Param y stored in fTop ##
325#Param w added to x and stored in fRight ##
326#Param h added to y and stored in fBottom ##
327
Cary Clark884dd7d2017-10-11 10:37:52 -0400328#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400329
330#Example
Cary Clark154beea2017-10-26 07:58:48 -0400331 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
332 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
333 rect.bottom(), rect.isEmpty() ? "true" : "false");
334 rect.sort();
335 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
336 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400337#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400338rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400339rect: -10, 35, 5, 60 isEmpty: false
340##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400341##
342
Cary Clark7fc1d122017-10-09 14:07:42 -0400343#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400344
345##
346
347# ------------------------------------------------------------------------------
348
349#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
350
Cary Clark7fc1d122017-10-09 14:07:42 -0400351Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400352
Cary Clark7fc1d122017-10-09 14:07:42 -0400353#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400354##
355
Cary Clark7fc1d122017-10-09 14:07:42 -0400356#Param irect integer rect ##
357
358#Return irect as SkRect ##
359
360#NoExample
361##
362
363#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400364
365##
366
367# ------------------------------------------------------------------------------
368
369#Method static SkRect Make(const SkISize& size)
370
Cary Clark7fc1d122017-10-09 14:07:42 -0400371Returns constructed IRect set to (0, 0, size.width(), size.height()).
372Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400373
Cary Clark7fc1d122017-10-09 14:07:42 -0400374#Param size integer values for Rect width and height ##
375
376#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400377
378#Example
Cary Clark154beea2017-10-26 07:58:48 -0400379 SkRect rect1 = SkRect::MakeSize({2, 35});
380 SkRect rect2 = SkRect::MakeIWH(2, 35);
381 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400382#StdOut
383rect1 == rect2
384##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400385##
386
Cary Clark7fc1d122017-10-09 14:07:42 -0400387#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400388
389##
390
391# ------------------------------------------------------------------------------
392
393#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
394
Cary Clark7fc1d122017-10-09 14:07:42 -0400395Returns constructed IRect set to irect, promoting integers to Scalar.
396Does not validate input; fLeft may be greater than fRight, fTop may be greater
397than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400398
Cary Clark7fc1d122017-10-09 14:07:42 -0400399#Param irect integer unsorted bounds ##
400
401#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400402
403#Example
Cary Clark154beea2017-10-26 07:58:48 -0400404 SkIRect i_rect1 = {2, 35, 22, 53};
405 SkRect f_rect = SkRect::Make(i_rect1);
406 f_rect.offset(0.49f, 0.49f);
407 SkIRect i_rect2;
408 f_rect.round(&i_rect2);
409 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400410##
411
Cary Clark7fc1d122017-10-09 14:07:42 -0400412#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400413
414##
415
Cary Clark2dc84ad2018-01-26 12:56:22 -0500416#Subtopic Constructors ##
417
418#Subtopic Properties
419
420#Table
421#Legend
422# name # description ##
423#Legend ##
424# bottom() # returns larger bounds in y, if sorted ##
425# centerX # returns midpoint in x ##
426# centerY # returns midpoint in y ##
427# height() # returns span in y ##
428# isEmpty # returns true if width or height are zero or negative ##
429# isFinite # returns true if no member is infinite or NaN ##
430# isSorted # returns true if width or height are zero or positive ##
431# left() # returns smaller bounds in x, if sorted ##
432# right() # returns larger bounds in x, if sorted ##
433# top() # returns smaller bounds in y, if sorted ##
434# width() # returns span in x ##
435# x() # returns bounds left ##
436# y() # returns bounds top ##
437#Table ##
438
Cary Clarkbc5697d2017-10-04 14:31:33 -0400439# ------------------------------------------------------------------------------
440
441#Method bool isEmpty() const
442
Cary Clark7fc1d122017-10-09 14:07:42 -0400443Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
444to or greater than fBottom. Call sort() to reverse rectangles with negative
445width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400446
Cary Clark7fc1d122017-10-09 14:07:42 -0400447#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400448
449#Example
Cary Clark154beea2017-10-26 07:58:48 -0400450 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
451 for (auto rect : tests) {
452 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
453 rect.bottom(), rect.isEmpty() ? "" : " not");
454 rect.sort();
455 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
456 rect.bottom(), rect.isEmpty() ? "" : " not");
457 }
458#StdOut
459rect: {20, 40, 10, 50} is empty
460sorted: {10, 40, 20, 50} is not empty
461rect: {20, 40, 20, 50} is empty
462sorted: {20, 40, 20, 50} is empty
463##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400464##
465
Cary Clark7fc1d122017-10-09 14:07:42 -0400466#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400467
468##
469
470# ------------------------------------------------------------------------------
471
472#Method bool isSorted() const
473
Cary Clark7fc1d122017-10-09 14:07:42 -0400474Returns true if fLeft is equal to or less than fRight, or if fTop is equal
475to or less than fBottom. Call sort() to reverse rectangles with negative
476width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400477
Cary Clark7fc1d122017-10-09 14:07:42 -0400478#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400479
480#Example
Cary Clark154beea2017-10-26 07:58:48 -0400481 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
482 for (auto rect : tests) {
483 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
484 rect.bottom(), rect.isSorted() ? "" : " not");
485 rect.sort();
486 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
487 rect.bottom(), rect.isSorted() ? "" : " not");
488 }
489#StdOut
490rect: {20, 40, 10, 50} is not sorted
491sorted: {10, 40, 20, 50} is sorted
492rect: {20, 40, 20, 50} is sorted
493sorted: {20, 40, 20, 50} is sorted
494##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400495##
496
Cary Clark7fc1d122017-10-09 14:07:42 -0400497#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400498
499##
500
501# ------------------------------------------------------------------------------
502
Cary Clarkbc5697d2017-10-04 14:31:33 -0400503#Method bool isFinite() const
504
Cary Clark7fc1d122017-10-09 14:07:42 -0400505Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
506and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400507
Cary Clark7fc1d122017-10-09 14:07:42 -0400508#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400509
510#Example
Mike Reed274218e2018-01-08 15:05:02 -0500511SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400512 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
513 SkDebugf("large width %g\n", largest.width());
514 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
515 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
516#StdOut
517largest is finite: true
518large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400519widest is finite: false
520##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400521##
522
Cary Clark7fc1d122017-10-09 14:07:42 -0400523#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400524
525##
526
527# ------------------------------------------------------------------------------
528
529#Method SkScalar x() const
530
Cary Clark7fc1d122017-10-09 14:07:42 -0400531Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
532Call sort() to reverse fLeft and fRight if needed.
533
534#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400535
536#Example
Cary Clark154beea2017-10-26 07:58:48 -0400537 SkRect unsorted = { 15, 5, 10, 25 };
538 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
539 SkRect sorted = unsorted.makeSorted();
540 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400541#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400542unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400543sorted.fLeft: 10 sorted.x(): 10
544##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400545##
546
Cary Clark7fc1d122017-10-09 14:07:42 -0400547#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400548
549##
550
551# ------------------------------------------------------------------------------
552
553#Method SkScalar y() const
554
Cary Clark7fc1d122017-10-09 14:07:42 -0400555Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
556and sort() to reverse fTop and fBottom if needed.
557
558#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400559
560#Example
Cary Clark154beea2017-10-26 07:58:48 -0400561 SkRect unsorted = { 15, 25, 10, 5 };
562 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
563 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400564 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
565#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400566unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400567sorted.fTop: 5 sorted.y(): 5
568##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400569##
570
Cary Clark7fc1d122017-10-09 14:07:42 -0400571#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400572
573##
574
575# ------------------------------------------------------------------------------
576
577#Method SkScalar left() const
578
Cary Clark7fc1d122017-10-09 14:07:42 -0400579Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
580Call sort() to reverse fLeft and fRight if needed.
581
582#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400583
584#Example
Cary Clark154beea2017-10-26 07:58:48 -0400585 SkRect unsorted = { 15, 5, 10, 25 };
586 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
587 SkRect sorted = unsorted.makeSorted();
588 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400589#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400590unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400591sorted.fLeft: 10 sorted.left(): 10
592##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400593##
594
Cary Clark7fc1d122017-10-09 14:07:42 -0400595#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400596
597##
598
599# ------------------------------------------------------------------------------
600
601#Method SkScalar top() const
602
Cary Clark7fc1d122017-10-09 14:07:42 -0400603Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
604and sort() to reverse fTop and fBottom if needed.
605
606#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400607
608#Example
Cary Clark154beea2017-10-26 07:58:48 -0400609 SkRect unsorted = { 15, 25, 10, 5 };
610 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
611 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400612 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
613#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400614unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400615sorted.fTop: 5 sorted.top(): 5
616##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400617##
618
Cary Clark7fc1d122017-10-09 14:07:42 -0400619#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400620
621##
622
623# ------------------------------------------------------------------------------
624
625#Method SkScalar right() const
626
Cary Clark7fc1d122017-10-09 14:07:42 -0400627Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
628Call sort() to reverse fLeft and fRight if needed.
629
630#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400631
632#Example
Cary Clark154beea2017-10-26 07:58:48 -0400633 SkRect unsorted = { 15, 25, 10, 5 };
634 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
635 SkRect sorted = unsorted.makeSorted();
636 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400637#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400638unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400639sorted.fRight: 15 sorted.right(): 15
640##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400641##
642
Cary Clark7fc1d122017-10-09 14:07:42 -0400643#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400644
645##
646
647# ------------------------------------------------------------------------------
648
649#Method SkScalar bottom() const
650
Cary Clark7fc1d122017-10-09 14:07:42 -0400651Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
652and sort() to reverse fTop and fBottom if needed.
653
654#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400655
656#Example
Cary Clark154beea2017-10-26 07:58:48 -0400657 SkRect unsorted = { 15, 25, 10, 5 };
658 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
659 SkRect sorted = unsorted.makeSorted();
660 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400661#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400662unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400663sorted.fBottom: 25 sorted.bottom(): 25
664##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400665##
666
Cary Clark7fc1d122017-10-09 14:07:42 -0400667#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400668
669##
670
671# ------------------------------------------------------------------------------
672
673#Method SkScalar width() const
674
Cary Clark7fc1d122017-10-09 14:07:42 -0400675Returns span on the x-axis. This does not check if Rect is sorted, or if
676result fits in 32-bit float; result may be negative or infinity.
677
678#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400679
680#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400681#Description
682Compare with SkIRect::width() example.
683##
Cary Clark154beea2017-10-26 07:58:48 -0400684 SkRect unsorted = { 15, 25, 10, 5 };
685 SkDebugf("unsorted width: %g\n", unsorted.width());
686 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
687 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400688#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400689unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400690large width: 4294967296
691##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400692##
693
Cary Clark7fc1d122017-10-09 14:07:42 -0400694#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400695
696##
697
698# ------------------------------------------------------------------------------
699
700#Method SkScalar height() const
701
Cary Clark7fc1d122017-10-09 14:07:42 -0400702Returns span on the y-axis. This does not check if IRect is sorted, or if
703result fits in 32-bit float; result may be negative or infinity.
704
705#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400706
707#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400708#Description
709Compare with SkIRect::height() example.
710##
Cary Clark154beea2017-10-26 07:58:48 -0400711 SkRect unsorted = { 15, 25, 10, 20 };
712 SkDebugf("unsorted height: %g\n", unsorted.height());
713 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
714 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400715#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400716unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400717large height: 4294967296
718##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400719##
720
Cary Clark7fc1d122017-10-09 14:07:42 -0400721#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400722
723##
724
725# ------------------------------------------------------------------------------
726
727#Method SkScalar centerX() const
728
Cary Clark7fc1d122017-10-09 14:07:42 -0400729Returns average of left edge and right edge. Result does not change if Rect
730is sorted. Result may overflow to infinity if Rect is far from the origin.
731
732#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400733
734#Example
Cary Clark154beea2017-10-26 07:58:48 -0400735 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
736 for (auto rect : tests) {
737 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
738 rect.sort();
739 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
740 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400741#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400742left: 20 right: 41 centerX: 30.5
743left: 20 right: 41 centerX: 30.5
744left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400745left: -41 right: -20 centerX: -30.5
746##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400747##
748
Cary Clark7fc1d122017-10-09 14:07:42 -0400749#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400750
751##
752
753# ------------------------------------------------------------------------------
754
755#Method SkScalar centerY() const
756
Cary Clark7fc1d122017-10-09 14:07:42 -0400757Returns average of top edge and bottom edge. Result does not change if Rect
758is sorted. Result may overflow to infinity if Rect is far from the origin.
759
760#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400761
762#Example
Cary Clark154beea2017-10-26 07:58:48 -0400763 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
764 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
765 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400766#StdOut
767left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
768##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400769##
770
Cary Clark7fc1d122017-10-09 14:07:42 -0400771#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400772
773##
774
Cary Clark2dc84ad2018-01-26 12:56:22 -0500775#Subtopic Properties ##
776
777#Subtopic Operators
778
779#Table
780#Legend
781# name # description ##
782#Legend ##
783# bool operator!=(const SkRect& a, const SkRect& b) # returns true if members are unequal ##
784# bool operator==(const SkRect& a, const SkRect& b) # returns true if members are equal ##
785#Table ##
786
Cary Clarkbc5697d2017-10-04 14:31:33 -0400787# ------------------------------------------------------------------------------
788
Cary Clark884dd7d2017-10-11 10:37:52 -0400789#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400790
Cary Clark7fc1d122017-10-09 14:07:42 -0400791Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
792equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400793
Cary Clark7fc1d122017-10-09 14:07:42 -0400794a and b are not equal if either contain NaN. a and b are equal if members
795contain zeroes width different signs.
796
797#Param a Rect to compare ##
798#Param b Rect to compare ##
799
800#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400801
802#Example
Cary Clark154beea2017-10-26 07:58:48 -0400803 auto debugster = [](const SkRect& test) -> void {
804 SkRect negZero = {-0.0f, -0.0f, 2, 2};
805 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
806 test.fLeft, test.fTop, test.fRight, test.fBottom,
807 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
808 test == negZero ? '=' : '!',
809 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
810 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
811 "and are" : "yet are not");
812 };
813 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
814 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
815 for (auto rect : tests) {
816 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400817 }
Cary Clark154beea2017-10-26 07:58:48 -0400818#StdOut
819tests are equal
820{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
821{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400822{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
823##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400824##
825
Cary Clark7fc1d122017-10-09 14:07:42 -0400826#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400827
828##
829
830# ------------------------------------------------------------------------------
831
Cary Clark884dd7d2017-10-11 10:37:52 -0400832#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400833
Cary Clark7fc1d122017-10-09 14:07:42 -0400834Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
835equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400836
Cary Clark7fc1d122017-10-09 14:07:42 -0400837a and b are not equal if either contain NaN. a and b are equal if members
838contain zeroes width different signs.
839
840#Param a Rect to compare ##
841#Param b Rect to compare ##
842
843#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400844
845#Example
Cary Clark154beea2017-10-26 07:58:48 -0400846 SkRect test = {0, 0, 2, SK_ScalarNaN};
847 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
848#StdOut
Cary Clark7fc1d122017-10-09 14:07:42 -0400849test with NaN is not equal to itself
850##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400851##
852
Cary Clark7fc1d122017-10-09 14:07:42 -0400853#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400854
855##
856
Cary Clark2dc84ad2018-01-26 12:56:22 -0500857#Subtopic Operators ##
858
859#Subtopic As_Points
860
861#Table
862#Legend
863# name # description ##
864#Legend ##
865# setBounds # sets to upper and lower limits of Point array ##
866# setBoundsCheck # sets to upper and lower limits of Point array ##
867# toQuad # returns four corners as Point ##
868#Table ##
869
Cary Clarkbc5697d2017-10-04 14:31:33 -0400870# ------------------------------------------------------------------------------
871
872#Method void toQuad(SkPoint quad[4]) const
873
Cary Clark7fc1d122017-10-09 14:07:42 -0400874Returns four points in quad that enclose Rect ordered as: top-left, top-right,
875bottom-right, bottom-left.
876
877#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400878Consider adding param to control whether quad is CW or CCW.
879##
880
Cary Clark7fc1d122017-10-09 14:07:42 -0400881#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400882
883#Example
Cary Clark154beea2017-10-26 07:58:48 -0400884 SkRect rect = {1, 2, 3, 4};
885 SkPoint corners[4];
886 rect.toQuad(corners);
887 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
888 SkDebugf("corners:");
889 for (auto corner : corners) {
890 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
891 }
892 SkDebugf("\n");
893#StdOut
894rect: {1, 2, 3, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400895corners: {1, 2} {3, 2} {3, 4} {1, 4}
896##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400897##
898
Cary Clark7fc1d122017-10-09 14:07:42 -0400899#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400900
901##
902
903# ------------------------------------------------------------------------------
904
Cary Clark2dc84ad2018-01-26 12:56:22 -0500905#Method void setBounds(const SkPoint pts[], int count)
906
907Sets to bounds of Point array with count entries. If count is zero or smaller,
908or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
909
910Result is either empty or sorted: fLeft is less than or equal to fRight, and
911fTop is less than or equal to fBottom.
912
913#Param pts Point array ##
914#Param count entries in array ##
915
916#Example
917 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
918 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
919 SkRect rect;
920 rect.setBounds(points, count);
921 if (count > 0) {
922 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
923 } else {
924 SkDebugf("%14s", " ");
925 }
926 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
927 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
928 }
929#StdOut
930 count: 0 rect: 0, 0, 0, 0
931added: 3, 4 count: 1 rect: 3, 4, 3, 4
932added: 1, 2 count: 2 rect: 1, 2, 3, 4
933added: 5, 6 count: 3 rect: 1, 2, 5, 6
934added: nan, 8 count: 4 rect: 0, 0, 0, 0
935##
936##
937
938#SeeAlso set setBoundsCheck SkPath::addPoly
939
940##
941
942# ------------------------------------------------------------------------------
943
944#Method bool setBoundsCheck(const SkPoint pts[], int count)
945
946Sets to bounds of Point array with count entries. Returns false if count is
947zero or smaller, or if Point array contains an infinity or NaN; in these cases
948sets Rect to (0, 0, 0, 0).
949
950Result is either empty or sorted: fLeft is less than or equal to fRight, and
951fTop is less than or equal to fBottom.
952
953#Param pts Point array ##
954#Param count entries in array ##
955
956#Return true if all Point values are finite ##
957
958#Example
959 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
960 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
961 SkRect rect;
962 bool success = rect.setBoundsCheck(points, count);
963 if (count > 0) {
964 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
965 } else {
966 SkDebugf("%14s", " ");
967 }
968 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
969 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
970 }
971#StdOut
972 count: 0 rect: 0, 0, 0, 0 success: true
973added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
974added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
975added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
976added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
977##
978##
979
980#SeeAlso set setBounds SkPath::addPoly
981
982##
983
984#Subtopic As_Points ##
985
986#Subtopic Set
987
988#Table
989#Legend
990# name # description ##
991#Legend ##
992# iset() # sets to int input (left, top, right, bottom) ##
993# isetWH # sets to int input (0, 0, width, height) ##
994# set() # sets to SkScalar input (left, top, right, bottom) and others ##
995# # void set(const SkIRect& src) ##
996# # void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
997# # void set(const SkPoint pts[], int count) ##
998# # void set(const SkPoint& p0, const SkPoint& p1) ##
999# setEmpty # sets to (0, 0, 0, 0) ##
1000# setLTRB # sets to SkScalar input (left, top, right, bottom) ##
1001# setWH # sets to SkScalar input (0, 0, width, height) ##
1002# setXYWH # sets to SkScalar input (x, y, width, height) ##
1003#Table ##
1004
1005# ------------------------------------------------------------------------------
1006
Cary Clarkbc5697d2017-10-04 14:31:33 -04001007#Method void setEmpty()
1008
Cary Clark7fc1d122017-10-09 14:07:42 -04001009Sets Rect to (0, 0, 0, 0).
1010
1011Many other rectangles are empty; if left is equal to or greater than right,
1012or if top is equal to or greater than bottom. Setting all members to zero
1013is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001014
1015#Example
Cary Clark154beea2017-10-26 07:58:48 -04001016 SkRect rect = {3, 4, 1, 2};
1017 for (int i = 0; i < 2; ++i) {
1018 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
1019 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
1020 rect.setEmpty();
1021 }
1022#StdOut
1023rect: {3, 4, 1, 2} is empty
1024rect: {0, 0, 0, 0} is empty
1025##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001026##
1027
Cary Clark7fc1d122017-10-09 14:07:42 -04001028#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -04001029
1030##
1031
1032# ------------------------------------------------------------------------------
1033
1034#Method void set(const SkIRect& src)
1035
Cary Clark7fc1d122017-10-09 14:07:42 -04001036Sets Rect to src, promoting src members from integer to Scalar.
1037Very large values in src may lose precision.
1038
1039#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001040
1041#Example
Cary Clark154beea2017-10-26 07:58:48 -04001042 SkIRect i_rect = {3, 4, 1, 2};
1043 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
1044 SkRect f_rect;
1045 f_rect.set(i_rect);
1046 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
1047#StdOut
1048i_rect: {3, 4, 1, 2}
1049f_rect: {3, 4, 1, 2}
1050##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001051##
1052
Cary Clark7fc1d122017-10-09 14:07:42 -04001053#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -04001054
1055##
1056
1057# ------------------------------------------------------------------------------
1058
1059#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1060
Cary Clark7fc1d122017-10-09 14:07:42 -04001061Sets Rect to (left, top, right, bottom).
1062left and right are not sorted; left is not necessarily less than right.
1063top and bottom are not sorted; top is not necessarily less than bottom.
1064
1065#Param left stored in fLeft ##
1066#Param top stored in fTop ##
1067#Param right stored in fRight ##
1068#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001069
1070#Example
Cary Clark154beea2017-10-26 07:58:48 -04001071 SkRect rect1 = {3, 4, 1, 2};
1072 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1073 SkRect rect2;
1074 rect2.set(3, 4, 1, 2);
1075 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1076#StdOut
1077rect1: {3, 4, 1, 2}
1078rect2: {3, 4, 1, 2}
1079##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001080##
1081
Cary Clark7fc1d122017-10-09 14:07:42 -04001082#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001083
1084##
1085
1086# ------------------------------------------------------------------------------
1087
1088#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1089
Cary Clark7fc1d122017-10-09 14:07:42 -04001090Sets Rect to (left, top, right, bottom).
1091left and right are not sorted; left is not necessarily less than right.
1092top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001093
Cary Clark7fc1d122017-10-09 14:07:42 -04001094#Param left stored in fLeft ##
1095#Param top stored in fTop ##
1096#Param right stored in fRight ##
1097#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001098
1099#Example
Cary Clark154beea2017-10-26 07:58:48 -04001100 SkRect rect1 = {3, 4, 1, 2};
1101 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1102 SkRect rect2;
1103 rect2.setLTRB(3, 4, 1, 2);
1104 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1105#StdOut
1106rect1: {3, 4, 1, 2}
1107rect2: {3, 4, 1, 2}
1108##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001109##
1110
Cary Clark7fc1d122017-10-09 14:07:42 -04001111#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001112
1113##
1114
1115# ------------------------------------------------------------------------------
1116
Cary Clarkbc5697d2017-10-04 14:31:33 -04001117#Method void set(const SkPoint pts[], int count)
1118
Cary Clark7fc1d122017-10-09 14:07:42 -04001119Sets to bounds of Point array with count entries. If count is zero or smaller,
1120or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001121
Cary Clark7fc1d122017-10-09 14:07:42 -04001122Result is either empty or sorted: fLeft is less than or equal to fRight, and
1123fTop is less than or equal to fBottom.
1124
1125#Param pts Point array ##
1126#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001127
1128#Example
Cary Clark154beea2017-10-26 07:58:48 -04001129 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1130 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1131 SkRect rect;
1132 rect.set(points, count);
1133 if (count > 0) {
1134 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1135 } else {
1136 SkDebugf("%14s", " ");
1137 }
1138 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1139 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1140 }
1141#StdOut
1142 count: 0 rect: 0, 0, 0, 0
1143added: 3, 4 count: 1 rect: 3, 4, 3, 4
1144added: 1, 2 count: 2 rect: 1, 2, 3, 4
1145added: 5, 6 count: 3 rect: 1, 2, 5, 6
1146added: nan, 8 count: 4 rect: 0, 0, 0, 0
1147##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001148##
1149
Cary Clark7fc1d122017-10-09 14:07:42 -04001150#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001151
1152##
1153
1154# ------------------------------------------------------------------------------
1155
Cary Clarkbc5697d2017-10-04 14:31:33 -04001156#Method void set(const SkPoint& p0, const SkPoint& p1)
1157
Cary Clark7fc1d122017-10-09 14:07:42 -04001158Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1159sorted and may be empty. Does not check to see if values are finite.
1160
1161#Param p0 corner to include ##
1162#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001163
1164#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001165#Description
1166p0 and p1 may be swapped and have the same effect unless one contains NaN.
1167##
Cary Clark154beea2017-10-26 07:58:48 -04001168 SkPoint point1 = {SK_ScalarNaN, 8};
1169 SkPoint point2 = {3, 4};
1170 SkRect rect;
1171 rect.set(point1, point2);
1172 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1173 rect.set(point2, point1);
1174 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001175##
1176
Cary Clark7fc1d122017-10-09 14:07:42 -04001177#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001178
1179##
1180
1181# ------------------------------------------------------------------------------
1182
1183#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1184
Cary Clark7fc1d122017-10-09 14:07:42 -04001185Sets Rect to
1186#Formula
1187(x, y, x + width, y + height)
1188##
1189. Does not validate input;
1190width or height may be negative.
1191
1192#Param x stored in fLeft ##
1193#Param y stored in fTop ##
1194#Param width added to x and stored in fRight ##
1195#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001196
1197#Example
Cary Clark154beea2017-10-26 07:58:48 -04001198 SkRect rect;
1199 rect.setXYWH(5, 35, -15, 25);
1200 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1201 rect.bottom(), rect.isEmpty() ? "true" : "false");
1202 rect.sort();
1203 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1204 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001205#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001206rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001207rect: -10, 35, 5, 60 isEmpty: false
1208##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001209##
1210
Cary Clark7fc1d122017-10-09 14:07:42 -04001211#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001212
1213##
1214
1215# ------------------------------------------------------------------------------
1216
1217#Method void setWH(SkScalar width, SkScalar height)
1218
Cary Clark7fc1d122017-10-09 14:07:42 -04001219Sets Rect to (0, 0, width, height). Does not validate input;
1220width or height may be negative.
1221
1222#Param width stored in fRight ##
1223#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001224
1225#Example
Cary Clark154beea2017-10-26 07:58:48 -04001226 SkRect rect;
1227 rect.setWH(-15, 25);
1228 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1229 rect.bottom(), rect.isEmpty() ? "true" : "false");
1230 rect.sort();
1231 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1232 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001233#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001234rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001235rect: -15, 0, 0, 25 isEmpty: false
1236##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001237##
1238
Cary Clark7fc1d122017-10-09 14:07:42 -04001239#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001240
1241##
1242
Cary Clark2dc84ad2018-01-26 12:56:22 -05001243#Subtopic Set ##
1244
1245#Subtopic From_Integers
1246
1247#Table
1248#Legend
1249# name # description ##
1250#Legend ##
1251# iset() # sets to int input (left, top, right, bottom) ##
1252# isetWH # sets to int input (0, 0, width, height) ##
1253#Table ##
1254
1255# ------------------------------------------------------------------------------
1256
1257#Method void iset(int left, int top, int right, int bottom)
1258
1259Sets Rect to (left, top, right, bottom).
1260All parameters are promoted from integer to Scalar.
1261left and right are not sorted; left is not necessarily less than right.
1262top and bottom are not sorted; top is not necessarily less than bottom.
1263
1264#Param left promoted to SkScalar and stored in fLeft ##
1265#Param top promoted to SkScalar and stored in fTop ##
1266#Param right promoted to SkScalar and stored in fRight ##
1267#Param bottom promoted to SkScalar and stored in fBottom ##
1268
1269#Example
1270 SkRect rect1 = {3, 4, 1, 2};
1271 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1272 SkRect rect2;
1273 rect2.iset(3, 4, 1, 2);
1274 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1275#StdOut
1276rect1: {3, 4, 1, 2}
1277rect2: {3, 4, 1, 2}
1278##
1279##
1280
1281#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1282
1283##
1284
1285# ------------------------------------------------------------------------------
1286
1287#Method void isetWH(int width, int height)
1288
1289Sets Rect to (0, 0, width, height).
1290width and height may be zero or negative. width and height are promoted from
1291integer to SkScalar, large values may lose precision.
1292
1293#Param width promoted to SkScalar and stored in fRight ##
1294#Param height promoted to SkScalar and stored in fBottom ##
1295
1296#Example
1297 SkRect rect1 = {0, 0, 1, 2};
1298 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1299 SkRect rect2;
1300 rect2.isetWH(1, 2);
1301 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1302#StdOut
1303rect1: {0, 0, 1, 2}
1304rect2: {0, 0, 1, 2}
1305##
1306##
1307
1308#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1309
1310##
1311
1312#Subtopic From_Integers ##
1313
1314#Subtopic Inset_Outset_Offset
1315
1316#Table
1317#Legend
1318# name # description ##
1319#Legend ##
1320# inset() # moves the sides symmetrically about the center ##
1321# makeInset # constructs from sides moved symmetrically about the center ##
1322# makeOffset # constructs from translated sides ##
1323# makeOutset # constructs from sides moved symmetrically about the center ##
1324# offset() # translates sides without changing width and height ##
1325# # void offset(SkScalar dx, SkScalar dy) ##
1326# # void offset(const SkPoint& delta) ##
1327# offsetTo # translates to (x, y) without changing width and height ##
1328# outset() # moves the sides symmetrically about the center ##
1329#Table ##
1330
Cary Clarkbc5697d2017-10-04 14:31:33 -04001331# ------------------------------------------------------------------------------
1332
Cary Clarkbc5697d2017-10-04 14:31:33 -04001333#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1334
Cary Clark7fc1d122017-10-09 14:07:42 -04001335Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001336
Cary Clark7fc1d122017-10-09 14:07:42 -04001337If dx is negative, Rect returned is moved to the left.
1338If dx is positive, Rect returned is moved to the right.
1339If dy is negative, Rect returned is moved upward.
1340If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001341
Cary Clark7fc1d122017-10-09 14:07:42 -04001342#Param dx added to fLeft and fRight ##
1343#Param dy added to fTop and fBottom ##
1344
1345#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001346
1347#Example
Cary Clark154beea2017-10-26 07:58:48 -04001348 SkRect rect = { 10, 50, 20, 60 };
1349 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1350 rect.bottom(), rect.isEmpty() ? "true" : "false");
1351 rect = rect.makeOffset(15, 32);
1352 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1353 rect.bottom(), rect.isEmpty() ? "true" : "false");
1354#StdOut
1355rect: 10, 50, 20, 60 isEmpty: false
1356rect: 25, 82, 35, 92 isEmpty: false
1357##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358##
1359
Cary Clark7fc1d122017-10-09 14:07:42 -04001360#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001361
1362##
1363
1364# ------------------------------------------------------------------------------
1365
1366#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1367
Cary Clark7fc1d122017-10-09 14:07:42 -04001368Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001369
Cary Clark7fc1d122017-10-09 14:07:42 -04001370If dx is negative, Rect returned is wider.
1371If dx is positive, Rect returned is narrower.
1372If dy is negative, Rect returned is taller.
1373If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001374
Cary Clark7fc1d122017-10-09 14:07:42 -04001375#Param dx added to fLeft and subtracted from fRight ##
1376#Param dy added to fTop and subtracted from fBottom ##
1377
1378#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001379
1380#Example
Cary Clark154beea2017-10-26 07:58:48 -04001381 SkRect rect = { 10, 50, 20, 60 };
1382 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1383 rect.bottom(), rect.isEmpty() ? "true" : "false");
1384 rect = rect.makeInset(15, 32);
1385 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1386 rect.bottom(), rect.isEmpty() ? "true" : "false");
1387#StdOut
1388rect: 10, 50, 20, 60 isEmpty: false
1389rect: 25, 82, 5, 28 isEmpty: true
1390##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001391##
1392
Cary Clark7fc1d122017-10-09 14:07:42 -04001393#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001394
1395##
1396
1397# ------------------------------------------------------------------------------
1398
1399#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1400
Cary Clark7fc1d122017-10-09 14:07:42 -04001401Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001402
Cary Clark7fc1d122017-10-09 14:07:42 -04001403If dx is negative, Rect returned is narrower.
1404If dx is positive, Rect returned is wider.
1405If dy is negative, Rect returned is shorter.
1406If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001407
Cary Clark7fc1d122017-10-09 14:07:42 -04001408#Param dx subtracted to fLeft and added from fRight ##
1409#Param dy subtracted to fTop and added from fBottom ##
1410
1411#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001412
1413#Example
Cary Clark154beea2017-10-26 07:58:48 -04001414 SkRect rect = { 10, 50, 20, 60 };
1415 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1416 rect.bottom(), rect.isEmpty() ? "true" : "false");
1417 rect = rect.makeOutset(15, 32);
1418 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1419 rect.bottom(), rect.isEmpty() ? "true" : "false");
1420#StdOut
1421rect: 10, 50, 20, 60 isEmpty: false
1422rect: -5, 18, 35, 92 isEmpty: false
1423##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001424##
1425
Cary Clark7fc1d122017-10-09 14:07:42 -04001426#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001427
1428##
1429
1430# ------------------------------------------------------------------------------
1431
1432#Method void offset(SkScalar dx, SkScalar dy)
1433
Cary Clark7fc1d122017-10-09 14:07:42 -04001434Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001435
Cary Clark7fc1d122017-10-09 14:07:42 -04001436If dx is negative, moves Rect to the left.
1437If dx is positive, moves Rect to the right.
1438If dy is negative, moves Rect upward.
1439If dy is positive, moves Rect downward.
1440
1441#Param dx offset added to fLeft and fRight ##
1442#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001443
1444#Example
Cary Clark154beea2017-10-26 07:58:48 -04001445 SkRect rect = { 10, 14, 50, 73 };
1446 rect.offset(5, 13);
1447 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1448#StdOut
1449rect: 15, 27, 55, 86
1450##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001451##
1452
Cary Clark7fc1d122017-10-09 14:07:42 -04001453#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001454
1455##
1456
1457# ------------------------------------------------------------------------------
1458
1459#Method void offset(const SkPoint& delta)
1460
Cary Clark7fc1d122017-10-09 14:07:42 -04001461Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1462fTop, fBottom.
1463
1464If delta.fX is negative, moves Rect to the left.
1465If delta.fX is positive, moves Rect to the right.
1466If delta.fY is negative, moves Rect upward.
1467If delta.fY is positive, moves Rect downward.
1468
1469#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001470
1471#Example
Cary Clark154beea2017-10-26 07:58:48 -04001472 SkRect rect = { 10, 14, 50, 73 };
1473 rect.offset({5, 13});
1474 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1475#StdOut
1476rect: 15, 27, 55, 86
1477##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001478##
1479
Cary Clark7fc1d122017-10-09 14:07:42 -04001480#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001481
1482##
1483
1484# ------------------------------------------------------------------------------
1485
1486#Method void offsetTo(SkScalar newX, SkScalar newY)
1487
Cary Clark7fc1d122017-10-09 14:07:42 -04001488Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1489are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001490
Cary Clark7fc1d122017-10-09 14:07:42 -04001491#Param newX stored in fLeft, preserving width() ##
1492#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001493
1494#Example
Cary Clark154beea2017-10-26 07:58:48 -04001495 SkRect rect = { 10, 14, 50, 73 };
1496 rect.offsetTo(15, 27);
1497 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1498#StdOut
1499rect: 15, 27, 55, 86
1500##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001501##
1502
Cary Clark7fc1d122017-10-09 14:07:42 -04001503#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001504
1505##
1506
1507# ------------------------------------------------------------------------------
1508
1509#Method void inset(SkScalar dx, SkScalar dy)
1510
Cary Clark7fc1d122017-10-09 14:07:42 -04001511Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001512
Cary Clark7fc1d122017-10-09 14:07:42 -04001513If dx is positive, makes Rect narrower.
1514If dx is negative, makes Rect wider.
1515If dy is positive, makes Rect shorter.
1516If dy is negative, makes Rect taller.
1517
1518#Param dx added to fLeft and subtracted from fRight ##
1519#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001520
1521#Example
Cary Clark154beea2017-10-26 07:58:48 -04001522 SkRect rect = { 10, 14, 50, 73 };
1523 rect.inset(5, 13);
1524 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1525#StdOut
1526rect: 15, 27, 45, 60
1527##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001528##
1529
Cary Clark7fc1d122017-10-09 14:07:42 -04001530#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001531
1532##
1533
1534# ------------------------------------------------------------------------------
1535
1536#Method void outset(SkScalar dx, SkScalar dy)
1537
Cary Clark7fc1d122017-10-09 14:07:42 -04001538Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001539
Cary Clark7fc1d122017-10-09 14:07:42 -04001540If dx is positive, makes Rect wider.
1541If dx is negative, makes Rect narrower.
1542If dy is positive, makes Rect taller.
1543If dy is negative, makes Rect shorter.
1544
1545#Param dx subtracted to fLeft and added from fRight ##
1546#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001547
1548#Example
Cary Clark154beea2017-10-26 07:58:48 -04001549 SkRect rect = { 10, 14, 50, 73 };
1550 rect.outset(5, 13);
1551 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1552#StdOut
1553rect: 5, 1, 55, 86
1554##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001555##
1556
Cary Clark7fc1d122017-10-09 14:07:42 -04001557#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001558
1559##
1560
Cary Clark2dc84ad2018-01-26 12:56:22 -05001561#Subtopic Inset_Outset_Offset ##
1562
1563#Subtopic Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001564
1565Rects intersect when they enclose a common area. To intersect, each of the pair
1566must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001567empty() returns false. The intersection of Rect pair can be described by:
1568
Cary Clark7fc1d122017-10-09 14:07:42 -04001569#Formula
1570(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1571 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1572##
Cary Clark154beea2017-10-26 07:58:48 -04001573.
1574
Cary Clark7fc1d122017-10-09 14:07:42 -04001575The intersection is only meaningful if the resulting Rect is not empty and
1576describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1577
Cary Clark2dc84ad2018-01-26 12:56:22 -05001578#Table
1579#Legend
1580# name # description ##
1581#Legend ##
1582# Intersects # returns true if areas overlap ##
1583# contains() # returns true if points are equal or inside ##
1584# # bool contains(const SkRect& r) const ##
1585# # bool contains(const SkIRect& r) const ##
1586# intersect() # sets to shared area; returns true if not empty ##
1587# # bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1588# # bool intersect(const SkRect& r) ##
1589# # bool intersect(const SkRect& a, const SkRect& b) ##
1590# intersects() # returns true if areas overlap ##
1591# # bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const ##
1592# # bool intersects(const SkRect& r) const ##
1593#Table ##
1594
1595# ------------------------------------------------------------------------------
1596
1597#Method bool contains(const SkRect& r) const
1598
1599Returns true if Rect contains r.
1600Returns false if Rect is empty or r is empty.
1601
1602Rect contains r when Rect area completely includes r area.
1603
1604#Param r Rect contained ##
1605
1606#Return true if all sides of Rect are outside r ##
1607
1608#Example
1609 SkRect rect = { 30, 50, 40, 60 };
1610 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1611 for (auto contained : tests) {
1612 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1613 rect.left(), rect.top(), rect.right(), rect.bottom(),
1614 rect.contains(contained) ? "contains" : "does not contain",
1615 contained.left(), contained.top(), contained.right(), contained.bottom());
1616 }
1617#StdOut
1618rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1619rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1620rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1621##
1622##
1623
1624#SeeAlso SkIRect::contains
1625
1626##
1627
1628# ------------------------------------------------------------------------------
1629
1630#Method bool contains(const SkIRect& r) const
1631
1632Returns true if Rect contains r.
1633Returns false if Rect is empty or r is empty.
1634
1635Rect contains r when Rect area completely includes r area.
1636
1637#Param r IRect contained ##
1638
1639#Return true if all sides of Rect are outside r ##
1640
1641#Example
1642 SkRect rect = { 30, 50, 40, 60 };
1643 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1644 for (auto contained : tests) {
1645 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1646 rect.left(), rect.top(), rect.right(), rect.bottom(),
1647 rect.contains(contained) ? "contains" : "does not contain",
1648 contained.left(), contained.top(), contained.right(), contained.bottom());
1649 }
1650#StdOut
1651rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1652rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1653rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1654##
1655##
1656
1657#SeeAlso SkIRect::contains
1658
1659##
1660
Cary Clarkbc5697d2017-10-04 14:31:33 -04001661# ------------------------------------------------------------------------------
1662
1663#Method bool intersect(const SkRect& r)
1664
Cary Clark7fc1d122017-10-09 14:07:42 -04001665Returns true if Rect intersects r, and sets Rect to intersection.
1666Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001667
Cary Clark7fc1d122017-10-09 14:07:42 -04001668Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001669
Cary Clark7fc1d122017-10-09 14:07:42 -04001670#Param r limit of result ##
1671
1672#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001673
1674#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001675#Description
1676Two SkDebugf calls are required. If the calls are combined, their arguments
1677may not be evaluated in left to right order: the printed intersection may
1678be before or after the call to intersect.
1679##
Cary Clark154beea2017-10-26 07:58:48 -04001680 SkRect leftRect = { 10, 40, 50, 80 };
1681 SkRect rightRect = { 30, 60, 70, 90 };
1682 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1683 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001684 leftRect.right(), leftRect.bottom());
1685#StdOut
1686 intersection: 30, 60, 50, 80
1687##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001688##
1689
Cary Clark7fc1d122017-10-09 14:07:42 -04001690#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001691
1692##
1693
1694# ------------------------------------------------------------------------------
1695
1696#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1697
Cary Clark7fc1d122017-10-09 14:07:42 -04001698Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1699construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001700
Cary Clark7fc1d122017-10-09 14:07:42 -04001701Returns true if Rect intersects construction, and sets Rect to intersection.
1702Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001703
Cary Clark7fc1d122017-10-09 14:07:42 -04001704Returns false if either construction or Rect is empty, leaving Rect unchanged.
1705
1706#Param left x minimum of constructed Rect ##
1707#Param top y minimum of constructed Rect ##
1708#Param right x maximum of constructed Rect ##
1709#Param bottom y maximum of constructed Rect ##
1710
1711#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001712
1713#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001714#Description
1715Two SkDebugf calls are required. If the calls are combined, their arguments
1716may not be evaluated in left to right order: the printed intersection may
1717be before or after the call to intersect.
1718##
Cary Clark154beea2017-10-26 07:58:48 -04001719 SkRect leftRect = { 10, 40, 50, 80 };
1720 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1721 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001722 leftRect.right(), leftRect.bottom());
1723#StdOut
1724 intersection: 30, 60, 50, 80
1725##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001726##
1727
Cary Clark7fc1d122017-10-09 14:07:42 -04001728#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001729
1730##
1731
1732# ------------------------------------------------------------------------------
1733
1734#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1735
Cary Clark7fc1d122017-10-09 14:07:42 -04001736Returns true if a intersects b, and sets Rect to intersection.
1737Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001738
Cary Clark7fc1d122017-10-09 14:07:42 -04001739Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001740
Cary Clark7fc1d122017-10-09 14:07:42 -04001741#Param a Rect to intersect ##
1742#Param b Rect to intersect ##
1743
1744#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001745
1746#Example
Cary Clark154beea2017-10-26 07:58:48 -04001747 SkRect result;
1748 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1749 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1750 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001751#StdOut
1752 intersection: 30, 60, 50, 80
1753##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001754##
1755
Cary Clark7fc1d122017-10-09 14:07:42 -04001756#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001757
1758##
1759
Cary Clark7fc1d122017-10-09 14:07:42 -04001760# ------------------------------------------------------------------------------
1761
Cary Clarkbc5697d2017-10-04 14:31:33 -04001762#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1763
Cary Clark7fc1d122017-10-09 14:07:42 -04001764Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1765construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001766
Cary Clark7fc1d122017-10-09 14:07:42 -04001767Returns true if Rect intersects construction.
1768Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769
Cary Clark7fc1d122017-10-09 14:07:42 -04001770#Param left x minimum of constructed Rect ##
1771#Param top y minimum of constructed Rect ##
1772#Param right x maximum of constructed Rect ##
1773#Param bottom y maximum of constructed Rect ##
1774
1775#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001776
1777#Example
Cary Clark154beea2017-10-26 07:58:48 -04001778 SkRect rect = { 10, 40, 50, 80 };
1779 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001780#StdOut
1781 intersection
1782##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001783##
1784
Cary Clark7fc1d122017-10-09 14:07:42 -04001785#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001786
1787##
1788
Cary Clark7fc1d122017-10-09 14:07:42 -04001789# ------------------------------------------------------------------------------
1790
Cary Clarkbc5697d2017-10-04 14:31:33 -04001791#Method bool intersects(const SkRect& r) const
1792
Cary Clark7fc1d122017-10-09 14:07:42 -04001793Returns true if Rect intersects r.
1794Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001795
Cary Clark7fc1d122017-10-09 14:07:42 -04001796#Param r Rect to intersect ##
1797
1798#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001799
1800#Example
Cary Clark154beea2017-10-26 07:58:48 -04001801 SkRect rect = { 10, 40, 50, 80 };
1802 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001803#StdOut
1804 intersection
1805##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001806##
1807
Cary Clark7fc1d122017-10-09 14:07:42 -04001808#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001809
1810##
1811
Cary Clark7fc1d122017-10-09 14:07:42 -04001812# ------------------------------------------------------------------------------
1813
Cary Clarkbc5697d2017-10-04 14:31:33 -04001814#Method static bool Intersects(const SkRect& a, const SkRect& b)
1815
Cary Clark7fc1d122017-10-09 14:07:42 -04001816Returns true if a intersects b.
1817Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001818
Cary Clark7fc1d122017-10-09 14:07:42 -04001819#Param a Rect to intersect ##
1820#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001821
Cary Clark7fc1d122017-10-09 14:07:42 -04001822#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001823
1824#Example
Cary Clark154beea2017-10-26 07:58:48 -04001825 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001826#StdOut
1827 intersection
1828##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001829##
1830
Cary Clark7fc1d122017-10-09 14:07:42 -04001831#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001832
1833##
1834
Cary Clark2dc84ad2018-01-26 12:56:22 -05001835#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001836
Cary Clark2dc84ad2018-01-26 12:56:22 -05001837#Subtopic Join
1838
1839#Table
1840#Legend
1841# name # description ##
1842#Legend ##
1843# join() # sets to union of bounds ##
1844# # void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1845# # void join(const SkRect& r) ##
1846# joinNonEmptyArg # sets to union of bounds, asserting that argument is not empty ##
1847# joinPossiblyEmptyRect # sets to union of bounds. Skips empty check for both ##
1848#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001849
1850# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001851
1852#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1853
Cary Clark7fc1d122017-10-09 14:07:42 -04001854Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1855construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001856
Cary Clark7fc1d122017-10-09 14:07:42 -04001857Sets Rect to the union of itself and the construction.
1858
1859Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1860Rect to construction.
1861
1862#Param left x minimum of constructed Rect ##
1863#Param top y minimum of constructed Rect ##
1864#Param right x maximum of constructed Rect ##
1865#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001866
1867#Example
Cary Clark154beea2017-10-26 07:58:48 -04001868 SkRect rect = { 10, 20, 15, 25};
1869 rect.join(50, 60, 55, 65);
1870 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001871#StdOut
1872 join: 10, 20, 55, 65
1873##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001874##
1875
Cary Clark7fc1d122017-10-09 14:07:42 -04001876#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001877
1878##
1879
Cary Clark7fc1d122017-10-09 14:07:42 -04001880# ------------------------------------------------------------------------------
1881
Cary Clarkbc5697d2017-10-04 14:31:33 -04001882#Method void join(const SkRect& r)
1883
Cary Clark7fc1d122017-10-09 14:07:42 -04001884Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885
Cary Clark7fc1d122017-10-09 14:07:42 -04001886Has no effect if r is empty. Otherwise, if Rect is empty, sets
1887Rect to r.
1888
1889#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001890
1891#Example
Cary Clark154beea2017-10-26 07:58:48 -04001892 SkRect rect = { 10, 20, 15, 25};
1893 rect.join({50, 60, 55, 65});
1894 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001895#StdOut
1896 join: 10, 20, 55, 65
1897##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001898##
1899
Cary Clark7fc1d122017-10-09 14:07:42 -04001900#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001901
1902##
1903
Cary Clark7fc1d122017-10-09 14:07:42 -04001904# ------------------------------------------------------------------------------
1905
Cary Clarkbc5697d2017-10-04 14:31:33 -04001906#Method void joinNonEmptyArg(const SkRect& r)
1907
Cary Clark7fc1d122017-10-09 14:07:42 -04001908Sets Rect to the union of itself and r.
1909
1910Asserts if r is empty and SK_DEBUG is defined.
1911If Rect is empty, sets Rect to r.
1912
1913May produce incorrect results if r is empty.
1914
1915#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001916
1917#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001918#Description
1919Since Rect is not sorted, first result is copy of toJoin.
1920##
Cary Clark154beea2017-10-26 07:58:48 -04001921 SkRect rect = { 10, 100, 15, 0};
1922 SkRect sorted = rect.makeSorted();
1923 SkRect toJoin = { 50, 60, 55, 65 };
1924 rect.joinNonEmptyArg(toJoin);
1925 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1926 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001927 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1928#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001929rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001930sorted: 10, 0, 55, 100
1931##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001932##
1933
Cary Clark7fc1d122017-10-09 14:07:42 -04001934#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001935
1936##
1937
Cary Clark7fc1d122017-10-09 14:07:42 -04001938# ------------------------------------------------------------------------------
1939
Cary Clarkbc5697d2017-10-04 14:31:33 -04001940#Method void joinPossiblyEmptyRect(const SkRect& r)
1941
Cary Clark7fc1d122017-10-09 14:07:42 -04001942Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001943
Cary Clark7fc1d122017-10-09 14:07:42 -04001944May produce incorrect results if Rect or r is empty.
1945
1946#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001947
1948#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001949#Description
1950Since Rect is not sorted, first result is not useful.
1951##
Cary Clark154beea2017-10-26 07:58:48 -04001952 SkRect rect = { 10, 100, 15, 0};
1953 SkRect sorted = rect.makeSorted();
1954 SkRect toJoin = { 50, 60, 55, 65 };
1955 rect.joinPossiblyEmptyRect(toJoin);
1956 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1957 sorted.joinPossiblyEmptyRect(toJoin);
1958 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001959#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001960rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001961sorted: 10, 0, 55, 100
1962##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001963##
1964
Cary Clark7fc1d122017-10-09 14:07:42 -04001965#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001966
1967##
1968
Cary Clark2dc84ad2018-01-26 12:56:22 -05001969#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001970
Cary Clark2dc84ad2018-01-26 12:56:22 -05001971#Subtopic Rounding
Cary Clarkbc5697d2017-10-04 14:31:33 -04001972
Cary Clark2dc84ad2018-01-26 12:56:22 -05001973#Table
1974#Legend
1975# name # description ##
1976#Legend ##
1977# round() # sets members to nearest integer value ##
1978# # void round(SkIRect* dst) const ##
1979# # SkIRect round() const ##
1980# roundIn # sets members to nearest integer value towards opposite ##
1981# roundOut # sets members to nearest integer value away from opposite ##
1982# # void roundOut(SkIRect* dst) const ##
1983# # void roundOut(SkRect* dst) const ##
1984# # SkIRect roundOut() const ##
1985#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001986
Cary Clarkbc5697d2017-10-04 14:31:33 -04001987#Method void round(SkIRect* dst) const
1988
Cary Clark7fc1d122017-10-09 14:07:42 -04001989Sets IRect by adding 0.5 and discarding the fractional portion of Rect
1990members, using
1991#Formula
1992(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
1993 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
1994##
1995.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001996
Cary Clark7fc1d122017-10-09 14:07:42 -04001997#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001998
1999#Example
Cary Clark154beea2017-10-26 07:58:48 -04002000 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2001 SkIRect round;
2002 rect.round(&round);
2003 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002004#StdOut
2005round: 31, 51, 41, 61
2006##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002007##
2008
Cary Clark7fc1d122017-10-09 14:07:42 -04002009#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002010
2011##
2012
Cary Clark7fc1d122017-10-09 14:07:42 -04002013# ------------------------------------------------------------------------------
2014
Cary Clarkbc5697d2017-10-04 14:31:33 -04002015#Method void roundOut(SkIRect* dst) const
2016
Cary Clark7fc1d122017-10-09 14:07:42 -04002017Sets IRect by discarding the fractional portion of fLeft and fTop; and
2018rounding up fRight and FBottom, using
2019#Formula
2020(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2021 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2022##
2023.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002024
Cary Clark7fc1d122017-10-09 14:07:42 -04002025#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002026
2027#Example
Cary Clark154beea2017-10-26 07:58:48 -04002028 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2029 SkIRect round;
2030 rect.roundOut(&round);
2031 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002032#StdOut
2033round: 30, 50, 41, 61
2034##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002035##
2036
Cary Clark7fc1d122017-10-09 14:07:42 -04002037#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002038
2039##
2040
Cary Clark7fc1d122017-10-09 14:07:42 -04002041# ------------------------------------------------------------------------------
2042
Cary Clarkbc5697d2017-10-04 14:31:33 -04002043#Method void roundOut(SkRect* dst) const
2044
Cary Clark7fc1d122017-10-09 14:07:42 -04002045Sets Rect by discarding the fractional portion of fLeft and fTop; and
2046rounding up fRight and FBottom, using
2047#Formula
2048(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2049 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2050##
2051.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002052
Cary Clark7fc1d122017-10-09 14:07:42 -04002053#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002054
2055#Example
Cary Clark154beea2017-10-26 07:58:48 -04002056 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2057 SkRect round;
2058 rect.roundOut(&round);
2059 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002060#StdOut
2061round: 30, 50, 41, 61
2062##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002063##
2064
Cary Clark7fc1d122017-10-09 14:07:42 -04002065#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002066
2067##
2068
Cary Clark7fc1d122017-10-09 14:07:42 -04002069# ------------------------------------------------------------------------------
2070
Cary Clarkbc5697d2017-10-04 14:31:33 -04002071#Method void roundIn(SkIRect* dst) const
2072
Cary Clark7fc1d122017-10-09 14:07:42 -04002073Sets Rect by rounding up fLeft and fTop; and
2074discarding the fractional portion of fRight and FBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002075
Cary Clark7fc1d122017-10-09 14:07:42 -04002076#Formula
2077(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2078 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2079##
2080.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002081
Cary Clark7fc1d122017-10-09 14:07:42 -04002082#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002083
2084#Example
Cary Clark154beea2017-10-26 07:58:48 -04002085 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2086 SkIRect round;
2087 rect.roundIn(&round);
2088 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002089#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002090round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002091##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002092##
2093
Cary Clark7fc1d122017-10-09 14:07:42 -04002094#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002095
2096##
2097
Cary Clark7fc1d122017-10-09 14:07:42 -04002098# ------------------------------------------------------------------------------
2099
Cary Clarkbc5697d2017-10-04 14:31:33 -04002100#Method SkIRect round() const
2101
Cary Clark7fc1d122017-10-09 14:07:42 -04002102Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2103members, using
2104#Formula
2105(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2106 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2107##
2108.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002109
Cary Clark7fc1d122017-10-09 14:07:42 -04002110#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002111
2112#Example
Cary Clark154beea2017-10-26 07:58:48 -04002113 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2114 SkIRect round = rect.round();
2115 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002116#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002117round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002118##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002119##
2120
Cary Clark7fc1d122017-10-09 14:07:42 -04002121#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002122
2123##
2124
Cary Clark7fc1d122017-10-09 14:07:42 -04002125# ------------------------------------------------------------------------------
2126
Cary Clarkbc5697d2017-10-04 14:31:33 -04002127#Method SkIRect roundOut() const
2128
Cary Clark7fc1d122017-10-09 14:07:42 -04002129Sets IRect by discarding the fractional portion of fLeft and fTop; and
2130rounding up fRight and FBottom, using
2131#Formula
2132(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2133 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2134##
2135.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002136
Cary Clark7fc1d122017-10-09 14:07:42 -04002137#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002138
2139#Example
Cary Clark154beea2017-10-26 07:58:48 -04002140 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2141 SkIRect round = rect.roundOut();
2142 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002143#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002144round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002145##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002146##
2147
Cary Clark7fc1d122017-10-09 14:07:42 -04002148#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002149
2150##
2151
Cary Clark2dc84ad2018-01-26 12:56:22 -05002152#Subtopic Rounding ##
2153
2154#Subtopic Sorting
2155
2156#Table
2157#Legend
2158# name # description ##
2159#Legend ##
2160# makeSorted # constructs, ordering sides from smaller to larger ##
2161# sort() # orders sides from smaller to larger ##
2162#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002163
2164# ------------------------------------------------------------------------------
2165
Cary Clarkbc5697d2017-10-04 14:31:33 -04002166#Method void sort()
2167
Cary Clark7fc1d122017-10-09 14:07:42 -04002168Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2169fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2170and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002171
2172#Example
Cary Clark154beea2017-10-26 07:58:48 -04002173 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2174 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2175 rect.sort();
2176 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002177#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002178rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002179sorted: 20.5, 10.5, 30.5, 50.5
2180##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002181##
2182
Cary Clark2dc84ad2018-01-26 12:56:22 -05002183#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002184
2185##
2186
Cary Clark7fc1d122017-10-09 14:07:42 -04002187# ------------------------------------------------------------------------------
2188
Cary Clarkbc5697d2017-10-04 14:31:33 -04002189#Method SkRect makeSorted() const
2190
Cary Clark7fc1d122017-10-09 14:07:42 -04002191Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2192with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2193and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002194
Cary Clark7fc1d122017-10-09 14:07:42 -04002195#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002196
2197#Example
Cary Clark154beea2017-10-26 07:58:48 -04002198 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2199 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2200 SkRect sort = rect.makeSorted();
2201 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002202#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002203rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002204sorted: 20.5, 10.5, 30.5, 50.5
2205##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002206##
2207
Cary Clark2dc84ad2018-01-26 12:56:22 -05002208#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002209
2210##
2211
Cary Clark2dc84ad2018-01-26 12:56:22 -05002212#Subtopic Sorting ##
2213
Cary Clark7fc1d122017-10-09 14:07:42 -04002214# ------------------------------------------------------------------------------
2215
Cary Clarkbc5697d2017-10-04 14:31:33 -04002216#Method const SkScalar* asScalars() const
2217
Cary Clark7fc1d122017-10-09 14:07:42 -04002218Returns pointer to first Scalar in Rect, to treat it as an array with four
2219entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002220
Cary Clark7fc1d122017-10-09 14:07:42 -04002221#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002222
2223#Example
Cary Clark154beea2017-10-26 07:58:48 -04002224 SkRect rect = {7, 11, 13, 17};
2225SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2226#StdOut
2227rect.asScalars() == &rect.fLeft
2228##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002229##
2230
Cary Clark7fc1d122017-10-09 14:07:42 -04002231#SeeAlso toQuad
2232
Cary Clarkbc5697d2017-10-04 14:31:33 -04002233##
2234
Cary Clark7fc1d122017-10-09 14:07:42 -04002235# ------------------------------------------------------------------------------
2236
Cary Clarkbc5697d2017-10-04 14:31:33 -04002237#Method void dump(bool asHex) const
2238
Cary Clark7fc1d122017-10-09 14:07:42 -04002239Writes text representation of Rect to standard output. Set asHex to true to
2240generate exact binary representations of floating point numbers.
2241
2242#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002243
2244#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002245 SkRect rect = {20, 30, 40, 50};
2246 for (bool dumpAsHex : { false, true } ) {
2247 rect.dump(dumpAsHex);
2248 SkDebugf("\n");
2249 }
2250#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002251SkRect::MakeLTRB(20, 30, 40, 50);
2252
2253SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2254 SkBits2Float(0x41f00000), /* 30.000000 */
2255 SkBits2Float(0x42200000), /* 40.000000 */
2256 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002257##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002258##
2259
Cary Clark7fc1d122017-10-09 14:07:42 -04002260#SeeAlso dumpHex
2261
Cary Clarkbc5697d2017-10-04 14:31:33 -04002262##
2263
Cary Clark7fc1d122017-10-09 14:07:42 -04002264# ------------------------------------------------------------------------------
2265
Cary Clarkbc5697d2017-10-04 14:31:33 -04002266#Method void dump() const
2267
Cary Clark7fc1d122017-10-09 14:07:42 -04002268Writes text representation of Rect to standard output. The representation may be
2269directly compiled as C++ code. Floating point values are written
2270with limited precision; it may not be possible to reconstruct original Rect
2271from output.
2272
Cary Clarkbc5697d2017-10-04 14:31:33 -04002273#Example
Cary Clark154beea2017-10-26 07:58:48 -04002274SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2275rect.dump();
2276SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2277SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002278#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002279SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002280rect is not equal to copy
2281##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002282##
2283
Cary Clark7fc1d122017-10-09 14:07:42 -04002284#SeeAlso dumpHex
2285
Cary Clarkbc5697d2017-10-04 14:31:33 -04002286##
2287
Cary Clark7fc1d122017-10-09 14:07:42 -04002288# ------------------------------------------------------------------------------
2289
Cary Clarkbc5697d2017-10-04 14:31:33 -04002290#Method void dumpHex() const
2291
Cary Clark7fc1d122017-10-09 14:07:42 -04002292Writes text representation of Rect to standard output. The representation may be
2293directly compiled as C++ code. Floating point values are written
2294in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2295original Rect.
2296
2297Use instead of dump() when submitting
2298#A bug reports against Skia # http://bug.skia.org ##
2299.
2300
Cary Clarkbc5697d2017-10-04 14:31:33 -04002301#Example
Cary Clark154beea2017-10-26 07:58:48 -04002302 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2303rect.dumpHex();
2304SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2305 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2306 SkBits2Float(0x40266666), /* 2.600000 */
2307 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002308SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2309#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002310SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2311 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2312 SkBits2Float(0x40266666), /* 2.600000 */
2313 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002314rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002315##
Cary Clark7fc1d122017-10-09 14:07:42 -04002316##
2317
2318#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002319
2320##
2321
Cary Clark0c95aab2018-01-08 16:20:59 -05002322#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
2323
2324#Deprecated
2325##
2326
Cary Clarkac47b882018-01-11 10:35:44 -05002327Returns constructed SkRect setting left and top to most negative finite value, and
2328setting right and bottom to most positive finite value.
2329
2330#Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
2331
Cary Clark0c95aab2018-01-08 16:20:59 -05002332##
2333
Cary Clarkbc5697d2017-10-04 14:31:33 -04002334#Struct SkRect ##
2335
2336#Topic Rect ##