Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1 | #Topic Rect |
| 2 | #Alias Rects |
| 3 | #Alias Rect_Reference |
| 4 | |
| 5 | #Struct SkRect |
| 6 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 7 | SkRect holds four SkScalar coordinates describing the upper and |
| 8 | lower bounds of a rectangle. SkRect may be created from outer bounds or |
| 9 | from position, width, and height. SkRect describes an area; if its right |
| 10 | is less than or equal to its left, or if its bottom is less than or equal to |
| 11 | its top, it is considered empty. |
| 12 | |
| 13 | # move to topic about MakeIWH and friends |
| 14 | SkRect can be constructed from int values to avoid compiler warnings that |
| 15 | integer input cannot convert to SkScalar without loss of precision. |
| 16 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 17 | #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 Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 31 | # description # function ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 32 | #Legend ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 33 | # 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 35 | #Table ## |
| 36 | #Subtopic ## |
| 37 | |
| 38 | #Subtopic Member_Functions |
| 39 | #Table |
| 40 | #Legend |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 41 | # description # function ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 42 | #Legend ## |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 43 | # 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 Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 50 | # MakeLargestS32 # Constructs largest signed integers that fit in 32-bit float. ## |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 51 | # 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 102 | #Table ## |
| 103 | #Subtopic ## |
| 104 | |
| 105 | #Topic ## |
| 106 | |
| 107 | #Member SkScalar fLeft |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 108 | May contain any value, including infinities and NaN. The smaller of the |
| 109 | horizontal values when sorted. When equal to or greater than fRight, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 110 | ## |
| 111 | |
| 112 | #Member SkScalar fTop |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 113 | May contain any value, including infinities and NaN. The smaller of the |
| 114 | vertical values when sorted. When equal to or greater than fBottom, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 115 | ## |
| 116 | |
| 117 | #Member SkScalar fRight |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 118 | May contain any value, including infinities and NaN. The larger of the |
| 119 | horizontal values when sorted. When equal to or less than fLeft, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 120 | ## |
| 121 | |
| 122 | #Member SkScalar fBottom |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 123 | May contain any value, including infinities and NaN. The larger of the |
| 124 | vertical values when sorted. When equal to or less than fTop, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 125 | ## |
| 126 | |
| 127 | # ------------------------------------------------------------------------------ |
| 128 | |
| 129 | #Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty() |
| 130 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 131 | Returns constructed Rect set to (0, 0, 0, 0). |
| 132 | Many other rectangles are empty; if left is equal to or greater than right, |
| 133 | or if top is equal to or greater than bottom. Setting all members to zero |
| 134 | is a convenience, but does not designate a special empty rectangle. |
| 135 | |
| 136 | #Return bounds (0, 0, 0, 0) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 137 | |
| 138 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 139 | 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
|
| 148 | MakeEmpty isEmpty: true
|
| 149 | offset rect isEmpty: true
|
| 150 | inset rect isEmpty: true
|
| 151 | outset rect isEmpty: false
|
| 152 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 153 | ## |
| 154 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 155 | #SeeAlso isEmpty setEmpty setLargestInverted SkIRect::MakeEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 156 | |
| 157 | ## |
| 158 | |
| 159 | # ------------------------------------------------------------------------------ |
| 160 | |
| 161 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest() |
| 162 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 163 | Returns constructed Rect setting left and top to most negative finite value, and |
| 164 | setting right and bottom to most positive finite value. |
| 165 | |
| 166 | #Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 167 | |
| 168 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 169 | 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
|
| 179 | MakeLargest isLargest: true
|
| 180 | MakeLargest isFinite: true
|
| 181 | outset a little isLargest: true
|
| 182 | outset a little isFinite: true
|
| 183 | outset a little more isLargest: false
|
| 184 | outset a little more isFinite: false
|
| 185 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 186 | ## |
| 187 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 188 | #SeeAlso MakeLargestS32 isLargest setLargest SkIRect::MakeLargest |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 189 | |
| 190 | ## |
| 191 | |
| 192 | # ------------------------------------------------------------------------------ |
| 193 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 194 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeLargestS32() |
| 195 | |
| 196 | Returns constructed Rect that can be represented exactly with IRect. The left |
| 197 | and top are set to the most negative integer value that fits in a 32-bit float, |
| 198 | and the right and bottom are set to the most positive finite value that fits in |
| 199 | a 32-bit float. |
| 200 | |
| 201 | These 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 |
| 208 | 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
|
| 213 | f_rect == r_rect
|
| 214 | ##
|
| 215 | ## |
| 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 224 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 225 | Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not |
| 226 | validate input; w or h may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 227 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 228 | Passing integer values may generate a compiler warning since Rect cannot |
| 229 | represent 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 235 | |
| 236 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 237 | 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 ?
|
| 242 | "" : "not "); |
| 243 | #StdOut |
| 244 | all equal |
| 245 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 246 | ## |
| 247 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 248 | #SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 249 | |
| 250 | ## |
| 251 | |
| 252 | # ------------------------------------------------------------------------------ |
| 253 | |
| 254 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) |
| 255 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 256 | Returns constructed Rect set to integer values (0, 0, w, h). Does not validate |
| 257 | input; w or h may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 258 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 259 | Use to avoid a compiler warning that input may lose precision when stored. |
| 260 | Use 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 266 | |
| 267 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 268 | 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());
|
| 274 | #StdOut |
| 275 | i_rect width: 25 f_rect width:25
|
| 276 | i_rect width: 125000111 f_rect width:125000112 |
| 277 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 278 | ## |
| 279 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 280 | #SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 281 | |
| 282 | ## |
| 283 | |
| 284 | # ------------------------------------------------------------------------------ |
| 285 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 286 | #Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 287 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 288 | Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not |
| 289 | validate input; size.width() or size.height() may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 290 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 291 | #Param size SkScalar values for Rect width and height ## |
| 292 | |
| 293 | #Return bounds (0, 0, size.width(), size.height()) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 294 | |
| 295 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 296 | 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());
|
| 302 | #StdOut |
| 303 | rect width: 25.5 height: 35.5
|
| 304 | floor width: 25 height: 35 |
| 305 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 306 | ## |
| 307 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 308 | #SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 309 | |
| 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 Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 317 | Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may |
| 318 | result in fLeft greater than fRight, or fTop greater than fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 319 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 320 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 326 | |
| 327 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 328 | 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");
|
| 334 | #StdOut |
| 335 | rect: 5, 35, 15, 25 isEmpty: true
|
| 336 | rect: 5, 25, 15, 35 isEmpty: false |
| 337 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 338 | ## |
| 339 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 340 | #SeeAlso MakeXYWH SkIRect::MakeLTRB |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 341 | |
| 342 | ## |
| 343 | |
| 344 | # ------------------------------------------------------------------------------ |
| 345 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 346 | #Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 347 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 348 | Returns constructed Rect set to |
| 349 | #Formula |
| 350 | (x, y, x + w, y + h) |
| 351 | ## |
| 352 | . Does not validate input; |
| 353 | w or h may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 354 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 355 | #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 Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 360 | #Return bounds at (x, y) with width w and height h ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 361 | |
| 362 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 363 | 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");
|
| 369 | #StdOut |
| 370 | rect: 5, 35, -10, 60 isEmpty: true
|
| 371 | rect: -10, 35, 5, 60 isEmpty: false |
| 372 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 373 | ## |
| 374 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 375 | #SeeAlso MakeLTRB SkIRect::MakeXYWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 376 | |
| 377 | ## |
| 378 | |
| 379 | # ------------------------------------------------------------------------------ |
| 380 | |
| 381 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect) |
| 382 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 383 | Deprecated. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 384 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 385 | #Deprecated |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 386 | ## |
| 387 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 388 | #Param irect integer rect ## |
| 389 | |
| 390 | #Return irect as SkRect ## |
| 391 | |
| 392 | #NoExample |
| 393 | ## |
| 394 | |
| 395 | #SeeAlso Make |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 396 | |
| 397 | ## |
| 398 | |
| 399 | # ------------------------------------------------------------------------------ |
| 400 | |
| 401 | #Method static SkRect Make(const SkISize& size) |
| 402 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 403 | Returns constructed IRect set to (0, 0, size.width(), size.height()). |
| 404 | Does not validate input; size.width() or size.height() may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 405 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 406 | #Param size integer values for Rect width and height ## |
| 407 | |
| 408 | #Return bounds (0, 0, size.width(), size.height()) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 409 | |
| 410 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 411 | SkRect rect1 = SkRect::MakeSize({2, 35});
|
| 412 | SkRect rect2 = SkRect::MakeIWH(2, 35);
|
| 413 | SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
|
| 414 | #StdOut |
| 415 | rect1 == rect2 |
| 416 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 417 | ## |
| 418 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 419 | #SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 420 | |
| 421 | ## |
| 422 | |
| 423 | # ------------------------------------------------------------------------------ |
| 424 | |
| 425 | #Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) |
| 426 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 427 | Returns constructed IRect set to irect, promoting integers to Scalar. |
| 428 | Does not validate input; fLeft may be greater than fRight, fTop may be greater |
| 429 | than fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 430 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 431 | #Param irect integer unsorted bounds ## |
| 432 | |
| 433 | #Return irect members converted to SkScalar ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 434 | |
| 435 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 436 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 442 | ## |
| 443 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 444 | #SeeAlso MakeLTRB |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 445 | |
| 446 | ## |
| 447 | |
| 448 | # ------------------------------------------------------------------------------ |
| 449 | |
| 450 | #Method bool isEmpty() const |
| 451 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 452 | Returns true if fLeft is equal to or greater than fRight, or if fTop is equal |
| 453 | to or greater than fBottom. Call sort() to reverse rectangles with negative |
| 454 | width() or height(). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 455 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 456 | #Return true if width() or height() are zero or negative ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 457 | |
| 458 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 459 | 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
|
| 468 | rect: {20, 40, 10, 50} is empty
|
| 469 | sorted: {10, 40, 20, 50} is not empty
|
| 470 | rect: {20, 40, 20, 50} is empty
|
| 471 | sorted: {20, 40, 20, 50} is empty
|
| 472 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 473 | ## |
| 474 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 475 | #SeeAlso MakeEmpty sort SkIRect::isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 476 | |
| 477 | ## |
| 478 | |
| 479 | # ------------------------------------------------------------------------------ |
| 480 | |
| 481 | #Method bool isSorted() const |
| 482 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 483 | Returns true if fLeft is equal to or less than fRight, or if fTop is equal |
| 484 | to or less than fBottom. Call sort() to reverse rectangles with negative |
| 485 | width() or height(). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 486 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 487 | #Return true if width() or height() are zero or positive ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 488 | |
| 489 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 490 | 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
|
| 499 | rect: {20, 40, 10, 50} is not sorted
|
| 500 | sorted: {10, 40, 20, 50} is sorted
|
| 501 | rect: {20, 40, 20, 50} is sorted
|
| 502 | sorted: {20, 40, 20, 50} is sorted
|
| 503 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 504 | ## |
| 505 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 506 | #SeeAlso sort makeSorted isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 507 | |
| 508 | ## |
| 509 | |
| 510 | # ------------------------------------------------------------------------------ |
| 511 | |
| 512 | #Method bool isLargest() const |
| 513 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 514 | Returns true if Rect encloses largest possible area. |
| 515 | |
| 516 | #Return true if equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 517 | |
| 518 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 519 | #Description |
| 520 | Note that the width cannot be represented as a 32-bit finite value. |
| 521 | ## |
| 522 | 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");
|
| 526 | SkDebugf("large is sorted: %s\n", large.isSorted() ? "true" : "false"); |
| 527 | SkDebugf("large is finite: %s\n", large.isFinite() ? "true" : "false");
|
| 528 | #StdOut
|
| 529 | large is largest: true
|
| 530 | large width inf
|
| 531 | large is empty: false
|
| 532 | large is sorted: true |
| 533 | large is finite: true |
| 534 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 535 | ## |
| 536 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 537 | #SeeAlso MakeLargest SkIRect::isLargest |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 538 | |
| 539 | ## |
| 540 | |
| 541 | # ------------------------------------------------------------------------------ |
| 542 | |
| 543 | #Method bool isFinite() const |
| 544 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 545 | Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, |
| 546 | and SK_ScalarMax or smaller. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 547 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 548 | #Return true if no member is infinite or NaN ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 549 | |
| 550 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 551 | 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
|
| 557 | largest is finite: true
|
| 558 | large width inf
|
| 559 | widest is finite: false |
| 560 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 561 | ## |
| 562 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 563 | #SeeAlso SkScalarIsFinite SkScalarIsNaN |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 564 | |
| 565 | ## |
| 566 | |
| 567 | # ------------------------------------------------------------------------------ |
| 568 | |
| 569 | #Method SkScalar x() const |
| 570 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 571 | Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. |
| 572 | Call sort() to reverse fLeft and fRight if needed. |
| 573 | |
| 574 | #Return fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 575 | |
| 576 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 577 | 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());
|
| 581 | #StdOut |
| 582 | unsorted.fLeft: 15 unsorted.x(): 15
|
| 583 | sorted.fLeft: 10 sorted.x(): 10 |
| 584 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 585 | ## |
| 586 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 587 | #SeeAlso fLeft left() y() SkIRect::x() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 588 | |
| 589 | ## |
| 590 | |
| 591 | # ------------------------------------------------------------------------------ |
| 592 | |
| 593 | #Method SkScalar y() const |
| 594 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 595 | Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, |
| 596 | and sort() to reverse fTop and fBottom if needed. |
| 597 | |
| 598 | #Return fTop ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 599 | |
| 600 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 601 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 602 | SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
|
| 603 | SkRect sorted = unsorted.makeSorted();
|
| 604 | SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y()); |
| 605 | #StdOut |
| 606 | unsorted.fTop: 25 unsorted.y(): 25
|
| 607 | sorted.fTop: 5 sorted.y(): 5 |
| 608 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 609 | ## |
| 610 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 611 | #SeeAlso fTop top() x() SkIRect::y() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 612 | |
| 613 | ## |
| 614 | |
| 615 | # ------------------------------------------------------------------------------ |
| 616 | |
| 617 | #Method SkScalar left() const |
| 618 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 619 | Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. |
| 620 | Call sort() to reverse fLeft and fRight if needed. |
| 621 | |
| 622 | #Return fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 623 | |
| 624 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 625 | 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());
|
| 629 | #StdOut |
| 630 | unsorted.fLeft: 15 unsorted.left(): 15
|
| 631 | sorted.fLeft: 10 sorted.left(): 10 |
| 632 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 633 | ## |
| 634 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 635 | #SeeAlso fLeft x() SkIRect::left() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 636 | |
| 637 | ## |
| 638 | |
| 639 | # ------------------------------------------------------------------------------ |
| 640 | |
| 641 | #Method SkScalar top() const |
| 642 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 643 | Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, |
| 644 | and sort() to reverse fTop and fBottom if needed. |
| 645 | |
| 646 | #Return fTop ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 647 | |
| 648 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 649 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 650 | SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
|
| 651 | SkRect sorted = unsorted.makeSorted();
|
| 652 | SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top()); |
| 653 | #StdOut |
| 654 | unsorted.fTop: 25 unsorted.top(): 25
|
| 655 | sorted.fTop: 5 sorted.top(): 5 |
| 656 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 657 | ## |
| 658 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 659 | #SeeAlso fTop y() SkIRect::top() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 660 | |
| 661 | ## |
| 662 | |
| 663 | # ------------------------------------------------------------------------------ |
| 664 | |
| 665 | #Method SkScalar right() const |
| 666 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 667 | Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid. |
| 668 | Call sort() to reverse fLeft and fRight if needed. |
| 669 | |
| 670 | #Return fRight ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 671 | |
| 672 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 673 | 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());
|
| 677 | #StdOut |
| 678 | unsorted.fRight: 10 unsorted.right(): 10
|
| 679 | sorted.fRight: 15 sorted.right(): 15 |
| 680 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 681 | ## |
| 682 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 683 | #SeeAlso fRight SkIRect::right() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 684 | |
| 685 | ## |
| 686 | |
| 687 | # ------------------------------------------------------------------------------ |
| 688 | |
| 689 | #Method SkScalar bottom() const |
| 690 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 691 | Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, |
| 692 | and sort() to reverse fTop and fBottom if needed. |
| 693 | |
| 694 | #Return fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 695 | |
| 696 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 697 | 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());
|
| 701 | #StdOut |
| 702 | unsorted.fBottom: 5 unsorted.bottom(): 5
|
| 703 | sorted.fBottom: 25 sorted.bottom(): 25 |
| 704 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 705 | ## |
| 706 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 707 | #SeeAlso fBottom SkIRect::bottom() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 708 | |
| 709 | ## |
| 710 | |
| 711 | # ------------------------------------------------------------------------------ |
| 712 | |
| 713 | #Method SkScalar width() const |
| 714 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 715 | Returns span on the x-axis. This does not check if Rect is sorted, or if |
| 716 | result fits in 32-bit float; result may be negative or infinity. |
| 717 | |
| 718 | #Return fRight minus fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 719 | |
| 720 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 721 | #Description |
| 722 | Compare with SkIRect::width() example. |
| 723 | ## |
| 724 | 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());
|
| 728 | #StdOut |
| 729 | unsorted width: -5
|
| 730 | large width: 4294967296 |
| 731 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 732 | ## |
| 733 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 734 | #SeeAlso height() SkIRect::width() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 735 | |
| 736 | ## |
| 737 | |
| 738 | # ------------------------------------------------------------------------------ |
| 739 | |
| 740 | #Method SkScalar height() const |
| 741 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 742 | Returns span on the y-axis. This does not check if IRect is sorted, or if |
| 743 | result fits in 32-bit float; result may be negative or infinity. |
| 744 | |
| 745 | #Return fBottom minus fTop ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 746 | |
| 747 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 748 | #Description |
| 749 | Compare with SkIRect::height() example. |
| 750 | ## |
| 751 | 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());
|
| 755 | #StdOut |
| 756 | unsorted height: -5
|
| 757 | large height: 4294967296 |
| 758 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 759 | ## |
| 760 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 761 | #SeeAlso width() SkIRect::height() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 762 | |
| 763 | ## |
| 764 | |
| 765 | # ------------------------------------------------------------------------------ |
| 766 | |
| 767 | #Method SkScalar centerX() const |
| 768 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 769 | Returns average of left edge and right edge. Result does not change if Rect |
| 770 | is sorted. Result may overflow to infinity if Rect is far from the origin. |
| 771 | |
| 772 | #Return midpoint in x ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 773 | |
| 774 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 775 | 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 | }
|
| 781 | #StdOut |
| 782 | left: 20 right: 41 centerX: 30.5
|
| 783 | left: 20 right: 41 centerX: 30.5
|
| 784 | left: -20 right: -41 centerX: -30.5
|
| 785 | left: -41 right: -20 centerX: -30.5 |
| 786 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 787 | ## |
| 788 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 789 | #SeeAlso centerY SkIRect::centerX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 790 | |
| 791 | ## |
| 792 | |
| 793 | # ------------------------------------------------------------------------------ |
| 794 | |
| 795 | #Method SkScalar centerY() const |
| 796 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 797 | Returns average of top edge and bottom edge. Result does not change if Rect |
| 798 | is sorted. Result may overflow to infinity if Rect is far from the origin. |
| 799 | |
| 800 | #Return midpoint in y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 801 | |
| 802 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 803 | 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);
|
| 806 | #StdOut |
| 807 | left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38 |
| 808 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 809 | ## |
| 810 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 811 | #SeeAlso centerX SkIRect::centerY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 812 | |
| 813 | ## |
| 814 | |
| 815 | # ------------------------------------------------------------------------------ |
| 816 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 817 | #Method bool operator==(const SkRect& a, const SkRect& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 818 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 819 | Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are |
| 820 | equal to the corresponding members in b. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 821 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 822 | a and b are not equal if either contain NaN. a and b are equal if members |
| 823 | contain 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 829 | |
| 830 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 831 | 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);
|
| 845 | } |
| 846 | #StdOut
|
| 847 | tests 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
|
| 850 | {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal |
| 851 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 852 | ## |
| 853 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 854 | #SeeAlso operator!=(const SkRect& a, const SkRect& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 855 | |
| 856 | ## |
| 857 | |
| 858 | # ------------------------------------------------------------------------------ |
| 859 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 860 | #Method bool operator!=(const SkRect& a, const SkRect& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 861 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 862 | Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not |
| 863 | equal the corresponding members in b. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 864 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 865 | a and b are not equal if either contain NaN. a and b are equal if members |
| 866 | contain 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 872 | |
| 873 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 874 | SkRect test = {0, 0, 2, SK_ScalarNaN};
|
| 875 | SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
|
| 876 | #StdOut
|
| 877 | test with NaN is not equal to itself |
| 878 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 879 | ## |
| 880 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 881 | #SeeAlso operator==(const SkRect& a, const SkRect& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 882 | |
| 883 | ## |
| 884 | |
| 885 | # ------------------------------------------------------------------------------ |
| 886 | |
| 887 | #Method void toQuad(SkPoint quad[4]) const |
| 888 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 889 | Returns four points in quad that enclose Rect ordered as: top-left, top-right, |
| 890 | bottom-right, bottom-left. |
| 891 | |
| 892 | #Private |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 893 | Consider adding param to control whether quad is CW or CCW. |
| 894 | ## |
| 895 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 896 | #Param quad storage for corners of Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 897 | |
| 898 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 899 | 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
|
| 909 | rect: {1, 2, 3, 4}
|
| 910 | corners: {1, 2} {3, 2} {3, 4} {1, 4} |
| 911 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 912 | ## |
| 913 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 914 | #SeeAlso SkPath::addRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 915 | |
| 916 | ## |
| 917 | |
| 918 | # ------------------------------------------------------------------------------ |
| 919 | |
| 920 | #Method void setEmpty() |
| 921 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 922 | Sets Rect to (0, 0, 0, 0). |
| 923 | |
| 924 | Many other rectangles are empty; if left is equal to or greater than right, |
| 925 | or if top is equal to or greater than bottom. Setting all members to zero |
| 926 | is a convenience, but does not designate a special empty rectangle. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 927 | |
| 928 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 929 | 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
|
| 936 | rect: {3, 4, 1, 2} is empty
|
| 937 | rect: {0, 0, 0, 0} is empty
|
| 938 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 939 | ## |
| 940 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 941 | #SeeAlso MakeEmpty SkIRect::setEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 942 | |
| 943 | ## |
| 944 | |
| 945 | # ------------------------------------------------------------------------------ |
| 946 | |
| 947 | #Method void set(const SkIRect& src) |
| 948 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 949 | Sets Rect to src, promoting src members from integer to Scalar. |
| 950 | Very large values in src may lose precision. |
| 951 | |
| 952 | #Param src integer Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 953 | |
| 954 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 955 | 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
|
| 961 | i_rect: {3, 4, 1, 2}
|
| 962 | f_rect: {3, 4, 1, 2}
|
| 963 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 964 | ## |
| 965 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 966 | #SeeAlso setLTRB SkIntToScalar |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 967 | |
| 968 | ## |
| 969 | |
| 970 | # ------------------------------------------------------------------------------ |
| 971 | |
| 972 | #Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 973 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 974 | Sets Rect to (left, top, right, bottom). |
| 975 | left and right are not sorted; left is not necessarily less than right. |
| 976 | top 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 982 | |
| 983 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 984 | 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
|
| 990 | rect1: {3, 4, 1, 2}
|
| 991 | rect2: {3, 4, 1, 2}
|
| 992 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 993 | ## |
| 994 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 995 | #SeeAlso setLTRB setXYWH SkIRect::set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 996 | |
| 997 | ## |
| 998 | |
| 999 | # ------------------------------------------------------------------------------ |
| 1000 | |
| 1001 | #Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 1002 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1003 | Sets Rect to (left, top, right, bottom). |
| 1004 | left and right are not sorted; left is not necessarily less than right. |
| 1005 | top and bottom are not sorted; top is not necessarily less than bottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1006 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1007 | #Param left stored in fLeft ## |
| 1008 | #Param top stored in fTop ## |
| 1009 | #Param right stored in fRight ## |
| 1010 | #Param bottom stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1011 | |
| 1012 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1013 | 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
|
| 1019 | rect1: {3, 4, 1, 2}
|
| 1020 | rect2: {3, 4, 1, 2}
|
| 1021 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1022 | ## |
| 1023 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1024 | #SeeAlso set setXYWH SkIRect::set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1025 | |
| 1026 | ## |
| 1027 | |
| 1028 | # ------------------------------------------------------------------------------ |
| 1029 | |
| 1030 | #Method void iset(int left, int top, int right, int bottom) |
| 1031 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1032 | Sets Rect to (left, top, right, bottom). |
| 1033 | All parameters are promoted from integer to Scalar. |
| 1034 | left and right are not sorted; left is not necessarily less than right. |
| 1035 | top and bottom are not sorted; top is not necessarily less than bottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1036 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1037 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1041 | |
| 1042 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1043 | 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
|
| 1049 | rect1: {3, 4, 1, 2}
|
| 1050 | rect2: {3, 4, 1, 2}
|
| 1051 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1052 | ## |
| 1053 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1054 | #SeeAlso set setLTRB SkIRect::set SkIntToScalar |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1055 | |
| 1056 | ## |
| 1057 | |
| 1058 | # ------------------------------------------------------------------------------ |
| 1059 | |
| 1060 | #Method void isetWH(int width, int height) |
| 1061 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1062 | Sets Rect to (0, 0, width, height). |
| 1063 | width and height may be zero or negative. width and height are promoted from |
| 1064 | integer to SkScalar, large values may lose precision. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1065 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1066 | #Param width promoted to SkScalar and stored in fRight ## |
| 1067 | #Param height promoted to SkScalar and stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1068 | |
| 1069 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1070 | 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);
|
| 1074 | SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); |
| 1075 | #StdOut
|
| 1076 | rect1: {0, 0, 1, 2}
|
| 1077 | rect2: {0, 0, 1, 2}
|
| 1078 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1079 | ## |
| 1080 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1081 | #SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1082 | |
| 1083 | ## |
| 1084 | |
| 1085 | # ------------------------------------------------------------------------------ |
| 1086 | |
| 1087 | #Method void set(const SkPoint pts[], int count) |
| 1088 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1089 | Sets to bounds of Point array with count entries. If count is zero or smaller, |
| 1090 | or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1091 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1092 | Result is either empty or sorted: fLeft is less than or equal to fRight, and |
| 1093 | fTop is less than or equal to fBottom. |
| 1094 | |
| 1095 | #Param pts Point array ## |
| 1096 | #Param count entries in array ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1097 | |
| 1098 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1099 | 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
|
| 1113 | added: 3, 4 count: 1 rect: 3, 4, 3, 4
|
| 1114 | added: 1, 2 count: 2 rect: 1, 2, 3, 4
|
| 1115 | added: 5, 6 count: 3 rect: 1, 2, 5, 6
|
| 1116 | added: nan, 8 count: 4 rect: 0, 0, 0, 0
|
| 1117 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1118 | ## |
| 1119 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1120 | #SeeAlso setBounds setBoundsCheck SkPath::addPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1121 | |
| 1122 | ## |
| 1123 | |
| 1124 | # ------------------------------------------------------------------------------ |
| 1125 | |
| 1126 | #Method void setBounds(const SkPoint pts[], int count) |
| 1127 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1128 | Sets to bounds of Point array with count entries. If count is zero or smaller, |
| 1129 | or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1130 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1131 | Result is either empty or sorted: fLeft is less than or equal to fRight, and |
| 1132 | fTop is less than or equal to fBottom. |
| 1133 | |
| 1134 | #Param pts Point array ## |
| 1135 | #Param count entries in array ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1136 | |
| 1137 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1138 | 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
|
| 1152 | added: 3, 4 count: 1 rect: 3, 4, 3, 4
|
| 1153 | added: 1, 2 count: 2 rect: 1, 2, 3, 4
|
| 1154 | added: 5, 6 count: 3 rect: 1, 2, 5, 6
|
| 1155 | added: nan, 8 count: 4 rect: 0, 0, 0, 0
|
| 1156 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1157 | ## |
| 1158 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1159 | #SeeAlso set setBoundsCheck SkPath::addPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1160 | |
| 1161 | ## |
| 1162 | |
| 1163 | # ------------------------------------------------------------------------------ |
| 1164 | |
| 1165 | #Method bool setBoundsCheck(const SkPoint pts[], int count) |
| 1166 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1167 | Sets to bounds of Point array with count entries. Returns false if count is |
| 1168 | zero or smaller, or if Point array contains an infinity or NaN; in these cases |
| 1169 | sets Rect to (0, 0, 0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1170 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1171 | Result is either empty or sorted: fLeft is less than or equal to fRight, and |
| 1172 | fTop is less than or equal to fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1173 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1174 | #Param pts Point array ## |
| 1175 | #Param count entries in array ## |
| 1176 | |
| 1177 | #Return true if all Point values are finite ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1178 | |
| 1179 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1180 | 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
|
| 1194 | added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
|
| 1195 | added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
|
| 1196 | added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
|
| 1197 | added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
|
| 1198 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1199 | ## |
| 1200 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1201 | #SeeAlso set setBounds SkPath::addPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1202 | |
| 1203 | ## |
| 1204 | |
| 1205 | # ------------------------------------------------------------------------------ |
| 1206 | |
| 1207 | #Method void set(const SkPoint& p0, const SkPoint& p1) |
| 1208 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1209 | Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is |
| 1210 | sorted 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1214 | |
| 1215 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1216 | #Description |
| 1217 | p0 and p1 may be swapped and have the same effect unless one contains NaN. |
| 1218 | ## |
| 1219 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1226 | ## |
| 1227 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1228 | #SeeAlso setBounds setBoundsCheck |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1229 | |
| 1230 | ## |
| 1231 | |
| 1232 | # ------------------------------------------------------------------------------ |
| 1233 | |
| 1234 | #Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) |
| 1235 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1236 | Sets Rect to |
| 1237 | #Formula |
| 1238 | (x, y, x + width, y + height) |
| 1239 | ## |
| 1240 | . Does not validate input; |
| 1241 | width 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1247 | |
| 1248 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1249 | 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");
|
| 1256 | #StdOut |
| 1257 | rect: 5, 35, -10, 60 isEmpty: true
|
| 1258 | rect: -10, 35, 5, 60 isEmpty: false |
| 1259 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1260 | ## |
| 1261 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1262 | #SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1263 | |
| 1264 | ## |
| 1265 | |
| 1266 | # ------------------------------------------------------------------------------ |
| 1267 | |
| 1268 | #Method void setWH(SkScalar width, SkScalar height) |
| 1269 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1270 | Sets Rect to (0, 0, width, height). Does not validate input; |
| 1271 | width or height may be negative. |
| 1272 | |
| 1273 | #Param width stored in fRight ## |
| 1274 | #Param height stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1275 | |
| 1276 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1277 | 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");
|
| 1284 | #StdOut |
| 1285 | rect: 0, 0, -15, 25 isEmpty: true
|
| 1286 | rect: -15, 0, 0, 25 isEmpty: false |
| 1287 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1288 | ## |
| 1289 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1290 | #SeeAlso MakeWH setXYWH isetWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1291 | |
| 1292 | ## |
| 1293 | |
| 1294 | # ------------------------------------------------------------------------------ |
| 1295 | |
| 1296 | #Method void setLargest() |
| 1297 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1298 | Sets rectangle left and top to most negative finite value, and sets |
| 1299 | right and bottom to most positive finite value. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1300 | |
| 1301 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1302 | 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
|
| 1313 | MakeLargest isLargest: true
|
| 1314 | MakeLargest isFinite: true
|
| 1315 | outset a little isLargest: true
|
| 1316 | outset a little isFinite: true
|
| 1317 | outset a little more isLargest: false
|
| 1318 | outset a little more isFinite: false
|
| 1319 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1320 | ## |
| 1321 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1322 | #SeeAlso MakeLargest isLargest setLargestInverted SK_ScalarMin SK_ScalarMax |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1323 | |
| 1324 | ## |
| 1325 | |
| 1326 | # ------------------------------------------------------------------------------ |
| 1327 | |
| 1328 | #Method void setLargestInverted() |
| 1329 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1330 | Sets rectangle left and top to most positive finite value, and sets |
| 1331 | right and bottom to most negative finite value. |
| 1332 | |
| 1333 | Use to initial Rect before one or more calls to growToInclude. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1334 | |
| 1335 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1336 | 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 } );
|
| 1345 | debugster("grown", ptBounds); |
| 1346 | #StdOut
|
| 1347 | original rect: 3.40282e+38, 3.40282e+38, -3.40282e+38, -3.40282e+38 isEmpty: true
|
| 1348 | grown rect: 42, 24, 42, 24 isEmpty: true
|
| 1349 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1350 | ## |
| 1351 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1352 | #SeeAlso growToInclude setEmpty setLargest |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1353 | |
| 1354 | ## |
| 1355 | |
| 1356 | # ------------------------------------------------------------------------------ |
| 1357 | |
| 1358 | #Method SkRect makeOffset(SkScalar dx, SkScalar dy) const |
| 1359 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1360 | Returns Rect offset by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1361 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1362 | If dx is negative, Rect returned is moved to the left. |
| 1363 | If dx is positive, Rect returned is moved to the right. |
| 1364 | If dy is negative, Rect returned is moved upward. |
| 1365 | If dy is positive, Rect returned is moved downward. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1366 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1367 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1371 | |
| 1372 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1373 | 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
|
| 1380 | rect: 10, 50, 20, 60 isEmpty: false
|
| 1381 | rect: 25, 82, 35, 92 isEmpty: false
|
| 1382 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1383 | ## |
| 1384 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1385 | #SeeAlso offset() makeInset makeOutset SkIRect::makeOffset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1386 | |
| 1387 | ## |
| 1388 | |
| 1389 | # ------------------------------------------------------------------------------ |
| 1390 | |
| 1391 | #Method SkRect makeInset(SkScalar dx, SkScalar dy) const |
| 1392 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1393 | Returns Rect, inset by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1394 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1395 | If dx is negative, Rect returned is wider. |
| 1396 | If dx is positive, Rect returned is narrower. |
| 1397 | If dy is negative, Rect returned is taller. |
| 1398 | If dy is positive, Rect returned is shorter. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1399 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1400 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1404 | |
| 1405 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1406 | 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
|
| 1413 | rect: 10, 50, 20, 60 isEmpty: false
|
| 1414 | rect: 25, 82, 5, 28 isEmpty: true
|
| 1415 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1416 | ## |
| 1417 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1418 | #SeeAlso inset() makeOffset makeOutset SkIRect::makeInset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1419 | |
| 1420 | ## |
| 1421 | |
| 1422 | # ------------------------------------------------------------------------------ |
| 1423 | |
| 1424 | #Method SkRect makeOutset(SkScalar dx, SkScalar dy) const |
| 1425 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1426 | Returns Rect, outset by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1427 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1428 | If dx is negative, Rect returned is narrower. |
| 1429 | If dx is positive, Rect returned is wider. |
| 1430 | If dy is negative, Rect returned is shorter. |
| 1431 | If dy is positive, Rect returned is taller. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1432 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1433 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1437 | |
| 1438 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1439 | 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
|
| 1446 | rect: 10, 50, 20, 60 isEmpty: false
|
| 1447 | rect: -5, 18, 35, 92 isEmpty: false
|
| 1448 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1449 | ## |
| 1450 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1451 | #SeeAlso outset() makeOffset makeInset SkIRect::makeOutset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1452 | |
| 1453 | ## |
| 1454 | |
| 1455 | # ------------------------------------------------------------------------------ |
| 1456 | |
| 1457 | #Method void offset(SkScalar dx, SkScalar dy) |
| 1458 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1459 | Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1460 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1461 | If dx is negative, moves Rect to the left. |
| 1462 | If dx is positive, moves Rect to the right. |
| 1463 | If dy is negative, moves Rect upward. |
| 1464 | If 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1468 | |
| 1469 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1470 | 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
|
| 1474 | rect: 15, 27, 55, 86
|
| 1475 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1476 | ## |
| 1477 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1478 | #SeeAlso offsetTo makeOffset SkIRect::offset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1479 | |
| 1480 | ## |
| 1481 | |
| 1482 | # ------------------------------------------------------------------------------ |
| 1483 | |
| 1484 | #Method void offset(const SkPoint& delta) |
| 1485 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1486 | Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to |
| 1487 | fTop, fBottom. |
| 1488 | |
| 1489 | If delta.fX is negative, moves Rect to the left. |
| 1490 | If delta.fX is positive, moves Rect to the right. |
| 1491 | If delta.fY is negative, moves Rect upward. |
| 1492 | If delta.fY is positive, moves Rect downward. |
| 1493 | |
| 1494 | #Param delta added to Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1495 | |
| 1496 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1497 | 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
|
| 1501 | rect: 15, 27, 55, 86
|
| 1502 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1503 | ## |
| 1504 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1505 | #SeeAlso offsetTo makeOffset SkIRect::offset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1506 | |
| 1507 | ## |
| 1508 | |
| 1509 | # ------------------------------------------------------------------------------ |
| 1510 | |
| 1511 | #Method void offsetTo(SkScalar newX, SkScalar newY) |
| 1512 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1513 | Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height |
| 1514 | are unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1515 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1516 | #Param newX stored in fLeft, preserving width() ## |
| 1517 | #Param newY stored in fTop, preserving height() ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1518 | |
| 1519 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1520 | 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
|
| 1524 | rect: 15, 27, 55, 86
|
| 1525 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1526 | ## |
| 1527 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1528 | #SeeAlso offset makeOffset setXYWH SkIRect::offsetTo |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1529 | |
| 1530 | ## |
| 1531 | |
| 1532 | # ------------------------------------------------------------------------------ |
| 1533 | |
| 1534 | #Method void inset(SkScalar dx, SkScalar dy) |
| 1535 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1536 | Insets Rect by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1537 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1538 | If dx is positive, makes Rect narrower. |
| 1539 | If dx is negative, makes Rect wider. |
| 1540 | If dy is positive, makes Rect shorter. |
| 1541 | If 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1545 | |
| 1546 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1547 | 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
|
| 1551 | rect: 15, 27, 45, 60
|
| 1552 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1553 | ## |
| 1554 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1555 | #SeeAlso outset makeInset SkIRect::inset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1556 | |
| 1557 | ## |
| 1558 | |
| 1559 | # ------------------------------------------------------------------------------ |
| 1560 | |
| 1561 | #Method void outset(SkScalar dx, SkScalar dy) |
| 1562 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1563 | Outsets Rect by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1564 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1565 | If dx is positive, makes Rect wider. |
| 1566 | If dx is negative, makes Rect narrower. |
| 1567 | If dy is positive, makes Rect taller. |
| 1568 | If 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1572 | |
| 1573 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1574 | 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
|
| 1578 | rect: 5, 1, 55, 86
|
| 1579 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1580 | ## |
| 1581 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1582 | #SeeAlso inset makeOutset SkIRect::outset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1583 | |
| 1584 | ## |
| 1585 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1586 | #Topic Intersection |
| 1587 | |
| 1588 | Rects intersect when they enclose a common area. To intersect, each of the pair |
| 1589 | must describe area; fLeft is less than fRight, and fTop is less than fBottom; |
| 1590 | empty() returns false. The intersection of Rect a and Rect b can be described by: |
| 1591 | #Formula |
| 1592 | (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), |
| 1593 | min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) |
| 1594 | ## |
| 1595 | The intersection is only meaningful if the resulting Rect is not empty and |
| 1596 | describes an area: fLeft is less than fRight, and fTop is less than fBottom. |
| 1597 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1598 | # ------------------------------------------------------------------------------ |
| 1599 | |
| 1600 | #Method bool intersect(const SkRect& r) |
| 1601 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1602 | Returns true if Rect intersects r, and sets Rect to intersection. |
| 1603 | Returns false if Rect does not intersect r, and leaves Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1604 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1605 | Returns false if either r or Rect is empty, leaving Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1606 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1607 | #Param r limit of result ## |
| 1608 | |
| 1609 | #Return true if r and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1610 | |
| 1611 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1612 | #Description |
| 1613 | Two SkDebugf calls are required. If the calls are combined, their arguments |
| 1614 | may not be evaluated in left to right order: the printed intersection may |
| 1615 | be before or after the call to intersect. |
| 1616 | ## |
| 1617 | SkRect leftRect = { 10, 40, 50, 80 };
|
| 1618 | SkRect rightRect = { 30, 60, 70, 90 };
|
| 1619 | SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
|
| 1620 | SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
|
| 1621 | leftRect.right(), leftRect.bottom()); |
| 1622 | #StdOut |
| 1623 | intersection: 30, 60, 50, 80 |
| 1624 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1625 | ## |
| 1626 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1627 | #SeeAlso intersects Intersects join SkIRect::intersect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1628 | |
| 1629 | ## |
| 1630 | |
| 1631 | # ------------------------------------------------------------------------------ |
| 1632 | |
| 1633 | #Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 1634 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1635 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1636 | construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1637 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1638 | Returns true if Rect intersects construction, and sets Rect to intersection. |
| 1639 | Returns false if Rect does not intersect construction, and leaves Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1640 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1641 | Returns false if either construction or Rect is empty, leaving Rect unchanged. |
| 1642 | |
| 1643 | #Param left x minimum of constructed Rect ## |
| 1644 | #Param top y minimum of constructed Rect ## |
| 1645 | #Param right x maximum of constructed Rect ## |
| 1646 | #Param bottom y maximum of constructed Rect ## |
| 1647 | |
| 1648 | #Return true if construction and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1649 | |
| 1650 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1651 | #Description |
| 1652 | Two SkDebugf calls are required. If the calls are combined, their arguments |
| 1653 | may not be evaluated in left to right order: the printed intersection may |
| 1654 | be before or after the call to intersect. |
| 1655 | ## |
| 1656 | SkRect leftRect = { 10, 40, 50, 80 };
|
| 1657 | SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
|
| 1658 | SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
|
| 1659 | leftRect.right(), leftRect.bottom()); |
| 1660 | #StdOut |
| 1661 | intersection: 30, 60, 50, 80 |
| 1662 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1663 | ## |
| 1664 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1665 | #SeeAlso intersects Intersects join SkIRect::intersect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1666 | |
| 1667 | ## |
| 1668 | |
| 1669 | # ------------------------------------------------------------------------------ |
| 1670 | |
| 1671 | #Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b) |
| 1672 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1673 | Returns true if a intersects b, and sets Rect to intersection. |
| 1674 | Returns false if a does not intersect b, and leaves Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1675 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1676 | Returns false if either a or b is empty, leaving Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1677 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1678 | #Param a Rect to intersect ## |
| 1679 | #Param b Rect to intersect ## |
| 1680 | |
| 1681 | #Return true if a and b have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1682 | |
| 1683 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1684 | SkRect result;
|
| 1685 | bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
|
| 1686 | SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
|
| 1687 | result.left(), result.top(), result.right(), result.bottom());
|
| 1688 | #StdOut |
| 1689 | intersection: 30, 60, 50, 80 |
| 1690 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1691 | ## |
| 1692 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1693 | #SeeAlso intersects Intersects join SkIRect::intersect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1694 | |
| 1695 | ## |
| 1696 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1697 | # ------------------------------------------------------------------------------ |
| 1698 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1699 | #Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const |
| 1700 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1701 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1702 | construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1703 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1704 | Returns true if Rect intersects construction. |
| 1705 | Returns false if either construction or Rect is empty, or do not intersect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1706 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1707 | #Param left x minimum of constructed Rect ## |
| 1708 | #Param top y minimum of constructed Rect ## |
| 1709 | #Param right x maximum of constructed Rect ## |
| 1710 | #Param bottom y maximum of constructed Rect ## |
| 1711 | |
| 1712 | #Return true if construction and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1713 | |
| 1714 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1715 | SkRect rect = { 10, 40, 50, 80 };
|
| 1716 | SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
|
| 1717 | #StdOut |
| 1718 | intersection |
| 1719 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1720 | ## |
| 1721 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1722 | #SeeAlso intersect Intersects SkIRect::Intersects |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1723 | |
| 1724 | ## |
| 1725 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1726 | # ------------------------------------------------------------------------------ |
| 1727 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1728 | #Method bool intersects(const SkRect& r) const |
| 1729 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1730 | Returns true if Rect intersects r. |
| 1731 | Returns false if either r or Rect is empty, or do not intersect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1732 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1733 | #Param r Rect to intersect ## |
| 1734 | |
| 1735 | #Return true if r and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1736 | |
| 1737 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1738 | SkRect rect = { 10, 40, 50, 80 };
|
| 1739 | SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
|
| 1740 | #StdOut |
| 1741 | intersection |
| 1742 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1743 | ## |
| 1744 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1745 | #SeeAlso intersect Intersects SkIRect::Intersects |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1746 | |
| 1747 | ## |
| 1748 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1749 | # ------------------------------------------------------------------------------ |
| 1750 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1751 | #Method static bool Intersects(const SkRect& a, const SkRect& b) |
| 1752 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1753 | Returns true if a intersects b. |
| 1754 | Returns false if either a or b is empty, or do not intersect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1755 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1756 | #Param a Rect to intersect ## |
| 1757 | #Param b Rect to intersect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1758 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1759 | #Return true if a and b have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1760 | |
| 1761 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1762 | SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
|
| 1763 | #StdOut |
| 1764 | intersection |
| 1765 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1766 | ## |
| 1767 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1768 | #SeeAlso intersect intersects SkIRect::Intersects |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1769 | |
| 1770 | ## |
| 1771 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1772 | #Topic Intersection ## |
| 1773 | |
| 1774 | |
| 1775 | # ------------------------------------------------------------------------------ |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1776 | |
| 1777 | #Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 1778 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1779 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1780 | construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1781 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1782 | Sets Rect to the union of itself and the construction. |
| 1783 | |
| 1784 | Has no effect if construction is empty. Otherwise, if Rect is empty, sets |
| 1785 | Rect to construction. |
| 1786 | |
| 1787 | #Param left x minimum of constructed Rect ## |
| 1788 | #Param top y minimum of constructed Rect ## |
| 1789 | #Param right x maximum of constructed Rect ## |
| 1790 | #Param bottom y maximum of constructed Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1791 | |
| 1792 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1793 | SkRect rect = { 10, 20, 15, 25};
|
| 1794 | rect.join(50, 60, 55, 65);
|
| 1795 | SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1796 | #StdOut |
| 1797 | join: 10, 20, 55, 65 |
| 1798 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1799 | ## |
| 1800 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1801 | #SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1802 | |
| 1803 | ## |
| 1804 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1805 | # ------------------------------------------------------------------------------ |
| 1806 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1807 | #Method void join(const SkRect& r) |
| 1808 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1809 | Sets Rect to the union of itself and r. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1810 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1811 | Has no effect if r is empty. Otherwise, if Rect is empty, sets |
| 1812 | Rect to r. |
| 1813 | |
| 1814 | #Param r expansion Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1815 | |
| 1816 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1817 | SkRect rect = { 10, 20, 15, 25};
|
| 1818 | rect.join({50, 60, 55, 65});
|
| 1819 | SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1820 | #StdOut |
| 1821 | join: 10, 20, 55, 65 |
| 1822 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1823 | ## |
| 1824 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1825 | #SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1826 | |
| 1827 | ## |
| 1828 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1829 | # ------------------------------------------------------------------------------ |
| 1830 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1831 | #Method void joinNonEmptyArg(const SkRect& r) |
| 1832 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1833 | Sets Rect to the union of itself and r. |
| 1834 | |
| 1835 | Asserts if r is empty and SK_DEBUG is defined. |
| 1836 | If Rect is empty, sets Rect to r. |
| 1837 | |
| 1838 | May produce incorrect results if r is empty. |
| 1839 | |
| 1840 | #Param r expansion Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1841 | |
| 1842 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1843 | #Description |
| 1844 | Since Rect is not sorted, first result is copy of toJoin. |
| 1845 | ## |
| 1846 | SkRect rect = { 10, 100, 15, 0};
|
| 1847 | SkRect sorted = rect.makeSorted();
|
| 1848 | SkRect toJoin = { 50, 60, 55, 65 };
|
| 1849 | rect.joinNonEmptyArg(toJoin);
|
| 1850 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1851 | sorted.joinNonEmptyArg(toJoin);
|
| 1852 | SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom); |
| 1853 | #StdOut |
| 1854 | rect: 50, 60, 55, 65
|
| 1855 | sorted: 10, 0, 55, 100 |
| 1856 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1857 | ## |
| 1858 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1859 | #SeeAlso join joinPossiblyEmptyRect SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1860 | |
| 1861 | ## |
| 1862 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1863 | # ------------------------------------------------------------------------------ |
| 1864 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1865 | #Method void joinPossiblyEmptyRect(const SkRect& r) |
| 1866 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1867 | Sets Rect to the union of itself and the construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1868 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1869 | May produce incorrect results if Rect or r is empty. |
| 1870 | |
| 1871 | #Param r expansion Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1872 | |
| 1873 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1874 | #Description |
| 1875 | Since Rect is not sorted, first result is not useful. |
| 1876 | ## |
| 1877 | SkRect rect = { 10, 100, 15, 0};
|
| 1878 | SkRect sorted = rect.makeSorted();
|
| 1879 | SkRect toJoin = { 50, 60, 55, 65 };
|
| 1880 | rect.joinPossiblyEmptyRect(toJoin);
|
| 1881 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1882 | sorted.joinPossiblyEmptyRect(toJoin);
|
| 1883 | SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
|
| 1884 | #StdOut |
| 1885 | rect: 10, 60, 55, 65
|
| 1886 | sorted: 10, 0, 55, 100 |
| 1887 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1888 | ## |
| 1889 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1890 | #SeeAlso joinNonEmptyArg join SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1891 | |
| 1892 | ## |
| 1893 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1894 | # ------------------------------------------------------------------------------ |
| 1895 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1896 | #Method void growToInclude(SkPoint pt) |
| 1897 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1898 | Grows Rect to include (pt.fX, pt.fY), modifying it so that: |
| 1899 | #Formula |
| 1900 | fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom |
| 1901 | ## |
| 1902 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1903 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1904 | If Rect is initialized with setLargestInverted, then Rect will contain bounds of |
| 1905 | Points after one or more calls. In this case, Rect is empty after first call. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1906 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1907 | #Param pt Point to include ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1908 | |
| 1909 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1910 | SkRect rect;
|
| 1911 | rect.setLargestInverted();
|
| 1912 | rect.growToInclude( { 42, 24 } );
|
| 1913 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1914 | SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 1915 | #StdOut |
| 1916 | rect: 42, 24, 42, 24 isEmpty: true |
| 1917 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1918 | ## |
| 1919 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1920 | #SeeAlso setLargestInverted join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1921 | |
| 1922 | ## |
| 1923 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1924 | # ------------------------------------------------------------------------------ |
| 1925 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1926 | #Method void growToInclude(const SkPoint pts[], int count) |
| 1927 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1928 | For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying |
| 1929 | it so that: |
| 1930 | #Formula |
| 1931 | fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom |
| 1932 | ## |
| 1933 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1934 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1935 | If Rect is initialized with setLargestInverted, then Rect will contain bounds of |
| 1936 | Points after one or more calls. In this case, Rect is empty after first call. |
| 1937 | |
| 1938 | #Param pts Point array ## |
| 1939 | #Param count number of points in array ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1940 | |
| 1941 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1942 | SkPoint pts[] = { { 30, 50 }, { 40, 50 }, { 30, 60 } };
|
| 1943 | SkRect rect = { pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY };
|
| 1944 | rect.growToInclude( pts[1] );
|
| 1945 | rect.growToInclude( pts[2] );
|
| 1946 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1947 | #StdOut |
| 1948 | rect: 30, 50, 40, 60 |
| 1949 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1950 | ## |
| 1951 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1952 | #SeeAlso setLargestInverted join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1953 | |
| 1954 | ## |
| 1955 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1956 | # ------------------------------------------------------------------------------ |
| 1957 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1958 | #Method void growToInclude(const SkPoint pts[], size_t stride, int count) |
| 1959 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1960 | For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying |
| 1961 | it so that: |
| 1962 | #Formula |
| 1963 | fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom |
| 1964 | ## |
| 1965 | . Point may be followed with other data in each array element. stride is number |
| 1966 | of bytes in element; the interval to skip to advance from one Point to |
| 1967 | the next. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1968 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1969 | If Rect is initialized with setLargestInverted, then Rect will contain bounds of |
| 1970 | Points after one or more calls. In this case, Rect is empty after first call. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1971 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1972 | #Param pts array of elements beginning with Point ## |
| 1973 | #Param stride size of pts elements in 32-bit words; zero or greater ## |
| 1974 | #Param count number of elements in array ## |
| 1975 | |
| 1976 | #Bug 7142 ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1977 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1978 | SkPoint3 pts[] = { { 30, 50, -1 }, { 40, 50, -1 }, { 30, 60, -1 } };
|
| 1979 | SkRect rect;
|
| 1980 | rect.setLargestInverted();
|
| 1981 | rect.growToInclude((SkPoint* ) &pts[0].fX, sizeof(SkPoint3), SK_ARRAY_COUNT(pts));
|
| 1982 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1983 | #StdOut |
| 1984 | #Volatile |
| 1985 | rect: 30, 50, 40, 60 |
| 1986 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1987 | ## |
| 1988 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1989 | #SeeAlso setLargestInverted join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1990 | |
| 1991 | ## |
| 1992 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1993 | # ------------------------------------------------------------------------------ |
| 1994 | |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame^] | 1995 | #Method bool contains(const SkRect& r) const |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1996 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 1997 | Returns true if Rect contains r. |
| 1998 | Returns false if Rect is empty or r is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1999 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2000 | Rect contains r when Rect area completely includes r area. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2001 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2002 | #Param r Rect contained ## |
| 2003 | |
| 2004 | #Return true if all sides of Rect are outside r ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2005 | |
| 2006 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2007 | SkRect rect = { 30, 50, 40, 60 };
|
| 2008 | SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
|
| 2009 | for (auto contained : tests) {
|
| 2010 | SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
|
| 2011 | rect.left(), rect.top(), rect.right(), rect.bottom(),
|
| 2012 | rect.contains(contained) ? "contains" : "does not contain",
|
| 2013 | contained.left(), contained.top(), contained.right(), contained.bottom());
|
| 2014 | }
|
| 2015 | #StdOut
|
| 2016 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
|
| 2017 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
|
| 2018 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
|
| 2019 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2020 | ## |
| 2021 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2022 | #SeeAlso SkIRect::contains |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2023 | |
| 2024 | ## |
| 2025 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2026 | # ------------------------------------------------------------------------------ |
| 2027 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2028 | #Method bool contains(const SkIRect& r) const |
| 2029 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2030 | Returns true if Rect contains r. |
| 2031 | Returns false if Rect is empty or r is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2032 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2033 | Rect contains r when Rect area completely includes r area. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2034 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2035 | #Param r IRect contained ## |
| 2036 | |
| 2037 | #Return true if all sides of Rect are outside r ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2038 | |
| 2039 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2040 | SkRect rect = { 30, 50, 40, 60 };
|
| 2041 | SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
|
| 2042 | for (auto contained : tests) {
|
| 2043 | SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
|
| 2044 | rect.left(), rect.top(), rect.right(), rect.bottom(),
|
| 2045 | rect.contains(contained) ? "contains" : "does not contain",
|
| 2046 | contained.left(), contained.top(), contained.right(), contained.bottom());
|
| 2047 | }
|
| 2048 | #StdOut
|
| 2049 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
|
| 2050 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
|
| 2051 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
|
| 2052 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2053 | ## |
| 2054 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2055 | #SeeAlso SkIRect::contains |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2056 | |
| 2057 | ## |
| 2058 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2059 | #Topic Round |
| 2060 | |
| 2061 | # ------------------------------------------------------------------------------ |
| 2062 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2063 | #Method void round(SkIRect* dst) const |
| 2064 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2065 | Sets IRect by adding 0.5 and discarding the fractional portion of Rect |
| 2066 | members, using |
| 2067 | #Formula |
| 2068 | (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), |
| 2069 | SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) |
| 2070 | ## |
| 2071 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2072 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2073 | #Param dst storage for IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2074 | |
| 2075 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2076 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2077 | SkIRect round;
|
| 2078 | rect.round(&round);
|
| 2079 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2080 | #StdOut |
| 2081 | round: 31, 51, 41, 61 |
| 2082 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2083 | ## |
| 2084 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2085 | #SeeAlso roundIn roundOut SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2086 | |
| 2087 | ## |
| 2088 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2089 | # ------------------------------------------------------------------------------ |
| 2090 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2091 | #Method void roundOut(SkIRect* dst) const |
| 2092 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2093 | Sets IRect by discarding the fractional portion of fLeft and fTop; and |
| 2094 | rounding up fRight and FBottom, using |
| 2095 | #Formula |
| 2096 | (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
| 2097 | SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) |
| 2098 | ## |
| 2099 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2100 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2101 | #Param dst storage for IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2102 | |
| 2103 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2104 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2105 | SkIRect round;
|
| 2106 | rect.roundOut(&round);
|
| 2107 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2108 | #StdOut |
| 2109 | round: 30, 50, 41, 61 |
| 2110 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2111 | ## |
| 2112 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2113 | #SeeAlso roundIn round SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2114 | |
| 2115 | ## |
| 2116 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2117 | # ------------------------------------------------------------------------------ |
| 2118 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2119 | #Method void roundOut(SkRect* dst) const |
| 2120 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2121 | Sets Rect by discarding the fractional portion of fLeft and fTop; and |
| 2122 | rounding up fRight and FBottom, using |
| 2123 | #Formula |
| 2124 | (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
| 2125 | SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) |
| 2126 | ## |
| 2127 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2128 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2129 | #Param dst storage for Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2130 | |
| 2131 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2132 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2133 | SkRect round;
|
| 2134 | rect.roundOut(&round);
|
| 2135 | SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2136 | #StdOut |
| 2137 | round: 30, 50, 41, 61 |
| 2138 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2139 | ## |
| 2140 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2141 | #SeeAlso roundIn round SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2142 | |
| 2143 | ## |
| 2144 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2145 | # ------------------------------------------------------------------------------ |
| 2146 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2147 | #Method void roundIn(SkIRect* dst) const |
| 2148 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2149 | Sets Rect by rounding up fLeft and fTop; and |
| 2150 | discarding the fractional portion of fRight and FBottom, using |
| 2151 | #Formula |
| 2152 | (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), |
| 2153 | SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) |
| 2154 | ## |
| 2155 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2156 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2157 | #Param dst storage for IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2158 | |
| 2159 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2160 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2161 | SkIRect round;
|
| 2162 | rect.roundIn(&round);
|
| 2163 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2164 | #StdOut |
| 2165 | round: 31, 51, 40, 60
|
| 2166 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2167 | ## |
| 2168 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2169 | #SeeAlso roundOut round SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2170 | |
| 2171 | ## |
| 2172 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2173 | # ------------------------------------------------------------------------------ |
| 2174 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2175 | #Method SkIRect round() const |
| 2176 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2177 | Returns IRect by adding 0.5 and discarding the fractional portion of Rect |
| 2178 | members, using |
| 2179 | #Formula |
| 2180 | (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), |
| 2181 | SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) |
| 2182 | ## |
| 2183 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2184 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2185 | #Return rounded IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2186 | |
| 2187 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2188 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2189 | SkIRect round = rect.round();
|
| 2190 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2191 | #StdOut |
| 2192 | round: 31, 51, 41, 61
|
| 2193 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2194 | ## |
| 2195 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2196 | #SeeAlso roundOut roundIn SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2197 | |
| 2198 | ## |
| 2199 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2200 | # ------------------------------------------------------------------------------ |
| 2201 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2202 | #Method SkIRect roundOut() const |
| 2203 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2204 | Sets IRect by discarding the fractional portion of fLeft and fTop; and |
| 2205 | rounding up fRight and FBottom, using |
| 2206 | #Formula |
| 2207 | (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
| 2208 | SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) |
| 2209 | ## |
| 2210 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2211 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2212 | #Return rounded IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2213 | |
| 2214 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2215 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2216 | SkIRect round = rect.roundOut();
|
| 2217 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2218 | #StdOut |
| 2219 | round: 30, 50, 41, 61
|
| 2220 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2221 | ## |
| 2222 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2223 | #SeeAlso round roundIn SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2224 | |
| 2225 | ## |
| 2226 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2227 | #Topic Round ## |
| 2228 | |
| 2229 | # ------------------------------------------------------------------------------ |
| 2230 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2231 | #Method void sort() |
| 2232 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2233 | Swaps fLeft and fRight if fLeft is greater than fRight; and swaps |
| 2234 | fTop and fBottom if fTop is greater than fBottom. Result may be empty; |
| 2235 | and width() and height() will be zero or positive. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2236 | |
| 2237 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2238 | SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
|
| 2239 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 2240 | rect.sort();
|
| 2241 | SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 2242 | #StdOut |
| 2243 | rect: 30.5, 50.5, 20.5, 10.5
|
| 2244 | sorted: 20.5, 10.5, 30.5, 50.5 |
| 2245 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2246 | ## |
| 2247 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2248 | #SeeAlso makeSorted SkIRect::sort |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2249 | |
| 2250 | ## |
| 2251 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2252 | # ------------------------------------------------------------------------------ |
| 2253 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2254 | #Method SkRect makeSorted() const |
| 2255 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2256 | Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and |
| 2257 | with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty; |
| 2258 | and width() and height() will be zero or positive. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2259 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2260 | #Return sorted Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2261 | |
| 2262 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2263 | SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
|
| 2264 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 2265 | SkRect sort = rect.makeSorted();
|
| 2266 | SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
|
| 2267 | #StdOut |
| 2268 | rect: 30.5, 50.5, 20.5, 10.5
|
| 2269 | sorted: 20.5, 10.5, 30.5, 50.5 |
| 2270 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2271 | ## |
| 2272 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2273 | #SeeAlso sort SkIRect::makeSorted |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2274 | |
| 2275 | ## |
| 2276 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2277 | # ------------------------------------------------------------------------------ |
| 2278 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2279 | #Method const SkScalar* asScalars() const |
| 2280 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2281 | Returns pointer to first Scalar in Rect, to treat it as an array with four |
| 2282 | entries. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2283 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2284 | #Return pointer to fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2285 | |
| 2286 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2287 | SkRect rect = {7, 11, 13, 17};
|
| 2288 | SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
|
| 2289 | #StdOut
|
| 2290 | rect.asScalars() == &rect.fLeft
|
| 2291 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2292 | ## |
| 2293 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2294 | #SeeAlso toQuad |
| 2295 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2296 | ## |
| 2297 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2298 | # ------------------------------------------------------------------------------ |
| 2299 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2300 | #Method void dump(bool asHex) const |
| 2301 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2302 | Writes text representation of Rect to standard output. Set asHex to true to |
| 2303 | generate exact binary representations of floating point numbers. |
| 2304 | |
| 2305 | #Param asHex true if SkScalar values are written as hexadecimal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2306 | |
| 2307 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2308 | SkRect rect = {20, 30, 40, 50}; |
| 2309 | for (bool dumpAsHex : { false, true } ) { |
| 2310 | rect.dump(dumpAsHex); |
| 2311 | SkDebugf("\n"); |
| 2312 | } |
| 2313 | #StdOut |
| 2314 | SkRect::MakeLTRB(20, 30, 40, 50);
|
| 2315 |
|
| 2316 | SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
|
| 2317 | SkBits2Float(0x41f00000), /* 30.000000 */
|
| 2318 | SkBits2Float(0x42200000), /* 40.000000 */
|
| 2319 | SkBits2Float(0x42480000) /* 50.000000 */);
|
| 2320 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2321 | ## |
| 2322 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2323 | #SeeAlso dumpHex |
| 2324 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2325 | ## |
| 2326 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2327 | # ------------------------------------------------------------------------------ |
| 2328 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2329 | #Method void dump() const |
| 2330 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2331 | Writes text representation of Rect to standard output. The representation may be |
| 2332 | directly compiled as C++ code. Floating point values are written |
| 2333 | with limited precision; it may not be possible to reconstruct original Rect |
| 2334 | from output. |
| 2335 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2336 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2337 | SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
|
| 2338 | rect.dump();
|
| 2339 | SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
|
| 2340 | SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
|
| 2341 | #StdOut |
| 2342 | SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
|
| 2343 | rect is not equal to copy |
| 2344 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2345 | ## |
| 2346 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2347 | #SeeAlso dumpHex |
| 2348 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2349 | ## |
| 2350 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2351 | # ------------------------------------------------------------------------------ |
| 2352 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2353 | #Method void dumpHex() const |
| 2354 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2355 | Writes text representation of Rect to standard output. The representation may be |
| 2356 | directly compiled as C++ code. Floating point values are written |
| 2357 | in hexadecimal to preserve their exact bit pattern. The output reconstructs the |
| 2358 | original Rect. |
| 2359 | |
| 2360 | Use instead of dump() when submitting |
| 2361 | #A bug reports against Skia # http://bug.skia.org ## |
| 2362 | . |
| 2363 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2364 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2365 | SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
|
| 2366 | rect.dumpHex();
|
| 2367 | SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
|
| 2368 | SkBits2Float(0x3f2aaaab), /* 0.666667 */
|
| 2369 | SkBits2Float(0x40266666), /* 2.600000 */
|
| 2370 | SkBits2Float(0x40e00000) /* 7.000000 */);
|
| 2371 | SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not "); |
| 2372 | #StdOut |
| 2373 | SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
|
| 2374 | SkBits2Float(0x3f2aaaab), /* 0.666667 */
|
| 2375 | SkBits2Float(0x40266666), /* 2.600000 */
|
| 2376 | SkBits2Float(0x40e00000) /* 7.000000 */);
|
| 2377 | rect is equal to copy |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2378 | ## |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame] | 2379 | ## |
| 2380 | |
| 2381 | #SeeAlso dump |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2382 | |
| 2383 | ## |
| 2384 | |
| 2385 | #Struct SkRect ## |
| 2386 | |
| 2387 | #Topic Rect ## |