blob: e8d1329a06af69f0a3234f6fd33b47d9b1f20515 [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 Clarkab2621d2018-01-30 10:08:57 -0500161#In Constructors
162#Line # constructs from bounds of (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400163Returns constructed Rect set to (0, 0, 0, 0).
164Many other rectangles are empty; if left is equal to or greater than right,
165or if top is equal to or greater than bottom. Setting all members to zero
166is a convenience, but does not designate a special empty rectangle.
167
168#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400169
170#Example
Cary Clark154beea2017-10-26 07:58:48 -0400171 SkRect rect = SkRect::MakeEmpty();
172 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
173 rect.offset(10, 10);
174 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
175 rect.inset(10, 10);
176 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
177 rect.outset(20, 20);
178 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
179#StdOut
180MakeEmpty isEmpty: true
181offset rect isEmpty: true
182inset rect isEmpty: true
183outset rect isEmpty: false
184##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400185##
186
Mike Reed274218e2018-01-08 15:05:02 -0500187#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty
Cary Clark884dd7d2017-10-11 10:37:52 -0400188
189##
190
191# ------------------------------------------------------------------------------
192
193#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400194
Cary Clarkab2621d2018-01-30 10:08:57 -0500195#In Constructors
196#Line # constructs from SkScalar input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400197Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
198validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400199
Cary Clark7fc1d122017-10-09 14:07:42 -0400200Passing integer values may generate a compiler warning since Rect cannot
201represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
202
203#Param w SkScalar width of constructed Rect ##
204#Param h SkScalar height of constructed Rect ##
205
206#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400207
208#Example
Cary Clark154beea2017-10-26 07:58:48 -0400209 SkRect rect1 = SkRect::MakeWH(25, 35);
210 SkRect rect2 = SkRect::MakeIWH(25, 35);
211 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
212 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
213 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400214 "" : "not ");
215#StdOut
216all equal
217##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400218##
219
Cary Clark7fc1d122017-10-09 14:07:42 -0400220#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400221
222##
223
224# ------------------------------------------------------------------------------
225
226#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
227
Cary Clarkab2621d2018-01-30 10:08:57 -0500228#In Constructors
229#Line # constructs from int input returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400230Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
231input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400232
Cary Clark7fc1d122017-10-09 14:07:42 -0400233Use to avoid a compiler warning that input may lose precision when stored.
234Use SkIRect for an exact integer rectangle.
235
236#Param w integer width of constructed Rect ##
237#Param h integer height of constructed Rect ##
238
239#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400240
241#Example
Cary Clark154beea2017-10-26 07:58:48 -0400242 SkIRect i_rect = SkIRect::MakeWH(25, 35);
243 SkRect f_rect = SkRect::MakeIWH(25, 35);
244 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
245 i_rect = SkIRect::MakeWH(125000111, 0);
246 f_rect = SkRect::MakeIWH(125000111, 0);
247 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400248#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400249i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400250i_rect width: 125000111 f_rect width:125000112
251##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400252##
253
Cary Clark7fc1d122017-10-09 14:07:42 -0400254#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400255
256##
257
258# ------------------------------------------------------------------------------
259
Cary Clark884dd7d2017-10-11 10:37:52 -0400260#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400261
Cary Clarkab2621d2018-01-30 10:08:57 -0500262#In Constructors
263#Line # constructs from Size returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400264Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
265validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400266
Cary Clark7fc1d122017-10-09 14:07:42 -0400267#Param size SkScalar values for Rect width and height ##
268
269#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400270
271#Example
Cary Clark154beea2017-10-26 07:58:48 -0400272 SkSize size = {25.5f, 35.5f};
273 SkRect rect = SkRect::MakeSize(size);
274 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
275 SkISize floor = size.toFloor();
276 rect = SkRect::MakeSize(SkSize::Make(floor));
277 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400278#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400279rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400280floor width: 25 height: 35
281##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400282##
283
Cary Clark7fc1d122017-10-09 14:07:42 -0400284#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400285
286##
287
288# ------------------------------------------------------------------------------
289
290#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
291 SkScalar b)
Cary Clarkab2621d2018-01-30 10:08:57 -0500292#In Constructors
293#Line # constructs from SkScalar left, top, right, bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
Cary Clark7fc1d122017-10-09 14:07:42 -0400295Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
296result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400297
Cary Clark7fc1d122017-10-09 14:07:42 -0400298#Param l SkScalar stored in fLeft ##
299#Param t SkScalar stored in fTop ##
300#Param r SkScalar stored in fRight ##
301#Param b SkScalar stored in fBottom ##
302
303#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400304
305#Example
Cary Clark154beea2017-10-26 07:58:48 -0400306 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
307 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
308 rect.bottom(), rect.isEmpty() ? "true" : "false");
309 rect.sort();
310 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
311 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400312#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400313rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400314rect: 5, 25, 15, 35 isEmpty: false
315##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400316##
317
Cary Clark7fc1d122017-10-09 14:07:42 -0400318#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400319
320##
321
322# ------------------------------------------------------------------------------
323
Cary Clark884dd7d2017-10-11 10:37:52 -0400324#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400325
Cary Clarkab2621d2018-01-30 10:08:57 -0500326#In Constructors
327#Line # constructs from SkScalar input returning (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400328Returns constructed Rect set to
329#Formula
330(x, y, x + w, y + h)
331##
332. Does not validate input;
333w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400334
Cary Clark7fc1d122017-10-09 14:07:42 -0400335#Param x stored in fLeft ##
336#Param y stored in fTop ##
337#Param w added to x and stored in fRight ##
338#Param h added to y and stored in fBottom ##
339
Cary Clark884dd7d2017-10-11 10:37:52 -0400340#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400341
342#Example
Cary Clark154beea2017-10-26 07:58:48 -0400343 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
344 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
345 rect.bottom(), rect.isEmpty() ? "true" : "false");
346 rect.sort();
347 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
348 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400349#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400350rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400351rect: -10, 35, 5, 60 isEmpty: false
352##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400353##
354
Cary Clark7fc1d122017-10-09 14:07:42 -0400355#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400356
357##
358
359# ------------------------------------------------------------------------------
360
361#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
362
Cary Clarkab2621d2018-01-30 10:08:57 -0500363#In Constructors
364#Line # deprecated ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400365Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400366
Cary Clark7fc1d122017-10-09 14:07:42 -0400367#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400368##
369
Cary Clark7fc1d122017-10-09 14:07:42 -0400370#Param irect integer rect ##
371
372#Return irect as SkRect ##
373
374#NoExample
375##
376
377#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400378
379##
380
381# ------------------------------------------------------------------------------
382
383#Method static SkRect Make(const SkISize& size)
384
Cary Clarkab2621d2018-01-30 10:08:57 -0500385#In Constructors
386#Line # constructs from ISize returning (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400387Returns constructed IRect set to (0, 0, size.width(), size.height()).
388Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400389
Cary Clark7fc1d122017-10-09 14:07:42 -0400390#Param size integer values for Rect width and height ##
391
392#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400393
394#Example
Cary Clark154beea2017-10-26 07:58:48 -0400395 SkRect rect1 = SkRect::MakeSize({2, 35});
396 SkRect rect2 = SkRect::MakeIWH(2, 35);
397 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400398#StdOut
399rect1 == rect2
400##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400401##
402
Cary Clark7fc1d122017-10-09 14:07:42 -0400403#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400404
405##
406
407# ------------------------------------------------------------------------------
408
409#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
410
Cary Clarkab2621d2018-01-30 10:08:57 -0500411#In Constructors
Cary Clark7fc1d122017-10-09 14:07:42 -0400412Returns constructed IRect set to irect, promoting integers to Scalar.
413Does not validate input; fLeft may be greater than fRight, fTop may be greater
414than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400415
Cary Clark7fc1d122017-10-09 14:07:42 -0400416#Param irect integer unsorted bounds ##
417
418#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400419
420#Example
Cary Clark154beea2017-10-26 07:58:48 -0400421 SkIRect i_rect1 = {2, 35, 22, 53};
422 SkRect f_rect = SkRect::Make(i_rect1);
423 f_rect.offset(0.49f, 0.49f);
424 SkIRect i_rect2;
425 f_rect.round(&i_rect2);
426 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400427##
428
Cary Clark7fc1d122017-10-09 14:07:42 -0400429#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400430
431##
432
Cary Clark2dc84ad2018-01-26 12:56:22 -0500433#Subtopic Constructors ##
434
435#Subtopic Properties
436
437#Table
438#Legend
439# name # description ##
440#Legend ##
441# bottom() # returns larger bounds in y, if sorted ##
442# centerX # returns midpoint in x ##
443# centerY # returns midpoint in y ##
444# height() # returns span in y ##
445# isEmpty # returns true if width or height are zero or negative ##
446# isFinite # returns true if no member is infinite or NaN ##
447# isSorted # returns true if width or height are zero or positive ##
448# left() # returns smaller bounds in x, if sorted ##
449# right() # returns larger bounds in x, if sorted ##
450# top() # returns smaller bounds in y, if sorted ##
451# width() # returns span in x ##
452# x() # returns bounds left ##
453# y() # returns bounds top ##
454#Table ##
455
Cary Clarkbc5697d2017-10-04 14:31:33 -0400456# ------------------------------------------------------------------------------
457
458#Method bool isEmpty() const
459
Cary Clarkab2621d2018-01-30 10:08:57 -0500460#In Properties
461#Line # returns true if width or height are zero or negative ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400462Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
463to or greater than fBottom. Call sort() to reverse rectangles with negative
464width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400465
Cary Clark7fc1d122017-10-09 14:07:42 -0400466#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400467
468#Example
Cary Clark154beea2017-10-26 07:58:48 -0400469 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
470 for (auto rect : tests) {
471 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
472 rect.bottom(), rect.isEmpty() ? "" : " not");
473 rect.sort();
474 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
475 rect.bottom(), rect.isEmpty() ? "" : " not");
476 }
477#StdOut
478rect: {20, 40, 10, 50} is empty
479sorted: {10, 40, 20, 50} is not empty
480rect: {20, 40, 20, 50} is empty
481sorted: {20, 40, 20, 50} is empty
482##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400483##
484
Cary Clark7fc1d122017-10-09 14:07:42 -0400485#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400486
487##
488
489# ------------------------------------------------------------------------------
490
491#Method bool isSorted() const
492
Cary Clarkab2621d2018-01-30 10:08:57 -0500493#In Properties
494#Line # returns true if width or height are zero or positive ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400495Returns true if fLeft is equal to or less than fRight, or if fTop is equal
496to or less than fBottom. Call sort() to reverse rectangles with negative
497width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400498
Cary Clark7fc1d122017-10-09 14:07:42 -0400499#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400500
501#Example
Cary Clark154beea2017-10-26 07:58:48 -0400502 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
503 for (auto rect : tests) {
504 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
505 rect.bottom(), rect.isSorted() ? "" : " not");
506 rect.sort();
507 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
508 rect.bottom(), rect.isSorted() ? "" : " not");
509 }
510#StdOut
511rect: {20, 40, 10, 50} is not sorted
512sorted: {10, 40, 20, 50} is sorted
513rect: {20, 40, 20, 50} is sorted
514sorted: {20, 40, 20, 50} is sorted
515##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400516##
517
Cary Clark7fc1d122017-10-09 14:07:42 -0400518#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400519
520##
521
522# ------------------------------------------------------------------------------
523
Cary Clarkbc5697d2017-10-04 14:31:33 -0400524#Method bool isFinite() const
525
Cary Clarkab2621d2018-01-30 10:08:57 -0500526#In Properties
527#Line # returns true if no member is infinite or NaN ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400528Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
529and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400530
Cary Clark7fc1d122017-10-09 14:07:42 -0400531#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400532
533#Example
Mike Reed274218e2018-01-08 15:05:02 -0500534SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
Cary Clark154beea2017-10-26 07:58:48 -0400535 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
536 SkDebugf("large width %g\n", largest.width());
537 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
538 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
539#StdOut
540largest is finite: true
541large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400542widest is finite: false
543##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400544##
545
Cary Clark7fc1d122017-10-09 14:07:42 -0400546#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400547
548##
549
550# ------------------------------------------------------------------------------
551
552#Method SkScalar x() const
553
Cary Clarkab2621d2018-01-30 10:08:57 -0500554#In Properties
555#Line # returns bounds left ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400556Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
557Call sort() to reverse fLeft and fRight if needed.
558
559#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400560
561#Example
Cary Clark154beea2017-10-26 07:58:48 -0400562 SkRect unsorted = { 15, 5, 10, 25 };
563 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
564 SkRect sorted = unsorted.makeSorted();
565 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400566#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400567unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400568sorted.fLeft: 10 sorted.x(): 10
569##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400570##
571
Cary Clark7fc1d122017-10-09 14:07:42 -0400572#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400573
574##
575
576# ------------------------------------------------------------------------------
577
578#Method SkScalar y() const
579
Cary Clarkab2621d2018-01-30 10:08:57 -0500580#In Properties
581#Line # returns bounds top ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400582Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
583and sort() to reverse fTop and fBottom if needed.
584
585#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400586
587#Example
Cary Clark154beea2017-10-26 07:58:48 -0400588 SkRect unsorted = { 15, 25, 10, 5 };
589 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
590 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400591 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
592#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400593unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400594sorted.fTop: 5 sorted.y(): 5
595##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400596##
597
Cary Clark7fc1d122017-10-09 14:07:42 -0400598#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400599
600##
601
602# ------------------------------------------------------------------------------
603
604#Method SkScalar left() const
605
Cary Clarkab2621d2018-01-30 10:08:57 -0500606#In Properties
607#Line # returns smaller bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400608Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
609Call sort() to reverse fLeft and fRight if needed.
610
611#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400612
613#Example
Cary Clark154beea2017-10-26 07:58:48 -0400614 SkRect unsorted = { 15, 5, 10, 25 };
615 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
616 SkRect sorted = unsorted.makeSorted();
617 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400618#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400619unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400620sorted.fLeft: 10 sorted.left(): 10
621##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400622##
623
Cary Clark7fc1d122017-10-09 14:07:42 -0400624#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400625
626##
627
628# ------------------------------------------------------------------------------
629
630#Method SkScalar top() const
631
Cary Clarkab2621d2018-01-30 10:08:57 -0500632#In Properties
633#Line # returns smaller bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400634Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
635and sort() to reverse fTop and fBottom if needed.
636
637#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400638
639#Example
Cary Clark154beea2017-10-26 07:58:48 -0400640 SkRect unsorted = { 15, 25, 10, 5 };
641 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
642 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400643 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
644#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400645unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400646sorted.fTop: 5 sorted.top(): 5
647##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400648##
649
Cary Clark7fc1d122017-10-09 14:07:42 -0400650#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400651
652##
653
654# ------------------------------------------------------------------------------
655
656#Method SkScalar right() const
657
Cary Clarkab2621d2018-01-30 10:08:57 -0500658#In Properties
659#Line # returns larger bounds in x, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400660Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
661Call sort() to reverse fLeft and fRight if needed.
662
663#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400664
665#Example
Cary Clark154beea2017-10-26 07:58:48 -0400666 SkRect unsorted = { 15, 25, 10, 5 };
667 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
668 SkRect sorted = unsorted.makeSorted();
669 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400670#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400671unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400672sorted.fRight: 15 sorted.right(): 15
673##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400674##
675
Cary Clark7fc1d122017-10-09 14:07:42 -0400676#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400677
678##
679
680# ------------------------------------------------------------------------------
681
682#Method SkScalar bottom() const
683
Cary Clarkab2621d2018-01-30 10:08:57 -0500684#In Properties
685#Line # returns larger bounds in y, if sorted ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400686Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
687and sort() to reverse fTop and fBottom if needed.
688
689#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400690
691#Example
Cary Clark154beea2017-10-26 07:58:48 -0400692 SkRect unsorted = { 15, 25, 10, 5 };
693 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
694 SkRect sorted = unsorted.makeSorted();
695 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400696#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400697unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400698sorted.fBottom: 25 sorted.bottom(): 25
699##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400700##
701
Cary Clark7fc1d122017-10-09 14:07:42 -0400702#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400703
704##
705
706# ------------------------------------------------------------------------------
707
708#Method SkScalar width() const
709
Cary Clarkab2621d2018-01-30 10:08:57 -0500710#In Properties
711#Line # returns span in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400712Returns span on the x-axis. This does not check if Rect is sorted, or if
713result fits in 32-bit float; result may be negative or infinity.
714
715#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400716
717#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400718#Description
719Compare with SkIRect::width() example.
720##
Cary Clark154beea2017-10-26 07:58:48 -0400721 SkRect unsorted = { 15, 25, 10, 5 };
722 SkDebugf("unsorted width: %g\n", unsorted.width());
723 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
724 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400725#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400726unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400727large width: 4294967296
728##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400729##
730
Cary Clark7fc1d122017-10-09 14:07:42 -0400731#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400732
733##
734
735# ------------------------------------------------------------------------------
736
737#Method SkScalar height() const
738
Cary Clarkab2621d2018-01-30 10:08:57 -0500739#In Properties
740#Line # returns span in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400741Returns span on the y-axis. This does not check if IRect is sorted, or if
742result fits in 32-bit float; result may be negative or infinity.
743
744#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400745
746#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400747#Description
748Compare with SkIRect::height() example.
749##
Cary Clark154beea2017-10-26 07:58:48 -0400750 SkRect unsorted = { 15, 25, 10, 20 };
751 SkDebugf("unsorted height: %g\n", unsorted.height());
752 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
753 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400754#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400755unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400756large height: 4294967296
757##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400758##
759
Cary Clark7fc1d122017-10-09 14:07:42 -0400760#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400761
762##
763
764# ------------------------------------------------------------------------------
765
766#Method SkScalar centerX() const
767
Cary Clarkab2621d2018-01-30 10:08:57 -0500768#In Properties
769#Line # returns midpoint in x ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400770Returns average of left edge and right edge. Result does not change if Rect
771is sorted. Result may overflow to infinity if Rect is far from the origin.
772
773#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400774
775#Example
Cary Clark154beea2017-10-26 07:58:48 -0400776 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
777 for (auto rect : tests) {
778 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
779 rect.sort();
780 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
781 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400782#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400783left: 20 right: 41 centerX: 30.5
784left: 20 right: 41 centerX: 30.5
785left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400786left: -41 right: -20 centerX: -30.5
787##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400788##
789
Cary Clark7fc1d122017-10-09 14:07:42 -0400790#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400791
792##
793
794# ------------------------------------------------------------------------------
795
796#Method SkScalar centerY() const
797
Cary Clarkab2621d2018-01-30 10:08:57 -0500798#In Properties
799#Line # returns midpoint in y ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400800Returns average of top edge and bottom edge. Result does not change if Rect
801is sorted. Result may overflow to infinity if Rect is far from the origin.
802
803#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400804
805#Example
Cary Clark154beea2017-10-26 07:58:48 -0400806 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
807 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
808 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400809#StdOut
810left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
811##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400812##
813
Cary Clark7fc1d122017-10-09 14:07:42 -0400814#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400815
816##
817
Cary Clark2dc84ad2018-01-26 12:56:22 -0500818#Subtopic Properties ##
819
820#Subtopic Operators
821
822#Table
823#Legend
Cary Clarkab2621d2018-01-30 10:08:57 -0500824# name # description ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500825#Legend ##
Cary Clarkab2621d2018-01-30 10:08:57 -0500826# operator!=(const SkRect& a, const SkRect& b) # returns true if members are unequal ##
827# operator==(const SkRect& a, const SkRect& b) # returns true if members are equal ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500828#Table ##
829
Cary Clarkbc5697d2017-10-04 14:31:33 -0400830# ------------------------------------------------------------------------------
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 Clarkab2621d2018-01-30 10:08:57 -0500834#In Operators
835#Line # returns true if members are equal ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400836Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
837equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400838
Cary Clark7fc1d122017-10-09 14:07:42 -0400839a and b are not equal if either contain NaN. a and b are equal if members
840contain zeroes width different signs.
841
842#Param a Rect to compare ##
843#Param b Rect to compare ##
844
845#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400846
847#Example
Cary Clark154beea2017-10-26 07:58:48 -0400848 auto debugster = [](const SkRect& test) -> void {
849 SkRect negZero = {-0.0f, -0.0f, 2, 2};
850 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
851 test.fLeft, test.fTop, test.fRight, test.fBottom,
852 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
853 test == negZero ? '=' : '!',
854 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
855 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
856 "and are" : "yet are not");
857 };
858 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
859 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
860 for (auto rect : tests) {
861 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400862 }
Cary Clark154beea2017-10-26 07:58:48 -0400863#StdOut
864tests are equal
865{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
866{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400867{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
868##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400869##
870
Cary Clark7fc1d122017-10-09 14:07:42 -0400871#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400872
873##
874
875# ------------------------------------------------------------------------------
876
Cary Clark884dd7d2017-10-11 10:37:52 -0400877#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400878
Cary Clarkab2621d2018-01-30 10:08:57 -0500879#In Operators
880#Line # returns true if members are unequal ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400881Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
882equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400883
Cary Clark7fc1d122017-10-09 14:07:42 -0400884a and b are not equal if either contain NaN. a and b are equal if members
885contain zeroes width different signs.
886
887#Param a Rect to compare ##
888#Param b Rect to compare ##
889
890#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400891
892#Example
Cary Clark154beea2017-10-26 07:58:48 -0400893 SkRect test = {0, 0, 2, SK_ScalarNaN};
894 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
895#StdOut
Cary Clark7fc1d122017-10-09 14:07:42 -0400896test with NaN is not equal to itself
897##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400898##
899
Cary Clark7fc1d122017-10-09 14:07:42 -0400900#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400901
902##
903
Cary Clark2dc84ad2018-01-26 12:56:22 -0500904#Subtopic Operators ##
905
906#Subtopic As_Points
907
908#Table
909#Legend
910# name # description ##
911#Legend ##
912# setBounds # sets to upper and lower limits of Point array ##
913# setBoundsCheck # sets to upper and lower limits of Point array ##
914# toQuad # returns four corners as Point ##
915#Table ##
916
Cary Clarkbc5697d2017-10-04 14:31:33 -0400917# ------------------------------------------------------------------------------
918
919#Method void toQuad(SkPoint quad[4]) const
920
Cary Clarkab2621d2018-01-30 10:08:57 -0500921#In As_Points
922#Line # returns four corners as Point ##
Cary Clark7fc1d122017-10-09 14:07:42 -0400923Returns four points in quad that enclose Rect ordered as: top-left, top-right,
924bottom-right, bottom-left.
925
926#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400927Consider adding param to control whether quad is CW or CCW.
928##
929
Cary Clark7fc1d122017-10-09 14:07:42 -0400930#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400931
932#Example
Cary Clark154beea2017-10-26 07:58:48 -0400933 SkRect rect = {1, 2, 3, 4};
934 SkPoint corners[4];
935 rect.toQuad(corners);
936 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
937 SkDebugf("corners:");
938 for (auto corner : corners) {
939 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
940 }
941 SkDebugf("\n");
942#StdOut
943rect: {1, 2, 3, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400944corners: {1, 2} {3, 2} {3, 4} {1, 4}
945##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400946##
947
Cary Clark7fc1d122017-10-09 14:07:42 -0400948#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400949
950##
951
952# ------------------------------------------------------------------------------
953
Cary Clark2dc84ad2018-01-26 12:56:22 -0500954#Method void setBounds(const SkPoint pts[], int count)
955
Cary Clarkab2621d2018-01-30 10:08:57 -0500956#In As_Points
957#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500958Sets to bounds of Point array with count entries. If count is zero or smaller,
959or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
960
961Result is either empty or sorted: fLeft is less than or equal to fRight, and
962fTop is less than or equal to fBottom.
963
964#Param pts Point array ##
965#Param count entries in array ##
966
967#Example
968 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
969 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
970 SkRect rect;
971 rect.setBounds(points, count);
972 if (count > 0) {
973 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
974 } else {
975 SkDebugf("%14s", " ");
976 }
977 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
978 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
979 }
980#StdOut
981 count: 0 rect: 0, 0, 0, 0
982added: 3, 4 count: 1 rect: 3, 4, 3, 4
983added: 1, 2 count: 2 rect: 1, 2, 3, 4
984added: 5, 6 count: 3 rect: 1, 2, 5, 6
985added: nan, 8 count: 4 rect: 0, 0, 0, 0
986##
987##
988
989#SeeAlso set setBoundsCheck SkPath::addPoly
990
991##
992
993# ------------------------------------------------------------------------------
994
995#Method bool setBoundsCheck(const SkPoint pts[], int count)
996
Cary Clarkab2621d2018-01-30 10:08:57 -0500997#In As_Points
998#Line # sets to upper and lower limits of Point array ##
Cary Clark2dc84ad2018-01-26 12:56:22 -0500999Sets to bounds of Point array with count entries. Returns false if count is
1000zero or smaller, or if Point array contains an infinity or NaN; in these cases
1001sets Rect to (0, 0, 0, 0).
1002
1003Result is either empty or sorted: fLeft is less than or equal to fRight, and
1004fTop is less than or equal to fBottom.
1005
1006#Param pts Point array ##
1007#Param count entries in array ##
1008
1009#Return true if all Point values are finite ##
1010
1011#Example
1012 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1013 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1014 SkRect rect;
1015 bool success = rect.setBoundsCheck(points, count);
1016 if (count > 0) {
1017 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1018 } else {
1019 SkDebugf("%14s", " ");
1020 }
1021 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
1022 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
1023 }
1024#StdOut
1025 count: 0 rect: 0, 0, 0, 0 success: true
1026added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
1027added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
1028added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
1029added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
1030##
1031##
1032
1033#SeeAlso set setBounds SkPath::addPoly
1034
1035##
1036
1037#Subtopic As_Points ##
1038
1039#Subtopic Set
1040
1041#Table
1042#Legend
1043# name # description ##
1044#Legend ##
1045# iset() # sets to int input (left, top, right, bottom) ##
1046# isetWH # sets to int input (0, 0, width, height) ##
1047# set() # sets to SkScalar input (left, top, right, bottom) and others ##
1048# # void set(const SkIRect& src) ##
1049# # void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1050# # void set(const SkPoint pts[], int count) ##
1051# # void set(const SkPoint& p0, const SkPoint& p1) ##
1052# setEmpty # sets to (0, 0, 0, 0) ##
1053# setLTRB # sets to SkScalar input (left, top, right, bottom) ##
1054# setWH # sets to SkScalar input (0, 0, width, height) ##
1055# setXYWH # sets to SkScalar input (x, y, width, height) ##
1056#Table ##
1057
1058# ------------------------------------------------------------------------------
1059
Cary Clarkbc5697d2017-10-04 14:31:33 -04001060#Method void setEmpty()
1061
Cary Clarkab2621d2018-01-30 10:08:57 -05001062#In Set
1063#Line # sets to (0, 0, 0, 0) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001064Sets Rect to (0, 0, 0, 0).
1065
1066Many other rectangles are empty; if left is equal to or greater than right,
1067or if top is equal to or greater than bottom. Setting all members to zero
1068is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001069
1070#Example
Cary Clark154beea2017-10-26 07:58:48 -04001071 SkRect rect = {3, 4, 1, 2};
1072 for (int i = 0; i < 2; ++i) {
1073 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
1074 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
1075 rect.setEmpty();
1076 }
1077#StdOut
1078rect: {3, 4, 1, 2} is empty
1079rect: {0, 0, 0, 0} is empty
1080##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001081##
1082
Cary Clark7fc1d122017-10-09 14:07:42 -04001083#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -04001084
1085##
1086
1087# ------------------------------------------------------------------------------
1088
1089#Method void set(const SkIRect& src)
1090
Cary Clarkab2621d2018-01-30 10:08:57 -05001091#In Set
1092#Line # sets to SkScalar input (left, top, right, bottom) and others ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001093Sets Rect to src, promoting src members from integer to Scalar.
1094Very large values in src may lose precision.
1095
1096#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001097
1098#Example
Cary Clark154beea2017-10-26 07:58:48 -04001099 SkIRect i_rect = {3, 4, 1, 2};
1100 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
1101 SkRect f_rect;
1102 f_rect.set(i_rect);
1103 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
1104#StdOut
1105i_rect: {3, 4, 1, 2}
1106f_rect: {3, 4, 1, 2}
1107##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001108##
1109
Cary Clark7fc1d122017-10-09 14:07:42 -04001110#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -04001111
1112##
1113
1114# ------------------------------------------------------------------------------
1115
1116#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1117
Cary Clarkab2621d2018-01-30 10:08:57 -05001118#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001119Sets Rect to (left, top, right, bottom).
1120left and right are not sorted; left is not necessarily less than right.
1121top and bottom are not sorted; top is not necessarily less than bottom.
1122
1123#Param left stored in fLeft ##
1124#Param top stored in fTop ##
1125#Param right stored in fRight ##
1126#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001127
1128#Example
Cary Clark154beea2017-10-26 07:58:48 -04001129 SkRect rect1 = {3, 4, 1, 2};
1130 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1131 SkRect rect2;
1132 rect2.set(3, 4, 1, 2);
1133 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1134#StdOut
1135rect1: {3, 4, 1, 2}
1136rect2: {3, 4, 1, 2}
1137##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001138##
1139
Cary Clark7fc1d122017-10-09 14:07:42 -04001140#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001141
1142##
1143
1144# ------------------------------------------------------------------------------
1145
1146#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1147
Cary Clarkab2621d2018-01-30 10:08:57 -05001148#In Set
1149#Line # sets to SkScalar input (left, top, right, bottom) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001150Sets Rect to (left, top, right, bottom).
1151left and right are not sorted; left is not necessarily less than right.
1152top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001153
Cary Clark7fc1d122017-10-09 14:07:42 -04001154#Param left stored in fLeft ##
1155#Param top stored in fTop ##
1156#Param right stored in fRight ##
1157#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001158
1159#Example
Cary Clark154beea2017-10-26 07:58:48 -04001160 SkRect rect1 = {3, 4, 1, 2};
1161 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1162 SkRect rect2;
1163 rect2.setLTRB(3, 4, 1, 2);
1164 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1165#StdOut
1166rect1: {3, 4, 1, 2}
1167rect2: {3, 4, 1, 2}
1168##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001169##
1170
Cary Clark7fc1d122017-10-09 14:07:42 -04001171#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001172
1173##
1174
1175# ------------------------------------------------------------------------------
1176
Cary Clarkbc5697d2017-10-04 14:31:33 -04001177#Method void set(const SkPoint pts[], int count)
1178
Cary Clarkab2621d2018-01-30 10:08:57 -05001179#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001180Sets to bounds of Point array with count entries. If count is zero or smaller,
1181or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001182
Cary Clark7fc1d122017-10-09 14:07:42 -04001183Result is either empty or sorted: fLeft is less than or equal to fRight, and
1184fTop is less than or equal to fBottom.
1185
1186#Param pts Point array ##
1187#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001188
1189#Example
Cary Clark154beea2017-10-26 07:58:48 -04001190 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1191 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1192 SkRect rect;
1193 rect.set(points, count);
1194 if (count > 0) {
1195 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1196 } else {
1197 SkDebugf("%14s", " ");
1198 }
1199 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1200 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1201 }
1202#StdOut
1203 count: 0 rect: 0, 0, 0, 0
1204added: 3, 4 count: 1 rect: 3, 4, 3, 4
1205added: 1, 2 count: 2 rect: 1, 2, 3, 4
1206added: 5, 6 count: 3 rect: 1, 2, 5, 6
1207added: nan, 8 count: 4 rect: 0, 0, 0, 0
1208##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001209##
1210
Cary Clark7fc1d122017-10-09 14:07:42 -04001211#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001212
1213##
1214
1215# ------------------------------------------------------------------------------
1216
Cary Clarkbc5697d2017-10-04 14:31:33 -04001217#Method void set(const SkPoint& p0, const SkPoint& p1)
1218
Cary Clarkab2621d2018-01-30 10:08:57 -05001219#In Set
Cary Clark7fc1d122017-10-09 14:07:42 -04001220Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1221sorted and may be empty. Does not check to see if values are finite.
1222
1223#Param p0 corner to include ##
1224#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001225
1226#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001227#Description
1228p0 and p1 may be swapped and have the same effect unless one contains NaN.
1229##
Cary Clark154beea2017-10-26 07:58:48 -04001230 SkPoint point1 = {SK_ScalarNaN, 8};
1231 SkPoint point2 = {3, 4};
1232 SkRect rect;
1233 rect.set(point1, point2);
1234 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1235 rect.set(point2, point1);
1236 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001237##
1238
Cary Clark7fc1d122017-10-09 14:07:42 -04001239#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001240
1241##
1242
1243# ------------------------------------------------------------------------------
1244
1245#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1246
Cary Clarkab2621d2018-01-30 10:08:57 -05001247#In Set
1248#Line # sets to SkScalar input (x, y, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001249Sets Rect to
1250#Formula
1251(x, y, x + width, y + height)
1252##
1253. Does not validate input;
1254width or height may be negative.
1255
1256#Param x stored in fLeft ##
1257#Param y stored in fTop ##
1258#Param width added to x and stored in fRight ##
1259#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001260
1261#Example
Cary Clark154beea2017-10-26 07:58:48 -04001262 SkRect rect;
1263 rect.setXYWH(5, 35, -15, 25);
1264 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1265 rect.bottom(), rect.isEmpty() ? "true" : "false");
1266 rect.sort();
1267 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1268 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001269#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001270rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001271rect: -10, 35, 5, 60 isEmpty: false
1272##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001273##
1274
Cary Clark7fc1d122017-10-09 14:07:42 -04001275#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001276
1277##
1278
1279# ------------------------------------------------------------------------------
1280
1281#Method void setWH(SkScalar width, SkScalar height)
1282
Cary Clarkab2621d2018-01-30 10:08:57 -05001283#In Set
1284#Line # sets to SkScalar input (0, 0, width, height) ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001285Sets Rect to (0, 0, width, height). Does not validate input;
1286width or height may be negative.
1287
1288#Param width stored in fRight ##
1289#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001290
1291#Example
Cary Clark154beea2017-10-26 07:58:48 -04001292 SkRect rect;
1293 rect.setWH(-15, 25);
1294 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1295 rect.bottom(), rect.isEmpty() ? "true" : "false");
1296 rect.sort();
1297 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1298 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001299#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001300rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001301rect: -15, 0, 0, 25 isEmpty: false
1302##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001303##
1304
Cary Clark7fc1d122017-10-09 14:07:42 -04001305#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001306
1307##
1308
Cary Clark2dc84ad2018-01-26 12:56:22 -05001309#Subtopic Set ##
1310
1311#Subtopic From_Integers
1312
1313#Table
1314#Legend
1315# name # description ##
1316#Legend ##
1317# iset() # sets to int input (left, top, right, bottom) ##
1318# isetWH # sets to int input (0, 0, width, height) ##
1319#Table ##
1320
1321# ------------------------------------------------------------------------------
1322
1323#Method void iset(int left, int top, int right, int bottom)
1324
Cary Clarkab2621d2018-01-30 10:08:57 -05001325#In From_Integers
1326#Line # sets to int input (left, top, right, bottom) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001327Sets Rect to (left, top, right, bottom).
1328All parameters are promoted from integer to Scalar.
1329left and right are not sorted; left is not necessarily less than right.
1330top and bottom are not sorted; top is not necessarily less than bottom.
1331
1332#Param left promoted to SkScalar and stored in fLeft ##
1333#Param top promoted to SkScalar and stored in fTop ##
1334#Param right promoted to SkScalar and stored in fRight ##
1335#Param bottom promoted to SkScalar and stored in fBottom ##
1336
1337#Example
1338 SkRect rect1 = {3, 4, 1, 2};
1339 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1340 SkRect rect2;
1341 rect2.iset(3, 4, 1, 2);
1342 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1343#StdOut
1344rect1: {3, 4, 1, 2}
1345rect2: {3, 4, 1, 2}
1346##
1347##
1348
1349#SeeAlso set setLTRB SkIRect::set SkIntToScalar
1350
1351##
1352
1353# ------------------------------------------------------------------------------
1354
1355#Method void isetWH(int width, int height)
1356
Cary Clarkab2621d2018-01-30 10:08:57 -05001357#In From_Integers
1358#Line # sets to int input (0, 0, width, height) ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001359Sets Rect to (0, 0, width, height).
1360width and height may be zero or negative. width and height are promoted from
1361integer to SkScalar, large values may lose precision.
1362
1363#Param width promoted to SkScalar and stored in fRight ##
1364#Param height promoted to SkScalar and stored in fBottom ##
1365
1366#Example
1367 SkRect rect1 = {0, 0, 1, 2};
1368 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1369 SkRect rect2;
1370 rect2.isetWH(1, 2);
1371 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1372#StdOut
1373rect1: {0, 0, 1, 2}
1374rect2: {0, 0, 1, 2}
1375##
1376##
1377
1378#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
1379
1380##
1381
1382#Subtopic From_Integers ##
1383
1384#Subtopic Inset_Outset_Offset
1385
1386#Table
1387#Legend
1388# name # description ##
1389#Legend ##
1390# inset() # moves the sides symmetrically about the center ##
1391# makeInset # constructs from sides moved symmetrically about the center ##
1392# makeOffset # constructs from translated sides ##
1393# makeOutset # constructs from sides moved symmetrically about the center ##
1394# offset() # translates sides without changing width and height ##
1395# # void offset(SkScalar dx, SkScalar dy) ##
1396# # void offset(const SkPoint& delta) ##
1397# offsetTo # translates to (x, y) without changing width and height ##
1398# outset() # moves the sides symmetrically about the center ##
1399#Table ##
1400
Cary Clarkbc5697d2017-10-04 14:31:33 -04001401# ------------------------------------------------------------------------------
1402
Cary Clarkbc5697d2017-10-04 14:31:33 -04001403#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1404
Cary Clarkab2621d2018-01-30 10:08:57 -05001405#In Inset_Outset_Offset
1406#Line # constructs from translated sides ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001407Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001408
Cary Clark7fc1d122017-10-09 14:07:42 -04001409If dx is negative, Rect returned is moved to the left.
1410If dx is positive, Rect returned is moved to the right.
1411If dy is negative, Rect returned is moved upward.
1412If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001413
Cary Clark7fc1d122017-10-09 14:07:42 -04001414#Param dx added to fLeft and fRight ##
1415#Param dy added to fTop and fBottom ##
1416
1417#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001418
1419#Example
Cary Clark154beea2017-10-26 07:58:48 -04001420 SkRect rect = { 10, 50, 20, 60 };
1421 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1422 rect.bottom(), rect.isEmpty() ? "true" : "false");
1423 rect = rect.makeOffset(15, 32);
1424 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1425 rect.bottom(), rect.isEmpty() ? "true" : "false");
1426#StdOut
1427rect: 10, 50, 20, 60 isEmpty: false
1428rect: 25, 82, 35, 92 isEmpty: false
1429##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001430##
1431
Cary Clark7fc1d122017-10-09 14:07:42 -04001432#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001433
1434##
1435
1436# ------------------------------------------------------------------------------
1437
1438#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1439
Cary Clarkab2621d2018-01-30 10:08:57 -05001440#In Inset_Outset_Offset
1441#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001442Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001443
Cary Clark7fc1d122017-10-09 14:07:42 -04001444If dx is negative, Rect returned is wider.
1445If dx is positive, Rect returned is narrower.
1446If dy is negative, Rect returned is taller.
1447If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001448
Cary Clark7fc1d122017-10-09 14:07:42 -04001449#Param dx added to fLeft and subtracted from fRight ##
1450#Param dy added to fTop and subtracted from fBottom ##
1451
1452#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001453
1454#Example
Cary Clark154beea2017-10-26 07:58:48 -04001455 SkRect rect = { 10, 50, 20, 60 };
1456 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1457 rect.bottom(), rect.isEmpty() ? "true" : "false");
1458 rect = rect.makeInset(15, 32);
1459 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1460 rect.bottom(), rect.isEmpty() ? "true" : "false");
1461#StdOut
1462rect: 10, 50, 20, 60 isEmpty: false
1463rect: 25, 82, 5, 28 isEmpty: true
1464##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001465##
1466
Cary Clark7fc1d122017-10-09 14:07:42 -04001467#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001468
1469##
1470
1471# ------------------------------------------------------------------------------
1472
1473#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1474
Cary Clarkab2621d2018-01-30 10:08:57 -05001475#In Inset_Outset_Offset
1476#Line # constructs from sides moved symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001477Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001478
Cary Clark7fc1d122017-10-09 14:07:42 -04001479If dx is negative, Rect returned is narrower.
1480If dx is positive, Rect returned is wider.
1481If dy is negative, Rect returned is shorter.
1482If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001483
Cary Clark7fc1d122017-10-09 14:07:42 -04001484#Param dx subtracted to fLeft and added from fRight ##
1485#Param dy subtracted to fTop and added from fBottom ##
1486
1487#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001488
1489#Example
Cary Clark154beea2017-10-26 07:58:48 -04001490 SkRect rect = { 10, 50, 20, 60 };
1491 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1492 rect.bottom(), rect.isEmpty() ? "true" : "false");
1493 rect = rect.makeOutset(15, 32);
1494 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1495 rect.bottom(), rect.isEmpty() ? "true" : "false");
1496#StdOut
1497rect: 10, 50, 20, 60 isEmpty: false
1498rect: -5, 18, 35, 92 isEmpty: false
1499##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001500##
1501
Cary Clark7fc1d122017-10-09 14:07:42 -04001502#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001503
1504##
1505
1506# ------------------------------------------------------------------------------
1507
1508#Method void offset(SkScalar dx, SkScalar dy)
1509
Cary Clarkab2621d2018-01-30 10:08:57 -05001510#In Inset_Outset_Offset
1511#Line # translates sides without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001512Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001513
Cary Clark7fc1d122017-10-09 14:07:42 -04001514If dx is negative, moves Rect to the left.
1515If dx is positive, moves Rect to the right.
1516If dy is negative, moves Rect upward.
1517If dy is positive, moves Rect downward.
1518
1519#Param dx offset added to fLeft and fRight ##
1520#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001521
1522#Example
Cary Clark154beea2017-10-26 07:58:48 -04001523 SkRect rect = { 10, 14, 50, 73 };
1524 rect.offset(5, 13);
1525 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1526#StdOut
1527rect: 15, 27, 55, 86
1528##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001529##
1530
Cary Clark7fc1d122017-10-09 14:07:42 -04001531#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001532
1533##
1534
1535# ------------------------------------------------------------------------------
1536
1537#Method void offset(const SkPoint& delta)
1538
Cary Clarkab2621d2018-01-30 10:08:57 -05001539#In Inset_Outset_Offset
Cary Clark7fc1d122017-10-09 14:07:42 -04001540Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1541fTop, fBottom.
1542
1543If delta.fX is negative, moves Rect to the left.
1544If delta.fX is positive, moves Rect to the right.
1545If delta.fY is negative, moves Rect upward.
1546If delta.fY is positive, moves Rect downward.
1547
1548#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001549
1550#Example
Cary Clark154beea2017-10-26 07:58:48 -04001551 SkRect rect = { 10, 14, 50, 73 };
1552 rect.offset({5, 13});
1553 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1554#StdOut
1555rect: 15, 27, 55, 86
1556##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001557##
1558
Cary Clark7fc1d122017-10-09 14:07:42 -04001559#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001560
1561##
1562
1563# ------------------------------------------------------------------------------
1564
1565#Method void offsetTo(SkScalar newX, SkScalar newY)
1566
Cary Clarkab2621d2018-01-30 10:08:57 -05001567#In Inset_Outset_Offset
1568#Line # translates to (x, y) without changing width and height ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001569Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1570are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001571
Cary Clark7fc1d122017-10-09 14:07:42 -04001572#Param newX stored in fLeft, preserving width() ##
1573#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001574
1575#Example
Cary Clark154beea2017-10-26 07:58:48 -04001576 SkRect rect = { 10, 14, 50, 73 };
1577 rect.offsetTo(15, 27);
1578 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1579#StdOut
1580rect: 15, 27, 55, 86
1581##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001582##
1583
Cary Clark7fc1d122017-10-09 14:07:42 -04001584#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001585
1586##
1587
1588# ------------------------------------------------------------------------------
1589
1590#Method void inset(SkScalar dx, SkScalar dy)
1591
Cary Clarkab2621d2018-01-30 10:08:57 -05001592#In Inset_Outset_Offset
1593#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001594Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001595
Cary Clark7fc1d122017-10-09 14:07:42 -04001596If dx is positive, makes Rect narrower.
1597If dx is negative, makes Rect wider.
1598If dy is positive, makes Rect shorter.
1599If dy is negative, makes Rect taller.
1600
1601#Param dx added to fLeft and subtracted from fRight ##
1602#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001603
1604#Example
Cary Clark154beea2017-10-26 07:58:48 -04001605 SkRect rect = { 10, 14, 50, 73 };
1606 rect.inset(5, 13);
1607 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1608#StdOut
1609rect: 15, 27, 45, 60
1610##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001611##
1612
Cary Clark7fc1d122017-10-09 14:07:42 -04001613#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001614
1615##
1616
1617# ------------------------------------------------------------------------------
1618
1619#Method void outset(SkScalar dx, SkScalar dy)
1620
Cary Clarkab2621d2018-01-30 10:08:57 -05001621#In Inset_Outset_Offset
1622#Line # moves the sides symmetrically about the center ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001623Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001624
Cary Clark7fc1d122017-10-09 14:07:42 -04001625If dx is positive, makes Rect wider.
1626If dx is negative, makes Rect narrower.
1627If dy is positive, makes Rect taller.
1628If dy is negative, makes Rect shorter.
1629
1630#Param dx subtracted to fLeft and added from fRight ##
1631#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001632
1633#Example
Cary Clark154beea2017-10-26 07:58:48 -04001634 SkRect rect = { 10, 14, 50, 73 };
1635 rect.outset(5, 13);
1636 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1637#StdOut
1638rect: 5, 1, 55, 86
1639##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001640##
1641
Cary Clark7fc1d122017-10-09 14:07:42 -04001642#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001643
1644##
1645
Cary Clark2dc84ad2018-01-26 12:56:22 -05001646#Subtopic Inset_Outset_Offset ##
1647
1648#Subtopic Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001649
1650Rects intersect when they enclose a common area. To intersect, each of the pair
1651must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001652empty() returns false. The intersection of Rect pair can be described by:
1653
Cary Clark7fc1d122017-10-09 14:07:42 -04001654#Formula
1655(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1656 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1657##
Cary Clark154beea2017-10-26 07:58:48 -04001658.
1659
Cary Clark7fc1d122017-10-09 14:07:42 -04001660The intersection is only meaningful if the resulting Rect is not empty and
1661describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1662
Cary Clark2dc84ad2018-01-26 12:56:22 -05001663#Table
1664#Legend
1665# name # description ##
1666#Legend ##
1667# Intersects # returns true if areas overlap ##
1668# contains() # returns true if points are equal or inside ##
1669# # bool contains(const SkRect& r) const ##
1670# # bool contains(const SkIRect& r) const ##
1671# intersect() # sets to shared area; returns true if not empty ##
1672# # bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1673# # bool intersect(const SkRect& r) ##
1674# # bool intersect(const SkRect& a, const SkRect& b) ##
1675# intersects() # returns true if areas overlap ##
1676# # bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const ##
1677# # bool intersects(const SkRect& r) const ##
1678#Table ##
1679
1680# ------------------------------------------------------------------------------
1681
1682#Method bool contains(const SkRect& r) const
1683
Cary Clarkab2621d2018-01-30 10:08:57 -05001684#In Intersection
1685#Line # returns true if points are equal or inside ##
Cary Clark2dc84ad2018-01-26 12:56:22 -05001686Returns true if Rect contains r.
1687Returns false if Rect is empty or r is empty.
1688
1689Rect contains r when Rect area completely includes r area.
1690
1691#Param r Rect contained ##
1692
1693#Return true if all sides of Rect are outside r ##
1694
1695#Example
1696 SkRect rect = { 30, 50, 40, 60 };
1697 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1698 for (auto contained : tests) {
1699 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
1700 rect.left(), rect.top(), rect.right(), rect.bottom(),
1701 rect.contains(contained) ? "contains" : "does not contain",
1702 contained.left(), contained.top(), contained.right(), contained.bottom());
1703 }
1704#StdOut
1705rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1706rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1707rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1708##
1709##
1710
1711#SeeAlso SkIRect::contains
1712
1713##
1714
1715# ------------------------------------------------------------------------------
1716
1717#Method bool contains(const SkIRect& r) const
1718
Cary Clarkab2621d2018-01-30 10:08:57 -05001719#In Intersection
Cary Clark2dc84ad2018-01-26 12:56:22 -05001720Returns true if Rect contains r.
1721Returns false if Rect is empty or r is empty.
1722
1723Rect contains r when Rect area completely includes r area.
1724
1725#Param r IRect contained ##
1726
1727#Return true if all sides of Rect are outside r ##
1728
1729#Example
1730 SkRect rect = { 30, 50, 40, 60 };
1731 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
1732 for (auto contained : tests) {
1733 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
1734 rect.left(), rect.top(), rect.right(), rect.bottom(),
1735 rect.contains(contained) ? "contains" : "does not contain",
1736 contained.left(), contained.top(), contained.right(), contained.bottom());
1737 }
1738#StdOut
1739rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
1740rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
1741rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
1742##
1743##
1744
1745#SeeAlso SkIRect::contains
1746
1747##
1748
Cary Clarkbc5697d2017-10-04 14:31:33 -04001749# ------------------------------------------------------------------------------
1750
1751#Method bool intersect(const SkRect& r)
1752
Cary Clarkab2621d2018-01-30 10:08:57 -05001753#In Intersection
1754#Line # sets to shared area; returns true if not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001755Returns true if Rect intersects r, and sets Rect to intersection.
1756Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001757
Cary Clark7fc1d122017-10-09 14:07:42 -04001758Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001759
Cary Clark7fc1d122017-10-09 14:07:42 -04001760#Param r limit of result ##
1761
1762#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001763
1764#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001765#Description
1766Two SkDebugf calls are required. If the calls are combined, their arguments
1767may not be evaluated in left to right order: the printed intersection may
1768be before or after the call to intersect.
1769##
Cary Clark154beea2017-10-26 07:58:48 -04001770 SkRect leftRect = { 10, 40, 50, 80 };
1771 SkRect rightRect = { 30, 60, 70, 90 };
1772 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1773 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001774 leftRect.right(), leftRect.bottom());
1775#StdOut
1776 intersection: 30, 60, 50, 80
1777##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001778##
1779
Cary Clark7fc1d122017-10-09 14:07:42 -04001780#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001781
1782##
1783
1784# ------------------------------------------------------------------------------
1785
1786#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1787
Cary Clarkab2621d2018-01-30 10:08:57 -05001788#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001789Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1790construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001791
Cary Clark7fc1d122017-10-09 14:07:42 -04001792Returns true if Rect intersects construction, and sets Rect to intersection.
1793Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001794
Cary Clark7fc1d122017-10-09 14:07:42 -04001795Returns false if either construction or Rect is empty, leaving Rect unchanged.
1796
1797#Param left x minimum of constructed Rect ##
1798#Param top y minimum of constructed Rect ##
1799#Param right x maximum of constructed Rect ##
1800#Param bottom y maximum of constructed Rect ##
1801
1802#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001803
1804#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001805#Description
1806Two SkDebugf calls are required. If the calls are combined, their arguments
1807may not be evaluated in left to right order: the printed intersection may
1808be before or after the call to intersect.
1809##
Cary Clark154beea2017-10-26 07:58:48 -04001810 SkRect leftRect = { 10, 40, 50, 80 };
1811 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1812 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001813 leftRect.right(), leftRect.bottom());
1814#StdOut
1815 intersection: 30, 60, 50, 80
1816##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001817##
1818
Cary Clark7fc1d122017-10-09 14:07:42 -04001819#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001820
1821##
1822
1823# ------------------------------------------------------------------------------
1824
1825#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1826
Cary Clarkab2621d2018-01-30 10:08:57 -05001827#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001828Returns true if a intersects b, and sets Rect to intersection.
1829Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001830
Cary Clark7fc1d122017-10-09 14:07:42 -04001831Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001832
Cary Clark7fc1d122017-10-09 14:07:42 -04001833#Param a Rect to intersect ##
1834#Param b Rect to intersect ##
1835
1836#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001837
1838#Example
Cary Clark154beea2017-10-26 07:58:48 -04001839 SkRect result;
1840 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1841 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1842 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001843#StdOut
1844 intersection: 30, 60, 50, 80
1845##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001846##
1847
Cary Clark7fc1d122017-10-09 14:07:42 -04001848#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001849
1850##
1851
Cary Clark7fc1d122017-10-09 14:07:42 -04001852# ------------------------------------------------------------------------------
1853
Cary Clarkbc5697d2017-10-04 14:31:33 -04001854#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1855
Cary Clarkab2621d2018-01-30 10:08:57 -05001856#In Intersection
1857#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001858Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1859construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001860
Cary Clark7fc1d122017-10-09 14:07:42 -04001861Returns true if Rect intersects construction.
1862Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001863
Cary Clark7fc1d122017-10-09 14:07:42 -04001864#Param left x minimum of constructed Rect ##
1865#Param top y minimum of constructed Rect ##
1866#Param right x maximum of constructed Rect ##
1867#Param bottom y maximum of constructed Rect ##
1868
1869#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001870
1871#Example
Cary Clark154beea2017-10-26 07:58:48 -04001872 SkRect rect = { 10, 40, 50, 80 };
1873 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001874#StdOut
1875 intersection
1876##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001877##
1878
Cary Clark7fc1d122017-10-09 14:07:42 -04001879#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001880
1881##
1882
Cary Clark7fc1d122017-10-09 14:07:42 -04001883# ------------------------------------------------------------------------------
1884
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885#Method bool intersects(const SkRect& r) const
1886
Cary Clarkab2621d2018-01-30 10:08:57 -05001887#In Intersection
Cary Clark7fc1d122017-10-09 14:07:42 -04001888Returns true if Rect intersects r.
1889Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001890
Cary Clark7fc1d122017-10-09 14:07:42 -04001891#Param r Rect to intersect ##
1892
1893#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001894
1895#Example
Cary Clark154beea2017-10-26 07:58:48 -04001896 SkRect rect = { 10, 40, 50, 80 };
1897 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001898#StdOut
1899 intersection
1900##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001901##
1902
Cary Clark7fc1d122017-10-09 14:07:42 -04001903#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001904
1905##
1906
Cary Clark7fc1d122017-10-09 14:07:42 -04001907# ------------------------------------------------------------------------------
1908
Cary Clarkbc5697d2017-10-04 14:31:33 -04001909#Method static bool Intersects(const SkRect& a, const SkRect& b)
1910
Cary Clarkab2621d2018-01-30 10:08:57 -05001911#In Intersection
1912#Line # returns true if areas overlap ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001913Returns true if a intersects b.
1914Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001915
Cary Clark7fc1d122017-10-09 14:07:42 -04001916#Param a Rect to intersect ##
1917#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001918
Cary Clark7fc1d122017-10-09 14:07:42 -04001919#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001920
1921#Example
Cary Clark154beea2017-10-26 07:58:48 -04001922 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001923#StdOut
1924 intersection
1925##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001926##
1927
Cary Clark7fc1d122017-10-09 14:07:42 -04001928#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001929
1930##
1931
Cary Clark2dc84ad2018-01-26 12:56:22 -05001932#Subtopic Intersection ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001933
Cary Clark2dc84ad2018-01-26 12:56:22 -05001934#Subtopic Join
1935
1936#Table
1937#Legend
1938# name # description ##
1939#Legend ##
1940# join() # sets to union of bounds ##
1941# # void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) ##
1942# # void join(const SkRect& r) ##
1943# joinNonEmptyArg # sets to union of bounds, asserting that argument is not empty ##
1944# joinPossiblyEmptyRect # sets to union of bounds. Skips empty check for both ##
1945#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001946
1947# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001948
1949#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1950
Cary Clarkab2621d2018-01-30 10:08:57 -05001951#In Join
1952#Line # sets to union of bounds ##
Cary Clark7fc1d122017-10-09 14:07:42 -04001953Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1954construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001955
Cary Clark7fc1d122017-10-09 14:07:42 -04001956Sets Rect to the union of itself and the construction.
1957
1958Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1959Rect to construction.
1960
1961#Param left x minimum of constructed Rect ##
1962#Param top y minimum of constructed Rect ##
1963#Param right x maximum of constructed Rect ##
1964#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001965
1966#Example
Cary Clark154beea2017-10-26 07:58:48 -04001967 SkRect rect = { 10, 20, 15, 25};
1968 rect.join(50, 60, 55, 65);
1969 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001970#StdOut
1971 join: 10, 20, 55, 65
1972##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001973##
1974
Cary Clark7fc1d122017-10-09 14:07:42 -04001975#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001976
1977##
1978
Cary Clark7fc1d122017-10-09 14:07:42 -04001979# ------------------------------------------------------------------------------
1980
Cary Clarkbc5697d2017-10-04 14:31:33 -04001981#Method void join(const SkRect& r)
1982
Cary Clarkab2621d2018-01-30 10:08:57 -05001983#In Join
Cary Clark7fc1d122017-10-09 14:07:42 -04001984Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001985
Cary Clark7fc1d122017-10-09 14:07:42 -04001986Has no effect if r is empty. Otherwise, if Rect is empty, sets
1987Rect to r.
1988
1989#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001990
1991#Example
Cary Clark154beea2017-10-26 07:58:48 -04001992 SkRect rect = { 10, 20, 15, 25};
1993 rect.join({50, 60, 55, 65});
1994 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001995#StdOut
1996 join: 10, 20, 55, 65
1997##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001998##
1999
Cary Clark7fc1d122017-10-09 14:07:42 -04002000#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04002001
2002##
2003
Cary Clark7fc1d122017-10-09 14:07:42 -04002004# ------------------------------------------------------------------------------
2005
Cary Clarkbc5697d2017-10-04 14:31:33 -04002006#Method void joinNonEmptyArg(const SkRect& r)
2007
Cary Clarkab2621d2018-01-30 10:08:57 -05002008#In Join
2009#Line # sets to union of bounds, asserting that argument is not empty ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002010Sets Rect to the union of itself and r.
2011
2012Asserts if r is empty and SK_DEBUG is defined.
2013If Rect is empty, sets Rect to r.
2014
2015May produce incorrect results if r is empty.
2016
2017#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002018
2019#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002020#Description
2021Since Rect is not sorted, first result is copy of toJoin.
2022##
Cary Clark154beea2017-10-26 07:58:48 -04002023 SkRect rect = { 10, 100, 15, 0};
2024 SkRect sorted = rect.makeSorted();
2025 SkRect toJoin = { 50, 60, 55, 65 };
2026 rect.joinNonEmptyArg(toJoin);
2027 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2028 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04002029 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
2030#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002031rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04002032sorted: 10, 0, 55, 100
2033##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002034##
2035
Cary Clark7fc1d122017-10-09 14:07:42 -04002036#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04002037
2038##
2039
Cary Clark7fc1d122017-10-09 14:07:42 -04002040# ------------------------------------------------------------------------------
2041
Cary Clarkbc5697d2017-10-04 14:31:33 -04002042#Method void joinPossiblyEmptyRect(const SkRect& r)
2043
Cary Clarkab2621d2018-01-30 10:08:57 -05002044#In Join
2045#Line # sets to union of bounds. Skips empty check for both ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002046Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002047
Cary Clark7fc1d122017-10-09 14:07:42 -04002048May produce incorrect results if Rect or r is empty.
2049
2050#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002051
2052#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002053#Description
2054Since Rect is not sorted, first result is not useful.
2055##
Cary Clark154beea2017-10-26 07:58:48 -04002056 SkRect rect = { 10, 100, 15, 0};
2057 SkRect sorted = rect.makeSorted();
2058 SkRect toJoin = { 50, 60, 55, 65 };
2059 rect.joinPossiblyEmptyRect(toJoin);
2060 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2061 sorted.joinPossiblyEmptyRect(toJoin);
2062 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002063#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002064rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04002065sorted: 10, 0, 55, 100
2066##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002067##
2068
Cary Clark7fc1d122017-10-09 14:07:42 -04002069#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04002070
2071##
2072
Cary Clark2dc84ad2018-01-26 12:56:22 -05002073#Subtopic Join ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002074
Cary Clark2dc84ad2018-01-26 12:56:22 -05002075#Subtopic Rounding
Cary Clarkbc5697d2017-10-04 14:31:33 -04002076
Cary Clark2dc84ad2018-01-26 12:56:22 -05002077#Table
2078#Legend
2079# name # description ##
2080#Legend ##
2081# round() # sets members to nearest integer value ##
2082# # void round(SkIRect* dst) const ##
2083# # SkIRect round() const ##
2084# roundIn # sets members to nearest integer value towards opposite ##
2085# roundOut # sets members to nearest integer value away from opposite ##
2086# # void roundOut(SkIRect* dst) const ##
2087# # void roundOut(SkRect* dst) const ##
2088# # SkIRect roundOut() const ##
2089#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002090
Cary Clarkbc5697d2017-10-04 14:31:33 -04002091#Method void round(SkIRect* dst) const
2092
Cary Clarkab2621d2018-01-30 10:08:57 -05002093#In Rounding
2094#Line # sets members to nearest integer value ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002095Sets IRect by adding 0.5 and discarding the fractional portion of Rect
2096members, using
2097#Formula
2098(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2099 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2100##
2101.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002102
Cary Clark7fc1d122017-10-09 14:07:42 -04002103#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104
2105#Example
Cary Clark154beea2017-10-26 07:58:48 -04002106 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2107 SkIRect round;
2108 rect.round(&round);
2109 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002110#StdOut
2111round: 31, 51, 41, 61
2112##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002113##
2114
Cary Clark7fc1d122017-10-09 14:07:42 -04002115#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002116
2117##
2118
Cary Clark7fc1d122017-10-09 14:07:42 -04002119# ------------------------------------------------------------------------------
2120
Cary Clarkbc5697d2017-10-04 14:31:33 -04002121#Method void roundOut(SkIRect* dst) const
2122
Cary Clarkab2621d2018-01-30 10:08:57 -05002123#In Rounding
2124#Line # sets members to nearest integer value away from opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002125Sets IRect by discarding the fractional portion of fLeft and fTop; and
2126rounding up fRight and FBottom, using
2127#Formula
2128(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2129 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2130##
2131.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002132
Cary Clark7fc1d122017-10-09 14:07:42 -04002133#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002134
2135#Example
Cary Clark154beea2017-10-26 07:58:48 -04002136 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2137 SkIRect round;
2138 rect.roundOut(&round);
2139 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002140#StdOut
2141round: 30, 50, 41, 61
2142##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002143##
2144
Cary Clark7fc1d122017-10-09 14:07:42 -04002145#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002146
2147##
2148
Cary Clark7fc1d122017-10-09 14:07:42 -04002149# ------------------------------------------------------------------------------
2150
Cary Clarkbc5697d2017-10-04 14:31:33 -04002151#Method void roundOut(SkRect* dst) const
2152
Cary Clarkab2621d2018-01-30 10:08:57 -05002153#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002154Sets Rect by discarding the fractional portion of fLeft and fTop; and
2155rounding up fRight and FBottom, using
2156#Formula
2157(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2158 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2159##
2160.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002161
Cary Clark7fc1d122017-10-09 14:07:42 -04002162#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002163
2164#Example
Cary Clark154beea2017-10-26 07:58:48 -04002165 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2166 SkRect round;
2167 rect.roundOut(&round);
2168 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002169#StdOut
2170round: 30, 50, 41, 61
2171##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002172##
2173
Cary Clark7fc1d122017-10-09 14:07:42 -04002174#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002175
2176##
2177
Cary Clark7fc1d122017-10-09 14:07:42 -04002178# ------------------------------------------------------------------------------
2179
Cary Clarkbc5697d2017-10-04 14:31:33 -04002180#Method void roundIn(SkIRect* dst) const
2181
Cary Clarkab2621d2018-01-30 10:08:57 -05002182#In Rounding
2183#Line # sets members to nearest integer value towards opposite ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002184Sets Rect by rounding up fLeft and fTop; and
2185discarding the fractional portion of fRight and FBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002186
Cary Clark7fc1d122017-10-09 14:07:42 -04002187#Formula
2188(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2189 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2190##
2191.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002192
Cary Clark7fc1d122017-10-09 14:07:42 -04002193#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002194
2195#Example
Cary Clark154beea2017-10-26 07:58:48 -04002196 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2197 SkIRect round;
2198 rect.roundIn(&round);
2199 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002200#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002201round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002202##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002203##
2204
Cary Clark7fc1d122017-10-09 14:07:42 -04002205#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002206
2207##
2208
Cary Clark7fc1d122017-10-09 14:07:42 -04002209# ------------------------------------------------------------------------------
2210
Cary Clarkbc5697d2017-10-04 14:31:33 -04002211#Method SkIRect round() const
2212
Cary Clarkab2621d2018-01-30 10:08:57 -05002213#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002214Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2215members, using
2216#Formula
2217(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2218 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2219##
2220.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002221
Cary Clark7fc1d122017-10-09 14:07:42 -04002222#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002223
2224#Example
Cary Clark154beea2017-10-26 07:58:48 -04002225 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2226 SkIRect round = rect.round();
2227 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002228#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002229round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002230##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002231##
2232
Cary Clark7fc1d122017-10-09 14:07:42 -04002233#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002234
2235##
2236
Cary Clark7fc1d122017-10-09 14:07:42 -04002237# ------------------------------------------------------------------------------
2238
Cary Clarkbc5697d2017-10-04 14:31:33 -04002239#Method SkIRect roundOut() const
2240
Cary Clarkab2621d2018-01-30 10:08:57 -05002241#In Rounding
Cary Clark7fc1d122017-10-09 14:07:42 -04002242Sets IRect by discarding the fractional portion of fLeft and fTop; and
2243rounding up fRight and FBottom, using
2244#Formula
2245(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2246 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2247##
2248.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002249
Cary Clark7fc1d122017-10-09 14:07:42 -04002250#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002251
2252#Example
Cary Clark154beea2017-10-26 07:58:48 -04002253 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2254 SkIRect round = rect.roundOut();
2255 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002256#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002257round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002258##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002259##
2260
Cary Clark7fc1d122017-10-09 14:07:42 -04002261#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002262
2263##
2264
Cary Clark2dc84ad2018-01-26 12:56:22 -05002265#Subtopic Rounding ##
2266
2267#Subtopic Sorting
2268
2269#Table
2270#Legend
2271# name # description ##
2272#Legend ##
2273# makeSorted # constructs, ordering sides from smaller to larger ##
2274# sort() # orders sides from smaller to larger ##
2275#Table ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002276
2277# ------------------------------------------------------------------------------
2278
Cary Clarkbc5697d2017-10-04 14:31:33 -04002279#Method void sort()
2280
Cary Clarkab2621d2018-01-30 10:08:57 -05002281#In Sorting
2282#Line # orders sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002283Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2284fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2285and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002286
2287#Example
Cary Clark154beea2017-10-26 07:58:48 -04002288 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2289 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2290 rect.sort();
2291 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002292#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002293rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002294sorted: 20.5, 10.5, 30.5, 50.5
2295##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002296##
2297
Cary Clark2dc84ad2018-01-26 12:56:22 -05002298#SeeAlso makeSorted SkIRect::sort isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002299
2300##
2301
Cary Clark7fc1d122017-10-09 14:07:42 -04002302# ------------------------------------------------------------------------------
2303
Cary Clarkbc5697d2017-10-04 14:31:33 -04002304#Method SkRect makeSorted() const
2305
Cary Clarkab2621d2018-01-30 10:08:57 -05002306#In Sorting
2307#Line # constructs, ordering sides from smaller to larger ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002308Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2309with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2310and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002311
Cary Clark7fc1d122017-10-09 14:07:42 -04002312#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002313
2314#Example
Cary Clark154beea2017-10-26 07:58:48 -04002315 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2316 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2317 SkRect sort = rect.makeSorted();
2318 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002319#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002320rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002321sorted: 20.5, 10.5, 30.5, 50.5
2322##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002323##
2324
Cary Clark2dc84ad2018-01-26 12:56:22 -05002325#SeeAlso sort SkIRect::makeSorted isSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002326
2327##
2328
Cary Clark2dc84ad2018-01-26 12:56:22 -05002329#Subtopic Sorting ##
2330
Cary Clark7fc1d122017-10-09 14:07:42 -04002331# ------------------------------------------------------------------------------
2332
Cary Clarkbc5697d2017-10-04 14:31:33 -04002333#Method const SkScalar* asScalars() const
2334
Cary Clarkab2621d2018-01-30 10:08:57 -05002335#Line # returns pointer to members as array ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002336Returns pointer to first Scalar in Rect, to treat it as an array with four
2337entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002338
Cary Clark7fc1d122017-10-09 14:07:42 -04002339#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002340
2341#Example
Cary Clark154beea2017-10-26 07:58:48 -04002342 SkRect rect = {7, 11, 13, 17};
2343SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2344#StdOut
2345rect.asScalars() == &rect.fLeft
2346##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002347##
2348
Cary Clark7fc1d122017-10-09 14:07:42 -04002349#SeeAlso toQuad
2350
Cary Clarkbc5697d2017-10-04 14:31:33 -04002351##
2352
Cary Clark7fc1d122017-10-09 14:07:42 -04002353# ------------------------------------------------------------------------------
2354
Cary Clarkbc5697d2017-10-04 14:31:33 -04002355#Method void dump(bool asHex) const
2356
Cary Clarkab2621d2018-01-30 10:08:57 -05002357#Line # sends text representation to standard output using floats ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002358Writes text representation of Rect to standard output. Set asHex to true to
2359generate exact binary representations of floating point numbers.
2360
2361#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002362
2363#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002364 SkRect rect = {20, 30, 40, 50};
2365 for (bool dumpAsHex : { false, true } ) {
2366 rect.dump(dumpAsHex);
2367 SkDebugf("\n");
2368 }
2369#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002370SkRect::MakeLTRB(20, 30, 40, 50);
2371
2372SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2373 SkBits2Float(0x41f00000), /* 30.000000 */
2374 SkBits2Float(0x42200000), /* 40.000000 */
2375 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002376##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002377##
2378
Cary Clark7fc1d122017-10-09 14:07:42 -04002379#SeeAlso dumpHex
2380
Cary Clarkbc5697d2017-10-04 14:31:33 -04002381##
2382
Cary Clark7fc1d122017-10-09 14:07:42 -04002383# ------------------------------------------------------------------------------
2384
Cary Clarkbc5697d2017-10-04 14:31:33 -04002385#Method void dump() const
2386
Cary Clark7fc1d122017-10-09 14:07:42 -04002387Writes text representation of Rect to standard output. The representation may be
2388directly compiled as C++ code. Floating point values are written
2389with limited precision; it may not be possible to reconstruct original Rect
2390from output.
2391
Cary Clarkbc5697d2017-10-04 14:31:33 -04002392#Example
Cary Clark154beea2017-10-26 07:58:48 -04002393SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2394rect.dump();
2395SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2396SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002397#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002398SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002399rect is not equal to copy
2400##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002401##
2402
Cary Clark7fc1d122017-10-09 14:07:42 -04002403#SeeAlso dumpHex
2404
Cary Clarkbc5697d2017-10-04 14:31:33 -04002405##
2406
Cary Clark7fc1d122017-10-09 14:07:42 -04002407# ------------------------------------------------------------------------------
2408
Cary Clarkbc5697d2017-10-04 14:31:33 -04002409#Method void dumpHex() const
2410
Cary Clarkab2621d2018-01-30 10:08:57 -05002411#Line # sends text representation to standard output using hexadecimal ##
Cary Clark7fc1d122017-10-09 14:07:42 -04002412Writes text representation of Rect to standard output. The representation may be
2413directly compiled as C++ code. Floating point values are written
2414in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2415original Rect.
2416
2417Use instead of dump() when submitting
2418#A bug reports against Skia # http://bug.skia.org ##
2419.
2420
Cary Clarkbc5697d2017-10-04 14:31:33 -04002421#Example
Cary Clark154beea2017-10-26 07:58:48 -04002422 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2423rect.dumpHex();
2424SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2425 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2426 SkBits2Float(0x40266666), /* 2.600000 */
2427 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002428SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2429#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002430SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2431 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2432 SkBits2Float(0x40266666), /* 2.600000 */
2433 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002434rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002435##
Cary Clark7fc1d122017-10-09 14:07:42 -04002436##
2437
2438#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002439
2440##
2441
Cary Clark0c95aab2018-01-08 16:20:59 -05002442#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
2443
Cary Clarkab2621d2018-01-30 10:08:57 -05002444#Line # deprecated ##
Cary Clark0c95aab2018-01-08 16:20:59 -05002445#Deprecated
2446##
2447
Cary Clarkac47b882018-01-11 10:35:44 -05002448Returns constructed SkRect setting left and top to most negative finite value, and
2449setting right and bottom to most positive finite value.
2450
2451#Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
2452
Cary Clark0c95aab2018-01-08 16:20:59 -05002453##
2454
Cary Clarkbc5697d2017-10-04 14:31:33 -04002455#Struct SkRect ##
2456
2457#Topic Rect ##