blob: 1a28f1bd1237de1be9103329d30aa7b491b12c7a [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Rect
2#Alias Rects
3#Alias Rect_Reference
4
5#Struct SkRect
6
Cary Clark7fc1d122017-10-09 14:07:42 -04007SkRect holds four SkScalar coordinates describing the upper and
8lower bounds of a rectangle. SkRect may be created from outer bounds or
9from position, width, and height. SkRect describes an area; if its right
10is less than or equal to its left, or if its bottom is less than or equal to
11its top, it is considered empty.
12
13# move to topic about MakeIWH and friends
14SkRect can be constructed from int values to avoid compiler warnings that
15integer input cannot convert to SkScalar without loss of precision.
16
Cary Clarkbc5697d2017-10-04 14:31:33 -040017#Topic Overview
18
19#Subtopic Subtopics
20#ToDo manually add subtopics ##
21#Table
22#Legend
23# topics # description ##
24#Legend ##
25#Table ##
26##
27
28#Subtopic Operators
29#Table
30#Legend
Cary Clark884dd7d2017-10-11 10:37:52 -040031# description # function ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040032#Legend ##
Cary Clark884dd7d2017-10-11 10:37:52 -040033# bool operator!=(const SkRect& a, const SkRect& b) # Returns true if member bits are unequal. ##
34# bool operator==(const SkRect& a, const SkRect& b) # Returns true if member bits are equal. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040035#Table ##
36#Subtopic ##
37
38#Subtopic Member_Functions
39#Table
40#Legend
Cary Clark7fc1d122017-10-09 14:07:42 -040041# description # function ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040042#Legend ##
Cary Clark7fc1d122017-10-09 14:07:42 -040043# Intersects # Returns true if areas overlap. ##
44# Make # Constructs from ISize returning (0, 0, width, height). ##
45# MakeEmpty # Constructs from bounds of (0, 0, 0, 0). ##
46# MakeFromIRect # Deprecated. ##
47# MakeIWH # Constructs from int input returning (0, 0, width, height). ##
48# MakeLTRB # Constructs from SkScalar left, top, right, bottom. ##
49# MakeLargest # Constructs (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
Cary Clark884dd7d2017-10-11 10:37:52 -040050# MakeLargestS32 # Constructs largest signed integers that fit in 32-bit float. ##
Cary Clark7fc1d122017-10-09 14:07:42 -040051# MakeSize # Constructs from Size returning (0, 0, width, height). ##
52# MakeWH # Constructs from SkScalar input returning (0, 0, width, height). ##
53# MakeXYWH # Constructs from SkScalar input returning (x, y, width, height). ##
54# asScalars # Returns pointer to members as array. ##
55# bottom() # Returns larger bounds in y, if sorted. ##
56# centerX # Returns midpoint in x. ##
57# centerY # Returns midpoint in y. ##
58# contains() # Returns true if points are equal or inside. ##
59# dump() # Sends text representation using floats to standard output. ##
60# dumpHex # Sends text representation using hexadecimal to standard output. ##
61# growToInclude # Sets to union of bounds and one or more Points. ##
62# height # Returns span in y. ##
63# inset() # Moves the sides symmetrically about the center. ##
64# intersect() # Sets to shared area; returns true if not empty. ##
65# intersects() # Returns true if areas overlap. ##
66# isEmpty # Returns true if width or height are zero or negative. ##
67# isFinite # Returns true if no member is infinite or NaN. ##
68# isLargest # Returns equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
69# isSorted # Returns true if width or height are zero or positive. ##
70# iset() # Sets to int input (left, top, right, bottom). ##
71# isetWH # Sets to int input (0, 0, width, height). ##
72# join() # Sets to union of bounds. ##
73# joinNonEmptyArg # Sets to union of bounds, asserting that argument is not empty. ##
74# joinPossiblyEmptyRect # Sets to union of bounds. Skips empty check for both. ##
75# left() # Returns smaller bounds in x, if sorted. ##
76# makeInset # Constructs from sides moved symmetrically about the center. ##
77# makeOffset # Constructs from translated sides. ##
78# makeOutset # Constructs from sides moved symmetrically about the center. ##
79# makeSorted # Constructs, ordering sides from smaller to larger. ##
80# offset() # Translates sides without changing width and height. ##
81# offsetTo # Translates to (x, y) without changing width and height. ##
82# outset() # Moves the sides symmetrically about the center. ##
83# right() # Returns larger bounds in x, if sorted. ##
84# round() # Sets members to nearest integer value. ##
85# roundIn # Sets members to nearest integer value towards opposite. ##
86# roundOut # Sets members to nearest integer value away from opposite. ##
87# set() # Sets to SkScalar input (left, top, right, bottom) and others. ##
88# setBounds # Sets to upper and lower limits of Point array. ##
89# setBoundsCheck # Sets to upper and lower limits of Point array. ##
90# setEmpty # Sets to (0, 0, 0, 0). ##
91# setLTRB # Sets to SkScalar input (left, top, right, bottom). ##
92# setLargest # Sets to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ##
93# setLargestInverted # Sets to (SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin). ##
94# setWH # Sets to SkScalar input (0, 0, width, height). ##
95# setXYWH # Sets to SkScalar input (x, y, width, height). ##
96# sort() # Orders sides from smaller to larger. ##
97# toQuad # Returns four corners as Point. ##
98# top() # Returns smaller bounds in y, if sorted. ##
99# width() # Returns span in x. ##
100# x() # Returns bounds left. ##
101# y() # Returns bounds top. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400102#Table ##
103#Subtopic ##
104
105#Topic ##
106
107#Member SkScalar fLeft
Cary Clark7fc1d122017-10-09 14:07:42 -0400108May contain any value, including infinities and NaN. The smaller of the
109horizontal values when sorted. When equal to or greater than fRight, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400110##
111
112#Member SkScalar fTop
Cary Clark7fc1d122017-10-09 14:07:42 -0400113May contain any value, including infinities and NaN. The smaller of the
114vertical values when sorted. When equal to or greater than fBottom, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400115##
116
117#Member SkScalar fRight
Cary Clark7fc1d122017-10-09 14:07:42 -0400118May contain any value, including infinities and NaN. The larger of the
119horizontal values when sorted. When equal to or less than fLeft, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400120##
121
122#Member SkScalar fBottom
Cary Clark7fc1d122017-10-09 14:07:42 -0400123May contain any value, including infinities and NaN. The larger of the
124vertical values when sorted. When equal to or less than fTop, Rect is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400125##
126
127# ------------------------------------------------------------------------------
128
129#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty()
130
Cary Clark7fc1d122017-10-09 14:07:42 -0400131Returns constructed Rect set to (0, 0, 0, 0).
132Many other rectangles are empty; if left is equal to or greater than right,
133or if top is equal to or greater than bottom. Setting all members to zero
134is a convenience, but does not designate a special empty rectangle.
135
136#Return bounds (0, 0, 0, 0) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400137
138#Example
Cary Clark154beea2017-10-26 07:58:48 -0400139 SkRect rect = SkRect::MakeEmpty();
140 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
141 rect.offset(10, 10);
142 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
143 rect.inset(10, 10);
144 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
145 rect.outset(20, 20);
146 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
147#StdOut
148MakeEmpty isEmpty: true
149offset rect isEmpty: true
150inset rect isEmpty: true
151outset rect isEmpty: false
152##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400153##
154
Cary Clark7fc1d122017-10-09 14:07:42 -0400155#SeeAlso isEmpty setEmpty setLargestInverted SkIRect::MakeEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400156
157##
158
159# ------------------------------------------------------------------------------
160
161#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest()
162
Cary Clark7fc1d122017-10-09 14:07:42 -0400163Returns constructed Rect setting left and top to most negative finite value, and
164setting right and bottom to most positive finite value.
165
166#Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400167
168#Example
Cary Clark154beea2017-10-26 07:58:48 -0400169 SkRect rect = SkRect::MakeLargest();
170 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
171 SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
172 rect.outset(1e31, 1e31);
173 SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
174 SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
175 rect.outset(1e32, 1e32);
176 SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
177 SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
178#StdOut
179MakeLargest isLargest: true
180MakeLargest isFinite: true
181outset a little isLargest: true
182outset a little isFinite: true
183outset a little more isLargest: false
184outset a little more isFinite: false
185##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400186##
187
Cary Clark884dd7d2017-10-11 10:37:52 -0400188#SeeAlso MakeLargestS32 isLargest setLargest SkIRect::MakeLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400189
190##
191
192# ------------------------------------------------------------------------------
193
Cary Clark884dd7d2017-10-11 10:37:52 -0400194#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargestS32()
195
196Returns constructed Rect that can be represented exactly with IRect. The left
197and top are set to the most negative integer value that fits in a 32-bit float,
198and the right and bottom are set to the most positive finite value that fits in
199a 32-bit float.
200
201These are the largest values for which round() is well defined.
202
203#Return bounds (SK_MinS32FitsInFloat, SK_MinS32FitsInFloat,
204 SK_MaxS32FitsInFloat, SK_MaxS32FitsInFloat)
205##
206
207#Example
Cary Clark154beea2017-10-26 07:58:48 -0400208 SkRect f_rect = SkRect::MakeLargestS32();
209 SkIRect i_rect = f_rect.round();
210 SkRect r_rect = SkRect::Make(i_rect);
211 SkDebugf("f_rect %c= r_rect\n", f_rect == r_rect ? '=' : '!');
212#StdOut
213f_rect == r_rect
214##
Cary Clark884dd7d2017-10-11 10:37:52 -0400215##
216
217#SeeAlso MakeLargest isLargest setLargest SkIRect::MakeLargest
218
219##
220
221# ------------------------------------------------------------------------------
222
223#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400224
Cary Clark7fc1d122017-10-09 14:07:42 -0400225Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not
226validate input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400227
Cary Clark7fc1d122017-10-09 14:07:42 -0400228Passing integer values may generate a compiler warning since Rect cannot
229represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
230
231#Param w SkScalar width of constructed Rect ##
232#Param h SkScalar height of constructed Rect ##
233
234#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400235
236#Example
Cary Clark154beea2017-10-26 07:58:48 -0400237 SkRect rect1 = SkRect::MakeWH(25, 35);
238 SkRect rect2 = SkRect::MakeIWH(25, 35);
239 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
240 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
241 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
Cary Clark7fc1d122017-10-09 14:07:42 -0400242 "" : "not ");
243#StdOut
244all equal
245##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400246##
247
Cary Clark7fc1d122017-10-09 14:07:42 -0400248#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400249
250##
251
252# ------------------------------------------------------------------------------
253
254#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h)
255
Cary Clark7fc1d122017-10-09 14:07:42 -0400256Returns constructed Rect set to integer values (0, 0, w, h). Does not validate
257input; w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400258
Cary Clark7fc1d122017-10-09 14:07:42 -0400259Use to avoid a compiler warning that input may lose precision when stored.
260Use SkIRect for an exact integer rectangle.
261
262#Param w integer width of constructed Rect ##
263#Param h integer height of constructed Rect ##
264
265#Return bounds (0, 0, w, h) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400266
267#Example
Cary Clark154beea2017-10-26 07:58:48 -0400268 SkIRect i_rect = SkIRect::MakeWH(25, 35);
269 SkRect f_rect = SkRect::MakeIWH(25, 35);
270 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
271 i_rect = SkIRect::MakeWH(125000111, 0);
272 f_rect = SkRect::MakeIWH(125000111, 0);
273 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400274#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400275i_rect width: 25 f_rect width:25
Cary Clark7fc1d122017-10-09 14:07:42 -0400276i_rect width: 125000111 f_rect width:125000112
277##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400278##
279
Cary Clark7fc1d122017-10-09 14:07:42 -0400280#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400281
282##
283
284# ------------------------------------------------------------------------------
285
Cary Clark884dd7d2017-10-11 10:37:52 -0400286#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400287
Cary Clark7fc1d122017-10-09 14:07:42 -0400288Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not
289validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400290
Cary Clark7fc1d122017-10-09 14:07:42 -0400291#Param size SkScalar values for Rect width and height ##
292
293#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400294
295#Example
Cary Clark154beea2017-10-26 07:58:48 -0400296 SkSize size = {25.5f, 35.5f};
297 SkRect rect = SkRect::MakeSize(size);
298 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
299 SkISize floor = size.toFloor();
300 rect = SkRect::MakeSize(SkSize::Make(floor));
301 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400302#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400303rect width: 25.5 height: 35.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400304floor width: 25 height: 35
305##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400306##
307
Cary Clark7fc1d122017-10-09 14:07:42 -0400308#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309
310##
311
312# ------------------------------------------------------------------------------
313
314#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
315 SkScalar b)
316
Cary Clark7fc1d122017-10-09 14:07:42 -0400317Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may
318result in fLeft greater than fRight, or fTop greater than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400319
Cary Clark7fc1d122017-10-09 14:07:42 -0400320#Param l SkScalar stored in fLeft ##
321#Param t SkScalar stored in fTop ##
322#Param r SkScalar stored in fRight ##
323#Param b SkScalar stored in fBottom ##
324
325#Return bounds (l, t, r, b) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400326
327#Example
Cary Clark154beea2017-10-26 07:58:48 -0400328 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
329 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
330 rect.bottom(), rect.isEmpty() ? "true" : "false");
331 rect.sort();
332 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
333 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400334#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400335rect: 5, 35, 15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400336rect: 5, 25, 15, 35 isEmpty: false
337##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400338##
339
Cary Clark7fc1d122017-10-09 14:07:42 -0400340#SeeAlso MakeXYWH SkIRect::MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400341
342##
343
344# ------------------------------------------------------------------------------
345
Cary Clark884dd7d2017-10-11 10:37:52 -0400346#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400347
Cary Clark7fc1d122017-10-09 14:07:42 -0400348Returns constructed Rect set to
349#Formula
350(x, y, x + w, y + h)
351##
352. Does not validate input;
353w or h may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400354
Cary Clark7fc1d122017-10-09 14:07:42 -0400355#Param x stored in fLeft ##
356#Param y stored in fTop ##
357#Param w added to x and stored in fRight ##
358#Param h added to y and stored in fBottom ##
359
Cary Clark884dd7d2017-10-11 10:37:52 -0400360#Return bounds at (x, y) with width w and height h ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400361
362#Example
Cary Clark154beea2017-10-26 07:58:48 -0400363 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
364 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
365 rect.bottom(), rect.isEmpty() ? "true" : "false");
366 rect.sort();
367 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
368 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400369#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400370rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -0400371rect: -10, 35, 5, 60 isEmpty: false
372##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400373##
374
Cary Clark7fc1d122017-10-09 14:07:42 -0400375#SeeAlso MakeLTRB SkIRect::MakeXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -0400376
377##
378
379# ------------------------------------------------------------------------------
380
381#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect)
382
Cary Clark7fc1d122017-10-09 14:07:42 -0400383Deprecated.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400384
Cary Clark7fc1d122017-10-09 14:07:42 -0400385#Deprecated
Cary Clarkbc5697d2017-10-04 14:31:33 -0400386##
387
Cary Clark7fc1d122017-10-09 14:07:42 -0400388#Param irect integer rect ##
389
390#Return irect as SkRect ##
391
392#NoExample
393##
394
395#SeeAlso Make
Cary Clarkbc5697d2017-10-04 14:31:33 -0400396
397##
398
399# ------------------------------------------------------------------------------
400
401#Method static SkRect Make(const SkISize& size)
402
Cary Clark7fc1d122017-10-09 14:07:42 -0400403Returns constructed IRect set to (0, 0, size.width(), size.height()).
404Does not validate input; size.width() or size.height() may be negative.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400405
Cary Clark7fc1d122017-10-09 14:07:42 -0400406#Param size integer values for Rect width and height ##
407
408#Return bounds (0, 0, size.width(), size.height()) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400409
410#Example
Cary Clark154beea2017-10-26 07:58:48 -0400411 SkRect rect1 = SkRect::MakeSize({2, 35});
412 SkRect rect2 = SkRect::MakeIWH(2, 35);
413 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
Cary Clark7fc1d122017-10-09 14:07:42 -0400414#StdOut
415rect1 == rect2
416##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400417##
418
Cary Clark7fc1d122017-10-09 14:07:42 -0400419#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize
Cary Clarkbc5697d2017-10-04 14:31:33 -0400420
421##
422
423# ------------------------------------------------------------------------------
424
425#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect)
426
Cary Clark7fc1d122017-10-09 14:07:42 -0400427Returns constructed IRect set to irect, promoting integers to Scalar.
428Does not validate input; fLeft may be greater than fRight, fTop may be greater
429than fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400430
Cary Clark7fc1d122017-10-09 14:07:42 -0400431#Param irect integer unsorted bounds ##
432
433#Return irect members converted to SkScalar ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400434
435#Example
Cary Clark154beea2017-10-26 07:58:48 -0400436 SkIRect i_rect1 = {2, 35, 22, 53};
437 SkRect f_rect = SkRect::Make(i_rect1);
438 f_rect.offset(0.49f, 0.49f);
439 SkIRect i_rect2;
440 f_rect.round(&i_rect2);
441 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
Cary Clarkbc5697d2017-10-04 14:31:33 -0400442##
443
Cary Clark7fc1d122017-10-09 14:07:42 -0400444#SeeAlso MakeLTRB
Cary Clarkbc5697d2017-10-04 14:31:33 -0400445
446##
447
448# ------------------------------------------------------------------------------
449
450#Method bool isEmpty() const
451
Cary Clark7fc1d122017-10-09 14:07:42 -0400452Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
453to or greater than fBottom. Call sort() to reverse rectangles with negative
454width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400455
Cary Clark7fc1d122017-10-09 14:07:42 -0400456#Return true if width() or height() are zero or negative ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400457
458#Example
Cary Clark154beea2017-10-26 07:58:48 -0400459 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
460 for (auto rect : tests) {
461 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
462 rect.bottom(), rect.isEmpty() ? "" : " not");
463 rect.sort();
464 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
465 rect.bottom(), rect.isEmpty() ? "" : " not");
466 }
467#StdOut
468rect: {20, 40, 10, 50} is empty
469sorted: {10, 40, 20, 50} is not empty
470rect: {20, 40, 20, 50} is empty
471sorted: {20, 40, 20, 50} is empty
472##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400473##
474
Cary Clark7fc1d122017-10-09 14:07:42 -0400475#SeeAlso MakeEmpty sort SkIRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400476
477##
478
479# ------------------------------------------------------------------------------
480
481#Method bool isSorted() const
482
Cary Clark7fc1d122017-10-09 14:07:42 -0400483Returns true if fLeft is equal to or less than fRight, or if fTop is equal
484to or less than fBottom. Call sort() to reverse rectangles with negative
485width() or height().
Cary Clarkbc5697d2017-10-04 14:31:33 -0400486
Cary Clark7fc1d122017-10-09 14:07:42 -0400487#Return true if width() or height() are zero or positive ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400488
489#Example
Cary Clark154beea2017-10-26 07:58:48 -0400490 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
491 for (auto rect : tests) {
492 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
493 rect.bottom(), rect.isSorted() ? "" : " not");
494 rect.sort();
495 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
496 rect.bottom(), rect.isSorted() ? "" : " not");
497 }
498#StdOut
499rect: {20, 40, 10, 50} is not sorted
500sorted: {10, 40, 20, 50} is sorted
501rect: {20, 40, 20, 50} is sorted
502sorted: {20, 40, 20, 50} is sorted
503##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400504##
505
Cary Clark7fc1d122017-10-09 14:07:42 -0400506#SeeAlso sort makeSorted isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400507
508##
509
510# ------------------------------------------------------------------------------
511
512#Method bool isLargest() const
513
Cary Clark7fc1d122017-10-09 14:07:42 -0400514Returns true if Rect encloses largest possible area.
515
516#Return true if equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400517
518#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400519#Description
520Note that the width cannot be represented as a 32-bit finite value.
521##
Cary Clark154beea2017-10-26 07:58:48 -0400522 SkRect large = SkRect::MakeLargest();
523 SkDebugf("large is largest: %s\n" ,large.isLargest() ? "true" : "false");
524 SkDebugf("large width %g\n", large.width());
525 SkDebugf("large is empty: %s\n", large.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -0400526 SkDebugf("large is sorted: %s\n", large.isSorted() ? "true" : "false");
Cary Clark154beea2017-10-26 07:58:48 -0400527 SkDebugf("large is finite: %s\n", large.isFinite() ? "true" : "false");
528#StdOut
529large is largest: true
530large width inf
531large is empty: false
Cary Clark7fc1d122017-10-09 14:07:42 -0400532large is sorted: true
533large is finite: true
534##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400535##
536
Cary Clark7fc1d122017-10-09 14:07:42 -0400537#SeeAlso MakeLargest SkIRect::isLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -0400538
539##
540
541# ------------------------------------------------------------------------------
542
543#Method bool isFinite() const
544
Cary Clark7fc1d122017-10-09 14:07:42 -0400545Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
546and SK_ScalarMax or smaller.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400547
Cary Clark7fc1d122017-10-09 14:07:42 -0400548#Return true if no member is infinite or NaN ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400549
550#Example
Cary Clark154beea2017-10-26 07:58:48 -0400551 SkRect largest = SkRect::MakeLargest();
552 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
553 SkDebugf("large width %g\n", largest.width());
554 SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
555 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
556#StdOut
557largest is finite: true
558large width inf
Cary Clark7fc1d122017-10-09 14:07:42 -0400559widest is finite: false
560##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400561##
562
Cary Clark7fc1d122017-10-09 14:07:42 -0400563#SeeAlso SkScalarIsFinite SkScalarIsNaN
Cary Clarkbc5697d2017-10-04 14:31:33 -0400564
565##
566
567# ------------------------------------------------------------------------------
568
569#Method SkScalar x() const
570
Cary Clark7fc1d122017-10-09 14:07:42 -0400571Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
572Call sort() to reverse fLeft and fRight if needed.
573
574#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400575
576#Example
Cary Clark154beea2017-10-26 07:58:48 -0400577 SkRect unsorted = { 15, 5, 10, 25 };
578 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
579 SkRect sorted = unsorted.makeSorted();
580 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
Cary Clark7fc1d122017-10-09 14:07:42 -0400581#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400582unsorted.fLeft: 15 unsorted.x(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400583sorted.fLeft: 10 sorted.x(): 10
584##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400585##
586
Cary Clark7fc1d122017-10-09 14:07:42 -0400587#SeeAlso fLeft left() y() SkIRect::x()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400588
589##
590
591# ------------------------------------------------------------------------------
592
593#Method SkScalar y() const
594
Cary Clark7fc1d122017-10-09 14:07:42 -0400595Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
596and sort() to reverse fTop and fBottom if needed.
597
598#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400599
600#Example
Cary Clark154beea2017-10-26 07:58:48 -0400601 SkRect unsorted = { 15, 25, 10, 5 };
602 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
603 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400604 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y());
605#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400606unsorted.fTop: 25 unsorted.y(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400607sorted.fTop: 5 sorted.y(): 5
608##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400609##
610
Cary Clark7fc1d122017-10-09 14:07:42 -0400611#SeeAlso fTop top() x() SkIRect::y()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400612
613##
614
615# ------------------------------------------------------------------------------
616
617#Method SkScalar left() const
618
Cary Clark7fc1d122017-10-09 14:07:42 -0400619Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid.
620Call sort() to reverse fLeft and fRight if needed.
621
622#Return fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400623
624#Example
Cary Clark154beea2017-10-26 07:58:48 -0400625 SkRect unsorted = { 15, 5, 10, 25 };
626 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
627 SkRect sorted = unsorted.makeSorted();
628 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
Cary Clark7fc1d122017-10-09 14:07:42 -0400629#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400630unsorted.fLeft: 15 unsorted.left(): 15
Cary Clark7fc1d122017-10-09 14:07:42 -0400631sorted.fLeft: 10 sorted.left(): 10
632##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400633##
634
Cary Clark7fc1d122017-10-09 14:07:42 -0400635#SeeAlso fLeft x() SkIRect::left()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400636
637##
638
639# ------------------------------------------------------------------------------
640
641#Method SkScalar top() const
642
Cary Clark7fc1d122017-10-09 14:07:42 -0400643Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
644and sort() to reverse fTop and fBottom if needed.
645
646#Return fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400647
648#Example
Cary Clark154beea2017-10-26 07:58:48 -0400649 SkRect unsorted = { 15, 25, 10, 5 };
650 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
651 SkRect sorted = unsorted.makeSorted();
Cary Clark7fc1d122017-10-09 14:07:42 -0400652 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top());
653#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400654unsorted.fTop: 25 unsorted.top(): 25
Cary Clark7fc1d122017-10-09 14:07:42 -0400655sorted.fTop: 5 sorted.top(): 5
656##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400657##
658
Cary Clark7fc1d122017-10-09 14:07:42 -0400659#SeeAlso fTop y() SkIRect::top()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400660
661##
662
663# ------------------------------------------------------------------------------
664
665#Method SkScalar right() const
666
Cary Clark7fc1d122017-10-09 14:07:42 -0400667Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid.
668Call sort() to reverse fLeft and fRight if needed.
669
670#Return fRight ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400671
672#Example
Cary Clark154beea2017-10-26 07:58:48 -0400673 SkRect unsorted = { 15, 25, 10, 5 };
674 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
675 SkRect sorted = unsorted.makeSorted();
676 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
Cary Clark7fc1d122017-10-09 14:07:42 -0400677#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400678unsorted.fRight: 10 unsorted.right(): 10
Cary Clark7fc1d122017-10-09 14:07:42 -0400679sorted.fRight: 15 sorted.right(): 15
680##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400681##
682
Cary Clark7fc1d122017-10-09 14:07:42 -0400683#SeeAlso fRight SkIRect::right()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400684
685##
686
687# ------------------------------------------------------------------------------
688
689#Method SkScalar bottom() const
690
Cary Clark7fc1d122017-10-09 14:07:42 -0400691Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid,
692and sort() to reverse fTop and fBottom if needed.
693
694#Return fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400695
696#Example
Cary Clark154beea2017-10-26 07:58:48 -0400697 SkRect unsorted = { 15, 25, 10, 5 };
698 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
699 SkRect sorted = unsorted.makeSorted();
700 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -0400701#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400702unsorted.fBottom: 5 unsorted.bottom(): 5
Cary Clark7fc1d122017-10-09 14:07:42 -0400703sorted.fBottom: 25 sorted.bottom(): 25
704##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400705##
706
Cary Clark7fc1d122017-10-09 14:07:42 -0400707#SeeAlso fBottom SkIRect::bottom()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400708
709##
710
711# ------------------------------------------------------------------------------
712
713#Method SkScalar width() const
714
Cary Clark7fc1d122017-10-09 14:07:42 -0400715Returns span on the x-axis. This does not check if Rect is sorted, or if
716result fits in 32-bit float; result may be negative or infinity.
717
718#Return fRight minus fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400719
720#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400721#Description
722Compare with SkIRect::width() example.
723##
Cary Clark154beea2017-10-26 07:58:48 -0400724 SkRect unsorted = { 15, 25, 10, 5 };
725 SkDebugf("unsorted width: %g\n", unsorted.width());
726 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
727 SkDebugf("large width: %.0f\n", large.width());
Cary Clark7fc1d122017-10-09 14:07:42 -0400728#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400729unsorted width: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400730large width: 4294967296
731##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400732##
733
Cary Clark7fc1d122017-10-09 14:07:42 -0400734#SeeAlso height() SkIRect::width()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400735
736##
737
738# ------------------------------------------------------------------------------
739
740#Method SkScalar height() const
741
Cary Clark7fc1d122017-10-09 14:07:42 -0400742Returns span on the y-axis. This does not check if IRect is sorted, or if
743result fits in 32-bit float; result may be negative or infinity.
744
745#Return fBottom minus fTop ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400746
747#Example
Cary Clark7fc1d122017-10-09 14:07:42 -0400748#Description
749Compare with SkIRect::height() example.
750##
Cary Clark154beea2017-10-26 07:58:48 -0400751 SkRect unsorted = { 15, 25, 10, 20 };
752 SkDebugf("unsorted height: %g\n", unsorted.height());
753 SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
754 SkDebugf("large height: %.0f\n", large.height());
Cary Clark7fc1d122017-10-09 14:07:42 -0400755#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400756unsorted height: -5
Cary Clark7fc1d122017-10-09 14:07:42 -0400757large height: 4294967296
758##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400759##
760
Cary Clark7fc1d122017-10-09 14:07:42 -0400761#SeeAlso width() SkIRect::height()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400762
763##
764
765# ------------------------------------------------------------------------------
766
767#Method SkScalar centerX() const
768
Cary Clark7fc1d122017-10-09 14:07:42 -0400769Returns average of left edge and right edge. Result does not change if Rect
770is sorted. Result may overflow to infinity if Rect is far from the origin.
771
772#Return midpoint in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400773
774#Example
Cary Clark154beea2017-10-26 07:58:48 -0400775 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
776 for (auto rect : tests) {
777 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
778 rect.sort();
779 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
780 }
Cary Clark7fc1d122017-10-09 14:07:42 -0400781#StdOut
Cary Clark154beea2017-10-26 07:58:48 -0400782left: 20 right: 41 centerX: 30.5
783left: 20 right: 41 centerX: 30.5
784left: -20 right: -41 centerX: -30.5
Cary Clark7fc1d122017-10-09 14:07:42 -0400785left: -41 right: -20 centerX: -30.5
786##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400787##
788
Cary Clark7fc1d122017-10-09 14:07:42 -0400789#SeeAlso centerY SkIRect::centerX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400790
791##
792
793# ------------------------------------------------------------------------------
794
795#Method SkScalar centerY() const
796
Cary Clark7fc1d122017-10-09 14:07:42 -0400797Returns average of top edge and bottom edge. Result does not change if Rect
798is sorted. Result may overflow to infinity if Rect is far from the origin.
799
800#Return midpoint in y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400801
802#Example
Cary Clark154beea2017-10-26 07:58:48 -0400803 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
804 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
805 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
Cary Clark7fc1d122017-10-09 14:07:42 -0400806#StdOut
807left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38
808##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400809##
810
Cary Clark7fc1d122017-10-09 14:07:42 -0400811#SeeAlso centerX SkIRect::centerY
Cary Clarkbc5697d2017-10-04 14:31:33 -0400812
813##
814
815# ------------------------------------------------------------------------------
816
Cary Clark884dd7d2017-10-11 10:37:52 -0400817#Method bool operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400818
Cary Clark7fc1d122017-10-09 14:07:42 -0400819Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
820equal to the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400821
Cary Clark7fc1d122017-10-09 14:07:42 -0400822a and b are not equal if either contain NaN. a and b are equal if members
823contain zeroes width different signs.
824
825#Param a Rect to compare ##
826#Param b Rect to compare ##
827
828#Return true if members are equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400829
830#Example
Cary Clark154beea2017-10-26 07:58:48 -0400831 auto debugster = [](const SkRect& test) -> void {
832 SkRect negZero = {-0.0f, -0.0f, 2, 2};
833 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
834 test.fLeft, test.fTop, test.fRight, test.fBottom,
835 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
836 test == negZero ? '=' : '!',
837 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
838 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
839 "and are" : "yet are not");
840 };
841 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
842 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
843 for (auto rect : tests) {
844 debugster(rect);
Cary Clark7fc1d122017-10-09 14:07:42 -0400845 }
Cary Clark154beea2017-10-26 07:58:48 -0400846#StdOut
847tests are equal
848{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
849{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
Cary Clark7fc1d122017-10-09 14:07:42 -0400850{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
851##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400852##
853
Cary Clark7fc1d122017-10-09 14:07:42 -0400854#SeeAlso operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400855
856##
857
858# ------------------------------------------------------------------------------
859
Cary Clark884dd7d2017-10-11 10:37:52 -0400860#Method bool operator!=(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400861
Cary Clark7fc1d122017-10-09 14:07:42 -0400862Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
863equal the corresponding members in b.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400864
Cary Clark7fc1d122017-10-09 14:07:42 -0400865a and b are not equal if either contain NaN. a and b are equal if members
866contain zeroes width different signs.
867
868#Param a Rect to compare ##
869#Param b Rect to compare ##
870
871#Return true if members are not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400872
873#Example
Cary Clark154beea2017-10-26 07:58:48 -0400874 SkRect test = {0, 0, 2, SK_ScalarNaN};
875 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
876#StdOut
Cary Clark7fc1d122017-10-09 14:07:42 -0400877test with NaN is not equal to itself
878##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400879##
880
Cary Clark7fc1d122017-10-09 14:07:42 -0400881#SeeAlso operator==(const SkRect& a, const SkRect& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -0400882
883##
884
885# ------------------------------------------------------------------------------
886
887#Method void toQuad(SkPoint quad[4]) const
888
Cary Clark7fc1d122017-10-09 14:07:42 -0400889Returns four points in quad that enclose Rect ordered as: top-left, top-right,
890bottom-right, bottom-left.
891
892#Private
Cary Clarkbc5697d2017-10-04 14:31:33 -0400893Consider adding param to control whether quad is CW or CCW.
894##
895
Cary Clark7fc1d122017-10-09 14:07:42 -0400896#Param quad storage for corners of Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400897
898#Example
Cary Clark154beea2017-10-26 07:58:48 -0400899 SkRect rect = {1, 2, 3, 4};
900 SkPoint corners[4];
901 rect.toQuad(corners);
902 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
903 SkDebugf("corners:");
904 for (auto corner : corners) {
905 SkDebugf(" {%g, %g}", corner.fX, corner.fY);
906 }
907 SkDebugf("\n");
908#StdOut
909rect: {1, 2, 3, 4}
Cary Clark7fc1d122017-10-09 14:07:42 -0400910corners: {1, 2} {3, 2} {3, 4} {1, 4}
911##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400912##
913
Cary Clark7fc1d122017-10-09 14:07:42 -0400914#SeeAlso SkPath::addRect
Cary Clarkbc5697d2017-10-04 14:31:33 -0400915
916##
917
918# ------------------------------------------------------------------------------
919
920#Method void setEmpty()
921
Cary Clark7fc1d122017-10-09 14:07:42 -0400922Sets Rect to (0, 0, 0, 0).
923
924Many other rectangles are empty; if left is equal to or greater than right,
925or if top is equal to or greater than bottom. Setting all members to zero
926is a convenience, but does not designate a special empty rectangle.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400927
928#Example
Cary Clark154beea2017-10-26 07:58:48 -0400929 SkRect rect = {3, 4, 1, 2};
930 for (int i = 0; i < 2; ++i) {
931 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
932 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
933 rect.setEmpty();
934 }
935#StdOut
936rect: {3, 4, 1, 2} is empty
937rect: {0, 0, 0, 0} is empty
938##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400939##
940
Cary Clark7fc1d122017-10-09 14:07:42 -0400941#SeeAlso MakeEmpty SkIRect::setEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -0400942
943##
944
945# ------------------------------------------------------------------------------
946
947#Method void set(const SkIRect& src)
948
Cary Clark7fc1d122017-10-09 14:07:42 -0400949Sets Rect to src, promoting src members from integer to Scalar.
950Very large values in src may lose precision.
951
952#Param src integer Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400953
954#Example
Cary Clark154beea2017-10-26 07:58:48 -0400955 SkIRect i_rect = {3, 4, 1, 2};
956 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
957 SkRect f_rect;
958 f_rect.set(i_rect);
959 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
960#StdOut
961i_rect: {3, 4, 1, 2}
962f_rect: {3, 4, 1, 2}
963##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400964##
965
Cary Clark7fc1d122017-10-09 14:07:42 -0400966#SeeAlso setLTRB SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -0400967
968##
969
970# ------------------------------------------------------------------------------
971
972#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
973
Cary Clark7fc1d122017-10-09 14:07:42 -0400974Sets Rect to (left, top, right, bottom).
975left and right are not sorted; left is not necessarily less than right.
976top and bottom are not sorted; top is not necessarily less than bottom.
977
978#Param left stored in fLeft ##
979#Param top stored in fTop ##
980#Param right stored in fRight ##
981#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400982
983#Example
Cary Clark154beea2017-10-26 07:58:48 -0400984 SkRect rect1 = {3, 4, 1, 2};
985 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
986 SkRect rect2;
987 rect2.set(3, 4, 1, 2);
988 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
989#StdOut
990rect1: {3, 4, 1, 2}
991rect2: {3, 4, 1, 2}
992##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400993##
994
Cary Clark7fc1d122017-10-09 14:07:42 -0400995#SeeAlso setLTRB setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400996
997##
998
999# ------------------------------------------------------------------------------
1000
1001#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1002
Cary Clark7fc1d122017-10-09 14:07:42 -04001003Sets Rect to (left, top, right, bottom).
1004left and right are not sorted; left is not necessarily less than right.
1005top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001006
Cary Clark7fc1d122017-10-09 14:07:42 -04001007#Param left stored in fLeft ##
1008#Param top stored in fTop ##
1009#Param right stored in fRight ##
1010#Param bottom stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001011
1012#Example
Cary Clark154beea2017-10-26 07:58:48 -04001013 SkRect rect1 = {3, 4, 1, 2};
1014 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1015 SkRect rect2;
1016 rect2.setLTRB(3, 4, 1, 2);
1017 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1018#StdOut
1019rect1: {3, 4, 1, 2}
1020rect2: {3, 4, 1, 2}
1021##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001022##
1023
Cary Clark7fc1d122017-10-09 14:07:42 -04001024#SeeAlso set setXYWH SkIRect::set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001025
1026##
1027
1028# ------------------------------------------------------------------------------
1029
1030#Method void iset(int left, int top, int right, int bottom)
1031
Cary Clark7fc1d122017-10-09 14:07:42 -04001032Sets Rect to (left, top, right, bottom).
1033All parameters are promoted from integer to Scalar.
1034left and right are not sorted; left is not necessarily less than right.
1035top and bottom are not sorted; top is not necessarily less than bottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001036
Cary Clark7fc1d122017-10-09 14:07:42 -04001037#Param left promoted to SkScalar and stored in fLeft ##
1038#Param top promoted to SkScalar and stored in fTop ##
1039#Param right promoted to SkScalar and stored in fRight ##
1040#Param bottom promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001041
1042#Example
Cary Clark154beea2017-10-26 07:58:48 -04001043 SkRect rect1 = {3, 4, 1, 2};
1044 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1045 SkRect rect2;
1046 rect2.iset(3, 4, 1, 2);
1047 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
1048#StdOut
1049rect1: {3, 4, 1, 2}
1050rect2: {3, 4, 1, 2}
1051##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001052##
1053
Cary Clark7fc1d122017-10-09 14:07:42 -04001054#SeeAlso set setLTRB SkIRect::set SkIntToScalar
Cary Clarkbc5697d2017-10-04 14:31:33 -04001055
1056##
1057
1058# ------------------------------------------------------------------------------
1059
1060#Method void isetWH(int width, int height)
1061
Cary Clark7fc1d122017-10-09 14:07:42 -04001062Sets Rect to (0, 0, width, height).
1063width and height may be zero or negative. width and height are promoted from
1064integer to SkScalar, large values may lose precision.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001065
Cary Clark7fc1d122017-10-09 14:07:42 -04001066#Param width promoted to SkScalar and stored in fRight ##
1067#Param height promoted to SkScalar and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001068
1069#Example
Cary Clark154beea2017-10-26 07:58:48 -04001070 SkRect rect1 = {0, 0, 1, 2};
1071 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
1072 SkRect rect2;
1073 rect2.isetWH(1, 2);
Cary Clark7fc1d122017-10-09 14:07:42 -04001074 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
Cary Clark154beea2017-10-26 07:58:48 -04001075#StdOut
1076rect1: {0, 0, 1, 2}
1077rect2: {0, 0, 1, 2}
1078##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001079##
1080
Cary Clark7fc1d122017-10-09 14:07:42 -04001081#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001082
1083##
1084
1085# ------------------------------------------------------------------------------
1086
1087#Method void set(const SkPoint pts[], int count)
1088
Cary Clark7fc1d122017-10-09 14:07:42 -04001089Sets to bounds of Point array with count entries. If count is zero or smaller,
1090or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001091
Cary Clark7fc1d122017-10-09 14:07:42 -04001092Result is either empty or sorted: fLeft is less than or equal to fRight, and
1093fTop is less than or equal to fBottom.
1094
1095#Param pts Point array ##
1096#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001097
1098#Example
Cary Clark154beea2017-10-26 07:58:48 -04001099 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1100 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1101 SkRect rect;
1102 rect.set(points, count);
1103 if (count > 0) {
1104 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1105 } else {
1106 SkDebugf("%14s", " ");
1107 }
1108 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1109 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1110 }
1111#StdOut
1112 count: 0 rect: 0, 0, 0, 0
1113added: 3, 4 count: 1 rect: 3, 4, 3, 4
1114added: 1, 2 count: 2 rect: 1, 2, 3, 4
1115added: 5, 6 count: 3 rect: 1, 2, 5, 6
1116added: nan, 8 count: 4 rect: 0, 0, 0, 0
1117##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001118##
1119
Cary Clark7fc1d122017-10-09 14:07:42 -04001120#SeeAlso setBounds setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001121
1122##
1123
1124# ------------------------------------------------------------------------------
1125
1126#Method void setBounds(const SkPoint pts[], int count)
1127
Cary Clark7fc1d122017-10-09 14:07:42 -04001128Sets to bounds of Point array with count entries. If count is zero or smaller,
1129or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001130
Cary Clark7fc1d122017-10-09 14:07:42 -04001131Result is either empty or sorted: fLeft is less than or equal to fRight, and
1132fTop is less than or equal to fBottom.
1133
1134#Param pts Point array ##
1135#Param count entries in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001136
1137#Example
Cary Clark154beea2017-10-26 07:58:48 -04001138 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1139 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1140 SkRect rect;
1141 rect.setBounds(points, count);
1142 if (count > 0) {
1143 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1144 } else {
1145 SkDebugf("%14s", " ");
1146 }
1147 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
1148 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1149 }
1150#StdOut
1151 count: 0 rect: 0, 0, 0, 0
1152added: 3, 4 count: 1 rect: 3, 4, 3, 4
1153added: 1, 2 count: 2 rect: 1, 2, 3, 4
1154added: 5, 6 count: 3 rect: 1, 2, 5, 6
1155added: nan, 8 count: 4 rect: 0, 0, 0, 0
1156##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001157##
1158
Cary Clark7fc1d122017-10-09 14:07:42 -04001159#SeeAlso set setBoundsCheck SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001160
1161##
1162
1163# ------------------------------------------------------------------------------
1164
1165#Method bool setBoundsCheck(const SkPoint pts[], int count)
1166
Cary Clark7fc1d122017-10-09 14:07:42 -04001167Sets to bounds of Point array with count entries. Returns false if count is
1168zero or smaller, or if Point array contains an infinity or NaN; in these cases
1169sets Rect to (0, 0, 0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001170
Cary Clark7fc1d122017-10-09 14:07:42 -04001171Result is either empty or sorted: fLeft is less than or equal to fRight, and
1172fTop is less than or equal to fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001173
Cary Clark7fc1d122017-10-09 14:07:42 -04001174#Param pts Point array ##
1175#Param count entries in array ##
1176
1177#Return true if all Point values are finite ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001178
1179#Example
Cary Clark154beea2017-10-26 07:58:48 -04001180 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
1181 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
1182 SkRect rect;
1183 bool success = rect.setBoundsCheck(points, count);
1184 if (count > 0) {
1185 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
1186 } else {
1187 SkDebugf("%14s", " ");
1188 }
1189 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
1190 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
1191 }
1192#StdOut
1193 count: 0 rect: 0, 0, 0, 0 success: true
1194added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
1195added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
1196added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
1197added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
1198##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001199##
1200
Cary Clark7fc1d122017-10-09 14:07:42 -04001201#SeeAlso set setBounds SkPath::addPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04001202
1203##
1204
1205# ------------------------------------------------------------------------------
1206
1207#Method void set(const SkPoint& p0, const SkPoint& p1)
1208
Cary Clark7fc1d122017-10-09 14:07:42 -04001209Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is
1210sorted and may be empty. Does not check to see if values are finite.
1211
1212#Param p0 corner to include ##
1213#Param p1 corner to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001214
1215#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001216#Description
1217p0 and p1 may be swapped and have the same effect unless one contains NaN.
1218##
Cary Clark154beea2017-10-26 07:58:48 -04001219 SkPoint point1 = {SK_ScalarNaN, 8};
1220 SkPoint point2 = {3, 4};
1221 SkRect rect;
1222 rect.set(point1, point2);
1223 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1224 rect.set(point2, point1);
1225 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001226##
1227
Cary Clark7fc1d122017-10-09 14:07:42 -04001228#SeeAlso setBounds setBoundsCheck
Cary Clarkbc5697d2017-10-04 14:31:33 -04001229
1230##
1231
1232# ------------------------------------------------------------------------------
1233
1234#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height)
1235
Cary Clark7fc1d122017-10-09 14:07:42 -04001236Sets Rect to
1237#Formula
1238(x, y, x + width, y + height)
1239##
1240. Does not validate input;
1241width or height may be negative.
1242
1243#Param x stored in fLeft ##
1244#Param y stored in fTop ##
1245#Param width added to x and stored in fRight ##
1246#Param height added to y and stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001247
1248#Example
Cary Clark154beea2017-10-26 07:58:48 -04001249 SkRect rect;
1250 rect.setXYWH(5, 35, -15, 25);
1251 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1252 rect.bottom(), rect.isEmpty() ? "true" : "false");
1253 rect.sort();
1254 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1255 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001256#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001257rect: 5, 35, -10, 60 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001258rect: -10, 35, 5, 60 isEmpty: false
1259##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001260##
1261
Cary Clark7fc1d122017-10-09 14:07:42 -04001262#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001263
1264##
1265
1266# ------------------------------------------------------------------------------
1267
1268#Method void setWH(SkScalar width, SkScalar height)
1269
Cary Clark7fc1d122017-10-09 14:07:42 -04001270Sets Rect to (0, 0, width, height). Does not validate input;
1271width or height may be negative.
1272
1273#Param width stored in fRight ##
1274#Param height stored in fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001275
1276#Example
Cary Clark154beea2017-10-26 07:58:48 -04001277 SkRect rect;
1278 rect.setWH(-15, 25);
1279 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1280 rect.bottom(), rect.isEmpty() ? "true" : "false");
1281 rect.sort();
1282 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1283 rect.bottom(), rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001284#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001285rect: 0, 0, -15, 25 isEmpty: true
Cary Clark7fc1d122017-10-09 14:07:42 -04001286rect: -15, 0, 0, 25 isEmpty: false
1287##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001288##
1289
Cary Clark7fc1d122017-10-09 14:07:42 -04001290#SeeAlso MakeWH setXYWH isetWH
Cary Clarkbc5697d2017-10-04 14:31:33 -04001291
1292##
1293
1294# ------------------------------------------------------------------------------
1295
1296#Method void setLargest()
1297
Cary Clark7fc1d122017-10-09 14:07:42 -04001298Sets rectangle left and top to most negative finite value, and sets
1299right and bottom to most positive finite value.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001300
1301#Example
Cary Clark154beea2017-10-26 07:58:48 -04001302 SkRect rect;
1303 rect.setLargest();
1304 SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
1305 SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
1306 rect.outset(1e31, 1e31);
1307 SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
1308 SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
1309 rect.outset(1e32, 1e32);
1310 SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
1311 SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
1312#StdOut
1313MakeLargest isLargest: true
1314MakeLargest isFinite: true
1315outset a little isLargest: true
1316outset a little isFinite: true
1317outset a little more isLargest: false
1318outset a little more isFinite: false
1319##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001320##
1321
Cary Clark7fc1d122017-10-09 14:07:42 -04001322#SeeAlso MakeLargest isLargest setLargestInverted SK_ScalarMin SK_ScalarMax
Cary Clarkbc5697d2017-10-04 14:31:33 -04001323
1324##
1325
1326# ------------------------------------------------------------------------------
1327
1328#Method void setLargestInverted()
1329
Cary Clark7fc1d122017-10-09 14:07:42 -04001330Sets rectangle left and top to most positive finite value, and sets
1331right and bottom to most negative finite value.
1332
1333Use to initial Rect before one or more calls to growToInclude.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001334
1335#Example
Cary Clark154beea2017-10-26 07:58:48 -04001336 auto debugster = [](const char* prefix, const SkRect& rect) -> void {
1337 SkDebugf("%s ", prefix);
1338 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1339 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
1340 };
1341 SkRect ptBounds;
1342 ptBounds.setLargestInverted();
1343 debugster("original", ptBounds);
1344 ptBounds.growToInclude( { 42, 24 } );
Cary Clark7fc1d122017-10-09 14:07:42 -04001345 debugster("grown", ptBounds);
Cary Clark154beea2017-10-26 07:58:48 -04001346#StdOut
1347original rect: 3.40282e+38, 3.40282e+38, -3.40282e+38, -3.40282e+38 isEmpty: true
1348grown rect: 42, 24, 42, 24 isEmpty: true
1349##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001350##
1351
Cary Clark7fc1d122017-10-09 14:07:42 -04001352#SeeAlso growToInclude setEmpty setLargest
Cary Clarkbc5697d2017-10-04 14:31:33 -04001353
1354##
1355
1356# ------------------------------------------------------------------------------
1357
1358#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const
1359
Cary Clark7fc1d122017-10-09 14:07:42 -04001360Returns Rect offset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001361
Cary Clark7fc1d122017-10-09 14:07:42 -04001362If dx is negative, Rect returned is moved to the left.
1363If dx is positive, Rect returned is moved to the right.
1364If dy is negative, Rect returned is moved upward.
1365If dy is positive, Rect returned is moved downward.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001366
Cary Clark7fc1d122017-10-09 14:07:42 -04001367#Param dx added to fLeft and fRight ##
1368#Param dy added to fTop and fBottom ##
1369
1370#Return Rect offset in x or y, with original width and height ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001371
1372#Example
Cary Clark154beea2017-10-26 07:58:48 -04001373 SkRect rect = { 10, 50, 20, 60 };
1374 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1375 rect.bottom(), rect.isEmpty() ? "true" : "false");
1376 rect = rect.makeOffset(15, 32);
1377 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1378 rect.bottom(), rect.isEmpty() ? "true" : "false");
1379#StdOut
1380rect: 10, 50, 20, 60 isEmpty: false
1381rect: 25, 82, 35, 92 isEmpty: false
1382##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001383##
1384
Cary Clark7fc1d122017-10-09 14:07:42 -04001385#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001386
1387##
1388
1389# ------------------------------------------------------------------------------
1390
1391#Method SkRect makeInset(SkScalar dx, SkScalar dy) const
1392
Cary Clark7fc1d122017-10-09 14:07:42 -04001393Returns Rect, inset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001394
Cary Clark7fc1d122017-10-09 14:07:42 -04001395If dx is negative, Rect returned is wider.
1396If dx is positive, Rect returned is narrower.
1397If dy is negative, Rect returned is taller.
1398If dy is positive, Rect returned is shorter.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001399
Cary Clark7fc1d122017-10-09 14:07:42 -04001400#Param dx added to fLeft and subtracted from fRight ##
1401#Param dy added to fTop and subtracted from fBottom ##
1402
1403#Return Rect inset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001404
1405#Example
Cary Clark154beea2017-10-26 07:58:48 -04001406 SkRect rect = { 10, 50, 20, 60 };
1407 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1408 rect.bottom(), rect.isEmpty() ? "true" : "false");
1409 rect = rect.makeInset(15, 32);
1410 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1411 rect.bottom(), rect.isEmpty() ? "true" : "false");
1412#StdOut
1413rect: 10, 50, 20, 60 isEmpty: false
1414rect: 25, 82, 5, 28 isEmpty: true
1415##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001416##
1417
Cary Clark7fc1d122017-10-09 14:07:42 -04001418#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001419
1420##
1421
1422# ------------------------------------------------------------------------------
1423
1424#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const
1425
Cary Clark7fc1d122017-10-09 14:07:42 -04001426Returns Rect, outset by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001427
Cary Clark7fc1d122017-10-09 14:07:42 -04001428If dx is negative, Rect returned is narrower.
1429If dx is positive, Rect returned is wider.
1430If dy is negative, Rect returned is shorter.
1431If dy is positive, Rect returned is taller.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001432
Cary Clark7fc1d122017-10-09 14:07:42 -04001433#Param dx subtracted to fLeft and added from fRight ##
1434#Param dy subtracted to fTop and added from fBottom ##
1435
1436#Return Rect outset symmetrically left and right, top and bottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001437
1438#Example
Cary Clark154beea2017-10-26 07:58:48 -04001439 SkRect rect = { 10, 50, 20, 60 };
1440 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1441 rect.bottom(), rect.isEmpty() ? "true" : "false");
1442 rect = rect.makeOutset(15, 32);
1443 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
1444 rect.bottom(), rect.isEmpty() ? "true" : "false");
1445#StdOut
1446rect: 10, 50, 20, 60 isEmpty: false
1447rect: -5, 18, 35, 92 isEmpty: false
1448##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001449##
1450
Cary Clark7fc1d122017-10-09 14:07:42 -04001451#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001452
1453##
1454
1455# ------------------------------------------------------------------------------
1456
1457#Method void offset(SkScalar dx, SkScalar dy)
1458
Cary Clark7fc1d122017-10-09 14:07:42 -04001459Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001460
Cary Clark7fc1d122017-10-09 14:07:42 -04001461If dx is negative, moves Rect to the left.
1462If dx is positive, moves Rect to the right.
1463If dy is negative, moves Rect upward.
1464If dy is positive, moves Rect downward.
1465
1466#Param dx offset added to fLeft and fRight ##
1467#Param dy offset added to fTop and fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001468
1469#Example
Cary Clark154beea2017-10-26 07:58:48 -04001470 SkRect rect = { 10, 14, 50, 73 };
1471 rect.offset(5, 13);
1472 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1473#StdOut
1474rect: 15, 27, 55, 86
1475##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001476##
1477
Cary Clark7fc1d122017-10-09 14:07:42 -04001478#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001479
1480##
1481
1482# ------------------------------------------------------------------------------
1483
1484#Method void offset(const SkPoint& delta)
1485
Cary Clark7fc1d122017-10-09 14:07:42 -04001486Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
1487fTop, fBottom.
1488
1489If delta.fX is negative, moves Rect to the left.
1490If delta.fX is positive, moves Rect to the right.
1491If delta.fY is negative, moves Rect upward.
1492If delta.fY is positive, moves Rect downward.
1493
1494#Param delta added to Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001495
1496#Example
Cary Clark154beea2017-10-26 07:58:48 -04001497 SkRect rect = { 10, 14, 50, 73 };
1498 rect.offset({5, 13});
1499 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1500#StdOut
1501rect: 15, 27, 55, 86
1502##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001503##
1504
Cary Clark7fc1d122017-10-09 14:07:42 -04001505#SeeAlso offsetTo makeOffset SkIRect::offset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001506
1507##
1508
1509# ------------------------------------------------------------------------------
1510
1511#Method void offsetTo(SkScalar newX, SkScalar newY)
1512
Cary Clark7fc1d122017-10-09 14:07:42 -04001513Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height
1514are unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001515
Cary Clark7fc1d122017-10-09 14:07:42 -04001516#Param newX stored in fLeft, preserving width() ##
1517#Param newY stored in fTop, preserving height() ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001518
1519#Example
Cary Clark154beea2017-10-26 07:58:48 -04001520 SkRect rect = { 10, 14, 50, 73 };
1521 rect.offsetTo(15, 27);
1522 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1523#StdOut
1524rect: 15, 27, 55, 86
1525##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001526##
1527
Cary Clark7fc1d122017-10-09 14:07:42 -04001528#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo
Cary Clarkbc5697d2017-10-04 14:31:33 -04001529
1530##
1531
1532# ------------------------------------------------------------------------------
1533
1534#Method void inset(SkScalar dx, SkScalar dy)
1535
Cary Clark7fc1d122017-10-09 14:07:42 -04001536Insets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001537
Cary Clark7fc1d122017-10-09 14:07:42 -04001538If dx is positive, makes Rect narrower.
1539If dx is negative, makes Rect wider.
1540If dy is positive, makes Rect shorter.
1541If dy is negative, makes Rect taller.
1542
1543#Param dx added to fLeft and subtracted from fRight ##
1544#Param dy added to fTop and subtracted from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001545
1546#Example
Cary Clark154beea2017-10-26 07:58:48 -04001547 SkRect rect = { 10, 14, 50, 73 };
1548 rect.inset(5, 13);
1549 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1550#StdOut
1551rect: 15, 27, 45, 60
1552##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001553##
1554
Cary Clark7fc1d122017-10-09 14:07:42 -04001555#SeeAlso outset makeInset SkIRect::inset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001556
1557##
1558
1559# ------------------------------------------------------------------------------
1560
1561#Method void outset(SkScalar dx, SkScalar dy)
1562
Cary Clark7fc1d122017-10-09 14:07:42 -04001563Outsets Rect by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001564
Cary Clark7fc1d122017-10-09 14:07:42 -04001565If dx is positive, makes Rect wider.
1566If dx is negative, makes Rect narrower.
1567If dy is positive, makes Rect taller.
1568If dy is negative, makes Rect shorter.
1569
1570#Param dx subtracted to fLeft and added from fRight ##
1571#Param dy subtracted to fTop and added from fBottom ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001572
1573#Example
Cary Clark154beea2017-10-26 07:58:48 -04001574 SkRect rect = { 10, 14, 50, 73 };
1575 rect.outset(5, 13);
1576 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1577#StdOut
1578rect: 5, 1, 55, 86
1579##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001580##
1581
Cary Clark7fc1d122017-10-09 14:07:42 -04001582#SeeAlso inset makeOutset SkIRect::outset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001583
1584##
1585
Cary Clark7fc1d122017-10-09 14:07:42 -04001586#Topic Intersection
1587
1588Rects intersect when they enclose a common area. To intersect, each of the pair
1589must describe area; fLeft is less than fRight, and fTop is less than fBottom;
Cary Clark154beea2017-10-26 07:58:48 -04001590empty() returns false. The intersection of Rect pair can be described by:
1591
Cary Clark7fc1d122017-10-09 14:07:42 -04001592#Formula
1593(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop),
1594 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom))
1595##
Cary Clark154beea2017-10-26 07:58:48 -04001596.
1597
Cary Clark7fc1d122017-10-09 14:07:42 -04001598The intersection is only meaningful if the resulting Rect is not empty and
1599describes an area: fLeft is less than fRight, and fTop is less than fBottom.
1600
Cary Clarkbc5697d2017-10-04 14:31:33 -04001601# ------------------------------------------------------------------------------
1602
1603#Method bool intersect(const SkRect& r)
1604
Cary Clark7fc1d122017-10-09 14:07:42 -04001605Returns true if Rect intersects r, and sets Rect to intersection.
1606Returns false if Rect does not intersect r, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001607
Cary Clark7fc1d122017-10-09 14:07:42 -04001608Returns false if either r or Rect is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001609
Cary Clark7fc1d122017-10-09 14:07:42 -04001610#Param r limit of result ##
1611
1612#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001613
1614#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001615#Description
1616Two SkDebugf calls are required. If the calls are combined, their arguments
1617may not be evaluated in left to right order: the printed intersection may
1618be before or after the call to intersect.
1619##
Cary Clark154beea2017-10-26 07:58:48 -04001620 SkRect leftRect = { 10, 40, 50, 80 };
1621 SkRect rightRect = { 30, 60, 70, 90 };
1622 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
1623 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001624 leftRect.right(), leftRect.bottom());
1625#StdOut
1626 intersection: 30, 60, 50, 80
1627##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001628##
1629
Cary Clark7fc1d122017-10-09 14:07:42 -04001630#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001631
1632##
1633
1634# ------------------------------------------------------------------------------
1635
1636#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1637
Cary Clark7fc1d122017-10-09 14:07:42 -04001638Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1639construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001640
Cary Clark7fc1d122017-10-09 14:07:42 -04001641Returns true if Rect intersects construction, and sets Rect to intersection.
1642Returns false if Rect does not intersect construction, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001643
Cary Clark7fc1d122017-10-09 14:07:42 -04001644Returns false if either construction or Rect is empty, leaving Rect unchanged.
1645
1646#Param left x minimum of constructed Rect ##
1647#Param top y minimum of constructed Rect ##
1648#Param right x maximum of constructed Rect ##
1649#Param bottom y maximum of constructed Rect ##
1650
1651#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001652
1653#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001654#Description
1655Two SkDebugf calls are required. If the calls are combined, their arguments
1656may not be evaluated in left to right order: the printed intersection may
1657be before or after the call to intersect.
1658##
Cary Clark154beea2017-10-26 07:58:48 -04001659 SkRect leftRect = { 10, 40, 50, 80 };
1660 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
1661 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
Cary Clark7fc1d122017-10-09 14:07:42 -04001662 leftRect.right(), leftRect.bottom());
1663#StdOut
1664 intersection: 30, 60, 50, 80
1665##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001666##
1667
Cary Clark7fc1d122017-10-09 14:07:42 -04001668#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001669
1670##
1671
1672# ------------------------------------------------------------------------------
1673
1674#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b)
1675
Cary Clark7fc1d122017-10-09 14:07:42 -04001676Returns true if a intersects b, and sets Rect to intersection.
1677Returns false if a does not intersect b, and leaves Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001678
Cary Clark7fc1d122017-10-09 14:07:42 -04001679Returns false if either a or b is empty, leaving Rect unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001680
Cary Clark7fc1d122017-10-09 14:07:42 -04001681#Param a Rect to intersect ##
1682#Param b Rect to intersect ##
1683
1684#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001685
1686#Example
Cary Clark154beea2017-10-26 07:58:48 -04001687 SkRect result;
1688 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
1689 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
1690 result.left(), result.top(), result.right(), result.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001691#StdOut
1692 intersection: 30, 60, 50, 80
1693##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001694##
1695
Cary Clark7fc1d122017-10-09 14:07:42 -04001696#SeeAlso intersects Intersects join SkIRect::intersect
Cary Clarkbc5697d2017-10-04 14:31:33 -04001697
1698##
1699
Cary Clark7fc1d122017-10-09 14:07:42 -04001700# ------------------------------------------------------------------------------
1701
Cary Clarkbc5697d2017-10-04 14:31:33 -04001702#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const
1703
Cary Clark7fc1d122017-10-09 14:07:42 -04001704Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1705construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001706
Cary Clark7fc1d122017-10-09 14:07:42 -04001707Returns true if Rect intersects construction.
1708Returns false if either construction or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001709
Cary Clark7fc1d122017-10-09 14:07:42 -04001710#Param left x minimum of constructed Rect ##
1711#Param top y minimum of constructed Rect ##
1712#Param right x maximum of constructed Rect ##
1713#Param bottom y maximum of constructed Rect ##
1714
1715#Return true if construction and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001716
1717#Example
Cary Clark154beea2017-10-26 07:58:48 -04001718 SkRect rect = { 10, 40, 50, 80 };
1719 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001720#StdOut
1721 intersection
1722##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001723##
1724
Cary Clark7fc1d122017-10-09 14:07:42 -04001725#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001726
1727##
1728
Cary Clark7fc1d122017-10-09 14:07:42 -04001729# ------------------------------------------------------------------------------
1730
Cary Clarkbc5697d2017-10-04 14:31:33 -04001731#Method bool intersects(const SkRect& r) const
1732
Cary Clark7fc1d122017-10-09 14:07:42 -04001733Returns true if Rect intersects r.
1734Returns false if either r or Rect is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001735
Cary Clark7fc1d122017-10-09 14:07:42 -04001736#Param r Rect to intersect ##
1737
1738#Return true if r and Rect have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001739
1740#Example
Cary Clark154beea2017-10-26 07:58:48 -04001741 SkRect rect = { 10, 40, 50, 80 };
1742 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001743#StdOut
1744 intersection
1745##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746##
1747
Cary Clark7fc1d122017-10-09 14:07:42 -04001748#SeeAlso intersect Intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001749
1750##
1751
Cary Clark7fc1d122017-10-09 14:07:42 -04001752# ------------------------------------------------------------------------------
1753
Cary Clarkbc5697d2017-10-04 14:31:33 -04001754#Method static bool Intersects(const SkRect& a, const SkRect& b)
1755
Cary Clark7fc1d122017-10-09 14:07:42 -04001756Returns true if a intersects b.
1757Returns false if either a or b is empty, or do not intersect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001758
Cary Clark7fc1d122017-10-09 14:07:42 -04001759#Param a Rect to intersect ##
1760#Param b Rect to intersect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001761
Cary Clark7fc1d122017-10-09 14:07:42 -04001762#Return true if a and b have area in common ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001763
1764#Example
Cary Clark154beea2017-10-26 07:58:48 -04001765 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
Cary Clark7fc1d122017-10-09 14:07:42 -04001766#StdOut
1767 intersection
1768##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001769##
1770
Cary Clark7fc1d122017-10-09 14:07:42 -04001771#SeeAlso intersect intersects SkIRect::Intersects
Cary Clarkbc5697d2017-10-04 14:31:33 -04001772
1773##
1774
Cary Clark7fc1d122017-10-09 14:07:42 -04001775#Topic Intersection ##
1776
1777
1778# ------------------------------------------------------------------------------
Cary Clarkbc5697d2017-10-04 14:31:33 -04001779
1780#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
1781
Cary Clark7fc1d122017-10-09 14:07:42 -04001782Constructs Rect to intersect from (left, top, right, bottom). Does not sort
1783construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001784
Cary Clark7fc1d122017-10-09 14:07:42 -04001785Sets Rect to the union of itself and the construction.
1786
1787Has no effect if construction is empty. Otherwise, if Rect is empty, sets
1788Rect to construction.
1789
1790#Param left x minimum of constructed Rect ##
1791#Param top y minimum of constructed Rect ##
1792#Param right x maximum of constructed Rect ##
1793#Param bottom y maximum of constructed Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001794
1795#Example
Cary Clark154beea2017-10-26 07:58:48 -04001796 SkRect rect = { 10, 20, 15, 25};
1797 rect.join(50, 60, 55, 65);
1798 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001799#StdOut
1800 join: 10, 20, 55, 65
1801##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001802##
1803
Cary Clark7fc1d122017-10-09 14:07:42 -04001804#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001805
1806##
1807
Cary Clark7fc1d122017-10-09 14:07:42 -04001808# ------------------------------------------------------------------------------
1809
Cary Clarkbc5697d2017-10-04 14:31:33 -04001810#Method void join(const SkRect& r)
1811
Cary Clark7fc1d122017-10-09 14:07:42 -04001812Sets Rect to the union of itself and r.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001813
Cary Clark7fc1d122017-10-09 14:07:42 -04001814Has no effect if r is empty. Otherwise, if Rect is empty, sets
1815Rect to r.
1816
1817#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001818
1819#Example
Cary Clark154beea2017-10-26 07:58:48 -04001820 SkRect rect = { 10, 20, 15, 25};
1821 rect.join({50, 60, 55, 65});
1822 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001823#StdOut
1824 join: 10, 20, 55, 65
1825##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001826##
1827
Cary Clark7fc1d122017-10-09 14:07:42 -04001828#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001829
1830##
1831
Cary Clark7fc1d122017-10-09 14:07:42 -04001832# ------------------------------------------------------------------------------
1833
Cary Clarkbc5697d2017-10-04 14:31:33 -04001834#Method void joinNonEmptyArg(const SkRect& r)
1835
Cary Clark7fc1d122017-10-09 14:07:42 -04001836Sets Rect to the union of itself and r.
1837
1838Asserts if r is empty and SK_DEBUG is defined.
1839If Rect is empty, sets Rect to r.
1840
1841May produce incorrect results if r is empty.
1842
1843#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001844
1845#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001846#Description
1847Since Rect is not sorted, first result is copy of toJoin.
1848##
Cary Clark154beea2017-10-26 07:58:48 -04001849 SkRect rect = { 10, 100, 15, 0};
1850 SkRect sorted = rect.makeSorted();
1851 SkRect toJoin = { 50, 60, 55, 65 };
1852 rect.joinNonEmptyArg(toJoin);
1853 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1854 sorted.joinNonEmptyArg(toJoin);
Cary Clark7fc1d122017-10-09 14:07:42 -04001855 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
1856#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001857rect: 50, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001858sorted: 10, 0, 55, 100
1859##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001860##
1861
Cary Clark7fc1d122017-10-09 14:07:42 -04001862#SeeAlso join joinPossiblyEmptyRect SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001863
1864##
1865
Cary Clark7fc1d122017-10-09 14:07:42 -04001866# ------------------------------------------------------------------------------
1867
Cary Clarkbc5697d2017-10-04 14:31:33 -04001868#Method void joinPossiblyEmptyRect(const SkRect& r)
1869
Cary Clark7fc1d122017-10-09 14:07:42 -04001870Sets Rect to the union of itself and the construction.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001871
Cary Clark7fc1d122017-10-09 14:07:42 -04001872May produce incorrect results if Rect or r is empty.
1873
1874#Param r expansion Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001875
1876#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04001877#Description
1878Since Rect is not sorted, first result is not useful.
1879##
Cary Clark154beea2017-10-26 07:58:48 -04001880 SkRect rect = { 10, 100, 15, 0};
1881 SkRect sorted = rect.makeSorted();
1882 SkRect toJoin = { 50, 60, 55, 65 };
1883 rect.joinPossiblyEmptyRect(toJoin);
1884 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1885 sorted.joinPossiblyEmptyRect(toJoin);
1886 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04001887#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04001888rect: 10, 60, 55, 65
Cary Clark7fc1d122017-10-09 14:07:42 -04001889sorted: 10, 0, 55, 100
1890##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001891##
1892
Cary Clark7fc1d122017-10-09 14:07:42 -04001893#SeeAlso joinNonEmptyArg join SkIRect::join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001894
1895##
1896
Cary Clark7fc1d122017-10-09 14:07:42 -04001897# ------------------------------------------------------------------------------
1898
Cary Clarkbc5697d2017-10-04 14:31:33 -04001899#Method void growToInclude(SkPoint pt)
1900
Cary Clark7fc1d122017-10-09 14:07:42 -04001901Grows Rect to include (pt.fX, pt.fY), modifying it so that:
Cary Clark154beea2017-10-26 07:58:48 -04001902
Cary Clark7fc1d122017-10-09 14:07:42 -04001903#Formula
1904fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1905##
1906.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001907
Cary Clark7fc1d122017-10-09 14:07:42 -04001908If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1909Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001910
Cary Clark7fc1d122017-10-09 14:07:42 -04001911#Param pt Point to include ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001912
1913#Example
Cary Clark154beea2017-10-26 07:58:48 -04001914 SkRect rect;
1915 rect.setLargestInverted();
1916 rect.growToInclude( { 42, 24 } );
1917 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
1918 SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
Cary Clark7fc1d122017-10-09 14:07:42 -04001919#StdOut
1920rect: 42, 24, 42, 24 isEmpty: true
1921##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001922##
1923
Cary Clark7fc1d122017-10-09 14:07:42 -04001924#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001925
1926##
1927
Cary Clark7fc1d122017-10-09 14:07:42 -04001928# ------------------------------------------------------------------------------
1929
Cary Clarkbc5697d2017-10-04 14:31:33 -04001930#Method void growToInclude(const SkPoint pts[], int count)
1931
Cary Clark7fc1d122017-10-09 14:07:42 -04001932For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1933it so that:
1934#Formula
1935fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1936##
1937.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001938
Cary Clark7fc1d122017-10-09 14:07:42 -04001939If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1940Points after one or more calls. In this case, Rect is empty after first call.
1941
1942#Param pts Point array ##
1943#Param count number of points in array ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001944
1945#Example
Cary Clark154beea2017-10-26 07:58:48 -04001946 SkPoint pts[] = { { 30, 50 }, { 40, 50 }, { 30, 60 } };
1947 SkRect rect = { pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY };
1948 rect.growToInclude( pts[1] );
1949 rect.growToInclude( pts[2] );
1950 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001951#StdOut
1952rect: 30, 50, 40, 60
1953##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001954##
1955
Cary Clark7fc1d122017-10-09 14:07:42 -04001956#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001957
1958##
1959
Cary Clark7fc1d122017-10-09 14:07:42 -04001960# ------------------------------------------------------------------------------
1961
Cary Clarkbc5697d2017-10-04 14:31:33 -04001962#Method void growToInclude(const SkPoint pts[], size_t stride, int count)
1963
Cary Clark7fc1d122017-10-09 14:07:42 -04001964For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying
1965it so that:
1966#Formula
1967fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom
1968##
Cary Clark154beea2017-10-26 07:58:48 -04001969.
1970
1971Point may be followed with other data in each array element. stride is number
1972of bytes in element; the interval to skip to advance from one Point to
Cary Clark7fc1d122017-10-09 14:07:42 -04001973the next.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001974
Cary Clark7fc1d122017-10-09 14:07:42 -04001975If Rect is initialized with setLargestInverted, then Rect will contain bounds of
1976Points after one or more calls. In this case, Rect is empty after first call.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001977
Cary Clark7fc1d122017-10-09 14:07:42 -04001978#Param pts array of elements beginning with Point ##
1979#Param stride size of pts elements in 32-bit words; zero or greater ##
1980#Param count number of elements in array ##
1981
1982#Bug 7142 ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001983#Example
Cary Clark154beea2017-10-26 07:58:48 -04001984 SkPoint3 pts[] = { { 30, 50, -1 }, { 40, 50, -1 }, { 30, 60, -1 } };
1985 SkRect rect;
1986 rect.setLargestInverted();
1987 rect.growToInclude((SkPoint* ) &pts[0].fX, sizeof(SkPoint3), SK_ARRAY_COUNT(pts));
1988 SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
Cary Clark7fc1d122017-10-09 14:07:42 -04001989#StdOut
1990#Volatile
1991rect: 30, 50, 40, 60
1992##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001993##
1994
Cary Clark7fc1d122017-10-09 14:07:42 -04001995#SeeAlso setLargestInverted join
Cary Clarkbc5697d2017-10-04 14:31:33 -04001996
1997##
1998
Cary Clark7fc1d122017-10-09 14:07:42 -04001999# ------------------------------------------------------------------------------
2000
Cary Clark884dd7d2017-10-11 10:37:52 -04002001#Method bool contains(const SkRect& r) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04002002
Cary Clark7fc1d122017-10-09 14:07:42 -04002003Returns true if Rect contains r.
2004Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002005
Cary Clark7fc1d122017-10-09 14:07:42 -04002006Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002007
Cary Clark7fc1d122017-10-09 14:07:42 -04002008#Param r Rect contained ##
2009
2010#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002011
2012#Example
Cary Clark154beea2017-10-26 07:58:48 -04002013 SkRect rect = { 30, 50, 40, 60 };
2014 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
2015 for (auto contained : tests) {
2016 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
2017 rect.left(), rect.top(), rect.right(), rect.bottom(),
2018 rect.contains(contained) ? "contains" : "does not contain",
2019 contained.left(), contained.top(), contained.right(), contained.bottom());
2020 }
2021#StdOut
2022rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
2023rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
2024rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
2025##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002026##
2027
Cary Clark7fc1d122017-10-09 14:07:42 -04002028#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04002029
2030##
2031
Cary Clark7fc1d122017-10-09 14:07:42 -04002032# ------------------------------------------------------------------------------
2033
Cary Clarkbc5697d2017-10-04 14:31:33 -04002034#Method bool contains(const SkIRect& r) const
2035
Cary Clark7fc1d122017-10-09 14:07:42 -04002036Returns true if Rect contains r.
2037Returns false if Rect is empty or r is empty.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002038
Cary Clark7fc1d122017-10-09 14:07:42 -04002039Rect contains r when Rect area completely includes r area.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002040
Cary Clark7fc1d122017-10-09 14:07:42 -04002041#Param r IRect contained ##
2042
2043#Return true if all sides of Rect are outside r ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002044
2045#Example
Cary Clark154beea2017-10-26 07:58:48 -04002046 SkRect rect = { 30, 50, 40, 60 };
2047 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
2048 for (auto contained : tests) {
2049 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
2050 rect.left(), rect.top(), rect.right(), rect.bottom(),
2051 rect.contains(contained) ? "contains" : "does not contain",
2052 contained.left(), contained.top(), contained.right(), contained.bottom());
2053 }
2054#StdOut
2055rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
2056rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
2057rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
2058##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002059##
2060
Cary Clark7fc1d122017-10-09 14:07:42 -04002061#SeeAlso SkIRect::contains
Cary Clarkbc5697d2017-10-04 14:31:33 -04002062
2063##
2064
Cary Clark7fc1d122017-10-09 14:07:42 -04002065#Topic Round
2066
2067# ------------------------------------------------------------------------------
2068
Cary Clarkbc5697d2017-10-04 14:31:33 -04002069#Method void round(SkIRect* dst) const
2070
Cary Clark7fc1d122017-10-09 14:07:42 -04002071Sets IRect by adding 0.5 and discarding the fractional portion of Rect
2072members, using
2073#Formula
2074(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2075 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2076##
2077.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002078
Cary Clark7fc1d122017-10-09 14:07:42 -04002079#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002080
2081#Example
Cary Clark154beea2017-10-26 07:58:48 -04002082 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2083 SkIRect round;
2084 rect.round(&round);
2085 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002086#StdOut
2087round: 31, 51, 41, 61
2088##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002089##
2090
Cary Clark7fc1d122017-10-09 14:07:42 -04002091#SeeAlso roundIn roundOut SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002092
2093##
2094
Cary Clark7fc1d122017-10-09 14:07:42 -04002095# ------------------------------------------------------------------------------
2096
Cary Clarkbc5697d2017-10-04 14:31:33 -04002097#Method void roundOut(SkIRect* dst) const
2098
Cary Clark7fc1d122017-10-09 14:07:42 -04002099Sets IRect by discarding the fractional portion of fLeft and fTop; and
2100rounding up fRight and FBottom, using
2101#Formula
2102(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2103 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2104##
2105.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002106
Cary Clark7fc1d122017-10-09 14:07:42 -04002107#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002108
2109#Example
Cary Clark154beea2017-10-26 07:58:48 -04002110 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2111 SkIRect round;
2112 rect.roundOut(&round);
2113 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002114#StdOut
2115round: 30, 50, 41, 61
2116##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002117##
2118
Cary Clark7fc1d122017-10-09 14:07:42 -04002119#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002120
2121##
2122
Cary Clark7fc1d122017-10-09 14:07:42 -04002123# ------------------------------------------------------------------------------
2124
Cary Clarkbc5697d2017-10-04 14:31:33 -04002125#Method void roundOut(SkRect* dst) const
2126
Cary Clark7fc1d122017-10-09 14:07:42 -04002127Sets Rect by discarding the fractional portion of fLeft and fTop; and
2128rounding up fRight and FBottom, using
2129#Formula
2130(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2131 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2132##
2133.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002134
Cary Clark7fc1d122017-10-09 14:07:42 -04002135#Param dst storage for Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002136
2137#Example
Cary Clark154beea2017-10-26 07:58:48 -04002138 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2139 SkRect round;
2140 rect.roundOut(&round);
2141 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002142#StdOut
2143round: 30, 50, 41, 61
2144##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002145##
2146
Cary Clark7fc1d122017-10-09 14:07:42 -04002147#SeeAlso roundIn round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002148
2149##
2150
Cary Clark7fc1d122017-10-09 14:07:42 -04002151# ------------------------------------------------------------------------------
2152
Cary Clarkbc5697d2017-10-04 14:31:33 -04002153#Method void roundIn(SkIRect* dst) const
2154
Cary Clark7fc1d122017-10-09 14:07:42 -04002155Sets Rect by rounding up fLeft and fTop; and
2156discarding the fractional portion of fRight and FBottom, using
Cary Clark154beea2017-10-26 07:58:48 -04002157
Cary Clark7fc1d122017-10-09 14:07:42 -04002158#Formula
2159(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
2160 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom))
2161##
2162.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002163
Cary Clark7fc1d122017-10-09 14:07:42 -04002164#Param dst storage for IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002165
2166#Example
Cary Clark154beea2017-10-26 07:58:48 -04002167 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2168 SkIRect round;
2169 rect.roundIn(&round);
2170 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002171#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002172round: 31, 51, 40, 60
Cary Clark7fc1d122017-10-09 14:07:42 -04002173##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002174##
2175
Cary Clark7fc1d122017-10-09 14:07:42 -04002176#SeeAlso roundOut round SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002177
2178##
2179
Cary Clark7fc1d122017-10-09 14:07:42 -04002180# ------------------------------------------------------------------------------
2181
Cary Clarkbc5697d2017-10-04 14:31:33 -04002182#Method SkIRect round() const
2183
Cary Clark7fc1d122017-10-09 14:07:42 -04002184Returns IRect by adding 0.5 and discarding the fractional portion of Rect
2185members, using
2186#Formula
2187(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
2188 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom))
2189##
2190.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002191
Cary Clark7fc1d122017-10-09 14:07:42 -04002192#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002193
2194#Example
Cary Clark154beea2017-10-26 07:58:48 -04002195 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2196 SkIRect round = rect.round();
2197 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002198#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002199round: 31, 51, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002200##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002201##
2202
Cary Clark7fc1d122017-10-09 14:07:42 -04002203#SeeAlso roundOut roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002204
2205##
2206
Cary Clark7fc1d122017-10-09 14:07:42 -04002207# ------------------------------------------------------------------------------
2208
Cary Clarkbc5697d2017-10-04 14:31:33 -04002209#Method SkIRect roundOut() const
2210
Cary Clark7fc1d122017-10-09 14:07:42 -04002211Sets IRect by discarding the fractional portion of fLeft and fTop; and
2212rounding up fRight and FBottom, using
2213#Formula
2214(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
2215 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom))
2216##
2217.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002218
Cary Clark7fc1d122017-10-09 14:07:42 -04002219#Return rounded IRect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002220
2221#Example
Cary Clark154beea2017-10-26 07:58:48 -04002222 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
2223 SkIRect round = rect.roundOut();
2224 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002225#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002226round: 30, 50, 41, 61
Cary Clark7fc1d122017-10-09 14:07:42 -04002227##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002228##
2229
Cary Clark7fc1d122017-10-09 14:07:42 -04002230#SeeAlso round roundIn SkScalarRoundToInt
Cary Clarkbc5697d2017-10-04 14:31:33 -04002231
2232##
2233
Cary Clark7fc1d122017-10-09 14:07:42 -04002234#Topic Round ##
2235
2236# ------------------------------------------------------------------------------
2237
Cary Clarkbc5697d2017-10-04 14:31:33 -04002238#Method void sort()
2239
Cary Clark7fc1d122017-10-09 14:07:42 -04002240Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
2241fTop and fBottom if fTop is greater than fBottom. Result may be empty;
2242and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002243
2244#Example
Cary Clark154beea2017-10-26 07:58:48 -04002245 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2246 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2247 rect.sort();
2248 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002249#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002250rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002251sorted: 20.5, 10.5, 30.5, 50.5
2252##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002253##
2254
Cary Clark7fc1d122017-10-09 14:07:42 -04002255#SeeAlso makeSorted SkIRect::sort
Cary Clarkbc5697d2017-10-04 14:31:33 -04002256
2257##
2258
Cary Clark7fc1d122017-10-09 14:07:42 -04002259# ------------------------------------------------------------------------------
2260
Cary Clarkbc5697d2017-10-04 14:31:33 -04002261#Method SkRect makeSorted() const
2262
Cary Clark7fc1d122017-10-09 14:07:42 -04002263Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and
2264with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
2265and width() and height() will be zero or positive.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002266
Cary Clark7fc1d122017-10-09 14:07:42 -04002267#Return sorted Rect ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002268
2269#Example
Cary Clark154beea2017-10-26 07:58:48 -04002270 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
2271 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
2272 SkRect sort = rect.makeSorted();
2273 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
Cary Clark7fc1d122017-10-09 14:07:42 -04002274#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002275rect: 30.5, 50.5, 20.5, 10.5
Cary Clark7fc1d122017-10-09 14:07:42 -04002276sorted: 20.5, 10.5, 30.5, 50.5
2277##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002278##
2279
Cary Clark7fc1d122017-10-09 14:07:42 -04002280#SeeAlso sort SkIRect::makeSorted
Cary Clarkbc5697d2017-10-04 14:31:33 -04002281
2282##
2283
Cary Clark7fc1d122017-10-09 14:07:42 -04002284# ------------------------------------------------------------------------------
2285
Cary Clarkbc5697d2017-10-04 14:31:33 -04002286#Method const SkScalar* asScalars() const
2287
Cary Clark7fc1d122017-10-09 14:07:42 -04002288Returns pointer to first Scalar in Rect, to treat it as an array with four
2289entries.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002290
Cary Clark7fc1d122017-10-09 14:07:42 -04002291#Return pointer to fLeft ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002292
2293#Example
Cary Clark154beea2017-10-26 07:58:48 -04002294 SkRect rect = {7, 11, 13, 17};
2295SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
2296#StdOut
2297rect.asScalars() == &rect.fLeft
2298##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002299##
2300
Cary Clark7fc1d122017-10-09 14:07:42 -04002301#SeeAlso toQuad
2302
Cary Clarkbc5697d2017-10-04 14:31:33 -04002303##
2304
Cary Clark7fc1d122017-10-09 14:07:42 -04002305# ------------------------------------------------------------------------------
2306
Cary Clarkbc5697d2017-10-04 14:31:33 -04002307#Method void dump(bool asHex) const
2308
Cary Clark7fc1d122017-10-09 14:07:42 -04002309Writes text representation of Rect to standard output. Set asHex to true to
2310generate exact binary representations of floating point numbers.
2311
2312#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002313
2314#Example
Cary Clark7fc1d122017-10-09 14:07:42 -04002315 SkRect rect = {20, 30, 40, 50};
2316 for (bool dumpAsHex : { false, true } ) {
2317 rect.dump(dumpAsHex);
2318 SkDebugf("\n");
2319 }
2320#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002321SkRect::MakeLTRB(20, 30, 40, 50);
2322
2323SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
2324 SkBits2Float(0x41f00000), /* 30.000000 */
2325 SkBits2Float(0x42200000), /* 40.000000 */
2326 SkBits2Float(0x42480000) /* 50.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002327##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002328##
2329
Cary Clark7fc1d122017-10-09 14:07:42 -04002330#SeeAlso dumpHex
2331
Cary Clarkbc5697d2017-10-04 14:31:33 -04002332##
2333
Cary Clark7fc1d122017-10-09 14:07:42 -04002334# ------------------------------------------------------------------------------
2335
Cary Clarkbc5697d2017-10-04 14:31:33 -04002336#Method void dump() const
2337
Cary Clark7fc1d122017-10-09 14:07:42 -04002338Writes text representation of Rect to standard output. The representation may be
2339directly compiled as C++ code. Floating point values are written
2340with limited precision; it may not be possible to reconstruct original Rect
2341from output.
2342
Cary Clarkbc5697d2017-10-04 14:31:33 -04002343#Example
Cary Clark154beea2017-10-26 07:58:48 -04002344SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2345rect.dump();
2346SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
2347SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
Cary Clark7fc1d122017-10-09 14:07:42 -04002348#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002349SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
Cary Clark7fc1d122017-10-09 14:07:42 -04002350rect is not equal to copy
2351##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002352##
2353
Cary Clark7fc1d122017-10-09 14:07:42 -04002354#SeeAlso dumpHex
2355
Cary Clarkbc5697d2017-10-04 14:31:33 -04002356##
2357
Cary Clark7fc1d122017-10-09 14:07:42 -04002358# ------------------------------------------------------------------------------
2359
Cary Clarkbc5697d2017-10-04 14:31:33 -04002360#Method void dumpHex() const
2361
Cary Clark7fc1d122017-10-09 14:07:42 -04002362Writes text representation of Rect to standard output. The representation may be
2363directly compiled as C++ code. Floating point values are written
2364in hexadecimal to preserve their exact bit pattern. The output reconstructs the
2365original Rect.
2366
2367Use instead of dump() when submitting
2368#A bug reports against Skia # http://bug.skia.org ##
2369.
2370
Cary Clarkbc5697d2017-10-04 14:31:33 -04002371#Example
Cary Clark154beea2017-10-26 07:58:48 -04002372 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
2373rect.dumpHex();
2374SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2375 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2376 SkBits2Float(0x40266666), /* 2.600000 */
2377 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002378SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
2379#StdOut
Cary Clark154beea2017-10-26 07:58:48 -04002380SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
2381 SkBits2Float(0x3f2aaaab), /* 0.666667 */
2382 SkBits2Float(0x40266666), /* 2.600000 */
2383 SkBits2Float(0x40e00000) /* 7.000000 */);
Cary Clark7fc1d122017-10-09 14:07:42 -04002384rect is equal to copy
Cary Clarkbc5697d2017-10-04 14:31:33 -04002385##
Cary Clark7fc1d122017-10-09 14:07:42 -04002386##
2387
2388#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04002389
2390##
2391
2392#Struct SkRect ##
2393
2394#Topic Rect ##